Skip to content

Commit

Permalink
feat: Add support for Huawei devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushTNM committed Jul 29, 2023
1 parent 6d159e3 commit 968aabe
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ object SettingsContract {
const val VERSION_INFO = "versionInfo"
const val DEVICE_DATA_VERSION_INFO = "deviceDataVersionInfo"

const val BRAND_SPOOF = "brandSpoof"

val PROJECTION = arrayOf(
ENABLED,
ANDROID_ID,
Expand All @@ -36,6 +38,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 @@ -100,6 +100,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 @@ -117,6 +118,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 @@ -135,6 +140,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 @@ -17,13 +17,13 @@
package org.microg.gms.auth.login;

import android.annotation.SuppressLint;
import android.app.Activity;
//import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
//import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.StringRes;
Expand All @@ -43,7 +43,12 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onNextButtonClicked();
if (!isHuaweiDevice()) {
onNextButtonClicked();
}
else {
onHuaweiButtonClicked();
}
}
});
findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
Expand All @@ -54,6 +59,12 @@ public void onClick(View v) {
});
}

private boolean isHuaweiDevice(){
String manufacturer = android.os.Build.MANUFACTURER;
String brand = android.os.Build.BRAND;
return manufacturer.toLowerCase().contains("huawei") || brand.toLowerCase().contains("huawei");
}

@SuppressLint("WrongViewCast")
private void formatTitle() {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
Expand All @@ -77,6 +88,9 @@ public void setNextButtonText(CharSequence text) {
((Button) findViewById(R.id.next_button)).setText(text);
}
}
protected void onHuaweiButtonClicked() {

}

public void setBackButtonText(@StringRes int res) {
setBackButtonText(getText(res));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
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.hideLauncherIcon;
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 @@ -165,11 +168,33 @@ public void onPageFinished(WebView view, String url) {
}
}

@Override
protected void onHuaweiButtonClicked() {
super.onHuaweiButtonClicked();
state++;
if (state == 1) {
// hideLauncherIcon(this, false);
// UtilsKt.hideIcon(this, false);
if (!isSpoofingEnabled(this)) {
LastCheckinInfo.clear(this);
setSpoofingEnabled(this, true);
}
init();
} else if (state == -1) {
setResult(RESULT_CANCELED);
finish();
}
}

@Override
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);
Expand Down Expand Up @@ -312,7 +337,7 @@ private void retrieveRtToken(String oAuthToken) {
.token(oAuthToken).isAccessToken()
.addAccount()
.getAccountId()
.droidguardResults(null /*TODO*/)
// .droidguardResults(null /*TODO*/)
.getResponseAsync(new HttpFormClient.Callback<AuthResponse>() {
@Override
public void onResponse(AuthResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,25 @@ 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.BOOTLOADER)
.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,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.content.ContentResolver;
Expand Down Expand Up @@ -57,7 +59,8 @@ 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,31 @@ 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)
}
}
}

// @JvmStatic
// fun hideLauncherIcon(context: Context, enabled: Boolean) {
// CheckIn.getContentUri(context)?.let {
// setSettings(context, it) {
// put(CheckIn.HIDE_LAUNCHER_ICON, enabled)
// }
// }
// }
}

0 comments on commit 968aabe

Please sign in to comment.