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.backuprestore; 18 19 import static com.android.healthfitness.flags.Flags.FLAG_CLOUD_BACKUP_AND_RESTORE; 20 21 import android.annotation.FlaggedApi; 22 import android.annotation.NonNull; 23 import android.annotation.SystemApi; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 27 import java.util.List; 28 import java.util.Objects; 29 30 /** 31 * Response for a {@link android.health.connect.HealthConnectManager#getChangesForBackup} call, 32 * which contains a paginated list of data to be backed up. 33 * 34 * @hide 35 */ 36 @FlaggedApi(FLAG_CLOUD_BACKUP_AND_RESTORE) 37 @SystemApi 38 public final class GetChangesForBackupResponse implements Parcelable { 39 40 // The version that the data is serialized with. 41 private final int mCurrentVersion; 42 43 @NonNull private final List<BackupChange> mChanges; 44 45 // The changeToken to be used for the next call to resume the backup. 46 @NonNull private final String mNextChangeToken; 47 48 /** 49 * @param currentVersion The version of the data contained in the response, with which the data 50 * is serialized. 51 * @param changes The changes to be backed up. 52 * @param nextChangeToken The change token to be used for the next call to resume the backup. 53 */ GetChangesForBackupResponse( int currentVersion, @NonNull List<BackupChange> changes, @NonNull String nextChangeToken)54 public GetChangesForBackupResponse( 55 int currentVersion, 56 @NonNull List<BackupChange> changes, 57 @NonNull String nextChangeToken) { 58 mCurrentVersion = currentVersion; 59 mChanges = changes; 60 mNextChangeToken = nextChangeToken; 61 } 62 GetChangesForBackupResponse(Parcel in)63 private GetChangesForBackupResponse(Parcel in) { 64 mCurrentVersion = in.readInt(); 65 mChanges = in.createTypedArrayList(BackupChange.CREATOR); 66 mNextChangeToken = in.readString(); 67 } 68 69 @Override equals(Object o)70 public boolean equals(Object o) { 71 if (this == o) return true; 72 if (!(o instanceof GetChangesForBackupResponse that)) return false; 73 return mCurrentVersion == that.mCurrentVersion 74 && mChanges.equals(that.mChanges) 75 && mNextChangeToken.equals(that.mNextChangeToken); 76 } 77 78 @Override hashCode()79 public int hashCode() { 80 return Objects.hash(mCurrentVersion, mChanges, mNextChangeToken); 81 } 82 83 @NonNull 84 public static final Creator<GetChangesForBackupResponse> CREATOR = 85 new Creator<>() { 86 @Override 87 public GetChangesForBackupResponse createFromParcel(Parcel in) { 88 return new GetChangesForBackupResponse(in); 89 } 90 91 @Override 92 public GetChangesForBackupResponse[] newArray(int size) { 93 return new GetChangesForBackupResponse[size]; 94 } 95 }; 96 97 /** 98 * The returned value should be passed to the {@link 99 * android.health.connect.HealthConnectManager#canRestore} call during restore. 100 * 101 * @return the version of the data, with which the data is serialized. 102 */ getCurrentVersion()103 public int getCurrentVersion() { 104 return mCurrentVersion; 105 } 106 107 /** 108 * @return the changes to be backed up. 109 */ 110 @NonNull getChanges()111 public List<BackupChange> getChanges() { 112 return mChanges; 113 } 114 115 /** 116 * Represents the pagination token to retrieve the next page of results. 117 * 118 * @return the change token to be used for the next call to resume the backup. 119 */ 120 @NonNull getNextChangeToken()121 public String getNextChangeToken() { 122 return mNextChangeToken; 123 } 124 125 @Override describeContents()126 public int describeContents() { 127 return 0; 128 } 129 130 @Override writeToParcel(@onNull Parcel dest, int flags)131 public void writeToParcel(@NonNull Parcel dest, int flags) { 132 dest.writeInt(mCurrentVersion); 133 dest.writeTypedList(mChanges); 134 dest.writeString(mNextChangeToken); 135 } 136 } 137