| 1 | /* |
| 2 | * Copyright (C) 2009 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.app.backup; |
| 18 | |
| 19 | import android.annotation.Nullable; |
| 20 | import android.annotation.SystemApi; |
| 21 | import android.app.backup.BackupAgent.BackupTransportFlags; |
| 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | |
| 25 | /** |
| 26 | * Descriptive information about a set of backed-up app data available for restore. |
| 27 | * Used by IRestoreSession clients. |
| 28 | * |
| 29 | * @hide |
| 30 | */ |
| 31 | @SystemApi |
| 32 | public class RestoreSet implements Parcelable { |
| 33 | /** |
| 34 | * Name of this restore set. May be user generated, may simply be the name |
| 35 | * of the handset model, e.g. "T-Mobile G1". |
| 36 | */ |
| 37 | @Nullable |
| 38 | public String name; |
| 39 | |
| 40 | /** |
| 41 | * Identifier of the device whose data this is. This will be as unique as |
| 42 | * is practically possible; for example, it might be an IMEI. |
| 43 | */ |
| 44 | @Nullable |
| 45 | public String device; |
| 46 | |
| 47 | /** |
| 48 | * Token that identifies this backup set unambiguously to the backup/restore |
| 49 | * transport. This is guaranteed to be valid for the duration of a restore |
| 50 | * session, but is meaningless once the session has ended. |
| 51 | */ |
| 52 | public long token; |
| 53 | |
| 54 | /** |
| 55 | * Properties of the {@link BackupTransport} transport that was used to obtain the data in |
| 56 | * this restore set. |
| 57 | */ |
| 58 | @BackupTransportFlags |
| 59 | public final int backupTransportFlags; |
| 60 | |
| 61 | /** |
| 62 | * Constructs a RestoreSet object that identifies a set of data that can be restored. |
| 63 | */ |
| 64 | public RestoreSet() { |
| 65 | // Leave everything zero / null |
| 66 | backupTransportFlags = 0; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Constructs a RestoreSet object that identifies a set of data that can be restored. |
| 71 | * |
| 72 | * @param name The name of the restore set. |
| 73 | * @param device The name of the device where the restore data is coming from. |
| 74 | * @param token The unique identifier for the current restore set. |
| 75 | */ |
| 76 | public RestoreSet(@Nullable String name, @Nullable String device, long token) { |
| 77 | this(name, device, token, /* backupTransportFlags */ 0); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Constructs a RestoreSet object that identifies a set of data that can be restored. |
| 82 | * |
| 83 | * @param name The name of the restore set. |
| 84 | * @param device The name of the device where the restore data is coming from. |
| 85 | * @param token The unique identifier for the current restore set. |
| 86 | * @param backupTransportFlags Flags returned by {@link BackupTransport#getTransportFlags()} |
| 87 | * implementation of the backup transport used by the source device |
| 88 | * to create this restore set. See {@link BackupAgent} for possible |
| 89 | * flag values. |
| 90 | */ |
| 91 | public RestoreSet(@Nullable String name, @Nullable String device, long token, |
| 92 | @BackupTransportFlags int backupTransportFlags) { |
| 93 | this.name = name; |
| 94 | this.device = device; |
| 95 | this.token = token; |
| 96 | this.backupTransportFlags = backupTransportFlags; |
| 97 | } |
| 98 | |
| 99 | // Parcelable implementation |
| 100 | public int describeContents() { |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | public void writeToParcel(Parcel out, int flags) { |
| 105 | out.writeString(name); |
| 106 | out.writeString(device); |
| 107 | out.writeLong(token); |
| 108 | out.writeInt(backupTransportFlags); |
| 109 | } |
| 110 | |
| 111 | public static final @android.annotation.NonNull Parcelable.Creator<RestoreSet> CREATOR |
| 112 | = new Parcelable.Creator<RestoreSet>() { |
| 113 | public RestoreSet createFromParcel(Parcel in) { |
| 114 | return new RestoreSet(in); |
| 115 | } |
| 116 | |
| 117 | public RestoreSet[] newArray(int size) { |
| 118 | return new RestoreSet[size]; |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | private RestoreSet(Parcel in) { |
| 123 | name = in.readString(); |
| 124 | device = in.readString(); |
| 125 | token = in.readLong(); |
| 126 | backupTransportFlags = in.readInt(); |
| 127 | } |
| 128 | } |