1 /* 2 * Copyright (C) 2024 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.exportimport; 18 19 import static com.android.healthfitness.flags.Flags.FLAG_EXPORT_IMPORT; 20 21 import android.annotation.FlaggedApi; 22 import android.annotation.IntDef; 23 import android.annotation.NonNull; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 30 /** 31 * Status for a data import. 32 * 33 * @hide 34 */ 35 @FlaggedApi(FLAG_EXPORT_IMPORT) 36 public final class ImportStatus implements Parcelable { 37 38 /** 39 * No error during the last data import. 40 * 41 * @hide 42 */ 43 public static final int DATA_IMPORT_ERROR_NONE = 0; 44 45 /** 46 * Unknown error during the last data import. 47 * 48 * @hide 49 */ 50 public static final int DATA_IMPORT_ERROR_UNKNOWN = 1; 51 52 /** 53 * Indicates that the last import failed because the user picked a file that was not exported by 54 * Health Connect. 55 * 56 * @hide 57 */ 58 public static final int DATA_IMPORT_ERROR_WRONG_FILE = 2; 59 60 /** 61 * Indicates that the last import failed because the version of the on device schema does not 62 * match the version of the imported database. 63 * 64 * @hide 65 */ 66 public static final int DATA_IMPORT_ERROR_VERSION_MISMATCH = 3; 67 68 /** @hide */ 69 @Retention(RetentionPolicy.SOURCE) 70 @IntDef({ 71 DATA_IMPORT_ERROR_NONE, 72 DATA_IMPORT_ERROR_UNKNOWN, 73 DATA_IMPORT_ERROR_WRONG_FILE, 74 DATA_IMPORT_ERROR_VERSION_MISMATCH 75 }) 76 public @interface DataImportError {} 77 78 @NonNull 79 public static final Creator<ImportStatus> CREATOR = 80 new Creator<>() { 81 @Override 82 public ImportStatus createFromParcel(Parcel in) { 83 return new ImportStatus(in); 84 } 85 86 @Override 87 public ImportStatus[] newArray(int size) { 88 return new ImportStatus[size]; 89 } 90 }; 91 92 @DataImportError private final int mDataImportError; 93 private final boolean mIsImportOngoing; 94 ImportStatus(@ataImportError int dataImportError, boolean isImportOngoing)95 public ImportStatus(@DataImportError int dataImportError, boolean isImportOngoing) { 96 mDataImportError = dataImportError; 97 mIsImportOngoing = isImportOngoing; 98 } 99 100 /** Returns the error status of the last import attempt. */ getDataImportError()101 public int getDataImportError() { 102 return mDataImportError; 103 } 104 105 /** Returns whether the import is ongoing. */ isImportOngoing()106 public boolean isImportOngoing() { 107 return mIsImportOngoing; 108 } 109 110 @Override describeContents()111 public int describeContents() { 112 return 0; 113 } 114 ImportStatus(@onNull Parcel in)115 private ImportStatus(@NonNull Parcel in) { 116 mDataImportError = in.readInt(); 117 mIsImportOngoing = in.readBoolean(); 118 } 119 120 @Override writeToParcel(@onNull Parcel dest, int flags)121 public void writeToParcel(@NonNull Parcel dest, int flags) { 122 dest.writeInt(mDataImportError); 123 dest.writeBoolean(mIsImportOngoing); 124 } 125 } 126