Skip to content

Commit

Permalink
Check package signature before each intent
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g authored and mar-v-in committed Sep 28, 2024
1 parent 2629fe0 commit 7d740f3
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ private Boolean isGoogleOrMicrogSig(PackageManager pm, String packageId) throws
return signatureIsIn(pm, packageId, signatures);
}

private Boolean isSystemGoogleOrMicrogSig(PackageManager pm, String packageId) throws PackageManager.NameNotFoundException {
return isSystem(pm, packageId) || isGoogleOrMicrogSig(pm, packageId);
}

private Boolean isMicrogSig(PackageManager pm, String packageId) throws PackageManager.NameNotFoundException {
List<String> signatures = Arrays.asList(MICROG_PRIMARY_KEYS);
return signatureIsIn(pm, packageId, signatures);
Expand Down Expand Up @@ -112,7 +116,7 @@ private String getTargetPackageWithoutPref() {
// Pref: gms > microG > self
PackageManager pm = context.getPackageManager();
try {
if (isSystem(pm, GMS_PACKAGE_NAME) || isGoogleOrMicrogSig(pm, GMS_PACKAGE_NAME)) {
if (isSystemGoogleOrMicrogSig(pm, GMS_PACKAGE_NAME)) {
Log.d(TAG, GMS_PACKAGE_NAME + " found !");
return GMS_PACKAGE_NAME;
} else {
Expand Down Expand Up @@ -242,15 +246,24 @@ public Connection(String actionString, boolean requireMicrog) {
private Intent getIntent() {
Intent intent;
ResolveInfo resolveInfo;
PackageManager pm = context.getPackageManager();
if (!Objects.equals(targetPackage, context.getPackageName())) {
intent = new Intent(actionString).setPackage(targetPackage);
if ((resolveInfo = context.getPackageManager().resolveService(intent, 0)) != null) {
if (requireMicrog && !isMicrog(resolveInfo)) {
Log.w(TAG, "GMS service found for " + actionString + " but looks not like microG");
} else {
Log.d(TAG, "GMS service found for " + actionString);
return intent;
try {
if ((resolveInfo = context.getPackageManager().resolveService(intent, 0)) != null) {
if (requireMicrog && !isMicrog(resolveInfo)) {
Log.w(TAG, "GMS service found for " + actionString + " but looks not like microG");
} else {
if (isSystemGoogleOrMicrogSig(pm, targetPackage)){
Log.d(TAG, "GMS service found for " + actionString);
return intent;
} else {
Log.w(TAG, "GMS service found for " + actionString + " but is not system, and doesn't have microG or Google signature");
}
}
}
} catch (PackageManager.NameNotFoundException e) {
Log.d(TAG, targetPackage + " not found");
}
}
intent = new Intent(actionString).setPackage(context.getPackageName());
Expand Down

0 comments on commit 7d740f3

Please sign in to comment.