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 9791f4f06b..9b894f3a12 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 @@ -34,6 +34,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, @@ -43,6 +44,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 dfb027d915..656c01c1e0 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 @@ -116,6 +116,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() } } @@ -133,6 +134,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?) @@ -151,6 +156,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 cff37f1361..90f44e8677 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.*; public class LoginActivity extends AssistantActivity { @@ -159,7 +161,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); } } @@ -169,6 +171,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); @@ -176,11 +182,19 @@ 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(); } } @@ -195,7 +209,7 @@ public void onBackPressed() { 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/CheckinClient.java b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinClient.java index 2374d25d6e..4e01ad98cc 100644 --- a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinClient.java +++ b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinClient.java @@ -81,26 +81,26 @@ public static CheckinResponse request(CheckinRequest request) throws IOException public static CheckinRequest makeRequest(Context context, DeviceConfiguration deviceConfiguration, DeviceIdentifier deviceIdent, PhoneInfo phoneInfo, LastCheckinInfo checkinInfo, Locale locale, - List accounts) { + List accounts, Boolean brandSpoof) { ProfileManager.ensureInitialized(context); CheckinRequest.Builder builder = new CheckinRequest.Builder() .accountCookie(new ArrayList<>()) .androidId(checkinInfo.getAndroidId()) .checkin(new CheckinRequest.Checkin.Builder() .build(new CheckinRequest.Checkin.Build.Builder() - .bootloader(Build.BOOTLOADER) - .brand(Build.BRAND) + .bootloader(brandSpoof ? "c2f2-0.2-5799621" : Build.BOOTLOADER) + .brand(brandSpoof ? "google" : Build.BRAND) .clientId("android-google") - .device(Build.DEVICE) - .fingerprint(Build.FINGERPRINT) - .hardware(Build.HARDWARE) - .manufacturer(Build.MANUFACTURER) - .model(Build.MODEL) + .device(brandSpoof ? "generic" : Build.DEVICE) + .fingerprint(brandSpoof ? "google/coral/coral:10/QD1A.190821.007/5831595:user/release-keys" : Build.FINGERPRINT) + .hardware(brandSpoof ? "coral" : Build.HARDWARE) + .manufacturer(brandSpoof ? "Google" : Build.MANUFACTURER) + .model(brandSpoof ? "mainline" : Build.MODEL) .otaInstalled(false) // TODO? //.packageVersionCode(Constants.MAX_REFERENCE_VERSION) - .product(Build.PRODUCT) - .radio(Build.RADIO) - .sdkVersion(Build.VERSION.SDK_INT) + .product(brandSpoof ? "coral" : Build.PRODUCT) + .radio(brandSpoof ? "" : Build.RADIO) + .sdkVersion(brandSpoof ? 29 : Build.VERSION.SDK_INT) .time(Build.TIME / 1000) .build()) .cellOperator(phoneInfo.cellOperator) 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 1604ed2565..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,8 +16,11 @@ 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; import android.content.ContentResolver; import android.content.Context; @@ -57,7 +60,7 @@ 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); + Utils.getPhoneInfo(context), info, Utils.getLocale(context), accounts, isSpoofingEnabled(context)); return handleResponse(context, CheckinClient.request(request)); } 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/login_assistant.xml b/play-services-core/src/main/res/layout/login_assistant.xml index d59a1b1a57..f41b3736de 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. --> -