Search in sources :

Example 61 with RunningAppProcessInfo

use of android.app.ActivityManager.RunningAppProcessInfo in project fdroidclient by f-droid.

the class FDroidApp method isAcraProcess.

/**
 * Asks if the current process is "org.fdroid.fdroid:acra".
 * <p>
 * This is helpful for bailing out of the {@link FDroidApp#onCreate} method early, preventing
 * problems that arise from executing the code twice. This happens due to the `android:process`
 * statement in AndroidManifest.xml causes another process to be created to run
 * {@link org.fdroid.fdroid.acra.CrashReportActivity}. This was causing lots of things to be
 * started/run twice including {@link CleanCacheWorker} and {@link WifiStateChangeService}.
 * <p>
 * Note that it is not perfect, because some devices seem to not provide a list of running app
 * processes when asked. In such situations, F-Droid may regress to the behaviour where some
 * services may run twice and thus cause weirdness or slowness. However that is probably better
 * for end users than experiencing a deterministic crash every time F-Droid is started.
 */
private boolean isAcraProcess() {
    ActivityManager manager = ContextCompat.getSystemService(this, ActivityManager.class);
    List<RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
    if (processes == null) {
        return false;
    }
    int pid = android.os.Process.myPid();
    for (RunningAppProcessInfo processInfo : processes) {
        if (processInfo.pid == pid && ACRA_ID.equals(processInfo.processName)) {
            return true;
        }
    }
    return false;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager)

Aggregations

RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)61 ActivityManager (android.app.ActivityManager)52 ArrayList (java.util.ArrayList)9 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)8 IOException (java.io.IOException)8 IActivityManager (android.app.IActivityManager)6 Context (android.content.Context)6 Build (android.os.Build)6 RemoteException (android.os.RemoteException)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 Fingerprint (android.hardware.fingerprint.Fingerprint)5 MemoryInfo (android.os.Debug.MemoryInfo)5 SuppressLint (android.annotation.SuppressLint)4 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)4 TestCrashException (com.microsoft.appcenter.crashes.model.TestCrashException)4 Device (com.microsoft.appcenter.ingestion.models.Device)4