Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit f0337b5d authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Move EN and GCM service in persistent subprocess

This increases stability/durability of these services in case of crashes
parent 6d423bb8
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -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 {
+25 −10
Original line number Diff line number Diff line
@@ -108,10 +108,10 @@
        tools:ignore="ProtectedPermissions" />

    <application
        android:forceQueryable="true"
        android:name="androidx.multidex.MultiDexApplication"
        android:allowBackup="false"
        android:extractNativeLibs="false"
        android:forceQueryable="true"
        android:icon="@mipmap/ic_core_service_app"
        android:label="@string/gms_app_name"
        android:theme="@style/Theme.AppCompat.DayNight">
@@ -128,12 +128,15 @@

        <!-- Location -->

        <activity android:name="org.microg.nlp.ui.BackendSettingsActivity" android:process=":ui" />
        <activity
            android:name="org.microg.nlp.ui.BackendSettingsActivity"
            android:process=":ui" />

        <activity
            android:name="org.microg.gms.ui.PlacePickerActivity"
            android:exported="true" android:process=":ui"
            android:exported="true"
            android:label="@string/pick_place_title"
            android:process=":ui"
            android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
            <intent-filter>
                <action android:name="com.google.android.gms.location.places.ui.PICK_PLACE" />
@@ -220,7 +223,8 @@

        <!-- Cloud Messaging -->
        <service
            android:name="org.microg.gms.gcm.PushRegisterService">
            android:name="org.microg.gms.gcm.PushRegisterService"
            android:process=":persistent">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTER" />
                <action android:name="com.google.android.c2dm.intent.UNREGISTER" />
@@ -229,24 +233,33 @@
            </intent-filter>
        </service>

        <receiver android:name="org.microg.gms.gcm.PushRegisterReceiver">
        <receiver
            android:name="org.microg.gms.gcm.PushRegisterReceiver"
            android:process=":persistent">
            <intent-filter>
                <action android:name="com.google.iid.TOKEN_REQUEST" />
            </intent-filter>
        </receiver>

        <service android:name="org.microg.gms.gcm.McsService" />
        <service
            android:name="org.microg.gms.gcm.McsService"
            android:process=":persistent" />

        <receiver
            android:name="org.microg.gms.gcm.SendReceiver">
            android:name="org.microg.gms.gcm.SendReceiver"
            android:process=":persistent">
            <intent-filter>
                <action android:name="com.google.android.gcm.intent.SEND" />
            </intent-filter>
        </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>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.AIRPLANE_MODE" />
@@ -267,7 +280,9 @@
            </intent-filter>
        </receiver>

        <receiver android:name="org.microg.gms.gcm.UnregisterReceiver">
        <receiver
            android:name="org.microg.gms.gcm.UnregisterReceiver"
            android:process=":persistent">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
                <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
+1 −3
Original line number Diff line number Diff line
@@ -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());
        }
+1 −3
Original line number Diff line number Diff line
@@ -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());
        }
+1 −3
Original line number Diff line number Diff line
@@ -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());
        }
Loading