Christopher Tate | 6a49dd0 | 2014-06-16 18:49:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Christopher Tate | d5cf722 | 2014-07-29 16:53:09 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Christopher Tate | 6a49dd0 | 2014-06-16 18:49:25 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | /** |
| 24 | * Description of the available restore data for a given package. Returned by a |
| 25 | * BackupTransport in response to a request about the next available restorable |
| 26 | * package. |
| 27 | * |
| 28 | * @see BackupTransport#nextRestorePackage() |
| 29 | * |
| 30 | * @hide |
| 31 | */ |
Christopher Tate | d5cf722 | 2014-07-29 16:53:09 -0700 | [diff] [blame] | 32 | @SystemApi |
Christopher Tate | 6a49dd0 | 2014-06-16 18:49:25 -0700 | [diff] [blame] | 33 | public class RestoreDescription implements Parcelable { |
| 34 | private final String mPackageName; |
| 35 | private final int mDataType; |
| 36 | |
Robert Berry | c4dd18c | 2017-07-06 13:04:47 +0100 | [diff] [blame] | 37 | private static final String NO_MORE_PACKAGES_SENTINEL = "NO_MORE_PACKAGES"; |
Christopher Tate | 6a49dd0 | 2014-06-16 18:49:25 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Return this constant RestoreDescription from BackupTransport.nextRestorePackage() |
| 41 | * to indicate that no more package data is available in the current restore operation. |
| 42 | */ |
| 43 | public static final RestoreDescription NO_MORE_PACKAGES = |
| 44 | new RestoreDescription(NO_MORE_PACKAGES_SENTINEL, 0); |
| 45 | |
| 46 | // --------------------------------------- |
| 47 | // Data type identifiers |
| 48 | |
| 49 | /** This package's restore data is an original-style key/value dataset */ |
| 50 | public static final int TYPE_KEY_VALUE = 1; |
| 51 | |
| 52 | /** This package's restore data is a tarball-type full data stream */ |
| 53 | public static final int TYPE_FULL_STREAM = 2; |
| 54 | |
Christopher Tate | 51fea57 | 2014-06-23 17:01:06 -0700 | [diff] [blame] | 55 | @Override |
| 56 | public String toString() { |
| 57 | return "RestoreDescription{" + mPackageName + " : " |
| 58 | + ((mDataType == TYPE_KEY_VALUE) ? "KEY_VALUE" : "STREAM") |
| 59 | + '}'; |
| 60 | } |
| 61 | |
Christopher Tate | 6a49dd0 | 2014-06-16 18:49:25 -0700 | [diff] [blame] | 62 | // --------------------------------------- |
| 63 | // API |
| 64 | |
| 65 | public RestoreDescription(String packageName, int dataType) { |
| 66 | mPackageName = packageName; |
| 67 | mDataType = dataType; |
| 68 | } |
| 69 | |
| 70 | public String getPackageName() { |
| 71 | return mPackageName; |
| 72 | } |
| 73 | |
| 74 | public int getDataType() { |
| 75 | return mDataType; |
| 76 | } |
| 77 | |
| 78 | // --------------------------------------- |
| 79 | // Parcelable implementation - not used by transport |
| 80 | |
| 81 | @Override |
| 82 | public int describeContents() { |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void writeToParcel(Parcel out, int flags) { |
| 88 | out.writeString(mPackageName); |
| 89 | out.writeInt(mDataType); |
| 90 | } |
| 91 | |
| 92 | public static final Parcelable.Creator<RestoreDescription> CREATOR |
| 93 | = new Parcelable.Creator<RestoreDescription>() { |
| 94 | public RestoreDescription createFromParcel(Parcel in) { |
| 95 | final RestoreDescription unparceled = new RestoreDescription(in); |
| 96 | return (NO_MORE_PACKAGES_SENTINEL.equals(unparceled.mPackageName)) |
| 97 | ? NO_MORE_PACKAGES |
| 98 | : unparceled; |
| 99 | } |
| 100 | |
| 101 | public RestoreDescription[] newArray(int size) { |
| 102 | return new RestoreDescription[size]; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | private RestoreDescription(Parcel in) { |
| 107 | mPackageName = in.readString(); |
| 108 | mDataType = in.readInt(); |
| 109 | } |
| 110 | } |