1 /* 2 * Copyright (C) 2017 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 com.android.server.backup.params; 18 19 import android.annotation.Nullable; 20 import android.app.backup.IBackupManagerMonitor; 21 import android.app.backup.IRestoreObserver; 22 import android.content.pm.PackageInfo; 23 24 import com.android.server.backup.internal.OnTaskFinishedListener; 25 import com.android.server.backup.transport.TransportClient; 26 27 public class RestoreParams { 28 public final TransportClient transportClient; 29 public final IRestoreObserver observer; 30 public final IBackupManagerMonitor monitor; 31 public final long token; 32 @Nullable public final PackageInfo packageInfo; 33 public final int pmToken; // in post-install restore, the PM's token for this transaction 34 public final boolean isSystemRestore; 35 @Nullable public final String[] filterSet; 36 public final OnTaskFinishedListener listener; 37 38 /** 39 * No kill after restore. 40 */ createForSinglePackage( TransportClient transportClient, IRestoreObserver observer, IBackupManagerMonitor monitor, long token, PackageInfo packageInfo, OnTaskFinishedListener listener)41 public static RestoreParams createForSinglePackage( 42 TransportClient transportClient, 43 IRestoreObserver observer, 44 IBackupManagerMonitor monitor, 45 long token, 46 PackageInfo packageInfo, 47 OnTaskFinishedListener listener) { 48 return new RestoreParams( 49 transportClient, 50 observer, 51 monitor, 52 token, 53 packageInfo, 54 /* pmToken */ 0, 55 /* isSystemRestore */ false, 56 /* filterSet */ null, 57 listener); 58 } 59 60 /** 61 * Kill after restore. 62 */ createForRestoreAtInstall( TransportClient transportClient, IRestoreObserver observer, IBackupManagerMonitor monitor, long token, String packageName, int pmToken, OnTaskFinishedListener listener)63 public static RestoreParams createForRestoreAtInstall( 64 TransportClient transportClient, 65 IRestoreObserver observer, 66 IBackupManagerMonitor monitor, 67 long token, 68 String packageName, 69 int pmToken, 70 OnTaskFinishedListener listener) { 71 String[] filterSet = {packageName}; 72 return new RestoreParams( 73 transportClient, 74 observer, 75 monitor, 76 token, 77 /* packageInfo */ null, 78 pmToken, 79 /* isSystemRestore */ false, 80 filterSet, 81 listener); 82 } 83 84 /** 85 * This is the form that Setup Wizard or similar restore UXes use. 86 */ createForRestoreAll( TransportClient transportClient, IRestoreObserver observer, IBackupManagerMonitor monitor, long token, OnTaskFinishedListener listener)87 public static RestoreParams createForRestoreAll( 88 TransportClient transportClient, 89 IRestoreObserver observer, 90 IBackupManagerMonitor monitor, 91 long token, 92 OnTaskFinishedListener listener) { 93 return new RestoreParams( 94 transportClient, 95 observer, 96 monitor, 97 token, 98 /* packageInfo */ null, 99 /* pmToken */ 0, 100 /* isSystemRestore */ true, 101 /* filterSet */ null, 102 listener); 103 } 104 105 /** 106 * Caller specifies whether is considered a system-level restore. 107 */ createForRestorePackages( TransportClient transportClient, IRestoreObserver observer, IBackupManagerMonitor monitor, long token, String[] filterSet, boolean isSystemRestore, OnTaskFinishedListener listener)108 public static RestoreParams createForRestorePackages( 109 TransportClient transportClient, 110 IRestoreObserver observer, 111 IBackupManagerMonitor monitor, 112 long token, 113 String[] filterSet, 114 boolean isSystemRestore, 115 OnTaskFinishedListener listener) { 116 return new RestoreParams( 117 transportClient, 118 observer, 119 monitor, 120 token, 121 /* packageInfo */ null, 122 /* pmToken */ 0, 123 isSystemRestore, 124 filterSet, 125 listener); 126 } 127 RestoreParams( TransportClient transportClient, IRestoreObserver observer, IBackupManagerMonitor monitor, long token, @Nullable PackageInfo packageInfo, int pmToken, boolean isSystemRestore, @Nullable String[] filterSet, OnTaskFinishedListener listener)128 private RestoreParams( 129 TransportClient transportClient, 130 IRestoreObserver observer, 131 IBackupManagerMonitor monitor, 132 long token, 133 @Nullable PackageInfo packageInfo, 134 int pmToken, 135 boolean isSystemRestore, 136 @Nullable String[] filterSet, 137 OnTaskFinishedListener listener) { 138 this.transportClient = transportClient; 139 this.observer = observer; 140 this.monitor = monitor; 141 this.token = token; 142 this.packageInfo = packageInfo; 143 this.pmToken = pmToken; 144 this.isSystemRestore = isSystemRestore; 145 this.filterSet = filterSet; 146 this.listener = listener; 147 } 148 } 149