Merge "Stop using CannotDeliverBroadcastException" into tm-qpr-dev

This commit is contained in:
Li Li
2022-11-23 00:52:57 +00:00
committed by Android (Google) Code Review
4 changed files with 27 additions and 35 deletions

View File

@@ -40,7 +40,6 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PACK
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.RemoteServiceException.BadForegroundServiceNotificationException; import android.app.RemoteServiceException.BadForegroundServiceNotificationException;
import android.app.RemoteServiceException.CannotDeliverBroadcastException;
import android.app.RemoteServiceException.CannotPostForegroundServiceNotificationException; import android.app.RemoteServiceException.CannotPostForegroundServiceNotificationException;
import android.app.RemoteServiceException.CrashedByAdbException; import android.app.RemoteServiceException.CrashedByAdbException;
import android.app.RemoteServiceException.ForegroundServiceDidNotStartInTimeException; import android.app.RemoteServiceException.ForegroundServiceDidNotStartInTimeException;
@@ -1975,9 +1974,6 @@ public final class ActivityThread extends ClientTransactionHandler
case ForegroundServiceDidNotStartInTimeException.TYPE_ID: case ForegroundServiceDidNotStartInTimeException.TYPE_ID:
throw generateForegroundServiceDidNotStartInTimeException(message, extras); throw generateForegroundServiceDidNotStartInTimeException(message, extras);
case CannotDeliverBroadcastException.TYPE_ID:
throw new CannotDeliverBroadcastException(message);
case CannotPostForegroundServiceNotificationException.TYPE_ID: case CannotPostForegroundServiceNotificationException.TYPE_ID:
throw new CannotPostForegroundServiceNotificationException(message); throw new CannotPostForegroundServiceNotificationException(message);

View File

@@ -407,6 +407,15 @@ public final class ApplicationExitInfo implements Parcelable {
*/ */
public static final int SUBREASON_PACKAGE_UPDATE = 25; public static final int SUBREASON_PACKAGE_UPDATE = 25;
/**
* The process was killed because of undelivered broadcasts; this would be set only when the
* reason is {@link #REASON_OTHER}.
*
* For internal use only.
* @hide
*/
public static final int SUBREASON_UNDELIVERED_BROADCAST = 26;
// If there is any OEM code which involves additional app kill reasons, it should // If there is any OEM code which involves additional app kill reasons, it should
// be categorized in {@link #REASON_OTHER}, with subreason code starting from 1000. // be categorized in {@link #REASON_OTHER}, with subreason code starting from 1000.
@@ -579,6 +588,7 @@ public final class ApplicationExitInfo implements Parcelable {
SUBREASON_STOP_APP, SUBREASON_STOP_APP,
SUBREASON_KILL_BACKGROUND, SUBREASON_KILL_BACKGROUND,
SUBREASON_PACKAGE_UPDATE, SUBREASON_PACKAGE_UPDATE,
SUBREASON_UNDELIVERED_BROADCAST,
}) })
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface SubReason {} public @interface SubReason {}
@@ -1283,6 +1293,8 @@ public final class ApplicationExitInfo implements Parcelable {
return "KILL BACKGROUND"; return "KILL BACKGROUND";
case SUBREASON_PACKAGE_UPDATE: case SUBREASON_PACKAGE_UPDATE:
return "PACKAGE UPDATE"; return "PACKAGE UPDATE";
case SUBREASON_UNDELIVERED_BROADCAST:
return "UNDELIVERED BROADCAST";
default: default:
return "UNKNOWN"; return "UNKNOWN";
} }

View File

