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.IntDef; 21 22 import com.android.adservices.ondevicepersonalization.flags.Flags; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** 28 * Exception thrown by OnDevicePersonalization APIs. 29 * 30 */ 31 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED) 32 public class OnDevicePersonalizationException extends Exception { 33 /** 34 * The {@link IsolatedService} that was invoked failed to run. 35 */ 36 public static final int ERROR_ISOLATED_SERVICE_FAILED = 1; 37 38 /** 39 * The {@link IsolatedService} was not started because personalization is disabled by 40 * device configuration. 41 */ 42 public static final int ERROR_PERSONALIZATION_DISABLED = 2; 43 44 /** 45 * The ODP module was unable to load the {@link IsolatedService}. 46 * @hide 47 */ 48 public static final int ERROR_ISOLATED_SERVICE_LOADING_FAILED = 3; 49 50 /** 51 * The ODP specific manifest settings for the {@link IsolatedService} are either missing or 52 * misconfigured. 53 * @hide 54 */ 55 public static final int ERROR_ISOLATED_SERVICE_MANIFEST_PARSING_FAILED = 4; 56 57 /** 58 * The {@link IsolatedService} was invoked but timed out before returning successfully. 59 * @hide 60 */ 61 public static final int ERROR_ISOLATED_SERVICE_TIMEOUT = 5; 62 63 /** 64 * The {@link IsolatedService}'s output failed validation checks. 65 * @hide 66 */ 67 public static final int ERROR_OUTPUT_VALIDATION_FAILED = 6; 68 69 /** 70 * The {@link IsolatedService}'s call to {@link FederatedComputeScheduler} failed. 71 * @hide 72 */ 73 public static final int ERROR_ISOLATED_SERVICE_FAILED_TRAINING = 7; 74 75 /** @hide */ 76 @IntDef(prefix = "ERROR_", value = { 77 ERROR_ISOLATED_SERVICE_FAILED, 78 ERROR_PERSONALIZATION_DISABLED 79 }) 80 @Retention(RetentionPolicy.SOURCE) 81 public @interface ErrorCode {} 82 83 private final @ErrorCode int mErrorCode; 84 85 /** @hide */ OnDevicePersonalizationException(@rrorCode int errorCode)86 public OnDevicePersonalizationException(@ErrorCode int errorCode) { 87 mErrorCode = errorCode; 88 } 89 90 /** @hide */ OnDevicePersonalizationException( @rrorCode int errorCode, String message)91 public OnDevicePersonalizationException( 92 @ErrorCode int errorCode, String message) { 93 super(message); 94 mErrorCode = errorCode; 95 } 96 97 /** @hide */ OnDevicePersonalizationException( @rrorCode int errorCode, Throwable cause)98 public OnDevicePersonalizationException( 99 @ErrorCode int errorCode, Throwable cause) { 100 super(cause); 101 mErrorCode = errorCode; 102 } 103 104 /** Returns the error code for this exception. */ getErrorCode()105 public @ErrorCode int getErrorCode() { 106 return mErrorCode; 107 } 108 } 109