BackupManager.java revision b1f573dca3ccdd113ca513f32c9964211ca71c78
1a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate/* 2a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * Copyright (C) 2009 The Android Open Source Project 3a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * 4a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * Licensed under the Apache License, Version 2.0 (the "License"); 5a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * you may not use this file except in compliance with the License. 6a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * You may obtain a copy of the License at 7a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * 8a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * http://www.apache.org/licenses/LICENSE-2.0 9a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * 10a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * Unless required by applicable law or agreed to in writing, software 11a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * distributed under the License is distributed on an "AS IS" BASIS, 12a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * See the License for the specific language governing permissions and 14a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * limitations under the License. 15a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate */ 16a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 174528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tatepackage android.app.backup; 18a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 19d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tateimport android.annotation.SystemApi; 20865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basargeimport android.content.ComponentName; 21a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tateimport android.content.Context; 22b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanotimport android.os.Bundle; 23fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromovimport android.os.Handler; 24fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromovimport android.os.Message; 25a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tateimport android.os.RemoteException; 26a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tateimport android.os.ServiceManager; 27c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tateimport android.util.Log; 28fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromovimport android.util.Pair; 29a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 30a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate/** 31d17da43c82c4edb97514d6138bc208eeba321636Scott Main * The interface through which an application interacts with the Android backup service to 32d17da43c82c4edb97514d6138bc208eeba321636Scott Main * request backup and restore operations. 33d17da43c82c4edb97514d6138bc208eeba321636Scott Main * Applications instantiate it using the constructor and issue calls through that instance. 345a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * <p> 355a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * When an application has made changes to data which should be backed up, a 365a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * call to {@link #dataChanged()} will notify the backup service. The system 375a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * will then schedule a backup operation to occur in the near future. Repeated 385a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * calls to {@link #dataChanged()} have no further effect until the backup 395a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * operation actually occurs. 405a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * <p> 41d17da43c82c4edb97514d6138bc208eeba321636Scott Main * A backup or restore operation for your application begins when the system launches the 42d17da43c82c4edb97514d6138bc208eeba321636Scott Main * {@link android.app.backup.BackupAgent} subclass you've declared in your manifest. See the 434528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tate * documentation for {@link android.app.backup.BackupAgent} for a detailed description 444e14a829129feee14ebe453f61a124784c870610Christopher Tate * of how the operation then proceeds. 455a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * <p> 464e14a829129feee14ebe453f61a124784c870610Christopher Tate * Several attributes affecting the operation of the backup and restore mechanism 4761fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * can be set on the <code> 4861fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 49d17da43c82c4edb97514d6138bc208eeba321636Scott Main * tag in your application's AndroidManifest.xml file. 50d17da43c82c4edb97514d6138bc208eeba321636Scott Main * 5161fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <div class="special reference"> 5261fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <h3>Developer Guides</h3> 5361fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p>For more information about using BackupManager, read the 5461fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/data/backup.html">Data Backup</a> developer guide.</p></div> 5561fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * 565a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * @attr ref android.R.styleable#AndroidManifestApplication_allowBackup 575a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * @attr ref android.R.styleable#AndroidManifestApplication_backupAgent 585a20ea16d7e5b70dc7bad8700f54170e4f220d12Kenny Root * @attr ref android.R.styleable#AndroidManifestApplication_killAfterRestore 594e14a829129feee14ebe453f61a124784c870610Christopher Tate * @attr ref android.R.styleable#AndroidManifestApplication_restoreAnyVersion 60a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate */ 61a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tatepublic class BackupManager { 62c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate private static final String TAG = "BackupManager"; 63c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate 64fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov // BackupObserver status codes 65fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov /** 66fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * Indicates that backup succeeded. 67fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 68fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @hide 69fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov */ 70fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @SystemApi 71fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public static final int SUCCESS = 0; 72fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 73fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov /** 74fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * Indicates that backup is either not enabled at all or 75fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * backup for the package was rejected by backup service 76fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * or backup transport, 77fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 78fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @hide 79fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov */ 80fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @SystemApi 81fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public static final int ERROR_BACKUP_NOT_ALLOWED = -2001; 82fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 83fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov /** 84fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * The requested app is not installed on the device. 85fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 86fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @hide 87fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov */ 88fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @SystemApi 89fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public static final int ERROR_PACKAGE_NOT_FOUND = -2002; 90fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 91fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov /** 92fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * The transport for some reason was not in a good state and 93fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * aborted the entire backup request. This is a transient 94fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * failure and should not be retried immediately. 95fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 96fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @hide 97fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov */ 98fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @SystemApi 99fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public static final int ERROR_TRANSPORT_ABORTED = BackupTransport.TRANSPORT_ERROR; 100fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 101fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov /** 102fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * Returned when the transport was unable to process the 103fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * backup request for a given package, for example if the 104fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * transport hit a transient network failure. The remaining 105fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * packages provided to {@link #requestBackup(String[], BackupObserver)} 106fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * will still be attempted. 107fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 108fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @hide 109fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov */ 110fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @SystemApi 111fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public static final int ERROR_TRANSPORT_PACKAGE_REJECTED = 112fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov BackupTransport.TRANSPORT_PACKAGE_REJECTED; 113fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 114fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov /** 115872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov * Returned when the transport reject the attempt to backup because 116872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov * backup data size exceeded current quota limit for this package. 117872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov * 118872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov * @hide 119872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov */ 120872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov @SystemApi 121872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov public static final int ERROR_TRANSPORT_QUOTA_EXCEEDED = 122872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov BackupTransport.TRANSPORT_QUOTA_EXCEEDED; 123872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov 124872d3b6e19933af6fa9ae65214b9f6df04fc3222Sergey Poromov /** 125fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * The {@link BackupAgent} for the requested package failed for some reason 126fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * and didn't provide appropriate backup data. 127fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 128fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @hide 129fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov */ 130fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @SystemApi 131fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public static final int ERROR_AGENT_FAILURE = BackupTransport.AGENT_ERROR; 132fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 13338c9c306405a4c706cb405ccbea098c5b661b1c0Christopher Tate /** 13438c9c306405a4c706cb405ccbea098c5b661b1c0Christopher Tate * Intent extra when any subsidiary backup-related UI is launched from Settings: does 13538c9c306405a4c706cb405ccbea098c5b661b1c0Christopher Tate * device policy or configuration permit backup operations to run at all? 13638c9c306405a4c706cb405ccbea098c5b661b1c0Christopher Tate * 13738c9c306405a4c706cb405ccbea098c5b661b1c0Christopher Tate * @hide 13838c9c306405a4c706cb405ccbea098c5b661b1c0Christopher Tate */ 13938c9c306405a4c706cb405ccbea098c5b661b1c0Christopher Tate public static final String EXTRA_BACKUP_SERVICES_AVAILABLE = "backup_services_available"; 14038c9c306405a4c706cb405ccbea098c5b661b1c0Christopher Tate 14138e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge /** 14238e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * If this flag is passed to {@link #requestBackup(String[], BackupObserver, int)}, 14338e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * BackupManager will pass a blank old state to BackupAgents of requested packages. 14438e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * 14538e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * @hide 14638e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge */ 14738e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge @SystemApi 14838e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge public static final int FLAG_NON_INCREMENTAL_BACKUP = 1; 14938e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge 15038e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge /** 15138e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * Use with {@link #requestBackup} to force backup of 15238e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * package meta data. Typically you do not need to explicitly request this be backed up as it is 15338e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * handled internally by the BackupManager. If you are requesting backups with 15438e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * FLAG_NON_INCREMENTAL, this package won't automatically be backed up and you have to 15538e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * explicitly request for its backup. 15638e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * 15738e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * @hide 15838e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge */ 15938e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge @SystemApi 16038e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge public static final String PACKAGE_MANAGER_SENTINEL = "@pm@"; 16138e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge 162865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 163865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge /** 164865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * This error code is passed to {@link SelectBackupTransportCallback#onFailure(int)} 165865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * if the requested transport is unavailable. 166865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * 167865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * @hide 168865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge */ 169865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge @SystemApi 170865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge public static final int ERROR_TRANSPORT_UNAVAILABLE = -1; 171865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 172865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge /** 173865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * This error code is passed to {@link SelectBackupTransportCallback#onFailure(int)} if the 174865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * requested transport is not a valid BackupTransport. 175865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * 176865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * @hide 177865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge */ 178865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge @SystemApi 179865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge public static final int ERROR_TRANSPORT_INVALID = -2; 180865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 181a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate private Context mContext; 182c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate private static IBackupManager sService; 183a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 184c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate private static void checkServiceBinder() { 185c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate if (sService == null) { 186c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate sService = IBackupManager.Stub.asInterface( 187c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate ServiceManager.getService(Context.BACKUP_SERVICE)); 188c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate } 189c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate } 190043dadc7516d20c3b3ccbcb20c53aaeef076a237Christopher Tate 191043dadc7516d20c3b3ccbcb20c53aaeef076a237Christopher Tate /** 192a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * Constructs a BackupManager object through which the application can 193a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * communicate with the Android backup system. 194c114eb55b442981e2ea0a8989aa6ed458fc418e4Christopher Tate * 195a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * @param context The {@link android.content.Context} that was provided when 196a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * one of your application's {@link android.app.Activity Activities} 197a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * was created. 198a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate */ 199c114eb55b442981e2ea0a8989aa6ed458fc418e4Christopher Tate public BackupManager(Context context) { 200a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate mContext = context; 201a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate } 202a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 203a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate /** 204a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * Notifies the Android backup system that your application wishes to back up 205a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * new changes to its data. A backup operation using your application's 2064e14a829129feee14ebe453f61a124784c870610Christopher Tate * {@link android.app.backup.BackupAgent} subclass will be scheduled when you 2074e14a829129feee14ebe453f61a124784c870610Christopher Tate * call this method. 208a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate */ 209a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate public void dataChanged() { 210c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate checkServiceBinder(); 211c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate if (sService != null) { 212c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate try { 213c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate sService.dataChanged(mContext.getPackageName()); 214c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate } catch (RemoteException e) { 215c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate Log.d(TAG, "dataChanged() couldn't connect"); 216c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate } 217c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate } 218c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate } 219c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate 220c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate /** 221c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate * Convenience method for callers who need to indicate that some other package 2224e14a829129feee14ebe453f61a124784c870610Christopher Tate * needs a backup pass. This can be useful in the case of groups of packages 2234e14a829129feee14ebe453f61a124784c870610Christopher Tate * that share a uid. 2244e14a829129feee14ebe453f61a124784c870610Christopher Tate * <p> 225c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate * This method requires that the application hold the "android.permission.BACKUP" 2264e14a829129feee14ebe453f61a124784c870610Christopher Tate * permission if the package named in the argument does not run under the same uid 2274e14a829129feee14ebe453f61a124784c870610Christopher Tate * as the caller. 228d17da43c82c4edb97514d6138bc208eeba321636Scott Main * 229d17da43c82c4edb97514d6138bc208eeba321636Scott Main * @param packageName The package name identifying the application to back up. 230c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate */ 231c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate public static void dataChanged(String packageName) { 232c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate checkServiceBinder(); 233c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate if (sService != null) { 2348a27f923eb9dbbe3c2d0184e82d9f1a98f1e4cdcChristopher Tate try { 235c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate sService.dataChanged(packageName); 2368a27f923eb9dbbe3c2d0184e82d9f1a98f1e4cdcChristopher Tate } catch (RemoteException e) { 237d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "dataChanged(pkg) couldn't connect"); 2388a27f923eb9dbbe3c2d0184e82d9f1a98f1e4cdcChristopher Tate } 239a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate } 240a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate } 2419b3905c4a25f2d785ce7535d1f2e1540b46bb561Christopher Tate 2429b3905c4a25f2d785ce7535d1f2e1540b46bb561Christopher Tate /** 2439c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * Restore the calling application from backup. The data will be restored from the 2449c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * current backup dataset if the application has stored data there, or from 2459c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * the dataset used during the last full device setup operation if the current 2469c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * backup dataset has no matching data. If no backup data exists for this application 2479c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * in either source, a nonzero value will be returned. 2489c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * 2499c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * <p>If this method returns zero (meaning success), the OS will attempt to retrieve 2509c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * a backed-up dataset from the remote transport, instantiate the application's 2519c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * backup agent, and pass the dataset to the agent's 2529c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * {@link android.app.backup.BackupAgent#onRestore(BackupDataInput, int, android.os.ParcelFileDescriptor) onRestore()} 2539c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * method. 2549c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * 255d17da43c82c4edb97514d6138bc208eeba321636Scott Main * @param observer The {@link RestoreObserver} to receive callbacks during the restore 256d17da43c82c4edb97514d6138bc208eeba321636Scott Main * operation. This must not be null. 257d17da43c82c4edb97514d6138bc208eeba321636Scott Main * 2589c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * @return Zero on success; nonzero on error. 2599c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate */ 2609c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate public int requestRestore(RestoreObserver observer) { 2619c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate int result = -1; 2629c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate checkServiceBinder(); 2639c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate if (sService != null) { 2649c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate RestoreSession session = null; 2659c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate try { 26644ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate IRestoreSession binder = sService.beginRestoreSession(mContext.getPackageName(), 26744ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate null); 268f5491fc1b61088843f280a6b55c1a995e2e6f939Christopher Tate if (binder != null) { 269f5491fc1b61088843f280a6b55c1a995e2e6f939Christopher Tate session = new RestoreSession(mContext, binder); 270f5491fc1b61088843f280a6b55c1a995e2e6f939Christopher Tate result = session.restorePackage(mContext.getPackageName(), observer); 271f5491fc1b61088843f280a6b55c1a995e2e6f939Christopher Tate } 2729c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate } catch (RemoteException e) { 273d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "restoreSelf() unable to contact service"); 2749c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate } finally { 2759c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate if (session != null) { 2769c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate session.endRestoreSession(); 2779c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate } 2789c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate } 2799c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate } 2809c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate return result; 2819c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate } 2829c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate 2832e5979236ccc06beec8b8f7f631f31bdedc79614Christopher Tate // system APIs start here 2842e5979236ccc06beec8b8f7f631f31bdedc79614Christopher Tate 2859c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate /** 286e28290e21f908b4e917099ff2aa41e3aab9310c2Christopher Tate * Begin the process of restoring data from backup. See the 2874528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tate * {@link android.app.backup.RestoreSession} class for documentation on that process. 2889c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate * @hide 2899b3905c4a25f2d785ce7535d1f2e1540b46bb561Christopher Tate */ 2902e5979236ccc06beec8b8f7f631f31bdedc79614Christopher Tate @SystemApi 29180202c8cb8c8e4ab507079e79b864c61a8eeeee9Christopher Tate public RestoreSession beginRestoreSession() { 29280202c8cb8c8e4ab507079e79b864c61a8eeeee9Christopher Tate RestoreSession session = null; 293c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate checkServiceBinder(); 294c8daa769256b039b6bc4c5acbe6b558cd776c00aChristopher Tate if (sService != null) { 2958a27f923eb9dbbe3c2d0184e82d9f1a98f1e4cdcChristopher Tate try { 29644ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate // All packages, current transport 29744ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate IRestoreSession binder = sService.beginRestoreSession(null, null); 298f5491fc1b61088843f280a6b55c1a995e2e6f939Christopher Tate if (binder != null) { 299f5491fc1b61088843f280a6b55c1a995e2e6f939Christopher Tate session = new RestoreSession(mContext, binder); 300f5491fc1b61088843f280a6b55c1a995e2e6f939Christopher Tate } 3018a27f923eb9dbbe3c2d0184e82d9f1a98f1e4cdcChristopher Tate } catch (RemoteException e) { 302d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "beginRestoreSession() couldn't connect"); 3038a27f923eb9dbbe3c2d0184e82d9f1a98f1e4cdcChristopher Tate } 3049b3905c4a25f2d785ce7535d1f2e1540b46bb561Christopher Tate } 30580202c8cb8c8e4ab507079e79b864c61a8eeeee9Christopher Tate return session; 3069b3905c4a25f2d785ce7535d1f2e1540b46bb561Christopher Tate } 307d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate 308d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate /** 309d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * Enable/disable the backup service entirely. When disabled, no backup 310d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * or restore operations will take place. Data-changed notifications will 311d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * still be observed and collected, however, so that changes made while the 312d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * mechanism was disabled will still be backed up properly if it is enabled 313d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * at some point in the future. 314d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 315d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * <p>Callers must hold the android.permission.BACKUP permission to use this method. 316d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 317d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @hide 318d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate */ 319d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate @SystemApi 320d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate public void setBackupEnabled(boolean isEnabled) { 321d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate checkServiceBinder(); 322d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate if (sService != null) { 323d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate try { 324d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate sService.setBackupEnabled(isEnabled); 325d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } catch (RemoteException e) { 326d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "setBackupEnabled() couldn't connect"); 327d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 328d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 329d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 330d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate 331d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate /** 332d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * Report whether the backup mechanism is currently enabled. 333d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 334d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * <p>Callers must hold the android.permission.BACKUP permission to use this method. 335d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 336d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @hide 337d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate */ 338d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate @SystemApi 339d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate public boolean isBackupEnabled() { 3409e079298edd022c43a960729442a53557fd16e45Christopher Tate checkServiceBinder(); 341d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate if (sService != null) { 342d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate try { 343d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate return sService.isBackupEnabled(); 344d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } catch (RemoteException e) { 345d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "isBackupEnabled() couldn't connect"); 346d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 347d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 348d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate return false; 349d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 350d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate 351d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate /** 352a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate * Enable/disable data restore at application install time. When enabled, app 353a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate * installation will include an attempt to fetch the app's historical data from 354a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate * the archival restore dataset (if any). When disabled, no such attempt will 355a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate * be made. 356a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate * 357a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate * <p>Callers must hold the android.permission.BACKUP permission to use this method. 358a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate * 359a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate * @hide 360a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate */ 361a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate @SystemApi 362a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate public void setAutoRestore(boolean isEnabled) { 363a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate checkServiceBinder(); 364a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate if (sService != null) { 365a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate try { 366a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate sService.setAutoRestore(isEnabled); 367a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate } catch (RemoteException e) { 368a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate Log.e(TAG, "setAutoRestore() couldn't connect"); 369a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate } 370a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate } 371a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate } 372a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate 373a63246d6daa02c6f3e4e78d0072d991387e14c87Christopher Tate /** 374d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * Identify the currently selected transport. Callers must hold the 375d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * android.permission.BACKUP permission to use this method. 376d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @return The name of the currently active backup transport. In case of 377d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * failure or if no transport is currently active, this method returns {@code null}. 378d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 379d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @hide 380d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate */ 381d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate @SystemApi 382d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate public String getCurrentTransport() { 383d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate checkServiceBinder(); 384d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate if (sService != null) { 385d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate try { 386d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate return sService.getCurrentTransport(); 387d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } catch (RemoteException e) { 388d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "getCurrentTransport() couldn't connect"); 389d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 390d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 391d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate return null; 392d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 393d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate 394d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate /** 395d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * Request a list of all available backup transports' names. Callers must 396d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * hold the android.permission.BACKUP permission to use this method. 397d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 398d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @hide 399d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate */ 400d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate @SystemApi 401d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate public String[] listAllTransports() { 402d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate checkServiceBinder(); 403d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate if (sService != null) { 404d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate try { 405d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate return sService.listAllTransports(); 406d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } catch (RemoteException e) { 407d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "listAllTransports() couldn't connect"); 408d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 409d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 410d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate return null; 411d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 412d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate 413d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate /** 414865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * Specify the current backup transport. 415865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * 416865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * <p> Callers must hold the android.permission.BACKUP permission to use this method. 417d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 418d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @param transport The name of the transport to select. This should be one 419865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * of the names returned by {@link #listAllTransports()}. This is the String returned by 420865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * {@link BackupTransport#name()} for the particular transport. 421d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @return The name of the previously selected transport. If the given transport 422d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * name is not one of the currently available transports, no change is made to 423d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * the current transport setting and the method returns null. 424d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 425d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @hide 426d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate */ 427865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge @Deprecated 428d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate @SystemApi 429d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate public String selectBackupTransport(String transport) { 430d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate checkServiceBinder(); 431d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate if (sService != null) { 432d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate try { 433d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate return sService.selectBackupTransport(transport); 434d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } catch (RemoteException e) { 435d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "selectBackupTransport() couldn't connect"); 436d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 437d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 438d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate return null; 439d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 440d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate 441d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate /** 442865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * Specify the current backup transport and get notified when the transport is ready to be used. 443865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * This method is async because BackupManager might need to bind to the specified transport 444865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * which is in a separate process. 445865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * 446865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * <p>Callers must hold the android.permission.BACKUP permission to use this method. 447865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * 448865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * @param transport ComponentName of the service hosting the transport. This is different from 449865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * the transport's name that is returned by {@link BackupTransport#name()}. 450865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * @param listener A listener object to get a callback on the transport being selected. 451865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * 452865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge * @hide 453865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge */ 454865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge @SystemApi 455865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge public void selectBackupTransport(ComponentName transport, 456865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge SelectBackupTransportCallback listener) { 457865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge checkServiceBinder(); 458865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge if (sService != null) { 459865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge try { 460865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge SelectTransportListenerWrapper wrapper = listener == null ? 461865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge null : new SelectTransportListenerWrapper(mContext, listener); 462865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge sService.selectBackupTransportAsync(transport, wrapper); 463865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } catch (RemoteException e) { 464865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge Log.e(TAG, "selectBackupTransportAsync() couldn't connect"); 465865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 466865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 467865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 468865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 469865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge /** 470d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * Schedule an immediate backup attempt for all pending key/value updates. This 471d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * is primarily intended for transports to use when they detect a suitable 472d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * opportunity for doing a backup pass. If there are no pending updates to 473d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * be sent, no action will be taken. Even if some updates are pending, the 474d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * transport will still be asked to confirm via the usual requestBackupTime() 475d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * method. 476d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 477d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * <p>Callers must hold the android.permission.BACKUP permission to use this method. 478d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * 479d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate * @hide 480d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate */ 481d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate @SystemApi 482d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate public void backupNow() { 483d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate checkServiceBinder(); 484d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate if (sService != null) { 485d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate try { 486d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate sService.backupNow(); 487d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } catch (RemoteException e) { 488d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate Log.e(TAG, "backupNow() couldn't connect"); 489d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 490d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 491d5cf722ae62d06d1fb6a9505c6f4c403a5d14a37Christopher Tate } 492511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate 493511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate /** 494511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * Ask the framework which dataset, if any, the given package's data would be 495511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * restored from if we were to install it right now. 496511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * 497511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * <p>Callers must hold the android.permission.BACKUP permission to use this method. 498511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * 499511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * @param packageName The name of the package whose most-suitable dataset we 500511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * wish to look up 501511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * @return The dataset token from which a restore should be attempted, or zero if 502511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * no suitable data is available. 503511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * 504511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate * @hide 505511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate */ 506511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate @SystemApi 507511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate public long getAvailableRestoreToken(String packageName) { 508511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate checkServiceBinder(); 509511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate if (sService != null) { 510511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate try { 511511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate return sService.getAvailableRestoreToken(packageName); 512511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate } catch (RemoteException e) { 513511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate Log.e(TAG, "getAvailableRestoreToken() couldn't connect"); 514511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate } 515511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate } 516511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate return 0; 517511d02fcc37dce092e17354d53023db44817ebe6Christopher Tate } 518fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 519fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov /** 5209448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov * Ask the framework whether this app is eligible for backup. 5219448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov * 5229448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov * <p>Callers must hold the android.permission.BACKUP permission to use this method. 5239448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov * 5249448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov * @param packageName The name of the package. 5259448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov * @return Whether this app is eligible for backup. 5269448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov * 5279448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov * @hide 5289448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov */ 5299448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov @SystemApi 5309448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov public boolean isAppEligibleForBackup(String packageName) { 5319448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov checkServiceBinder(); 5329448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov if (sService != null) { 5339448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov try { 5349448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov return sService.isAppEligibleForBackup(packageName); 5359448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov } catch (RemoteException e) { 5369448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov Log.e(TAG, "isAppEligibleForBackup(pkg) couldn't connect"); 5379448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov } 5389448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov } 5399448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov return false; 5409448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov } 5419448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov 5429448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov /** 543fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * Request an immediate backup, providing an observer to which results of the backup operation 544fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * will be published. The Android backup system will decide for each package whether it will 545fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * be full app data backup or key/value-pair-based backup. 546fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 547fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * <p>If this method returns {@link BackupManager#SUCCESS}, the OS will attempt to backup all 548fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * provided packages using the remote transport. 549fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 550fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @param packages List of package names to backup. 551fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @param observer The {@link BackupObserver} to receive callbacks during the backup 552899edf6f4fef302ff219ee346b47afc5c8b640aaSergey Poromov * operation. Could be {@code null}. 553fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @return {@link BackupManager#SUCCESS} on success; nonzero on error. 554fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @exception IllegalArgumentException on null or empty {@code packages} param. 555fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * 556fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * @hide 557fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov */ 558fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @SystemApi 559fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public int requestBackup(String[] packages, BackupObserver observer) { 560b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot return requestBackup(packages, observer, null, 0); 56138e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge } 56238e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge 56338e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge /** 56438e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * Request an immediate backup, providing an observer to which results of the backup operation 56538e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * will be published. The Android backup system will decide for each package whether it will 56638e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * be full app data backup or key/value-pair-based backup. 56738e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * 56838e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * <p>If this method returns {@link BackupManager#SUCCESS}, the OS will attempt to backup all 56938e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * provided packages using the remote transport. 57038e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * 57138e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * @param packages List of package names to backup. 57238e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * @param observer The {@link BackupObserver} to receive callbacks during the backup 57338e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * operation. Could be {@code null}. 574b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot * @param monitor The {@link BackupManagerMonitorWrapper} to receive callbacks of important 575b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot * events during the backup operation. Could be {@code null}. 57638e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * @param flags {@link #FLAG_NON_INCREMENTAL_BACKUP}. 57738e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * @return {@link BackupManager#SUCCESS} on success; nonzero on error. 57838e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * @throws IllegalArgumentException on null or empty {@code packages} param. 57938e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge * @hide 58038e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge */ 58138e7486d3870797f7cc6e2cd2f5b59462a66b1a6Shreyas Basarge @SystemApi 582b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot public int requestBackup(String[] packages, BackupObserver observer, 583b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot BackupManagerMonitor monitor, int flags) { 584fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov checkServiceBinder(); 585fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov if (sService != null) { 586fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov try { 587899edf6f4fef302ff219ee346b47afc5c8b640aaSergey Poromov BackupObserverWrapper observerWrapper = observer == null 588899edf6f4fef302ff219ee346b47afc5c8b640aaSergey Poromov ? null 589899edf6f4fef302ff219ee346b47afc5c8b640aaSergey Poromov : new BackupObserverWrapper(mContext, observer); 590b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot BackupManagerMonitorWrapper monitorWrapper = monitor == null 591b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot ? null 592b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot : new BackupManagerMonitorWrapper(monitor); 593b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot return sService.requestBackup(packages, observerWrapper, monitorWrapper, flags); 594fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } catch (RemoteException e) { 595fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov Log.e(TAG, "requestBackup() couldn't connect"); 596fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 597fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 598fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov return -1; 599fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 600fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 601fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov /* 602fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * We wrap incoming binder calls with a private class implementation that 603fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * redirects them into main-thread actions. This serializes the backup 604fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov * progress callbacks nicely within the usual main-thread lifecycle pattern. 605fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov */ 606fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @SystemApi 607fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov private class BackupObserverWrapper extends IBackupObserver.Stub { 608fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov final Handler mHandler; 609fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov final BackupObserver mObserver; 610fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 611fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov static final int MSG_UPDATE = 1; 612fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov static final int MSG_RESULT = 2; 613fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov static final int MSG_FINISHED = 3; 614fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 615fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov BackupObserverWrapper(Context context, BackupObserver observer) { 616fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mHandler = new Handler(context.getMainLooper()) { 617fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @Override 618fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public void handleMessage(Message msg) { 619fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov switch (msg.what) { 620fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov case MSG_UPDATE: 621fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov Pair<String, BackupProgress> obj = 622fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov (Pair<String, BackupProgress>) msg.obj; 623fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mObserver.onUpdate(obj.first, obj.second); 624fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov break; 625fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov case MSG_RESULT: 626fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mObserver.onResult((String)msg.obj, msg.arg1); 627fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov break; 628fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov case MSG_FINISHED: 629fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mObserver.backupFinished(msg.arg1); 630fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov break; 631fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov default: 632fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov Log.w(TAG, "Unknown message: " + msg); 633fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov break; 634fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 635fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 636fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov }; 637fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mObserver = observer; 638fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 639fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 640fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov // Binder calls into this object just enqueue on the main-thread handler 641fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @Override 642fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public void onUpdate(String currentPackage, BackupProgress backupProgress) { 643fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mHandler.sendMessage( 644fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mHandler.obtainMessage(MSG_UPDATE, Pair.create(currentPackage, backupProgress))); 645fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 646fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 647fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @Override 648fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public void onResult(String currentPackage, int status) { 649fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mHandler.sendMessage( 6504b51d99a019f9b14e5698ba16e9540c179bdcd05Sergey Poromov mHandler.obtainMessage(MSG_RESULT, status, 0, currentPackage)); 651fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 652fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov 653fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov @Override 654fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov public void backupFinished(int status) { 655fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mHandler.sendMessage( 656fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov mHandler.obtainMessage(MSG_FINISHED, status, 0)); 657fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 658fe06bf64d204c459699b0bf6465f9fb69208345eSergey Poromov } 659865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 660865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge private class SelectTransportListenerWrapper extends ISelectBackupTransportCallback.Stub { 661865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 662865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge private final Handler mHandler; 663865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge private final SelectBackupTransportCallback mListener; 664865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 665865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge SelectTransportListenerWrapper(Context context, SelectBackupTransportCallback listener) { 666865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge mHandler = new Handler(context.getMainLooper()); 667865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge mListener = listener; 668865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 669865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 670865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge @Override 671865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge public void onSuccess(final String transportName) { 672865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge mHandler.post(new Runnable() { 673865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge @Override 674865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge public void run() { 675865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge mListener.onSuccess(transportName); 676865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 677865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge }); 678865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 679865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge 680865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge @Override 681865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge public void onFailure(final int reason) { 682865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge mHandler.post(new Runnable() { 683865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge @Override 684865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge public void run() { 685865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge mListener.onFailure(reason); 686865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 687865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge }); 688865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 689865303fce57b968f5bd7efb4dd23ccb1a3747b93Shreyas Basarge } 690b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot 691b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot private class BackupManagerMonitorWrapper extends IBackupManagerMonitor.Stub { 692b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot final BackupManagerMonitor mMonitor; 693b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot 694b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot BackupManagerMonitorWrapper(BackupManagerMonitor monitor) { 695b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot mMonitor = monitor; 696b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot } 697b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot 698b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot @Override 699b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot public void onEvent(final Bundle event) throws RemoteException { 700b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot mMonitor.onEvent(event); 701b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot } 702b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot } 703b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot 704a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate} 705