Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #155 from Oizaro/master
Browse files Browse the repository at this point in the history
Remove getDefaultSharedPreferences calls
  • Loading branch information
KevinX8 committed Jul 6, 2021
2 parents 4c9230d + c86b9ab commit 020b789
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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.CheckinPrefs.hideLauncherIcon;
import static org.microg.gms.checkin.CheckinPrefs.isSpoofingEnabled;
import static org.microg.gms.checkin.CheckinPrefs.setSpoofingEnabled;
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
import static org.microg.gms.common.Constants.GMS_VERSION_CODE;

Expand Down Expand Up @@ -163,16 +166,17 @@ protected void onHuaweiButtonClicked() {
state++;
if (state == 1) {
if (SDK_INT >= Build.VERSION_CODES.M) {
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("pref_hide_launcher_icon", false).apply();
hideLauncherIcon(this, false);
UtilsKt.hideIcon(this, false);
}
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(HuaweiButtonPreference, true).apply();
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(LoginButtonPreference, true)) {
if (!isSpoofingEnabled(this)) {
LastCheckinInfo.clear(this);
CheckinClient.brandSpoof = true;
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(LoginButtonPreference, true).apply();
setSpoofingEnabled(this, true);
}
init();
} else if (state == -1) {
setResult(RESULT_CANCELED);
finish();
}
}

