summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2021-11-17 18:11:17 +0000
committerMakoto Onuki <omakoto@google.com>2021-11-17 18:18:24 +0000
commit543acbc321d699ccbc0cd2baa0447dd4a309f118 (patch)
tree04aeb87af4710c57121c543cdd2571ce596fc5d0 /core/java/android
parent68d184985b4101c65f2583dd8bc5505abe92b61c (diff)
parentabdd86b297820b88ef9f0402e31a93f18b7c5956 (diff)
Merge "Use different exceptions for different crash reasons" into sc-v2-dev am: 5dcf36ad8d am: abdd86b297
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16276394 Change-Id: I0b67b009bf110b56fdb86778213092f15e758fab
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/ActivityThread.java28
-rw-r--r--core/java/android/app/ForegroundServiceDidNotStartInTimeException.java33
-rw-r--r--core/java/android/app/IActivityManager.aidl2
-rw-r--r--core/java/android/app/RemoteServiceException.java103
4 files changed, 121 insertions, 45 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index ffa7cf18819e..c89e8b0f8d32 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -41,6 +41,12 @@ import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UptimeMillisLong;
+import android.app.RemoteServiceException.BadForegroundServiceNotificationException;
+import android.app.RemoteServiceException.CannotDeliverBroadcastException;
+import android.app.RemoteServiceException.CannotPostForegroundServiceNotificationException;
+import android.app.RemoteServiceException.CrashedByAdbException;
+import android.app.RemoteServiceException.ForegroundServiceDidNotStartInTimeException;
+import android.app.RemoteServiceException.MissingRequestPasswordComplexityPermissionException;
import android.app.assist.AssistContent;
import android.app.assist.AssistStructure;
import android.app.backup.BackupAgent;
@@ -1929,11 +1935,27 @@ public final class ActivityThread extends ClientTransactionHandler
private void throwRemoteServiceException(String message, int typeId) {
// Use a switch to ensure all the type IDs are unique.
switch (typeId) {
- case ForegroundServiceDidNotStartInTimeException.TYPE_ID: // 1
+ case ForegroundServiceDidNotStartInTimeException.TYPE_ID:
throw new ForegroundServiceDidNotStartInTimeException(message);
- case RemoteServiceException.TYPE_ID: // 0
+
+ case CannotDeliverBroadcastException.TYPE_ID:
+ throw new CannotDeliverBroadcastException(message);
+
+ case CannotPostForegroundServiceNotificationException.TYPE_ID:
+ throw new CannotPostForegroundServiceNotificationException(message);
+
+ case BadForegroundServiceNotificationException.TYPE_ID:
+ throw new BadForegroundServiceNotificationException(message);
+
+ case MissingRequestPasswordComplexityPermissionException.TYPE_ID:
+ throw new MissingRequestPasswordComplexityPermissionException(message);
+
+ case CrashedByAdbException.TYPE_ID:
+ throw new CrashedByAdbException(message);
+
default:
- throw new RemoteServiceException(message);
+ throw new RemoteServiceException(message
+ + " (with unwknown typeId:" + typeId + ")");
}
}
diff --git a/core/java/android/app/ForegroundServiceDidNotStartInTimeException.java b/core/java/android/app/ForegroundServiceDidNotStartInTimeException.java
deleted file mode 100644
index 364291e69ad6..000000000000
--- a/core/java/android/app/ForegroundServiceDidNotStartInTimeException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.app;
-
-/**
- * Exception used to crash an app process when it didn't call {@link Service#startForeground}
- * in time after the service was started with
- * {@link android.content.Context#startForegroundService}.
- *
- * @hide
- */
-public class ForegroundServiceDidNotStartInTimeException extends RemoteServiceException {
- /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
- public static final int TYPE_ID = 1;
-
- public ForegroundServiceDidNotStartInTimeException(String msg) {
- super(msg);
- }
-}
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index 853d5e83abad..8bb40590d069 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -330,8 +330,6 @@ interface IActivityManager {
void handleApplicationStrictModeViolation(in IBinder app, int penaltyMask,
in StrictMode.ViolationInfo crashInfo);
boolean isTopActivityImmersive();
- void crashApplication(int uid, int initialPid, in String packageName, int userId,
- in String message, boolean force);
void crashApplicationWithType(int uid, int initialPid, in String packageName, int userId,
in String message, boolean force, int exceptionTypeId);
/** @deprecated -- use getProviderMimeTypeAsync */
diff --git a/core/java/android/app/RemoteServiceException.java b/core/java/android/app/RemoteServiceException.java
index 4b32463e2996..1038530d92d3 100644
--- a/core/java/android/app/RemoteServiceException.java
+++ b/core/java/android/app/RemoteServiceException.java
@@ -19,20 +19,109 @@ package android.app;
import android.util.AndroidRuntimeException;
/**
- * Exception used by {@link ActivityThread} to crash an app process.
+ * Exception used by {@link ActivityThread} to crash an app process for an unknown cause.
+ * An exception of this class is no longer supposed to be thrown. Instead, we use fine-grained
+ * sub-exceptions.
+ *
+ * Subclasses must be registered in
+ * {@link android.app.ActivityThread#throwRemoteServiceException(java.lang.String, int)}.
*
* @hide
*/
public class RemoteServiceException extends AndroidRuntimeException {
+ public RemoteServiceException(String msg) {
+ super(msg);
+ }
+
/**
- * The type ID passed to {@link IApplicationThread#scheduleCrash}.
+ * Exception used to crash an app process when it didn't call {@link Service#startForeground}
+ * in time after the service was started with
+ * {@link android.content.Context#startForegroundService}.
*
- * Assign a unique ID to each subclass. See the above method for the numbers that are already
- * taken.
+ * @hide
*/
- public static final int TYPE_ID = 0;
+ public static class ForegroundServiceDidNotStartInTimeException extends RemoteServiceException {
+ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
+ public static final int TYPE_ID = 1;
- public RemoteServiceException(String msg) {
- super(msg);
+ public ForegroundServiceDidNotStartInTimeException(String msg) {
+ super(msg);
+ }
+ }
+
+ /**
+ * 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
+ * while posting a notification of a foreground service.
+ *
+ * @hide
+ */
+ public static class CannotPostForegroundServiceNotificationException
+ extends RemoteServiceException {
+ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
+ public static final int TYPE_ID = 3;
+
+ public CannotPostForegroundServiceNotificationException(String msg) {
+ super(msg);
+ }
+ }
+
+ /**
+ * Exception used to crash an app process when the system finds an error in a foreground service
+ * notification.
+ *
+ * @hide
+ */
+ public static class BadForegroundServiceNotificationException extends RemoteServiceException {
+ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
+ public static final int TYPE_ID = 4;
+
+ public BadForegroundServiceNotificationException(String msg) {
+ super(msg);
+ }
+ }
+
+ /**
+ * Exception used to crash an app process when it calls a setting activity that requires
+ * the {@code REQUEST_PASSWORD_COMPLEXITY} permission.
+ *
+ * @hide
+ */
+ public static class MissingRequestPasswordComplexityPermissionException
+ extends RemoteServiceException {
+ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
+ public static final int TYPE_ID = 5;
+
+ public MissingRequestPasswordComplexityPermissionException(String msg) {
+ super(msg);
+ }
+ }
+
+ /**
+ * Exception used to crash an app process by {@code adb shell am crash}.
+ *
+ * @hide
+ */
+ public static class CrashedByAdbException extends RemoteServiceException {
+ /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
+ public static final int TYPE_ID = 6;
+
+ public CrashedByAdbException(String msg) {
+ super(msg);
+ }
}
}