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

Commit 805ea307 authored by Adrian Roos's avatar Adrian Roos
Browse files

Allow restarting foreground services once

If a process is important to the user, even if it is not
hosting an activity, we'll allow it to be restarted once

Change-Id: I3e2997d1ebe87514e8ce71f81698241234487ed8
Fixes: 30250003
parent a0f07728
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -16,29 +16,22 @@

package com.android.server.am;

import android.app.ActivityManagerInternal;
import android.app.ActivityOptions;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.IPackageDataObserver;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.BidiFormatter;
import android.util.Slog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;

import java.util.List;

import static com.android.server.am.ActivityManagerService.IS_USER_BUILD;

final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListener {
@@ -47,7 +40,7 @@ final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListen
    private final AppErrorResult mResult;
    private final ProcessRecord mProc;
    private final boolean mRepeating;
    private final boolean mForeground;
    private final boolean mIsRestartable;

    private CharSequence mName;

@@ -74,7 +67,7 @@ final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListen
        mProc = data.proc;
        mResult = data.result;
        mRepeating = data.repeating;
        mForeground = data.task != null;
        mIsRestartable = data.task != null || data.isRestartableForService;
        BidiFormatter bidi = BidiFormatter.getInstance();

        if ((mProc.pkgList.size() == 1) &&
@@ -118,7 +111,7 @@ final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListen
        LayoutInflater.from(context).inflate(
                com.android.internal.R.layout.app_error_dialog, frame, true);

        boolean hasRestart = !mRepeating && mForeground;
        boolean hasRestart = !mRepeating && mIsRestartable;
        final boolean hasReceiver = mProc.errorReportReceiver != null;

        final TextView restart = (TextView) findViewById(com.android.internal.R.id.aerr_restart);
@@ -214,5 +207,6 @@ final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListen
        TaskRecord task;
        boolean repeating;
        ProcessRecord proc;
        boolean isRestartableForService;
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -627,12 +627,20 @@ class AppErrors {
            }
        }

        boolean procIsBoundForeground =
                (app.curProcState == ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
        // Bump up the crash count of any services currently running in the proc.
        for (int i=app.services.size()-1; i>=0; i--) {
            // Any services running in the application need to be placed
            // back in the pending list.
            ServiceRecord sr = app.services.valueAt(i);
            sr.crashCount++;

            // Allow restarting for started or bound foreground services that are crashing the
            // first time. This includes wallpapers.
            if (sr.crashCount <= 1 && (sr.isForeground || procIsBoundForeground)) {
                data.isRestartableForService = true;
            }
        }

        // If the crashing process is what we consider to be the "home process" and it has been