diff --git a/play-services-base-core/src/main/java/org/microg/gms/common/PackageUtils.java b/play-services-base-core/src/main/java/org/microg/gms/common/PackageUtils.java index b4b3d69d..965edca2 100644 --- a/play-services-base-core/src/main/java/org/microg/gms/common/PackageUtils.java +++ b/play-services-base-core/src/main/java/org/microg/gms/common/PackageUtils.java @@ -24,6 +24,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.Signature; import android.os.Binder; +import android.util.Log; import androidx.annotation.Nullable; @@ -245,6 +246,36 @@ public class PackageUtils { } } + public static boolean isPersistentProcess() { + String processName = getProcessName(); + if (processName == null) { + Log.w("GmsPackageUtils", "Can't determine process name of current process"); + return false; + } + return processName.endsWith(":persistent"); + } + + public static boolean isMainProcess(Context context) { + String processName = getProcessName(); + if (processName == null) { + Log.w("GmsPackageUtils", "Can't determine process name of current process"); + return false; + } + return processName.equals(context.getPackageName()); + } + + public static void warnIfNotPersistentProcess(Class clazz) { + if (!isPersistentProcess()) { + Log.w("GmsPackageUtils", clazz.getSimpleName() + " initialized outside persistent process", new RuntimeException()); + } + } + + public static void warnIfNotMainProcess(Context context, Class clazz) { + if (!isMainProcess(context)) { + Log.w("GmsPackageUtils", clazz.getSimpleName() + " initialized outside main process", new RuntimeException()); + } + } + public static String sha1sum(byte[] bytes) { MessageDigest md; try { diff --git a/play-services-core/src/main/AndroidManifest.xml b/play-services-core/src/main/AndroidManifest.xml index 572697b7..31edf4fa 100644 --- a/play-services-core/src/main/AndroidManifest.xml +++ b/play-services-core/src/main/AndroidManifest.xml @@ -108,10 +108,10 @@ tools:ignore="ProtectedPermissions" /> @@ -128,12 +128,15 @@ - + @@ -220,7 +223,8 @@ + android:name="org.microg.gms.gcm.PushRegisterService" + android:process=":persistent"> @@ -229,24 +233,33 @@ - + - + + android:name="org.microg.gms.gcm.SendReceiver" + android:process=":persistent"> - + - + @@ -267,7 +280,9 @@ - + diff --git a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java index f4f5b76d..ad073059 100644 --- a/play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java +++ b/play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java @@ -21,9 +21,7 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL public static CheckinPrefs get(Context context) { if (INSTANCE == null) { - if (!context.getPackageName().equals(PackageUtils.getProcessName())) { - Log.w("Preferences", CheckinPrefs.class.getName() + " initialized outside main process", new RuntimeException()); - } + PackageUtils.warnIfNotMainProcess(context, CheckinPrefs.class); if (context == null) return new CheckinPrefs(null); INSTANCE = new CheckinPrefs(context.getApplicationContext()); } diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/GcmPrefs.java b/play-services-core/src/main/java/org/microg/gms/gcm/GcmPrefs.java index 852f85ea..188ee94e 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/GcmPrefs.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/GcmPrefs.java @@ -53,9 +53,7 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe public static GcmPrefs get(Context context) { if (INSTANCE == null) { - if (!context.getPackageName().equals(PackageUtils.getProcessName())) { - Log.w("Preferences", GcmPrefs.class.getName() + " initialized outside main process", new RuntimeException()); - } + PackageUtils.warnIfNotPersistentProcess(GcmPrefs.class); if (context == null) return new GcmPrefs(null); INSTANCE = new GcmPrefs(context.getApplicationContext()); } diff --git a/play-services-core/src/main/java/org/microg/gms/snet/SafetyNetPrefs.java b/play-services-core/src/main/java/org/microg/gms/snet/SafetyNetPrefs.java index e3c11a89..4b49610c 100644 --- a/play-services-core/src/main/java/org/microg/gms/snet/SafetyNetPrefs.java +++ b/play-services-core/src/main/java/org/microg/gms/snet/SafetyNetPrefs.java @@ -38,9 +38,7 @@ public class SafetyNetPrefs implements SharedPreferences.OnSharedPreferenceChang public static SafetyNetPrefs get(Context context) { if (INSTANCE == null) { - if (!context.getPackageName().equals(PackageUtils.getProcessName())) { - Log.w("Preferences", SafetyNetPrefs.class.getName() + " initialized outside main process", new RuntimeException()); - } + PackageUtils.warnIfNotMainProcess(context, SafetyNetPrefs.class); if (context == null) return new SafetyNetPrefs(null); INSTANCE = new SafetyNetPrefs(context.getApplicationContext()); } diff --git a/play-services-nearby-core/src/main/AndroidManifest.xml b/play-services-nearby-core/src/main/AndroidManifest.xml index 59512cdf..a05e274a 100644 --- a/play-services-nearby-core/src/main/AndroidManifest.xml +++ b/play-services-nearby-core/src/main/AndroidManifest.xml @@ -21,20 +21,34 @@ - - - - + + + + - + - + - + @@ -46,8 +60,8 @@ + android:exported="false" + android:grantUriPermissions="true"> diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposurePreferences.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposurePreferences.kt index 9b840f73..0fdfd03c 100644 --- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposurePreferences.kt +++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposurePreferences.kt @@ -8,18 +8,14 @@ package org.microg.gms.nearby.exposurenotification import android.content.Context import android.content.Intent import android.content.SharedPreferences -import android.util.Log import androidx.preference.PreferenceManager import org.microg.gms.common.PackageUtils - class ExposurePreferences(private val context: Context) { private var preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) init { - if (context.packageName != PackageUtils.getProcessName()) { - Log.w("Preferences", ExposurePreferences::class.simpleName + " initialized outside main process", RuntimeException()) - } + PackageUtils.warnIfNotPersistentProcess(ExposurePreferences::class.java) } var enabled