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 17 package android.health.connect; 18 19 import android.annotation.IntDef; 20 import android.annotation.Nullable; 21 22 import java.lang.annotation.Retention; 23 import java.lang.annotation.RetentionPolicy; 24 25 /** Class representing health connect exceptions. */ 26 public class HealthConnectException extends RuntimeException { 27 /** An unknown error occurred while processing the call. */ 28 public static final int ERROR_UNKNOWN = 1; 29 /** 30 * An internal error occurred which the caller cannot address. 31 * 32 * <p>This error may be considered similar to {@link IllegalStateException} 33 */ 34 public static final int ERROR_INTERNAL = 2; 35 /** 36 * The caller supplied invalid arguments to the call. 37 * 38 * <p>This error may be considered similar to {@link IllegalArgumentException}. 39 */ 40 public static final int ERROR_INVALID_ARGUMENT = 3; 41 /** 42 * An issue occurred reading or writing to storage. The call might succeed if repeated. 43 * 44 * <p>This error may be considered similar to {@link java.io.IOException}. 45 */ 46 public static final int ERROR_IO = 4; 47 /** 48 * The caller doesn't have the correct permissions for this call. 49 * 50 * <p>This error may be considered similar to {@link java.lang.SecurityException}. 51 */ 52 public static final int ERROR_SECURITY = 5; 53 /** 54 * An IPC related error occurred. 55 * 56 * <p>This error may be considered similar to {@link android.os.RemoteException}. 57 */ 58 public static final int ERROR_REMOTE = 6; 59 /** The caller exhausted the allotted rate limit. */ 60 public static final int ERROR_RATE_LIMIT_EXCEEDED = 7; 61 /** 62 * Data sync is in progress. Data read and writes are blocked. 63 * 64 * <p>Caller should try this api call again later. 65 */ 66 public static final int ERROR_DATA_SYNC_IN_PROGRESS = 8; 67 /** 68 * This operation is currently not supported by the platform. 69 * 70 * <p>Caller may try this api call again later. 71 */ 72 public static final int ERROR_UNSUPPORTED_OPERATION = 9; 73 74 @ErrorCode private final int mErrorCode; 75 76 /** 77 * Initializes an {@link HealthConnectException} with a result code and message. 78 * 79 * @param errorCode One of the constants documented in {@link HealthConnectException}. 80 * @param message The detailed error message. 81 * @hide 82 */ HealthConnectException(@rrorCode int errorCode, @Nullable String message)83 public HealthConnectException(@ErrorCode int errorCode, @Nullable String message) { 84 super(message); 85 mErrorCode = errorCode; 86 } 87 88 /** 89 * Initializes an {@link HealthConnectException} with a result code, message and the cause. 90 * 91 * @param errorCode One of the constants documented in {@link HealthConnectException}. 92 * @param message The detailed error message. 93 * @param cause The Throwable that caused the exception to happen. 94 * @hide 95 */ HealthConnectException( @rrorCode int errorCode, @Nullable String message, @Nullable Throwable cause)96 public HealthConnectException( 97 @ErrorCode int errorCode, @Nullable String message, @Nullable Throwable cause) { 98 super(message, cause); 99 mErrorCode = errorCode; 100 } 101 102 /** 103 * Initializes an {@link HealthConnectException} with a result code. 104 * 105 * @param errorCode One of the constants documented in {@link HealthConnectException}. 106 * @hide 107 */ HealthConnectException(@rrorCode int errorCode)108 public HealthConnectException(@ErrorCode int errorCode) { 109 this(errorCode, null); 110 } 111 getErrorCode()112 public int getErrorCode() { 113 return mErrorCode; 114 } 115 116 /** 117 * Error codes from {@link HealthConnectManager} methods. 118 * 119 * @hide 120 */ 121 @IntDef( 122 value = { 123 ERROR_UNKNOWN, 124 ERROR_INTERNAL, 125 ERROR_INVALID_ARGUMENT, 126 ERROR_IO, 127 ERROR_SECURITY, 128 ERROR_REMOTE, 129 ERROR_DATA_SYNC_IN_PROGRESS, 130 ERROR_RATE_LIMIT_EXCEEDED, 131 ERROR_UNSUPPORTED_OPERATION 132 }) 133 @Retention(RetentionPolicy.SOURCE) 134 public @interface ErrorCode {} 135 } 136