Skip to content

Commit

Permalink
Merge branch 'master' into fix_silentSignIn_error
Browse files Browse the repository at this point in the history
  • Loading branch information
mar-v-in authored Dec 18, 2024
2 parents 2eff0d1 + 107083e commit 784cbaf
Show file tree
Hide file tree
Showing 97 changed files with 5,238 additions and 358 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ buildscript {
ext.slf4jVersion = '1.7.36'
ext.volleyVersion = '1.2.1'
ext.wireVersion = '4.8.0'
ext.tinkVersion = '1.13.0'

ext.androidBuildGradleVersion = '8.2.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@

package com.google.android.gms.dynamite.descriptors.com.google.android.gms.ads.dynamite;

import android.content.Context;
import android.content.ContextWrapper;
import android.webkit.WebSettings;
import androidx.annotation.Keep;

@Keep
public class ModuleDescriptor {
public static final String MODULE_ID = "com.google.android.gms.ads.dynamite";
public static final int MODULE_VERSION = 230500001;

/**
* The ads module might try to access the user agent, requiring initialization on the main thread,
* which may result in deadlocks when invoked from any other thread. This only happens with microG,
* because we don't use the highly privileged SELinux Sandbox that regular Play Services uses
* (which allows apps to read the user-agent from Play Services instead of the WebView). To prevent
* the issue we pre-emptively initialize the WebView.
*/
public static void init(Context context) {
if (context instanceof ContextWrapper) {
context = ((ContextWrapper) context).getBaseContext();
}
WebSettings.getDefaultUserAgent(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@ public static void checkPackageUid(Context context, String packageName, int call
@Deprecated
@Nullable
public static String firstSignatureDigest(Context context, String packageName) {
return firstSignatureDigest(context.getPackageManager(), packageName);
return firstSignatureDigest(context, packageName, false);
}

/**
* @deprecated We should stop using SHA-1 for certificate fingerprints!
*/
@Deprecated
@Nullable
public static String firstSignatureDigest(Context context, String packageName, boolean useSigningInfo) {
return firstSignatureDigest(context.getPackageManager(), packageName, useSigningInfo);
}

/**
Expand All @@ -103,13 +112,33 @@ public static String firstSignatureDigest(Context context, String packageName) {
@Deprecated
@Nullable
public static String firstSignatureDigest(PackageManager packageManager, String packageName) {
return firstSignatureDigest(packageManager, packageName, false);
}

/**
* @deprecated We should stop using SHA-1 for certificate fingerprints!
*/
@Deprecated
@Nullable
public static String firstSignatureDigest(PackageManager packageManager, String packageName, boolean useSigningInfo) {
final PackageInfo info;
try {
info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES | (useSigningInfo && SDK_INT >= 28 ? PackageManager.GET_SIGNING_CERTIFICATES : 0));
} catch (PackageManager.NameNotFoundException e) {
return null;
}
if (info != null && info.signatures != null && info.signatures.length > 0) {
if (info == null) return null;
if (SDK_INT >= 28 && useSigningInfo && info.signingInfo != null) {
if (!info.signingInfo.hasMultipleSigners()) {
for (Signature sig : info.signingInfo.getSigningCertificateHistory()) {
String digest = sha1sum(sig.toByteArray());
if (digest != null) {
return digest;
}
}
}
}
if (info.signatures != null) {
for (Signature sig : info.signatures) {
String digest = sha1sum(sig.toByteArray());
if (digest != null) {
Expand All @@ -135,13 +164,33 @@ public static byte[] firstSignatureDigestBytes(Context context, String packageNa
@Deprecated
@Nullable
public static byte[] firstSignatureDigestBytes(PackageManager packageManager, String packageName) {
return firstSignatureDigestBytes(packageManager, packageName, false);
}

/**
* @deprecated We should stop using SHA-1 for certificate fingerprints!
*/
@Deprecated
@Nullable
public static byte[] firstSignatureDigestBytes(PackageManager packageManager, String packageName, boolean useSigningInfo) {
final PackageInfo info;
try {
info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES | (useSigningInfo && SDK_INT >= 28 ? PackageManager.GET_SIGNING_CERTIFICATES : 0));
} catch (PackageManager.NameNotFoundException e) {
return null;
}
if (info != null && info.signatures != null && info.signatures.length > 0) {
if (info == null) return null;
if (SDK_INT >= 28 && useSigningInfo && info.signingInfo != null) {
if (!info.signingInfo.hasMultipleSigners()) {
for (Signature sig : info.signingInfo.getSigningCertificateHistory()) {
byte[] digest = sha1bytes(sig.toByteArray());
if (digest != null) {
return digest;
}
}
}
}
if (info.signatures != null) {
for (Signature sig : info.signatures) {
byte[] digest = sha1bytes(sig.toByteArray());
if (digest != null) {
Expand Down
1 change: 1 addition & 0 deletions play-services-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation project(':play-services-cronet-core')
implementation project(':play-services-droidguard-core')
implementation project(':play-services-fido-core')
implementation project(':play-services-fitness-core')
implementation project(':play-services-gmscompliance-core')
implementation project(':play-services-location-core')
implementation project(':play-services-location-core-base')
Expand Down
19 changes: 5 additions & 14 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@
android:enabled="true"
android:exported="true"
android:process=":ui"
android:configChanges="keyboardHidden|keyboard|orientation|screenSize"
android:configChanges="keyboardHidden|keyboard|orientation|screenSize|smallestScreenSize|layoutDirection"
android:launchMode="singleTask"
android:excludeFromRecents="false">
<intent-filter>
Expand Down Expand Up @@ -771,6 +771,10 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.gms.location.settings.LOCATION_SHARING"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

<activity
Expand Down Expand Up @@ -832,17 +836,6 @@
</intent-filter>
</service>

<!-- fitness -->

<service
android:name="com.google.android.gms.fitness.service.history.FitHistoryBroker"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.fitness.HistoryApi" />
</intent-filter>
</service>

<!-- backup -->

<activity
Expand Down Expand Up @@ -1069,13 +1062,11 @@
<action android:name="com.google.android.gms.fido.u2f.thirdparty.START" />
<action android:name="com.google.android.gms.fido.u2f.zeroparty.START" />
<action android:name="com.google.android.gms.fitness.BleApi" />
<action android:name="com.google.android.gms.fitness.ConfigApi" />
<action android:name="com.google.android.gms.fitness.GoalsApi" />
<action android:name="com.google.android.gms.fitness.GoogleFitnessService.START" />
<action android:name="com.google.android.gms.fitness.InternalApi" />
<action android:name="com.google.android.gms.fitness.RecordingApi" />
<action android:name="com.google.android.gms.fitness.SensorsApi" />
<action android:name="com.google.android.gms.fitness.SessionsApi" />
<action android:name="com.google.android.gms.fonts.service.START" />
<action android:name="com.google.android.gms.freighter.service.START" />
<action android:name="com.google.android.gms.growth.service.START" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ public static DynamiteContext create(String moduleId, Context originalContext) {
DynamiteModuleInfo moduleInfo = new DynamiteModuleInfo(moduleId);
Context gmsContext = originalContext.createPackageContext(Constants.GMS_PACKAGE_NAME, 0);
Context originalAppContext = originalContext.getApplicationContext();
DynamiteContext dynamiteContext;
if (originalAppContext == null || originalAppContext == originalContext) {
return new DynamiteContext(moduleInfo, originalContext, gmsContext, null);
dynamiteContext = new DynamiteContext(moduleInfo, originalContext, gmsContext, null);
} else {
return new DynamiteContext(moduleInfo, originalContext, gmsContext, new DynamiteContext(moduleInfo, originalAppContext, gmsContext, null));
dynamiteContext = new DynamiteContext(moduleInfo, originalContext, gmsContext, new DynamiteContext(moduleInfo, originalAppContext, gmsContext, null));
}
moduleInfo.init(dynamiteContext);
return dynamiteContext;
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import java.util.Collection;
import java.util.Collections;

import static android.content.Context.CONTEXT_IGNORE_SECURITY;
import static android.content.Context.CONTEXT_INCLUDE_CODE;
import android.content.Context;

public class DynamiteModuleInfo {
private Class<?> descriptor;
Expand Down Expand Up @@ -51,4 +50,12 @@ public Collection<String> getMergedClasses() {
return Collections.emptySet();
}
}

public void init(Context dynamiteContext) {
try {
descriptor.getMethod("init", Context.class).invoke(null, dynamiteContext);
} catch (Exception e) {
// Ignore
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private void addPackageInstalledAndSignedResult(Context context, ResultCollector
}

private boolean addPackageSignedResult(Context context, ResultCollector collector, String nicePackageName, String androidPackageName, String signatureHash) {
boolean hashMatches = signatureHash.equals(PackageUtils.firstSignatureDigest(context, androidPackageName));
boolean hashMatches = signatureHash.equals(PackageUtils.firstSignatureDigest(context, androidPackageName, true)) &&
signatureHash.equals(PackageUtils.firstSignatureDigest(context, androidPackageName, false));
collector.addResult(context.getString(R.string.self_check_name_correct_sig, nicePackageName),
hashMatches ? Positive : Negative,
context.getString(R.string.self_check_resolution_correct_sig, nicePackageName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private boolean addSystemSpoofsSignature(Context context, ResultCollector collec
if (knowsPermission) {
grantsPermission = ContextCompat.checkSelfPermission(context, FAKE_SIGNATURE_PERMISSION) == PERMISSION_GRANTED;
}
boolean spoofsSignature = GMS_PACKAGE_SIGNATURE_SHA1.equals(PackageUtils.firstSignatureDigest(context, Constants.GMS_PACKAGE_NAME));
boolean spoofsSignature = GMS_PACKAGE_SIGNATURE_SHA1.equals(PackageUtils.firstSignatureDigest(context, Constants.GMS_PACKAGE_NAME, true)) &&
GMS_PACKAGE_SIGNATURE_SHA1.equals(PackageUtils.firstSignatureDigest(context, Constants.GMS_PACKAGE_NAME, false));
if (knowsPermission && !spoofsSignature && !grantsPermission) {
collector.addResult(
context.getString(R.string.self_check_name_system_spoofs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ private val ALLOWED_WEB_PREFIXES = setOf(
)

private val ACTION_TO_SCREEN_ID = hashMapOf(
ACTION_MY_ACCOUNT to 1,
ACTION_ACCOUNT_PREFERENCES_SETTINGS to 1,
ACTION_SECURITY_SETTINGS to 10006,
ACTION_PRIVACY_SETTINGS to 10004,
ACTION_LOCATION_SHARING to 210,
)

class MainActivity : AppCompatActivity() {
Expand All @@ -134,7 +133,7 @@ class MainActivity : AppCompatActivity() {
Log.d(TAG, "Invoked with ${intent.action} and extras $extras")
super.onCreate(savedInstanceState)

val screenId = intent?.getIntExtra(EXTRA_SCREEN_ID, -1).takeIf { it != -1 } ?: ACTION_TO_SCREEN_ID[intent.action] ?: 1
val screenId = ACTION_TO_SCREEN_ID[intent.action] ?: intent?.getIntExtra(EXTRA_SCREEN_ID, -1)?.takeIf { it > 0 } ?: 1
val product = intent?.getStringExtra(EXTRA_SCREEN_MY_ACTIVITY_PRODUCT)
val kidOnboardingParams = intent?.getStringExtra(EXTRA_SCREEN_KID_ONBOARDING_PARAMS)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const val ACTION_MY_ACCOUNT = "com.google.android.gms.accountsettings.MY_ACCOUNT
const val ACTION_ACCOUNT_PREFERENCES_SETTINGS = "com.google.android.gms.accountsettings.ACCOUNT_PREFERENCES_SETTINGS"
const val ACTION_PRIVACY_SETTINGS = "com.google.android.gms.accountsettings.PRIVACY_SETTINGS"
const val ACTION_SECURITY_SETTINGS = "com.google.android.gms.accountsettings.SECURITY_SETTINGS"
const val ACTION_LOCATION_SHARING = "com.google.android.gms.location.settings.LOCATION_SHARING"

const val EXTRA_CALLING_PACKAGE_NAME = "extra.callingPackageName"
const val EXTRA_IGNORE_ACCOUNT = "extra.ignoreAccount"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ class AssistedSignInActivity : AppCompatActivity() {
errorResult(Status(CommonStatusCodes.ERROR, "accounts is empty."))
return
}
AssistedSignInFragment(googleSignInOptions!!, beginSignInRequest!!, accounts, clientPackageName!!,
{ errorResult(it) },
{ loginResult(it) })
.show(supportFragmentManager, AssistedSignInFragment.TAG)
val fragment = supportFragmentManager.findFragmentByTag(AssistedSignInFragment.TAG)
if (fragment != null) {
val assistedSignInFragment = fragment as AssistedSignInFragment
assistedSignInFragment.cancelLogin(true)
} else {
AssistedSignInFragment.newInstance(clientPackageName!!, googleSignInOptions!!, beginSignInRequest!!)
.show(supportFragmentManager, AssistedSignInFragment.TAG)
}
return
}

Expand All @@ -114,15 +118,15 @@ class AssistedSignInActivity : AppCompatActivity() {
startActivityForResult(intent, REQUEST_CODE_SIGN_IN)
}

private fun errorResult(status: Status) {
fun errorResult(status: Status) {
Log.d(TAG, "errorResult: $status")
setResult(RESULT_CANCELED, Intent().apply {
putExtra(AuthConstants.STATUS, SafeParcelableSerializer.serializeToBytes(status))
})
finish()
}

private fun loginResult(googleSignInAccount: GoogleSignInAccount?) {
fun loginResult(googleSignInAccount: GoogleSignInAccount?) {
if (googleSignInAccount == null) {
errorResult(Status(CommonStatusCodes.CANCELED, "User cancelled."))
return
Expand Down
Loading

0 comments on commit 784cbaf

Please sign in to comment.