Skip to content

Commit 18b1a49

Browse files
muhomorrthestinger
authored andcommitted
gmscompat: don't use GSF for fresh installs
On existing installs, GmsCore uses GSF to perform a one-time migration of GSF databases into itself.
1 parent 1761365 commit 18b1a49

File tree

16 files changed

+79
-21
lines changed

16 files changed

+79
-21
lines changed

core/api/system-current.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4912,7 +4912,6 @@ package android.ext {
49124912
field public static final String EUICC_SUPPORT_PIXEL_NAME = "com.google.euiccpixel";
49134913
field public static final int GMS_CORE = 2; // 0x2
49144914
field public static final String GMS_CORE_NAME = "com.google.android.gms";
4915-
field public static final int GSF = 1; // 0x1
49164915
field public static final String GSF_NAME = "com.google.android.gsf";
49174916
field public static final int G_CAMERA = 8; // 0x8
49184917
field public static final String G_CAMERA_NAME = "com.google.android.GoogleCamera";

core/api/system-lint-baseline.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,8 +2227,6 @@ UnflaggedApi: android.ext.PackageId#GMS_CORE:
22272227
New API must be flagged with @FlaggedApi: field android.ext.PackageId.GMS_CORE
22282228
UnflaggedApi: android.ext.PackageId#GMS_CORE_NAME:
22292229
New API must be flagged with @FlaggedApi: field android.ext.PackageId.GMS_CORE_NAME
2230-
UnflaggedApi: android.ext.PackageId#GSF:
2231-
New API must be flagged with @FlaggedApi: field android.ext.PackageId.GSF
22322230
UnflaggedApi: android.ext.PackageId#GSF_NAME:
22332231
New API must be flagged with @FlaggedApi: field android.ext.PackageId.GSF_NAME
22342232
UnflaggedApi: android.ext.PackageId#G_CAMERA:

core/java/android/app/ContextImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,13 @@ public Context createContextForSdkInSandbox(ApplicationInfo sdkInfo, int flags)
27942794
@Override
27952795
public Context createPackageContext(String packageName, int flags)
27962796
throws NameNotFoundException {
2797+
if (GmsCompat.isEnabled()) {
2798+
Context res = GmcPackageManager.maybeOverrideGsfPackageContext(packageName);
2799+
if (res != null) {
2800+
return res;
2801+
}
2802+
}
2803+
27972804
return createPackageContextAsUser(packageName, flags, mUser);
27982805
}
27992806

core/java/android/app/compat/gms/GmsCompat.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public static boolean isEnabledFor(int packageId, boolean isPrivileged) {
134134

135135
return switch (packageId) {
136136
case
137-
PackageId.GSF,
138137
PackageId.GMS_CORE,
139138
PackageId.PLAY_STORE,
140139
PackageId.G_SEARCH_APP,
@@ -156,7 +155,6 @@ public static boolean canBeEnabledFor(String pkgName) {
156155

157156
return switch (pkgName) {
158157
case
159-
PackageId.GSF_NAME,
160158
PackageId.GMS_CORE_NAME,
161159
PackageId.PLAY_STORE_NAME,
162160
PackageId.G_SEARCH_APP_NAME,

core/java/android/ext/PackageId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface PackageId {
1313
int UNKNOWN = 0;
1414

1515
String GSF_NAME = "com.google.android.gsf";
16-
int GSF = 1;
16+
// no longer needed: int GSF = 1
1717

1818
String GMS_CORE_NAME = "com.google.android.gms";
1919
int GMS_CORE = 2;

core/java/com/android/internal/gmscompat/BinderGca2Gms.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.util.ArraySet;
1313
import android.util.Log;
1414

15+
import com.android.internal.gmscompat.flags.GmsFlag;
1516
import com.android.internal.gmscompat.util.GmcActivityUtils;
1617

1718
import java.util.concurrent.Callable;
@@ -46,13 +47,12 @@ public void invalidateConfigCaches() {
4647
updatePhenotype(phenotypeDb, GmsHooks.config());
4748
}
4849

49-
// Gservices flags are hosted by GservicesProvider ContentProvider in
50-
// "Google Services Framework" app.
50+
// Gservices flags are hosted by GservicesProvider ContentProvider in GmsCore.
5151
// Its clients register change listeners via
5252
// BroadcastReceivers (com.google.gservices.intent.action.GSERVICES_CHANGED) and
5353
// ContentResolver#registerContentObserver().
5454
// Code below performs a delete of a non-existing key (key is chosen randomly).
55-
// GSF will notify all of its listeners after this operation, despite database remaining
55+
// GmsCore will notify all of its listeners after this operation, despite database remaining
5656
// unchanged. There's no other simple way to achieve the same effect (AFAIK).
5757
//
5858
// Additional values from GmsCompatConfig will be added only inside client's processes,
@@ -62,7 +62,7 @@ public void invalidateConfigCaches() {
6262
ContentValues cv = new ContentValues();
6363
cv.put("iquee6jo8ooquoomaeraip7gah4shee8phiet0Ahng0yeipei3", (String) null);
6464

65-
Uri gservicesUri = Uri.parse("content://" + GmsInfo.PACKAGE_GSF + ".gservices/override");
65+
Uri gservicesUri = Uri.parse("content://" + GmsFlag.GSERVICES_CONTENT_PROVIDER_AUTHORITY + "/override");
6666
cr.update(gservicesUri, cv, null, null);
6767
}
6868

core/java/com/android/internal/gmscompat/GmsInfo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
/** @hide */
2222
public final class GmsInfo {
2323
// Package names for GMS apps
24-
public static final String PACKAGE_GSF = PackageId.GSF_NAME; // "Google Services Framework"
2524
public static final String PACKAGE_GMS_CORE = PackageId.GMS_CORE_NAME; // "Play services"
2625
public static final String PACKAGE_PLAY_STORE = PackageId.PLAY_STORE_NAME;
2726

2827
// "Google" app. "GSA" (G Search App) is its internal name
2928
public static final String PACKAGE_GSA = PackageId.G_SEARCH_APP_NAME;
3029

3130
// Used for restricting accessibility of exported components, reducing the scope of broadcasts, etc.
32-
// Held by GSF, GmsCore, Play Store.
31+
// Held by GmsCore and Play Store.
3332
public static final String SIGNATURE_PROTECTED_PERMISSION = "com.google.android.providers.gsf.permission.WRITE_GSERVICES";
3433
}

core/java/com/android/internal/gmscompat/flags/GmsFlag.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ public class GmsFlag implements Parcelable {
4949
public @Nullable String[] permissions;
5050

5151
public static final String NAMESPACE_GSERVICES = "gservices";
52+
// Gservices content provider is hosted by GmsCore since Android 15. It was hosted by GSF before 15.
53+
public static final String GSERVICES_CONTENT_PROVIDER_AUTHORITY = "com.google.android.gsf.gservices";
5254

5355
public static final String GSERVICES_URI = "content://"
54-
+ GmsInfo.PACKAGE_GSF + '.' + NAMESPACE_GSERVICES + "/prefix";
56+
+ GSERVICES_CONTENT_PROVIDER_AUTHORITY + "/prefix";
5557

5658
public static final String PHENOTYPE_URI_PREFIX = "content://"
5759
+ GmsInfo.PACKAGE_GMS_CORE + ".phenotype/";

core/java/com/android/internal/gmscompat/sysservice/GmcPackageManager.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@
3535
import android.content.pm.InstallSourceInfo;
3636
import android.content.pm.PackageInfo;
3737
import android.content.pm.PackageInstaller;
38+
import android.content.pm.PackageManager;
3839
import android.content.pm.SharedLibraryInfo;
3940
import android.content.pm.VersionedPackage;
4041
import android.ext.PackageId;
41-
import android.os.Build;
4242
import android.os.Process;
4343
import android.os.RemoteException;
4444
import android.os.UserHandle;
45-
import android.provider.Settings;
4645
import android.util.ArrayMap;
4746
import android.util.ArraySet;
4847
import android.util.Log;
@@ -529,7 +528,6 @@ private static boolean shouldHideDisabledState(String pkgName) {
529528
}
530529

531530
switch (pkgName) {
532-
case GmsInfo.PACKAGE_GSF:
533531
case GmsInfo.PACKAGE_GMS_CORE:
534532
return false;
535533
default:
@@ -626,4 +624,43 @@ public void setComponentEnabledSettings(List<ComponentEnabledSetting> settings)
626624
}
627625
}
628626

627+
/** @see android.app.ContextImpl#createPackageContext */
628+
@Nullable
629+
public static Context maybeOverrideGsfPackageContext(String packageName) {
630+
if (!GmsCompat.isGmsCore()) {
631+
return null;
632+
}
633+
634+
if (!PackageId.GSF_NAME.equals(packageName)) {
635+
return null;
636+
}
637+
638+
// On first launch, GmsCore attempts to migrate GSF databases into itself. GSF is a
639+
// hasCode=false package since Android 15 and is not needed for fresh installs of GmsCore.
640+
// If GSF is absent, GmsCore crashes when it tries to create package context for GSF as
641+
// part of database migration. To prevent this crash, return GmsCore app context instead
642+
// of GSF package context, which turns database migration into a no-op.
643+
644+
Context ctx = GmsCompat.appContext();
645+
PackageManager pkgManager = ctx.getPackageManager();
646+
647+
try {
648+
pkgManager.getApplicationInfo(packageName, 0);
649+
} catch (PackageManager.NameNotFoundException e) {
650+
Log.d(TAG, "replacing GSF package context with GmsCore app context", new Throwable());
651+
return ctx;
652+
}
653+
654+
try {
655+
PackageInfo pi = pkgManager.getPackageInfo(PackageId.GMS_CORE_NAME, 0);
656+
if (pi.sharedUserId == null) {
657+
// GmsCore has left the GSF sharedUid but GSF is still present
658+
Log.d(TAG, "maybeReplaceGsfPackageName: sharedUserId is null, ignoring GSF", new Throwable());
659+
return ctx;
660+
}
661+
return null;
662+
} catch (NameNotFoundException e) {
663+
throw new IllegalStateException(e);
664+
}
665+
}
629666
}

core/java/com/android/internal/pm/pkg/parsing/ParsingPackageUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import android.content.res.Resources;
6464
import android.content.res.TypedArray;
6565
import android.content.res.XmlResourceParser;
66+
import android.ext.PackageId;
6667
import android.net.Uri;
6768
import android.os.Build;
6869
import android.os.Bundle;
@@ -1210,6 +1211,12 @@ private static ParseResult<ParsingPackage> parseSharedUser(ParseInput input,
12101211
if (PackageManager.ENABLE_SHARED_UID_MIGRATION) {
12111212
int max = anInteger(0, R.styleable.AndroidManifest_sharedUserMaxSdkVersion, sa);
12121213
leaving = (max != 0) && (max < Build.VERSION.RESOURCES_SDK_INT);
1214+
1215+
if (android.ext.PackageId.GMS_CORE_NAME.equals(pkg.getPackageName())) {
1216+
// Ignore sharedUid for fresh installs of GmsCore. On existing installs, sharedUid
1217+
// is needed for access to GSF.
1218+
leaving = true;
1219+
}
12131220
}
12141221

12151222
return input.success(pkg
@@ -2507,6 +2514,12 @@ private void parseBaseAppBasicFlags(ParsingPackage pkg, TypedArray sa) {
25072514
} else if (enabledOverride == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
25082515
pkg.setEnabled(true);
25092516
}
2517+
2518+
if (PackageId.GSF_NAME.equals(pkg.getPackageName())) {
2519+
// GSF is a hasCode=false package on GMS Android 15+. GrapheneOS doesn't include GSF as a
2520+
// preinstalled app, so pre-35 GSF remains after update from pre-Android 15.
2521+
pkg.setDeclaredHavingCode(false);
2522+
}
25102523
}
25112524

25122525
/**

0 commit comments

Comments
 (0)