1bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate/* 2bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * Copyright (C) 2014 The Android Open Source Project 3bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * 4bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * Licensed under the Apache License, Version 2.0 (the "License"); 5bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * you may not use this file except in compliance with the License. 6bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * You may obtain a copy of the License at 7bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * 8bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * http://www.apache.org/licenses/LICENSE-2.0 9bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * 10bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * Unless required by applicable law or agreed to in writing, software 11bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * distributed under the License is distributed on an "AS IS" BASIS, 12bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * See the License for the specific language governing permissions and 14bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate * limitations under the License. 15bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate */ 16bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 17bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tatepackage com.android.server.backup; 18bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 19bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.app.backup.IBackupManager; 20bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.app.backup.IFullBackupRestoreObserver; 21bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.app.backup.IRestoreSession; 22bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.content.Context; 23bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.content.Intent; 24bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.os.Binder; 25bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.os.Environment; 26bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.os.IBinder; 27bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.os.ParcelFileDescriptor; 28bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.os.Process; 29bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.os.RemoteException; 30bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.os.SystemProperties; 31bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.os.UserHandle; 32bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport android.util.Slog; 33bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 34bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport java.io.File; 35bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport java.io.FileDescriptor; 36bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport java.io.IOException; 37bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tateimport java.io.PrintWriter; 38bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 39bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tatepublic class Trampoline extends IBackupManager.Stub { 40bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate static final String TAG = "BackupManagerService"; 41bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate static final boolean DEBUG_TRAMPOLINE = false; 42bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 43bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // When this file is present, the backup service is inactive 44bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate static final String BACKUP_SUPPRESS_FILENAME = "backup-suppress"; 45bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 46bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // Product-level suppression of backup/restore 47bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate static final String BACKUP_DISABLE_PROPERTY = "ro.backup.disable"; 48bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 49bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate final Context mContext; 50bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate final File mSuppressFile; // existence testing & creating synchronized on 'this' 51bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate final boolean mGlobalDisable; 52bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate volatile BackupManagerService mService; 53bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 54bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public Trampoline(Context context) { 55bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate mContext = context; 56bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate File dir = new File(Environment.getSecureDataDirectory(), "backup"); 57bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate dir.mkdirs(); 58bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate mSuppressFile = new File(dir, BACKUP_SUPPRESS_FILENAME); 59bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate mGlobalDisable = SystemProperties.getBoolean(BACKUP_DISABLE_PROPERTY, false); 60bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 61bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 62bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // internal control API 63bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void initialize(final int whichUser) { 64bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // Note that only the owner user is currently involved in backup/restore 65bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (whichUser == UserHandle.USER_OWNER) { 66bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // Does this product support backup/restore at all? 67bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (mGlobalDisable) { 68bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate Slog.i(TAG, "Backup/restore not supported"); 69bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return; 70bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 71bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 72bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate synchronized (this) { 73bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (!mSuppressFile.exists()) { 74bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate mService = new BackupManagerService(mContext, this); 75bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } else { 76bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate Slog.i(TAG, "Backup inactive in user " + whichUser); 77bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 78bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 79bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 80bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 81bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 82bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void setBackupServiceActive(final int userHandle, boolean makeActive) { 83bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // Only the DPM should be changing the active state of backup 84bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate final int caller = Binder.getCallingUid(); 85bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (caller != Process.SYSTEM_UID 86bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate && caller != Process.ROOT_UID) { 87bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate throw new SecurityException("No permission to configure backup activity"); 88bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 89bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 90bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (mGlobalDisable) { 91bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate Slog.i(TAG, "Backup/restore not supported"); 92bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return; 93bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 94bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 95bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (userHandle == UserHandle.USER_OWNER) { 96bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate synchronized (this) { 97201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban if (makeActive != isBackupServiceActive(userHandle)) { 98bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate Slog.i(TAG, "Making backup " 99bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate + (makeActive ? "" : "in") + "active in user " + userHandle); 100bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (makeActive) { 101bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate mService = new BackupManagerService(mContext, this); 102bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate mSuppressFile.delete(); 103bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } else { 104bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate mService = null; 105bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate try { 106bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate mSuppressFile.createNewFile(); 107bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } catch (IOException e) { 108bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate Slog.e(TAG, "Unable to persist backup service inactivity"); 109bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 110bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 111bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 112bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 113bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 114bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 115bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 116201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban /** 117201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban * Querying activity state of backup service. Calling this method before initialize yields 118201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban * undefined result. 119201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban * @param userHandle The user in which the activity state of backup service is queried. 120201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban * @return true if the service is active. 121201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban */ 122201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban public boolean isBackupServiceActive(final int userHandle) { 123201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban if (userHandle == UserHandle.USER_OWNER) { 124201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban synchronized (this) { 125201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban return mService != null; 126201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban } 127201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban } 128201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban return false; 129201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban } 130201caf57f9a9699e04620eac9b1fcdaf4338d2f0Zoltan Szatmary-Ban 131bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // IBackupManager binder API 132bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 133bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void dataChanged(String packageName) throws RemoteException { 134bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 135bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 136bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.dataChanged(packageName); 137bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 138bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 139bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 140bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 141bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void clearBackupData(String transportName, String packageName) 142bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate throws RemoteException { 143bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 144bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 145bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.clearBackupData(transportName, packageName); 146bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 147bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 148bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 149bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 150bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void agentConnected(String packageName, IBinder agent) throws RemoteException { 151bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 152bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 153bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.agentConnected(packageName, agent); 154bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 155bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 156bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 157bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 158bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void agentDisconnected(String packageName) throws RemoteException { 159bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 160bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 161bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.agentDisconnected(packageName); 162bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 163bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 164bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 165bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 166bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void restoreAtInstall(String packageName, int token) throws RemoteException { 167bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 168bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 169bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.restoreAtInstall(packageName, token); 170bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 171bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 172bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 173bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 174bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void setBackupEnabled(boolean isEnabled) throws RemoteException { 175bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 176bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 177bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.setBackupEnabled(isEnabled); 178bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 179bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 180bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 181bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 182bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void setAutoRestore(boolean doAutoRestore) throws RemoteException { 183bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 184bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 185bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.setAutoRestore(doAutoRestore); 186bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 187bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 188bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 189bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 190bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void setBackupProvisioned(boolean isProvisioned) throws RemoteException { 191bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 192bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 193bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.setBackupProvisioned(isProvisioned); 194bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 195bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 196bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 197bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 198bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public boolean isBackupEnabled() throws RemoteException { 199bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 200bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.isBackupEnabled() : false; 201bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 202bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 203bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 204bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public boolean setBackupPassword(String currentPw, String newPw) throws RemoteException { 205bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 206bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.setBackupPassword(currentPw, newPw) : false; 207bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 208bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 209bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 210bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public boolean hasBackupPassword() throws RemoteException { 211bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 212bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.hasBackupPassword() : false; 213bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 214bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 215bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 216bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void backupNow() throws RemoteException { 217bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 218bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 219bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.backupNow(); 220bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 221bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 222bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 223bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 224bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean includeObbs, 225bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate boolean includeShared, boolean doWidgets, boolean allApps, 226bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate boolean allIncludesSystem, boolean doCompress, String[] packageNames) 227bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate throws RemoteException { 228bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 229bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 230bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.fullBackup(fd, includeApks, includeObbs, includeShared, doWidgets, 231bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate allApps, allIncludesSystem, doCompress, packageNames); 232bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 233bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 234bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 235bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 236bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void fullTransportBackup(String[] packageNames) throws RemoteException { 237bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 238bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 239bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.fullTransportBackup(packageNames); 240bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 241bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 242bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 243bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 244bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void fullRestore(ParcelFileDescriptor fd) throws RemoteException { 245bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 246bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 247bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.fullRestore(fd); 248bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 249bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 250bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 251bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 252bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void acknowledgeFullBackupOrRestore(int token, boolean allow, String curPassword, 253bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate String encryptionPassword, IFullBackupRestoreObserver observer) 254bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate throws RemoteException { 255bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 256bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 257bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.acknowledgeFullBackupOrRestore(token, allow, 258bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate curPassword, encryptionPassword, observer); 259bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 260bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 261bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 262bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 263bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public String getCurrentTransport() throws RemoteException { 264bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 265bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.getCurrentTransport() : null; 266bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 267bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 268bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 269bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public String[] listAllTransports() throws RemoteException { 270bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 271bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.listAllTransports() : null; 272bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 273bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 274bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 275bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public String selectBackupTransport(String transport) throws RemoteException { 276bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 277bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.selectBackupTransport(transport) : null; 278bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 279bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 280bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 281bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public Intent getConfigurationIntent(String transport) throws RemoteException { 282bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 283bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.getConfigurationIntent(transport) : null; 284bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 285bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 286bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 287bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public String getDestinationString(String transport) throws RemoteException { 288bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 289bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.getDestinationString(transport) : null; 290bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 291bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 292bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 293bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public Intent getDataManagementIntent(String transport) throws RemoteException { 294bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 295bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.getDataManagementIntent(transport) : null; 296bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 297bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 298bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 299bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public String getDataManagementLabel(String transport) throws RemoteException { 300bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 301bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.getDataManagementLabel(transport) : null; 302bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 303bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 304bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 305bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public IRestoreSession beginRestoreSession(String packageName, String transportID) 306bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate throws RemoteException { 307bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 308bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.beginRestoreSession(packageName, transportID) : null; 309bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 310bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 311bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 31211ae768cf1b8348e761ad9c09e98788da1e591b1Christopher Tate public void opComplete(int token, long result) throws RemoteException { 313bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 314bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 31511ae768cf1b8348e761ad9c09e98788da1e591b1Christopher Tate svc.opComplete(token, result); 316bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 317bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 318bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 319bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate @Override 320511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate public long getAvailableRestoreToken(String packageName) { 321511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate BackupManagerService svc = mService; 322511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate return (svc != null) ? svc.getAvailableRestoreToken(packageName) : 0; 323511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate } 324511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate 325511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate @Override 326bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 3278dd7d01c1a07d9893ce1207c90869fe3d40fbcedChristopher Tate mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); 3288dd7d01c1a07d9893ce1207c90869fe3d40fbcedChristopher Tate 329bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 330bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 331bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.dump(fd, pw, args); 332bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } else { 333bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate pw.println("Inactive"); 334bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 335bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 336bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 337bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // Full backup/restore entry points - non-Binder; called directly 338bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate // by the full-backup scheduled job 339bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate /* package */ boolean beginFullBackup(FullBackupJob scheduledJob) { 340bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 341bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate return (svc != null) ? svc.beginFullBackup(scheduledJob) : false; 342bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 343bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate 344bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate /* package */ void endFullBackup() { 345bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate BackupManagerService svc = mService; 346bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate if (svc != null) { 347bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate svc.endFullBackup(); 348bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 349bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate } 350bbe23b31dcd0eec8af5b5198970de7ff2a9ef79aChristopher Tate} 351