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 19 import android.annotation.SystemApi; 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 */ 32 @SystemApi 33 public 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 toString()56 public String toString() { 57 return "RestoreDescription{" + mPackageName + " : " 58 + ((mDataType == TYPE_KEY_VALUE) ? "KEY_VALUE" : "STREAM") 59 + '}'; 60 } 61 62 // --------------------------------------- 63 // API 64 RestoreDescription(String packageName, int dataType)65 public RestoreDescription(String packageName, int dataType) { 66 mPackageName = packageName; 67 mDataType = dataType; 68 } 69 getPackageName()70 public String getPackageName() { 71 return mPackageName; 72 } 73 getDataType()74 public int getDataType() { 75 return mDataType; 76 } 77 78 // --------------------------------------- 79 // Parcelable implementation - not used by transport 80 81 @Override describeContents()82 public int describeContents() { 83 return 0; 84 } 85 86 @Override writeToParcel(Parcel out, int flags)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 RestoreDescription(Parcel in)106 private RestoreDescription(Parcel in) { 107 mPackageName = in.readString(); 108 mDataType = in.readInt(); 109 } 110 } 111