From 805ea307e726e31a179a3ac9856b0588450bcc63 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 27 Jul 2016 12:25:54 -0700 Subject: [PATCH] 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 --- .../java/com/android/server/am/AppErrorDialog.java | 14 ++++---------- .../core/java/com/android/server/am/AppErrors.java | 8 ++++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/am/AppErrorDialog.java b/services/core/java/com/android/server/am/AppErrorDialog.java index e37feb2641551..646f6ce0653a1 100644 --- a/services/core/java/com/android/server/am/AppErrorDialog.java +++ b/services/core/java/com/android/server/am/AppErrorDialog.java @@ -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; } } diff --git a/services/core/java/com/android/server/am/AppErrors.java b/services/core/java/com/android/server/am/AppErrors.java index 5807502ef791f..1f156dfd19851 100644 --- a/services/core/java/com/android/server/am/AppErrors.java +++ b/services/core/java/com/android/server/am/AppErrors.java @@ -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