mirror of
https://github.com/YTVanced/VancedMicroG
synced 2024-12-04 00:37:27 +00:00
Move EN and GCM service in persistent subprocess
This increases stability/durability of these services in case of crashes
This commit is contained in:
parent
6d423bb8e4
commit
f0337b5dcd
7 changed files with 83 additions and 33 deletions
|
@ -24,6 +24,7 @@ import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.Signature;
|
import android.content.pm.Signature;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
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) {
|
public static String sha1sum(byte[] bytes) {
|
||||||
MessageDigest md;
|
MessageDigest md;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -108,10 +108,10 @@
|
||||||
tools:ignore="ProtectedPermissions" />
|
tools:ignore="ProtectedPermissions" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:forceQueryable="true"
|
|
||||||
android:name="androidx.multidex.MultiDexApplication"
|
android:name="androidx.multidex.MultiDexApplication"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:extractNativeLibs="false"
|
android:extractNativeLibs="false"
|
||||||
|
android:forceQueryable="true"
|
||||||
android:icon="@mipmap/ic_core_service_app"
|
android:icon="@mipmap/ic_core_service_app"
|
||||||
android:label="@string/gms_app_name"
|
android:label="@string/gms_app_name"
|
||||||
android:theme="@style/Theme.AppCompat.DayNight">
|
android:theme="@style/Theme.AppCompat.DayNight">
|
||||||
|
@ -128,12 +128,15 @@
|
||||||
|
|
||||||
<!-- Location -->
|
<!-- Location -->
|
||||||
|
|
||||||
<activity android:name="org.microg.nlp.ui.BackendSettingsActivity" android:process=":ui" />
|
<activity
|
||||||
|
android:name="org.microg.nlp.ui.BackendSettingsActivity"
|
||||||
|
android:process=":ui" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.microg.gms.ui.PlacePickerActivity"
|
android:name="org.microg.gms.ui.PlacePickerActivity"
|
||||||
android:exported="true" android:process=":ui"
|
android:exported="true"
|
||||||
android:label="@string/pick_place_title"
|
android:label="@string/pick_place_title"
|
||||||
|
android:process=":ui"
|
||||||
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
|
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.android.gms.location.places.ui.PICK_PLACE" />
|
<action android:name="com.google.android.gms.location.places.ui.PICK_PLACE" />
|
||||||
|
@ -220,7 +223,8 @@
|
||||||
|
|
||||||
<!-- Cloud Messaging -->
|
<!-- Cloud Messaging -->
|
||||||
<service
|
<service
|
||||||
android:name="org.microg.gms.gcm.PushRegisterService">
|
android:name="org.microg.gms.gcm.PushRegisterService"
|
||||||
|
android:process=":persistent">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.android.c2dm.intent.REGISTER" />
|
<action android:name="com.google.android.c2dm.intent.REGISTER" />
|
||||||
<action android:name="com.google.android.c2dm.intent.UNREGISTER" />
|
<action android:name="com.google.android.c2dm.intent.UNREGISTER" />
|
||||||
|
@ -229,24 +233,33 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<receiver android:name="org.microg.gms.gcm.PushRegisterReceiver">
|
<receiver
|
||||||
|
android:name="org.microg.gms.gcm.PushRegisterReceiver"
|
||||||
|
android:process=":persistent">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.iid.TOKEN_REQUEST" />
|
<action android:name="com.google.iid.TOKEN_REQUEST" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<service android:name="org.microg.gms.gcm.McsService" />
|
<service
|
||||||
|
android:name="org.microg.gms.gcm.McsService"
|
||||||
|
android:process=":persistent" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name="org.microg.gms.gcm.SendReceiver">
|
android:name="org.microg.gms.gcm.SendReceiver"
|
||||||
|
android:process=":persistent">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.android.gcm.intent.SEND" />
|
<action android:name="com.google.android.gcm.intent.SEND" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver android:name="org.microg.gms.gcm.ServiceInfoReceiver" />
|
<receiver
|
||||||
|
android:name="org.microg.gms.gcm.ServiceInfoReceiver"
|
||||||
|
android:process=":persistent" />
|
||||||
|
|
||||||
<receiver android:name="org.microg.gms.gcm.TriggerReceiver">
|
<receiver
|
||||||
|
android:name="org.microg.gms.gcm.TriggerReceiver"
|
||||||
|
android:process=":persistent">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.AIRPLANE_MODE" />
|
<action android:name="android.intent.action.AIRPLANE_MODE" />
|
||||||
|
@ -267,7 +280,9 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver android:name="org.microg.gms.gcm.UnregisterReceiver">
|
<receiver
|
||||||
|
android:name="org.microg.gms.gcm.UnregisterReceiver"
|
||||||
|
android:process=":persistent">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
|
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
|
||||||
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
|
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
|
||||||
|
|
|
@ -21,9 +21,7 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL
|
||||||
|
|
||||||
public static CheckinPrefs get(Context context) {
|
public static CheckinPrefs get(Context context) {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
if (!context.getPackageName().equals(PackageUtils.getProcessName())) {
|
PackageUtils.warnIfNotMainProcess(context, CheckinPrefs.class);
|
||||||
Log.w("Preferences", CheckinPrefs.class.getName() + " initialized outside main process", new RuntimeException());
|
|
||||||
}
|
|
||||||
if (context == null) return new CheckinPrefs(null);
|
if (context == null) return new CheckinPrefs(null);
|
||||||
INSTANCE = new CheckinPrefs(context.getApplicationContext());
|
INSTANCE = new CheckinPrefs(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,7 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe
|
||||||
|
|
||||||
public static GcmPrefs get(Context context) {
|
public static GcmPrefs get(Context context) {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
if (!context.getPackageName().equals(PackageUtils.getProcessName())) {
|
PackageUtils.warnIfNotPersistentProcess(GcmPrefs.class);
|
||||||
Log.w("Preferences", GcmPrefs.class.getName() + " initialized outside main process", new RuntimeException());
|
|
||||||
}
|
|
||||||
if (context == null) return new GcmPrefs(null);
|
if (context == null) return new GcmPrefs(null);
|
||||||
INSTANCE = new GcmPrefs(context.getApplicationContext());
|
INSTANCE = new GcmPrefs(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,7 @@ public class SafetyNetPrefs implements SharedPreferences.OnSharedPreferenceChang
|
||||||
|
|
||||||
public static SafetyNetPrefs get(Context context) {
|
public static SafetyNetPrefs get(Context context) {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
if (!context.getPackageName().equals(PackageUtils.getProcessName())) {
|
PackageUtils.warnIfNotMainProcess(context, SafetyNetPrefs.class);
|
||||||
Log.w("Preferences", SafetyNetPrefs.class.getName() + " initialized outside main process", new RuntimeException());
|
|
||||||
}
|
|
||||||
if (context == null) return new SafetyNetPrefs(null);
|
if (context == null) return new SafetyNetPrefs(null);
|
||||||
INSTANCE = new SafetyNetPrefs(context.getApplicationContext());
|
INSTANCE = new SafetyNetPrefs(context.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,20 +21,34 @@
|
||||||
|
|
||||||
<!-- Exposure Notifications -->
|
<!-- Exposure Notifications -->
|
||||||
|
|
||||||
<service android:name="org.microg.gms.nearby.exposurenotification.ScannerService" />
|
<service
|
||||||
<service android:name="org.microg.gms.nearby.exposurenotification.AdvertiserService" />
|
android:name="org.microg.gms.nearby.exposurenotification.ScannerService"
|
||||||
<service android:name="org.microg.gms.nearby.exposurenotification.CleanupService" />
|
android:process=":persistent" />
|
||||||
<service android:name="org.microg.gms.nearby.exposurenotification.NotifyService" />
|
<service
|
||||||
|
android:name="org.microg.gms.nearby.exposurenotification.AdvertiserService"
|
||||||
|
android:process=":persistent" />
|
||||||
|
<service
|
||||||
|
android:name="org.microg.gms.nearby.exposurenotification.CleanupService"
|
||||||
|
android:process=":persistent" />
|
||||||
|
<service
|
||||||
|
android:name="org.microg.gms.nearby.exposurenotification.NotifyService"
|
||||||
|
android:process=":persistent" />
|
||||||
|
|
||||||
<service android:name="org.microg.gms.nearby.exposurenotification.ExposureNotificationService">
|
<service
|
||||||
|
android:name="org.microg.gms.nearby.exposurenotification.ExposureNotificationService"
|
||||||
|
android:process=":persistent">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.android.gms.nearby.exposurenotification.START" />
|
<action android:name="com.google.android.gms.nearby.exposurenotification.START" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<receiver android:name="org.microg.gms.nearby.exposurenotification.ServiceInfoReceiver" />
|
<receiver
|
||||||
|
android:name="org.microg.gms.nearby.exposurenotification.ServiceInfoReceiver"
|
||||||
|
android:process=":persistent" />
|
||||||
|
|
||||||
<receiver android:name="org.microg.gms.nearby.exposurenotification.ServiceTrigger">
|
<receiver
|
||||||
|
android:name="org.microg.gms.nearby.exposurenotification.ServiceTrigger"
|
||||||
|
android:process=":persistent">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
|
||||||
|
@ -46,8 +60,8 @@
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:authorities="${applicationId}.microg.exposure.export"
|
android:authorities="${applicationId}.microg.exposure.export"
|
||||||
android:grantUriPermissions="true"
|
android:exported="false"
|
||||||
android:exported="false">
|
android:grantUriPermissions="true">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/preferences_exposure_notifications_exportedfiles" />
|
android:resource="@xml/preferences_exposure_notifications_exportedfiles" />
|
||||||
|
|
|
@ -8,18 +8,14 @@ package org.microg.gms.nearby.exposurenotification
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.util.Log
|
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import org.microg.gms.common.PackageUtils
|
import org.microg.gms.common.PackageUtils
|
||||||
|
|
||||||
|
|
||||||
class ExposurePreferences(private val context: Context) {
|
class ExposurePreferences(private val context: Context) {
|
||||||
private var preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
private var preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (context.packageName != PackageUtils.getProcessName()) {
|
PackageUtils.warnIfNotPersistentProcess(ExposurePreferences::class.java)
|
||||||
Log.w("Preferences", ExposurePreferences::class.simpleName + " initialized outside main process", RuntimeException())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var enabled
|
var enabled
|
||||||
|
|
Loading…
Reference in a new issue