1 /*
2  * Copyright (C) 2022 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.adservices.ondevicepersonalization;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.IntRange;
21 
22 import com.android.adservices.ondevicepersonalization.flags.Flags;
23 
24 /**
25  * A class that an {@link IsolatedService} can use to signal a failure in handling a request and
26  * return an error to be logged and aggregated. The error is not reported to the app that invoked
27  * the {@link IsolatedService} in order to prevent data leakage from the {@link IsolatedService} to
28  * an app. The platform does not interpret the error code, it only logs and aggregates it.
29  */
30 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED)
31 public final class IsolatedServiceException extends Exception {
32     @IntRange(from = 1, to = 127) private final int mErrorCode;
33 
34     /**
35      * Creates an {@link IsolatedServiceException} with an error code to be logged. The meaning of
36      * the error code is defined by the {@link IsolatedService}. The platform does not interpret
37      * the error code.
38      *
39      * @param errorCode An error code defined by the {@link IsolatedService}.
40      */
IsolatedServiceException(@ntRangefrom = 1, to = 127) int errorCode)41     public IsolatedServiceException(@IntRange(from = 1, to = 127) int errorCode) {
42         super("IsolatedServiceException: Error " + errorCode);
43         mErrorCode = errorCode;
44     }
45 
46     /**
47      * Returns the error code for this exception.
48      * @hide
49      */
getErrorCode()50     public @IntRange(from = 1, to = 127) int getErrorCode() {
51         return mErrorCode;
52     }
53 }
54