@@ -70,21 +70,6 @@ public class RemoteServiceException extends AndroidRuntimeException {
} }
} }
/**
* Exception used to crash an app process when the system received a RemoteException
* while delivering a broadcast to an app process.
*
* @hide
*/
public static class CannotDeliverBroadcastException extends RemoteServiceException {
/** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
public static final int TYPE_ID = 2;
public CannotDeliverBroadcastException(String msg) {
super(msg);
}
}
/** /**
* Exception used to crash an app process when the system received a RemoteException * Exception used to crash an app process when the system received a RemoteException
* while posting a notification of a foreground service. * while posting a notification of a foreground service.
@@ -94,7 +79,7 @@ public class RemoteServiceException extends AndroidRuntimeException {
public static class CannotPostForegroundServiceNotificationException public static class CannotPostForegroundServiceNotificationException
extends RemoteServiceException { extends RemoteServiceException {
/** The type ID passed to {@link IApplicationThread#scheduleCrash}. */ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
public static final int TYPE_ID = 3; public static final int TYPE_ID = 2;
public CannotPostForegroundServiceNotificationException(String msg) { public CannotPostForegroundServiceNotificationException(String msg) {
super(msg); super(msg);
@@ -109,7 +94,7 @@ public class RemoteServiceException extends AndroidRuntimeException {
*/ */
public static class BadForegroundServiceNotificationException extends RemoteServiceException { public static class BadForegroundServiceNotificationException extends RemoteServiceException {
/** The type ID passed to {@link IApplicationThread#scheduleCrash}. */ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
public static final int TYPE_ID = 4; public static final int TYPE_ID = 3;
public BadForegroundServiceNotificationException(String msg) { public BadForegroundServiceNotificationException(String msg) {
super(msg); super(msg);
@@ -125,7 +110,7 @@ public class RemoteServiceException extends AndroidRuntimeException {
public static class MissingRequestPasswordComplexityPermissionException public static class MissingRequestPasswordComplexityPermissionException
extends RemoteServiceException { extends RemoteServiceException {
/** The type ID passed to {@link IApplicationThread#scheduleCrash}. */ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
public static final int TYPE_ID = 5; public static final int TYPE_ID = 4;
public MissingRequestPasswordComplexityPermissionException(String msg) { public MissingRequestPasswordComplexityPermissionException(String msg) {
super(msg); super(msg);
@@ -139,7 +124,7 @@ public class RemoteServiceException extends AndroidRuntimeException {
*/ */
public static class CrashedByAdbException extends RemoteServiceException { public static class CrashedByAdbException extends RemoteServiceException {
/** The type ID passed to {@link IApplicationThread#scheduleCrash}. */ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
public static final int TYPE_ID = 6; public static final int TYPE_ID = 5;
public CrashedByAdbException(String msg) { public CrashedByAdbException(String msg) {
super(msg); super(msg);

View File

@@ -45,10 +45,10 @@ import android.annotation.Nullable;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.AppGlobals; import android.app.AppGlobals;
import android.app.AppOpsManager; import android.app.AppOpsManager;
import android.app.ApplicationExitInfo;
import android.app.BroadcastOptions; import android.app.BroadcastOptions;
import android.app.IApplicationThread; import android.app.IApplicationThread;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.RemoteServiceException.CannotDeliverBroadcastException;
import android.app.usage.UsageEvents.Event; import android.app.usage.UsageEvents.Event;
import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal;
import android.content.ComponentName; import android.content.ComponentName;
@@ -665,18 +665,14 @@ public final class BroadcastQueue {
thread.scheduleRegisteredReceiver(receiver, intent, resultCode, thread.scheduleRegisteredReceiver(receiver, intent, resultCode,
data, extras, ordered, sticky, sendingUser, data, extras, ordered, sticky, sendingUser,
app.mState.getReportedProcState()); app.mState.getReportedProcState());
// TODO: Uncomment this when (b/28322359) is fixed and we aren't getting
// DeadObjectException when the process isn't actually dead.
//} catch (DeadObjectException ex) {
// Failed to call into the process. It's dying so just let it die and move on.
// throw ex;
} catch (RemoteException ex) { } catch (RemoteException ex) {
// Failed to call into the process. It's either dying or wedged. Kill it gently. // Failed to call into the process. It's either dying or wedged. Kill it gently.
synchronized (mService) { synchronized (mService) {
Slog.w(TAG, "Can't deliver broadcast to " + app.processName final String msg = "Failed to schedule " + intent + " to " + receiver
+ " (pid " + app.getPid() + "). Crashing it."); + " via " + app + ": " + ex;
app.scheduleCrashLocked("can't deliver broadcast", Slog.w(TAG, msg);
CannotDeliverBroadcastException.TYPE_ID, /* extras=*/ null); app.killLocked("Can't deliver broadcast", ApplicationExitInfo.REASON_OTHER,
ApplicationExitInfo.SUBREASON_UNDELIVERED_BROADCAST, true);
} }
throw ex; throw ex;
} }
@@ -1890,8 +1886,11 @@ public final class BroadcastQueue {
processCurBroadcastLocked(r, app); processCurBroadcastLocked(r, app);
return; return;
} catch (RemoteException e) { } catch (RemoteException e) {
Slog.w(TAG, "Exception when sending broadcast to " final String msg = "Failed to schedule " + r.intent + " to " + info
+ r.curComponent, e); + " via " + app + ": " + e;
Slog.w(TAG, msg);
app.killLocked("Can't deliver broadcast", ApplicationExitInfo.REASON_OTHER,
ApplicationExitInfo.SUBREASON_UNDELIVERED_BROADCAST, true);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Slog.wtf(TAG, "Failed sending broadcast to " Slog.wtf(TAG, "Failed sending broadcast to "
+ r.curComponent + " with " + r.intent, e); + r.curComponent + " with " + r.intent, e);