1 /* 2 * Copyright (C) 2023 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 package android.app; 17 18 import android.annotation.NonNull; 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Exception thrown when {@link Service#startForeground} is called on a service that's not 24 * actually started. 25 */ 26 public final class StartForegroundCalledOnStoppedServiceException 27 extends IllegalStateException implements Parcelable { 28 /** 29 * Constructor. 30 */ StartForegroundCalledOnStoppedServiceException(@onNull String message)31 public StartForegroundCalledOnStoppedServiceException(@NonNull String message) { 32 super(message); 33 } 34 StartForegroundCalledOnStoppedServiceException(@onNull Parcel source)35 StartForegroundCalledOnStoppedServiceException(@NonNull Parcel source) { 36 super(source.readString()); 37 } 38 39 @Override describeContents()40 public int describeContents() { 41 return 0; 42 } 43 44 @Override writeToParcel(@onNull Parcel dest, int flags)45 public void writeToParcel(@NonNull Parcel dest, int flags) { 46 dest.writeString(getMessage()); 47 } 48 49 public static final @NonNull Creator<StartForegroundCalledOnStoppedServiceException> 50 CREATOR = new Creator<StartForegroundCalledOnStoppedServiceException>() { 51 @NonNull 52 public StartForegroundCalledOnStoppedServiceException createFromParcel( 53 Parcel source) { 54 return new StartForegroundCalledOnStoppedServiceException(source); 55 } 56 57 @NonNull 58 public StartForegroundCalledOnStoppedServiceException[] newArray(int size) { 59 return new StartForegroundCalledOnStoppedServiceException[size]; 60 } 61 }; 62 } 63