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; 18 19 import android.app.IBackupAgent; 20 import android.app.backup.IBackupManager; 21 import android.app.backup.IBackupManagerMonitor; 22 import android.app.backup.IBackupObserver; 23 import android.app.backup.IFullBackupRestoreObserver; 24 import android.app.backup.IRestoreSession; 25 import android.app.backup.ISelectBackupTransportCallback; 26 import android.content.ComponentName; 27 import android.content.Intent; 28 import android.content.pm.ApplicationInfo; 29 import android.os.IBinder; 30 import android.os.ParcelFileDescriptor; 31 import java.io.FileDescriptor; 32 import java.io.PrintWriter; 33 34 /** 35 * Interface for BackupManagerService. 36 * 37 * Current and future implementations of BackupManagerService should use this interface, so that 38 * Trampoline is able to switch between them. 39 */ 40 public interface BackupManagerServiceInterface { 41 42 void unlockSystemUser(); 43 44 // Utility: build a new random integer token 45 int generateRandomIntegerToken(); 46 47 boolean setBackupPassword(String currentPw, String newPw); 48 49 boolean hasBackupPassword(); 50 51 // fire off a backup agent, blocking until it attaches or times out 52 IBackupAgent bindToAgentSynchronous(ApplicationInfo app, int mode); 53 54 // Get the restore-set token for the best-available restore set for this package: 55 // the active set if possible, else the ancestral one. Returns zero if none available. 56 long getAvailableRestoreToken(String packageName); 57 58 int requestBackup(String[] packages, IBackupObserver observer, int flags); 59 60 int requestBackup(String[] packages, IBackupObserver observer, 61 IBackupManagerMonitor monitor, int flags); 62 63 // Cancel all running backups. 64 void cancelBackups(); 65 66 void prepareOperationTimeout(int token, long interval, BackupRestoreTask callback, 67 int operationType); 68 69 // synchronous waiter case 70 boolean waitUntilOperationComplete(int token); 71 72 void tearDownAgentAndKill(ApplicationInfo app); 73 74 boolean beginFullBackup(FullBackupJob scheduledJob); 75 76 // The job scheduler says our constraints don't hold any more, 77 // so tear down any ongoing backup task right away. 78 void endFullBackup(); 79 80 void dataChanged(String packageName); 81 82 // Initialize the given transport 83 void initializeTransports(String[] transportName, IBackupObserver observer); 84 85 // Clear the given package's backup data from the current transport 86 void clearBackupData(String transportName, String packageName); 87 88 // Run a backup pass immediately for any applications that have declared 89 // that they have pending updates. 90 void backupNow(); 91 92 // Run a backup pass for the given packages, writing the resulting data stream 93 // to the supplied file descriptor. This method is synchronous and does not return 94 // to the caller until the backup has been completed. 95 // 96 // This is the variant used by 'adb backup'; it requires on-screen confirmation 97 // by the user because it can be used to offload data over untrusted USB. 98 void adbBackup(ParcelFileDescriptor fd, boolean includeApks, boolean includeObbs, 99 boolean includeShared, boolean doWidgets, boolean doAllApps, boolean includeSystem, 100 boolean compress, boolean doKeyValue, String[] pkgList); 101 102 void fullTransportBackup(String[] pkgNames); 103 104 void adbRestore(ParcelFileDescriptor fd); 105 106 // Confirm that the previously-requested full backup/restore operation can proceed. This 107 // is used to require a user-facing disclosure about the operation. 108 void acknowledgeAdbBackupOrRestore(int token, boolean allow, 109 String curPassword, String encPpassword, IFullBackupRestoreObserver observer); 110 111 // Enable/disable backups 112 void setBackupEnabled(boolean enable); 113 114 // Enable/disable automatic restore of app data at install time 115 void setAutoRestore(boolean doAutoRestore); 116 117 // Mark the backup service as having been provisioned 118 void setBackupProvisioned(boolean available); 119 120 // Report whether the backup mechanism is currently enabled 121 boolean isBackupEnabled(); 122 123 // Update the transport attributes 124 void updateTransportAttributes( 125 ComponentName transportComponent, 126 String name, 127 Intent configurationIntent, 128 String currentDestinationString, 129 Intent dataManagementIntent, 130 String dataManagementLabel); 131 132 // Report the name of the currently active transport 133 String getCurrentTransport(); 134 135 // Report all known, available backup transports 136 String[] listAllTransports(); 137 138 ComponentName[] listAllTransportComponents(); 139 140 String[] getTransportWhitelist(); 141 142 // Select which transport to use for the next backup operation. 143 String selectBackupTransport(String transport); 144 145 void selectBackupTransportAsync(ComponentName transport, 146 ISelectBackupTransportCallback listener); 147 148 // Supply the configuration Intent for the given transport. If the name is not one 149 // of the available transports, or if the transport does not supply any configuration 150 // UI, the method returns null. 151 Intent getConfigurationIntent(String transportName); 152 153 // Supply the configuration summary string for the given transport. If the name is 154 // not one of the available transports, or if the transport does not supply any 155 // summary / destination string, the method can return null. 156 // 157 // This string is used VERBATIM as the summary text of the relevant Settings item! 158 String getDestinationString(String transportName); 159 160 // Supply the manage-data intent for the given transport. 161 Intent getDataManagementIntent(String transportName); 162 163 // Supply the menu label for affordances that fire the manage-data intent 164 // for the given transport. 165 String getDataManagementLabel(String transportName); 166 167 // Callback: a requested backup agent has been instantiated. This should only 168 // be called from the Activity Manager. 169 void agentConnected(String packageName, IBinder agentBinder); 170 171 // Callback: a backup agent has failed to come up, or has unexpectedly quit. 172 // If the agent failed to come up in the first place, the agentBinder argument 173 // will be null. This should only be called from the Activity Manager. 174 void agentDisconnected(String packageName); 175 176 // An application being installed will need a restore pass, then the Package Manager 177 // will need to be told when the restore is finished. 178 void restoreAtInstall(String packageName, int token); 179 180 // Hand off a restore session 181 IRestoreSession beginRestoreSession(String packageName, String transport); 182 183 // Note that a currently-active backup agent has notified us that it has 184 // completed the given outstanding asynchronous backup/restore operation. 185 void opComplete(int token, long result); 186 187 boolean isAppEligibleForBackup(String packageName); 188 189 String[] filterAppsEligibleForBackup(String[] packages); 190 191 void dump(FileDescriptor fd, PrintWriter pw, String[] args); 192 193 IBackupManager getBackupManagerBinder(); 194 195 // Gets access to the backup/restore agent timeout parameters. 196 BackupAgentTimeoutParameters getAgentTimeoutParameters(); 197 } 198