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 Nov 29, 2023
1 parent 44e37bb commit 2bd4dcf
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 61 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -92,6 +92,5 @@ subprojects {
repositories {
mavenCentral()
google()
if (hasModule("hms", false)) maven {url 'https://developer.huawei.com/repo/'}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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?)
Expand All @@ -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<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.GMS_PACKAGE_NAME;
import static org.microg.gms.common.Constants.GMS_VERSION_CODE;
import static org.microg.gms.common.Constants.GOOGLE_GMS_PACKAGE_NAME;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -161,25 +163,37 @@ 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();
}
}

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 @@ -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;
Expand Down Expand Up @@ -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);
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)
}
}
}
}
8 changes: 4 additions & 4 deletions play-services-core/src/main/res/layout/ask_gcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,25 @@
android:divider="?attr/dividerHorizontal"
android:orientation="vertical">

<com.google.android.material.button.MaterialButton
<Button
style="?android:attr/buttonBarButtonStyle"
android:id="@+id/permission_allow_button"
android:layout_width="match_parent"
android:layout_height="56dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/allow">
</com.google.android.material.button.MaterialButton>
</Button>

<com.google.android.material.button.MaterialButton
<Button
style="?android:attr/buttonBarButtonStyle"
android:id="@+id/permission_deny_button"
android:layout_width="match_parent"
android:layout_height="56dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/deny">
</com.google.android.material.button.MaterialButton>
</Button>

</LinearLayout>

Expand Down
18 changes: 8 additions & 10 deletions play-services-core/src/main/res/layout/#_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 @@ -65,13 +65,12 @@
android:layout_height="54dip">

<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 @@ -82,15 +81,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 @@ -123,6 +123,7 @@ This can take a couple of minutes."</string>
<string name="pref_auth_trust_google_summary">When disabled, the user is asked before an apps 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 allows unauthorized devices to #, but may have unforeseen consequences.</string>

Expand Down

0 comments on commit 2bd4dcf

Please # to comment.