diff --git a/build.gradle b/build.gradle index 0b556ce2f3..6caeddac9f 100644 --- a/build.gradle +++ b/build.gradle @@ -82,7 +82,7 @@ allprojects { apply plugin: 'idea' group = 'org.microg.gms' - ext.appVersionCode = 234355000 + ext.appVersionCode = 234414000 ext.baseVersion = ext.appVersionCode.toString()[0..1] + '.' + ext.appVersionCode.toString()[2..3] + '.' + ext.appVersionCode.toString()[4..5] version = "0.3.0."+ext.baseVersion.replaceAll("\\.", "") ext.isReleaseVersion = false @@ -92,6 +92,5 @@ subprojects { repositories { mavenCentral() google() - if (hasModule("hms", false)) maven {url 'https://developer.huawei.com/repo/'} } } diff --git a/play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsContract.kt b/play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsContract.kt index c0df792e45..033d65aa12 100644 --- a/play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsContract.kt +++ b/play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsContract.kt @@ -27,6 +27,7 @@ object SettingsContract { const val SECURITY_TOKEN = "securityToken" const val VERSION_INFO = "versionInfo" const val DEVICE_DATA_VERSION_INFO = "deviceDataVersionInfo" + const val BRAND_SPOOF = "brandSpoof" val PROJECTION = arrayOf( ENABLED, @@ -36,6 +37,7 @@ object SettingsContract { SECURITY_TOKEN, VERSION_INFO, DEVICE_DATA_VERSION_INFO, + BRAND_SPOOF ) const val PREFERENCES_NAME = "checkin" const val INITIAL_DIGEST = "1-929a0dca0eee55513280171a8585da7dcd3700f8" diff --git a/play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsProvider.kt b/play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsProvider.kt index 3f907ed9de..7899cba149 100644 --- a/play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsProvider.kt +++ b/play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsProvider.kt @@ -101,6 +101,7 @@ class SettingsProvider : ContentProvider() { CheckIn.SECURITY_TOKEN -> checkInPrefs.getLong(key, 0) CheckIn.VERSION_INFO -> checkInPrefs.getString(key, "") ?: "" CheckIn.DEVICE_DATA_VERSION_INFO -> checkInPrefs.getString(key, "") ?: "" + CheckIn.BRAND_SPOOF -> getSettingsBoolean(key, false) else -> throw IllegalArgumentException() } } @@ -118,6 +119,10 @@ class SettingsProvider : ContentProvider() { // special case: not saved in checkInPrefs updateCheckInEnabled(value as Boolean) } + if (key == CheckIn.BRAND_SPOOF) { + // special case: not saved in checkInPrefs + updateSpoofingEnabled(value as Boolean) + } when (key) { CheckIn.ANDROID_ID -> editor.putLong(key, value as Long) CheckIn.DIGEST -> editor.putString(key, value as String?) @@ -136,6 +141,12 @@ class SettingsProvider : ContentProvider() { .apply() } + private fun updateSpoofingEnabled(enabled: Boolean) { + preferences.edit() + .putBoolean(CheckIn.BRAND_SPOOF, enabled) + .apply() + } + private fun queryGcm(p: Array): Cursor = MatrixCursor(p).addRow(p) { key -> when (key) { Gcm.ENABLE_GCM -> getSettingsBoolean(key, false) diff --git a/play-services-core/src/main/java/org/microg/gms/auth/login/AssistantActivity.java b/play-services-core/src/main/java/org/microg/gms/auth/login/AssistantActivity.java index afe4366ef3..6c3b876e03 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/login/AssistantActivity.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/login/AssistantActivity.java @@ -40,18 +40,8 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login_assistant); formatTitle(); - findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onNextButtonClicked(); - } - }); - findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onBackButtonClicked(); - } - }); + findViewById(R.id.spoof_button).setOnClickListener(v -> onHuaweiButtonClicked()); + findViewById(R.id.next_button).setOnClickListener(v -> onNextButtonClicked()); } @SuppressLint("WrongViewCast") @@ -65,37 +55,37 @@ private void formatTitle() { } } - public void setNextButtonText(@StringRes int res) { - setNextButtonText(getText(res)); + public void setSpoofButtonText(@StringRes int res) { + setSpoofButtonText(getText(res)); } - public void setNextButtonText(CharSequence text) { + public void setSpoofButtonText(CharSequence text) { if (text == null) { - findViewById(R.id.next_button).setVisibility(View.GONE); + findViewById(R.id.spoof_button).setVisibility(View.GONE); } else { - findViewById(R.id.next_button).setVisibility(View.VISIBLE); - ((Button) findViewById(R.id.next_button)).setText(text); + findViewById(R.id.spoof_button).setVisibility(View.VISIBLE); + ((Button) findViewById(R.id.spoof_button)).setText(text); } } - public void setBackButtonText(@StringRes int res) { - setBackButtonText(getText(res)); + public void setNextButtonText(@StringRes int res) { + setNextButtonText(getText(res)); } - public void setBackButtonText(CharSequence text) { + public void setNextButtonText(CharSequence text) { if (text == null) { - findViewById(R.id.back_button).setVisibility(View.GONE); + findViewById(R.id.next_button).setVisibility(View.GONE); } else { - findViewById(R.id.back_button).setVisibility(View.VISIBLE); - ((Button) findViewById(R.id.back_button)).setText(text); + findViewById(R.id.next_button).setVisibility(View.VISIBLE); + ((Button) findViewById(R.id.next_button)).setText(text); } } - protected void onNextButtonClicked() { + protected void onHuaweiButtonClicked() { } - protected void onBackButtonClicked() { + protected void onNextButtonClicked() { } diff --git a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java index 9dad4bb4f1..bfd9bc749b 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java @@ -75,6 +75,8 @@ import static android.view.View.VISIBLE; import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT; import static org.microg.gms.auth.AuthPrefs.isAuthVisible; +import static org.microg.gms.checkin.CheckinPreferences.isSpoofingEnabled; +import static org.microg.gms.checkin.CheckinPreferences.setSpoofingEnabled; import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME; import static org.microg.gms.common.Constants.GMS_VERSION_CODE; import static org.microg.gms.common.Constants.GOOGLE_GMS_PACKAGE_NAME; @@ -151,7 +153,7 @@ public void onPageFinished(WebView view, String url) { init(); } else { setMessage(R.string.auth_before_connect); - setBackButtonText(android.R.string.cancel); + setSpoofButtonText(R.string.brand_spoof_button); setNextButtonText(R.string.auth_sign_in); } } @@ -161,6 +163,10 @@ protected void onNextButtonClicked() { super.onNextButtonClicked(); state++; if (state == 1) { + if (isSpoofingEnabled(this)) { + LastCheckinInfo.clear(this); + setSpoofingEnabled(this, false); + } init(); } else if (state == -1) { setResult(RESULT_CANCELED); @@ -168,18 +174,26 @@ protected void onNextButtonClicked() { } } + @Override - protected void onBackButtonClicked() { - super.onBackButtonClicked(); - state--; - if (state == -1) { + protected void onHuaweiButtonClicked() { + super.onHuaweiButtonClicked(); + state++; + if (state == 1) { + if (!isSpoofingEnabled(this)) { + LastCheckinInfo.clear(this); + setSpoofingEnabled(this, true); + } + init(); + } else if (state == -1) { + setResult(RESULT_CANCELED); finish(); } } private void init() { setTitle(R.string.just_a_sec); - setBackButtonText(null); + setSpoofButtonText(null); setNextButtonText(null); View loading = getLayoutInflater().inflate(R.layout.login_assistant_loading, authContent, false); authContent.removeAllViews(); diff --git a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java index e1ed11edf5..70a49fe400 100644 --- a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java +++ b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinManager.java @@ -16,6 +16,8 @@ package org.microg.gms.checkin; +import static org.microg.gms.checkin.CheckinPreferences.isSpoofingEnabled; + import android.accounts.Account; import android.accounts.AccountManager; import android.os.Build; @@ -58,22 +60,10 @@ public static synchronized LastCheckinInfo checkin(Context context, boolean forc } CheckinRequest request = CheckinClient.makeRequest(context, new DeviceConfiguration(context), Utils.getDeviceIdentifier(context), - Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts, isHuaweiDevice()); + Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts, isSpoofingEnabled(context)); return handleResponse(context, CheckinClient.request(request)); } - private static boolean isHuaweiDevice() { - String brand = Build.BRAND.toLowerCase().replace(" ", ""); - String manufacturer = Build.MANUFACTURER.toLowerCase().replace(" ", ""); - - boolean isEmui = Build.DISPLAY.toLowerCase().startsWith("emui"); - boolean isHuawei = manufacturer.contains("huawei") || brand.contains("huawei") || brand.contains("华为"); - boolean isHonor = manufacturer.contains("honor") || brand.contains("honor"); - boolean isNova = manufacturer.contains("nova") || brand.contains("nova"); - - return (isEmui || isHuawei || isHonor || isNova); - } - private static LastCheckinInfo handleResponse(Context context, CheckinResponse response) { LastCheckinInfo info = new LastCheckinInfo(response); info.write(context); diff --git a/play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPreferences.kt b/play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPreferences.kt index 0323466548..aee6447f07 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPreferences.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/checkin/CheckinPreferences.kt @@ -8,6 +8,7 @@ import android.content.Context import android.content.Intent import org.microg.gms.settings.SettingsContract import org.microg.gms.settings.SettingsContract.CheckIn +import org.microg.gms.settings.SettingsContract.setSettings object CheckinPreferences { @@ -29,4 +30,22 @@ object CheckinPreferences { } } + @JvmStatic + fun isSpoofingEnabled(context: Context): Boolean? { + val projection = arrayOf(CheckIn.BRAND_SPOOF) + return CheckIn.getContentUri(context)?.let { + SettingsContract.getSettings(context, it, projection) { c -> + c.getInt(0) != 0 + } + } + } + + @JvmStatic + fun setSpoofingEnabled(context: Context, enabled: Boolean) { + CheckIn.getContentUri(context)?.let { + setSettings(context, it) { + put(CheckIn.BRAND_SPOOF, enabled) + } + } + } } diff --git a/play-services-core/src/main/res/layout/ask_gcm.xml b/play-services-core/src/main/res/layout/ask_gcm.xml index 49a9475356..c21204df00 100644 --- a/play-services-core/src/main/res/layout/ask_gcm.xml +++ b/play-services-core/src/main/res/layout/ask_gcm.xml @@ -65,7 +65,7 @@ android:divider="?attr/dividerHorizontal" android:orientation="vertical"> - - + - - + diff --git a/play-services-core/src/main/res/layout/login_assistant.xml b/play-services-core/src/main/res/layout/login_assistant.xml index c24de1a3c4..2189bff67c 100644 --- a/play-services-core/src/main/res/layout/login_assistant.xml +++ b/play-services-core/src/main/res/layout/login_assistant.xml @@ -14,7 +14,7 @@ ~ limitations under the License. --> -