diff options
| author | Makoto Onuki <omakoto@google.com> | 2021-04-07 17:31:11 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-04-07 17:31:11 +0000 |
| commit | 779f120a91c38b718f97aeb027b26b24cbd86672 (patch) | |
| tree | 925d4cd0f8d977728d31fe06d5a4ed16c7b7afa1 /core/java/android | |
| parent | d05767a0afad7b30c7d7a44f5f5ed1d1af9e3854 (diff) | |
| parent | 9de6e4e26b993f438de77a1171a3cc989193e745 (diff) | |
Merge "Use descriptive exception for FGS start timeout" into sc-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 25 | ||||
| -rw-r--r-- | core/java/android/app/ForegroundServiceDidNotStartInTimeException.java | 33 | ||||
| -rw-r--r-- | core/java/android/app/IActivityManager.aidl | 2 | ||||
| -rw-r--r-- | core/java/android/app/IApplicationThread.aidl | 2 | ||||
| -rw-r--r-- | core/java/android/app/RemoteServiceException.java | 38 |
5 files changed, 90 insertions, 10 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index e596e7c2ab06..e50432eaa299 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -236,12 +236,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -final class RemoteServiceException extends AndroidRuntimeException { - public RemoteServiceException(String msg) { - super(msg); - } -} - /** * This manages the execution of the main thread in an * application process, scheduling and executing activities, @@ -1274,8 +1268,9 @@ public final class ActivityThread extends ClientTransactionHandler sendMessage(H.DISPATCH_PACKAGE_BROADCAST, packages, cmd); } - public void scheduleCrash(String msg) { - sendMessage(H.SCHEDULE_CRASH, msg); + @Override + public void scheduleCrash(String msg, int typeId) { + sendMessage(H.SCHEDULE_CRASH, msg, typeId); } public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken, @@ -1892,6 +1887,17 @@ 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 + throw new ForegroundServiceDidNotStartInTimeException(message); + case RemoteServiceException.TYPE_ID: // 0 + default: + throw new RemoteServiceException(message); + } + } + class H extends Handler { public static final int BIND_APPLICATION = 110; @UnsupportedAppUsage @@ -2105,7 +2111,8 @@ public final class ActivityThread extends ClientTransactionHandler Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); break; case SCHEDULE_CRASH: - throw new RemoteServiceException((String)msg.obj); + throwRemoteServiceException((String) msg.obj, msg.arg1); + break; case DUMP_HEAP: handleDumpHeap((DumpHeapData) msg.obj); break; diff --git a/core/java/android/app/ForegroundServiceDidNotStartInTimeException.java b/core/java/android/app/ForegroundServiceDidNotStartInTimeException.java new file mode 100644 index 000000000000..364291e69ad6 --- /dev/null +++ b/core/java/android/app/ForegroundServiceDidNotStartInTimeException.java @@ -0,0 +1,33 @@ +/* + * 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 1b8eb8add791..f9279da172a0 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -321,6 +321,8 @@ interface IActivityManager { 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 */ @UnsupportedAppUsage(maxTargetSdk = 29, publicAlternatives = "Use {@link android.content.ContentResolver#getType} public API instead.") diff --git a/core/java/android/app/IApplicationThread.aidl b/core/java/android/app/IApplicationThread.aidl index b5294d5b6f4e..78e7ce8c594e 100644 --- a/core/java/android/app/IApplicationThread.aidl +++ b/core/java/android/app/IApplicationThread.aidl @@ -106,7 +106,7 @@ oneway interface IApplicationThread { void scheduleOnNewActivityOptions(IBinder token, in Bundle options); void scheduleSuicide(); void dispatchPackageBroadcast(int cmd, in String[] packages); - void scheduleCrash(in String msg); + void scheduleCrash(in String msg, int typeId); void dumpHeap(boolean managed, boolean mallocInfo, boolean runGc, in String path, in ParcelFileDescriptor fd, in RemoteCallback finishCallback); void dumpActivity(in ParcelFileDescriptor fd, IBinder servicetoken, in String prefix, diff --git a/core/java/android/app/RemoteServiceException.java b/core/java/android/app/RemoteServiceException.java new file mode 100644 index 000000000000..4b32463e2996 --- /dev/null +++ b/core/java/android/app/RemoteServiceException.java @@ -0,0 +1,38 @@ +/* + * 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; + +import android.util.AndroidRuntimeException; + +/** + * Exception used by {@link ActivityThread} to crash an app process. + * + * @hide + */ +public class RemoteServiceException extends AndroidRuntimeException { + /** + * The type ID passed to {@link IApplicationThread#scheduleCrash}. + * + * Assign a unique ID to each subclass. See the above method for the numbers that are already + * taken. + */ + public static final int TYPE_ID = 0; + + public RemoteServiceException(String msg) { + super(msg); + } +} |