Expand All @@ -181,11 +185,9 @@ protected void onNextButtonClicked() {
super.onNextButtonClicked();
state++;
if (state == 1) {
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(LoginButtonPreference, true).apply();
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(HuaweiButtonPreference, true)) {
if (isSpoofingEnabled(this)) {
LastCheckinInfo.clear(this);
CheckinClient.brandSpoof = false;
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(HuaweiButtonPreference, true).apply();
setSpoofingEnabled(this, false);
}
init();
} else if (state == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public class CheckinClient {
private static final List<String> TODO_LIST_STRING = new ArrayList<>(); // TODO
private static final List<CheckinRequest.Checkin.Statistic> TODO_LIST_CHECKIN = new ArrayList<CheckinRequest.Checkin.Statistic>(); // TODO
private static final String SERVICE_URL = "https://android.clients.google.com/checkin";
public static boolean brandSpoof = false;


public static CheckinResponse request(CheckinRequest request) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(SERVICE_URL).openConnection();
connection.setRequestMethod("POST");
Expand Down Expand Up @@ -79,7 +78,7 @@ public static CheckinResponse request(CheckinRequest request) throws IOException
public static CheckinRequest makeRequest(Build build, DeviceConfiguration deviceConfiguration,
DeviceIdentifier deviceIdent, PhoneInfo phoneInfo,
LastCheckinInfo checkinInfo, Locale locale,
List<Account> accounts) {
List<Account> accounts, Boolean brandSpoof) {
CheckinRequest.Builder builder = new CheckinRequest.Builder()
.accountCookie(new ArrayList<>())
.androidId(checkinInfo.getAndroidId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.microg.gms.checkin.CheckinPrefs.isSpoofingEnabled;

public class CheckinManager {
private static final String TAG = "GmsCheckinManager";
private static final long MIN_CHECKIN_INTERVAL = 3 * 60 * 60 * 1000; // 3 hours
Expand All @@ -58,7 +60,8 @@ public static synchronized LastCheckinInfo checkin(Context context, boolean forc
}
CheckinRequest request = CheckinClient.makeRequest(Utils.getBuild(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 @@ -7,6 +7,7 @@ package org.microg.gms.checkin
import android.content.Context
import org.microg.mgms.settings.SettingsContract
import org.microg.mgms.settings.SettingsContract.CheckIn
import org.microg.mgms.settings.SettingsContract.setSettings

object CheckinPrefs {

Expand All @@ -18,4 +19,26 @@ object CheckinPrefs {
}
}

@JvmStatic
fun isSpoofingEnabled(context: Context): Boolean {
val projection = arrayOf(CheckIn.BRAND_SPOOF)
return SettingsContract.getSettings(context, CheckIn.CONTENT_URI, projection) { c ->
c.getInt(0) != 0
}
}

@JvmStatic
fun setSpoofingEnabled(context: Context, enabled: Boolean) {
setSettings(context, CheckIn.CONTENT_URI) {
put(CheckIn.BRAND_SPOOF, enabled)
}
}

@JvmStatic
fun hideLauncherIcon(context: Context, enabled: Boolean) {
setSettings(context, CheckIn.CONTENT_URI) {
put(CheckIn.HIDE_LAUNCHER_ICON, enabled)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.content.ComponentName
import android.content.pm.PackageManager
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
Expand All @@ -23,6 +22,7 @@ import org.microg.gms.gcm.McsConstants.ACTION_RECONNECT
import org.microg.gms.gcm.McsService
import org.microg.gms.gcm.TriggerReceiver
import org.microg.gms.gcm.getGcmServiceInfo
import org.microg.mgms.settings.SettingsContract
import org.microg.tools.ui.ResourceSettingsFragment

class SettingsFragment : ResourceSettingsFragment() {
Expand Down Expand Up @@ -57,7 +57,7 @@ class SettingsFragment : ResourceSettingsFragment() {
true
}

findPreference<SwitchPreferenceCompat>(PREF_CAST_HIDE_LAUNCHER_ICON)?.apply {
findPreference<SwitchPreferenceCompat>(SettingsContract.CheckIn.HIDE_LAUNCHER_ICON)?.apply {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
setOnPreferenceChangeListener { _, newValue ->
requireActivity().hideIcon(newValue as Boolean)
Expand Down Expand Up @@ -101,8 +101,6 @@ class SettingsFragment : ResourceSettingsFragment() {
const val PREF_GCM = "pref_gcm"
const val PREF_CHECKIN = "pref_checkin"
const val PREF_CAST_DOUBLE_FIX_ENABLED = "pref_cast_double_fix_enabled"
const val PREF_CAST_HIDE_LAUNCHER_ICON = "pref_hide_launcher_icon"
const val BRAND_SPOOF_FIX_ENABLED = "brand_spoof_fix_enabled"
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ object SettingsContract {
const val VERSION_INFO = "versionInfo"
const val DEVICE_DATA_VERSION_INFO = "deviceDataVersionInfo"

const val BRAND_SPOOF = "brandSpoof"

const val HIDE_LAUNCHER_ICON = "hideLauncherIcon"

val PROJECTION = arrayOf(
ENABLED,
ANDROID_ID,
Expand All @@ -31,6 +35,8 @@ object SettingsContract {
SECURITY_TOKEN,
VERSION_INFO,
DEVICE_DATA_VERSION_INFO,
BRAND_SPOOF,
HIDE_LAUNCHER_ICON,
)
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 @@ -85,6 +85,8 @@ 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)
CheckIn.HIDE_LAUNCHER_ICON -> getSettingsBoolean(key, false)
else -> throw IllegalArgumentException()
}
}
Expand All @@ -104,6 +106,14 @@ 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)
}
if (key == CheckIn.HIDE_LAUNCHER_ICON) {
// special case: not saved in checkInPrefs
updateHideLauncherIcon(value as Boolean)
}
when (key) {
CheckIn.ANDROID_ID -> editor.putLong(key, value as Long)
CheckIn.DIGEST -> editor.putString(key, value as String?)
Expand All @@ -122,6 +132,18 @@ class SettingsProvider : ContentProvider() {
.apply()
}

private fun updateSpoofingEnabled(enabled: Boolean) {
preferences.edit()
.putBoolean(CheckIn.BRAND_SPOOF, enabled)
.apply()
}

private fun updateHideLauncherIcon(enabled: Boolean) {
preferences.edit()
.putBoolean(CheckIn.HIDE_LAUNCHER_ICON, enabled)
.apply()
}

private fun queryGcm(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
when (key) {
Gcm.ENABLE_GCM -> getSettingsBoolean(key, true)
Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Tato akce může trvat několik minut."</string>

<string name="pref_about_title">O aplikaci Vanced microG</string>
<string name="pref_cast_double_fix">Opravit duplicity ve Vysílání</string>
<string name="pref_hide_launcher_icon">Skrýt ikonu ze spouštěče</string>
<string name="hideLauncherIcon">Skrýt ikonu ze spouštěče</string>

<string name="brand_spoof_button">Huawei</string>

Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Esto puede tardar unos minutos."</string>

<string name="pref_about_title">Acerca de Vanced microG</string>
<string name="pref_cast_double_fix">Solucion para Cast duplicado</string>
<string name="pref_hide_launcher_icon">Ocultar microG del lanzador</string>
<string name="hideLauncherIcon">Ocultar microG del lanzador</string>

<string name="brand_spoof_button">Huawei</string>

Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Ini bisa berlangsung beberapa menit."</string>

<string name="pref_about_title">Tentang Vanced microG</string>
<string name="pref_cast_double_fix">Perbaikan Cast terduplikasi</string>
<string name="pref_hide_launcher_icon">Sembunyikan microG dari peluncur</string>
<string name="hideLauncherIcon">Sembunyikan microG dari peluncur</string>

<string name="pref_switcher_title">Registrasi perangkat</string>
<string name="pref_checkin_enable_summary">Registrasi perangkat anda ke layanan Google dan buat pengenal perangkat unik. Vanced microG strips mengenal bits selain dari akun Google anda dari data registrasi.</string>
Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Questo potrà richiedere un paio di minuti"</string>

<string name="pref_about_title">Informazioni su Vanced microG</string>
<string name="pref_cast_double_fix">Correzione cast duplicato</string>
<string name="pref_hide_launcher_icon">Nascondi microG dal launcher</string>
<string name="hideLauncherIcon">Nascondi microG dal launcher</string>

<string name="pref_switcher_title">Registra dispositivo</string>
<string name="pref_checkin_enable_summary">Registra il tuo dispositivo sui servizi Google e crea un identificatore univoco del dispositivo. Verranno rimossi dai Servizi Vanced microG alcuni bit utili per identificare i dati di registrazione, oltre al nome dell\'account Google.</string>
Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

<string name="pref_about_title">О Vanced microG</string>
<string name="pref_cast_double_fix">Исправление двух кнопок трансляции</string>
<string name="pref_hide_launcher_icon">скрыть микрог из лаунчера</string>
<string name="hideLauncherIcon">скрыть микрог из лаунчера</string>

<string name="brand_spoof_button">Huawei</string>

Expand Down
2 changes: 1 addition & 1 deletion play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ This can take a couple of minutes."</string>

<string name="pref_about_title">About Vanced microG</string>
<string name="pref_cast_double_fix">Cast duplication fix</string>
<string name="pref_hide_launcher_icon">Hide icon from launcher</string>
<string name="hideLauncherIcon">Hide icon from launcher</string>

<string name="brand_spoof_button">Huawei</string>

Expand Down
4 changes: 2 additions & 2 deletions play-services-core/src/main/res/xml/preferences_start.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
android:summary="@string/pref_cast_double_fix_summary"
android:defaultValue="false"/>
<SwitchPreferenceCompat
android:key="pref_hide_launcher_icon"
android:title="@string/pref_hide_launcher_icon"
android:key="hideLauncherIcon"
android:title="@string/hideLauncherIcon"
android:icon="@drawable/ic_baseline_hide_source_24"
android:defaultValue="true"/>
</PreferenceCategory>
Expand Down

0 comments on commit 020b789

Please sign in to comment.