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
17package android.app.backup;
18
19import android.annotation.SystemApi;
20import android.os.Parcel;
21import 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 */
32@SystemApi
33public class RestoreDescription implements Parcelable {
34    private final String mPackageName;
35    private final int mDataType;
36
37    private static final String NO_MORE_PACKAGES_SENTINEL = "";
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
55    @Override
56    public String toString() {
57        return "RestoreDescription{" + mPackageName + " : "
58                + ((mDataType == TYPE_KEY_VALUE) ? "KEY_VALUE" : "STREAM")
59                + '}';
60    }
61
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}
111