16a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate/* 26a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * Copyright (C) 2014 The Android Open Source Project 36a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * 46a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * Licensed under the Apache License, Version 2.0 (the "License"); 56a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * you may not use this file except in compliance with the License. 66a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * You may obtain a copy of the License at 76a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * 86a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * http://www.apache.org/licenses/LICENSE-2.0 96a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * 106a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * Unless required by applicable law or agreed to in writing, software 116a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * distributed under the License is distributed on an "AS IS" BASIS, 126a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * See the License for the specific language governing permissions and 146a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * limitations under the License. 156a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate */ 166a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 176a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tatepackage android.app.backup; 186a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 19d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tateimport android.annotation.SystemApi; 206a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tateimport android.os.Parcel; 216a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tateimport android.os.Parcelable; 226a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 236a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate/** 246a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * Description of the available restore data for a given package. Returned by a 256a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * BackupTransport in response to a request about the next available restorable 266a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * package. 276a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * 286a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * @see BackupTransport#nextRestorePackage() 296a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * 306a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * @hide 316a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate */ 32d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate@SystemApi 336a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tatepublic class RestoreDescription implements Parcelable { 346a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate private final String mPackageName; 356a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate private final int mDataType; 366a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 376a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate private static final String NO_MORE_PACKAGES_SENTINEL = ""; 386a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 396a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate /** 406a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * Return this constant RestoreDescription from BackupTransport.nextRestorePackage() 416a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate * to indicate that no more package data is available in the current restore operation. 426a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate */ 436a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public static final RestoreDescription NO_MORE_PACKAGES = 446a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate new RestoreDescription(NO_MORE_PACKAGES_SENTINEL, 0); 456a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 466a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate // --------------------------------------- 476a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate // Data type identifiers 486a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 496a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate /** This package's restore data is an original-style key/value dataset */ 506a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public static final int TYPE_KEY_VALUE = 1; 516a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 526a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate /** This package's restore data is a tarball-type full data stream */ 536a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public static final int TYPE_FULL_STREAM = 2; 546a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 5551fea57e06fcb1dab1d239a5fff6e75ba2b7cee7Christopher Tate @Override 5651fea57e06fcb1dab1d239a5fff6e75ba2b7cee7Christopher Tate public String toString() { 5751fea57e06fcb1dab1d239a5fff6e75ba2b7cee7Christopher Tate return "RestoreDescription{" + mPackageName + " : " 5851fea57e06fcb1dab1d239a5fff6e75ba2b7cee7Christopher Tate + ((mDataType == TYPE_KEY_VALUE) ? "KEY_VALUE" : "STREAM") 5951fea57e06fcb1dab1d239a5fff6e75ba2b7cee7Christopher Tate + '}'; 6051fea57e06fcb1dab1d239a5fff6e75ba2b7cee7Christopher Tate } 6151fea57e06fcb1dab1d239a5fff6e75ba2b7cee7Christopher Tate 626a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate // --------------------------------------- 636a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate // API 646a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 656a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public RestoreDescription(String packageName, int dataType) { 666a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate mPackageName = packageName; 676a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate mDataType = dataType; 686a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate } 696a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 706a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public String getPackageName() { 716a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate return mPackageName; 726a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate } 736a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 746a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public int getDataType() { 756a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate return mDataType; 766a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate } 776a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 786a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate // --------------------------------------- 796a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate // Parcelable implementation - not used by transport 806a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 816a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate @Override 826a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public int describeContents() { 836a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate return 0; 846a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate } 856a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 866a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate @Override 876a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public void writeToParcel(Parcel out, int flags) { 886a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate out.writeString(mPackageName); 896a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate out.writeInt(mDataType); 906a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate } 916a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 926a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public static final Parcelable.Creator<RestoreDescription> CREATOR 936a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate = new Parcelable.Creator<RestoreDescription>() { 946a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public RestoreDescription createFromParcel(Parcel in) { 956a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate final RestoreDescription unparceled = new RestoreDescription(in); 966a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate return (NO_MORE_PACKAGES_SENTINEL.equals(unparceled.mPackageName)) 976a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate ? NO_MORE_PACKAGES 986a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate : unparceled; 996a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate } 1006a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 1016a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate public RestoreDescription[] newArray(int size) { 1026a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate return new RestoreDescription[size]; 1036a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate } 1046a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate }; 1056a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate 1066a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate private RestoreDescription(Parcel in) { 1076a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate mPackageName = in.readString(); 1086a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate mDataType = in.readInt(); 1096a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate } 1106a49dd087f29cfca82d55dfabeb97439ef84b508Christopher Tate} 111