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