Skip to content

Commit

Permalink
Auth: Allow stripping device name from requests
Browse files Browse the repository at this point in the history
Helps with some banned devices. Enable for -hw build by default.

(cherry picked from commit 9028d03)
  • Loading branch information
mar-v-in authored and WSTxda committed Feb 28, 2024
1 parent c69ef9b commit 024e92c
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ object SettingsContract {
const val TRUST_GOOGLE = "auth_manager_trust_google"
const val VISIBLE = "auth_manager_visible"
const val INCLUDE_ANDROID_ID = "auth_include_android_id"
const val STRIP_DEVICE_NAME = "auth_strip_device_name"

val PROJECTION = arrayOf(
TRUST_GOOGLE,
VISIBLE,
INCLUDE_ANDROID_ID,
STRIP_DEVICE_NAME,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class SettingsProvider : ContentProvider() {
Auth.TRUST_GOOGLE -> getSettingsBoolean(key, true)
Auth.VISIBLE -> getSettingsBoolean(key, false)
Auth.INCLUDE_ANDROID_ID -> getSettingsBoolean(key, true)
Auth.STRIP_DEVICE_NAME -> getSettingsBoolean(key, false)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
Expand All @@ -211,6 +212,7 @@ class SettingsProvider : ContentProvider() {
Auth.TRUST_GOOGLE -> editor.putBoolean(key, value as Boolean)
Auth.VISIBLE -> editor.putBoolean(key, value as Boolean)
Auth.INCLUDE_ANDROID_ID -> editor.putBoolean(key, value as Boolean)
Auth.STRIP_DEVICE_NAME -> editor.putBoolean(key, value as Boolean)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
Expand Down
3 changes: 0 additions & 3 deletions play-services-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ dependencies {

implementation "androidx.lifecycle:lifecycle-service:$lifecycleVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

// Material Components
implementation "com.google.android.material:material:$materialVersion"
}

android {
Expand Down
3 changes: 3 additions & 0 deletions play-services-core/src/huawei/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
<meta-data
android:name="org.microg.gms.settings.auth_include_android_id"
android:value="false" />
<meta-data
android:name="org.microg.gms.settings.auth_strip_device_name"
android:value="true" />
</application>
</manifest>
3 changes: 3 additions & 0 deletions play-services-core/src/huaweilh/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<meta-data
android:name="org.microg.gms.settings.auth_include_android_id"
android:value="false" />
<meta-data
android:name="org.microg.gms.settings.auth_strip_device_name"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.droidguard_enabled"
android:value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public AuthRequest fromContext(Context context) {
if (AuthPrefs.shouldIncludeAndroidId(context)) {
androidIdHex = Long.toHexString(LastCheckinInfo.read(context).getAndroidId());
}
if (AuthPrefs.shouldStripDeviceName(context)) {
deviceName = "";
buildVersion = "";
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ object AuthPrefs {
}
}

@JvmStatic
fun shouldStripDeviceName(context: Context): Boolean {
return SettingsContract.getSettings(context, Auth.getContentUri(context), arrayOf(Auth.STRIP_DEVICE_NAME)) { c ->
c.getInt(0) != 0
}
}

}
5 changes: 2 additions & 3 deletions play-services-core/src/main/res/menu/gcm_menu_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

<item
android:id="@+id/menu_advanced"
android:title="@string/menu_advanced"
android:icon="@drawable/ic_settings"
app:showAsAction="ifRoom"/>

android:title="@string/menu_advanced"
app:showAsAction="ifRoom" />
</menu>
2 changes: 2 additions & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ This can take a couple of minutes"</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 sign in, but may have unforeseen consequences</string>
<string name="pref_auth_strip_device_name_title">Strip device name for authentication</string>
<string name="pref_auth_strip_device_name_summary">When enabled, authentication requests won\'t include the device\'s name, which may allow unauthorized devices to sign in, but may have unforeseen consequences.</string>

<string name="pref_checkin_enable_summary">Registers your device to Google services and creates a unique device identifier. MicroG strips identifying bits other than your Google account name from registration data</string>
<string name="pref_device_registration_android_id">Android ID</string>
Expand Down
6 changes: 6 additions & 0 deletions play-services-core/src/main/res/xml/preferences_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@
android:key="auth_include_android_id"
android:summary="@string/pref_auth_include_android_id_summary"
android:title="@string/pref_auth_include_android_id_title" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="auth_strip_device_name"
android:summary="@string/pref_auth_strip_device_name_summary"
android:title="@string/pref_auth_strip_device_name_title"/>
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 024e92c

Please sign in to comment.