Skip to content

Commit

Permalink
Add Huawei button
Browse files Browse the repository at this point in the history
  • Loading branch information
YT-Advanced committed Mar 27, 2024
1 parent 5439ac6 commit bf9c585
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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?)
Expand All @@ -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<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
when (key) {
Gcm.ENABLE_GCM -> getSettingsBoolean(key, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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() {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -169,18 +171,30 @@ 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);
finish();
}
}


@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();
}
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Account> accounts) {
List<Account> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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)
}
}
}
}
18 changes: 8 additions & 10 deletions play-services-core/src/main/res/layout/login_assistant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
~ limitations under the License.
-->

<RelativeLayout
<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/auth_root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
Expand Down Expand Up @@ -66,13 +66,12 @@
android:background="#e4e7e9">

<Button
android:id="@+id/back_button"
style="?attr/buttonBarNegativeButtonStyle"
android:id="@+id/spoof_button"
style="?attr/buttonBarPositiveButtonStyle"
android:layout_width="wrap_content"
android:layout_height="48dip"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="0dp"
android:paddingLeft="38dp"
android:paddingRight="38dp"
android:textAllCaps="true"
Expand All @@ -83,15 +82,14 @@
android:id="@+id/next_button"
style="?attr/buttonBarPositiveButtonStyle"
android:layout_width="wrap_content"
android:layout_height="48dip"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="0dp"
android:paddingLeft="38dp"
android:paddingRight="38dp"
android:textAllCaps="true"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="16sp"/>
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ This can take a couple of minutes."</string>
<string name="pref_auth_trust_google_summary">When disabled, the user is asked before an app\'s authorization request is sent to Google. Some applications will fail to use the Google account if this is disabled.</string>
<string name="pref_auth_visible_title">Allow apps to find accounts</string>
<string name="pref_auth_visible_summary">When enabled, all applications on this device will be able to see email address of your Google Accounts without prior authorization.</string>
<string name="brand_spoof_button">Huawei</string>
<string name="pref_auth_include_android_id_title">Authenticate with device registration</string>
<string name="pref_auth_include_android_id_summary">When disabled, authentication requests won\'t be linked to the device registration, which may allow unauthorized devices to sign in, but may have unforeseen consequences.</string>
<string name="pref_auth_strip_device_name_title">Strip device name for authentication</string>
Expand Down

0 comments on commit bf9c585

Please sign in to comment.