Introduce the ForegroundServiceTypeNotAllowedException
Bug: 254662240
Bug: 246792057
Test: CtsAppFgsTestCases from follow-up CLs
Change-Id: If2245681ed2d0ed76d956e3c5542bf99b287ba07
diff --git a/core/api/current.txt b/core/api/current.txt
index 05c9012..c56267f 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -5275,6 +5275,13 @@
field @NonNull public static final android.os.Parcelable.Creator<android.app.ForegroundServiceStartNotAllowedException> CREATOR;
}
+ public final class ForegroundServiceTypeNotAllowedException extends android.app.ServiceStartNotAllowedException implements android.os.Parcelable {
+ ctor public ForegroundServiceTypeNotAllowedException(@NonNull String);
+ method public int describeContents();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.app.ForegroundServiceTypeNotAllowedException> CREATOR;
+ }
+
@Deprecated public class Fragment implements android.content.ComponentCallbacks2 android.view.View.OnCreateContextMenuListener {
ctor @Deprecated public Fragment();
method @Deprecated public void dump(String, java.io.FileDescriptor, java.io.PrintWriter, String[]);
diff --git a/core/java/android/app/ForegroundServiceTypeNotAllowedException.java b/core/java/android/app/ForegroundServiceTypeNotAllowedException.java
new file mode 100644
index 0000000..c258242
--- /dev/null
+++ b/core/java/android/app/ForegroundServiceTypeNotAllowedException.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2022 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.annotation.NonNull;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * Exception thrown when an app tries to start a foreground {@link Service} without a valid type.
+ */
+public final class ForegroundServiceTypeNotAllowedException
+ extends ServiceStartNotAllowedException implements Parcelable {
+ /**
+ * Constructor.
+ */
+ public ForegroundServiceTypeNotAllowedException(@NonNull String message) {
+ super(message);
+ }
+
+ ForegroundServiceTypeNotAllowedException(@NonNull Parcel source) {
+ super(source.readString());
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeString(getMessage());
+ }
+
+ public static final @NonNull Creator<android.app.ForegroundServiceTypeNotAllowedException>
+ CREATOR = new Creator<android.app.ForegroundServiceTypeNotAllowedException>() {
+ @NonNull
+ public android.app.ForegroundServiceTypeNotAllowedException createFromParcel(
+ Parcel source) {
+ return new android.app.ForegroundServiceTypeNotAllowedException(source);
+ }
+
+ @NonNull
+ public android.app.ForegroundServiceTypeNotAllowedException[] newArray(int size) {
+ return new android.app.ForegroundServiceTypeNotAllowedException[size];
+ }
+ };
+}