Debian Codegraph @

core/java/android/app/RemoteServiceException.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package android.app;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.ComponentName;
22 import android.os.Bundle;
23 import android.util.AndroidRuntimeException;
24
25 /**
26 * Exception used by {@link ActivityThread} to crash an app process for an unknown cause.
27 * An exception of this class is no longer supposed to be thrown. Instead, we use fine-grained
28 * sub-exceptions.
29 *
30 * Subclasses must be registered in
31 * {@link android.app.ActivityThread#throwRemoteServiceException(java.lang.String, int)}.
32 *
33 * @hide
34 */
35 public class RemoteServiceException extends AndroidRuntimeException {
36 public RemoteServiceException(String msg) {
37 super(msg);
38 }
39
40 public RemoteServiceException(String msg, Throwable cause) {
41 super(msg, cause);
42 }
43
44 /**
45 * Exception used to crash an app process when it didn't call {@link Service#startForeground}
46 * in time after the service was started with
47 * {@link android.content.Context#startForegroundService}.
48 *
49 * @hide
50 */
51 public static class ForegroundServiceDidNotStartInTimeException extends RemoteServiceException {
52 /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
53 public static final int TYPE_ID = 1;
54
55 private static final String KEY_SERVICE_CLASS_NAME = "serviceclassname";
56
57 public ForegroundServiceDidNotStartInTimeException(String msg, Throwable cause) {
58 super(msg, cause);
59 }
60
61 public static Bundle createExtrasForService(@NonNull ComponentName service) {
62 Bundle b = new Bundle();
63 b.putString(KEY_SERVICE_CLASS_NAME, service.getClassName());
64 return b;
65 }
66
67 @Nullable
68 public static String getServiceClassNameFromExtras(@Nullable Bundle extras) {
69 return (extras == null) ? null : extras.getString(KEY_SERVICE_CLASS_NAME);
70 }
71 }
72
73 /**
74 * Exception used to crash an app process when the system received a RemoteException
75 * while posting a notification of a foreground service.
76 *
77 * @hide
78 */
79 public static class CannotPostForegroundServiceNotificationException
80 extends RemoteServiceException {
81 /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
82 public static final int TYPE_ID = 2;
83
84 public CannotPostForegroundServiceNotificationException(String msg) {
85 super(msg);
86 }
87 }
88
89 /**
90 * Exception used to crash an app process when the system finds an error in a foreground service
91 * notification.
92 *
93 * @hide
94 */
95 public static class BadForegroundServiceNotificationException extends RemoteServiceException {
96 /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
97 public static final int TYPE_ID = 3;
98
99 public BadForegroundServiceNotificationException(String msg) {
100 super(msg);
101 }
102 }
103
104 /**
105 * Exception used to crash an app process when it calls a setting activity that requires
106 * the {@code REQUEST_PASSWORD_COMPLEXITY} permission.
107 *
108 * @hide
109 */
110 public static class MissingRequestPasswordComplexityPermissionException
111 extends RemoteServiceException {
112 /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
113 public static final int TYPE_ID = 4;
114
115 public MissingRequestPasswordComplexityPermissionException(String msg) {
116 super(msg);
117 }
118 }
119
120 /**
121 * Exception used to crash an app process by {@code adb shell am crash}.
122 *
123 * @hide
124 */
125 public static class CrashedByAdbException extends RemoteServiceException {
126 /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
127 public static final int TYPE_ID = 5;
128
129 public CrashedByAdbException(String msg) {
130 super(msg);
131 }
132 }
133 }