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