BackupManager.java revision 043dadc7516d20c3b3ccbcb20c53aaeef076a237
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 17a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tatepackage android.backup; 18a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 19a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tateimport android.content.Context; 20a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tateimport android.os.RemoteException; 21a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tateimport android.os.ServiceManager; 22a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 23a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate/** 24a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * BackupManager is the interface to the system's backup service. 25a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * Applications simply instantiate one, and then use that instance 26a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * to communicate with the backup infrastructure. 27a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * 28a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * <p>When your application has made changes to data it wishes to have 29a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * backed up, call {@link #dataChanged()} to notify the backup service. 30a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * The system will then schedule a backup operation to occur in the near 31a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * future. Repeated calls to {@link #dataChanged()} have no further effect 32a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * until the backup operation actually occurs. 33c114eb55b442981e2ea0a8989aa6ed458fc418e4Christopher Tate * 34a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * <p>The backup operation itself begins with the system launching the 35a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * {@link BackupService} subclass declared in your manifest. See the documentation 36a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * for {@link BackupService} for a detailed description of how the backup then proceeds. 37c114eb55b442981e2ea0a8989aa6ed458fc418e4Christopher Tate * 38c114eb55b442981e2ea0a8989aa6ed458fc418e4Christopher Tate * @hide pending API solidification 39a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate */ 40a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tatepublic class BackupManager { 41a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate private Context mContext; 42a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate private IBackupManager mService; 43a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 44a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate /** 45043dadc7516d20c3b3ccbcb20c53aaeef076a237Christopher Tate * Defined backup transports understood by {@link IBackupManager.selectBackupTransport}. 46043dadc7516d20c3b3ccbcb20c53aaeef076a237Christopher Tate */ 47043dadc7516d20c3b3ccbcb20c53aaeef076a237Christopher Tate public static final int TRANSPORT_ADB = 1; 48043dadc7516d20c3b3ccbcb20c53aaeef076a237Christopher Tate public static final int TRANSPORT_GOOGLE = 2; 49043dadc7516d20c3b3ccbcb20c53aaeef076a237Christopher Tate 50043dadc7516d20c3b3ccbcb20c53aaeef076a237Christopher Tate /** 51a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * Constructs a BackupManager object through which the application can 52a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * communicate with the Android backup system. 53c114eb55b442981e2ea0a8989aa6ed458fc418e4Christopher Tate * 54a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * @param context The {@link android.content.Context} that was provided when 55a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * one of your application's {@link android.app.Activity Activities} 56a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * was created. 57a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate */ 58c114eb55b442981e2ea0a8989aa6ed458fc418e4Christopher Tate public BackupManager(Context context) { 59a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate mContext = context; 60a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate mService = IBackupManager.Stub.asInterface( 61a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate ServiceManager.getService(Context.BACKUP_SERVICE)); 62a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate } 63a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate 64a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate /** 65a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * Notifies the Android backup system that your application wishes to back up 66a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * new changes to its data. A backup operation using your application's 67a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate * {@link BackupService} subclass will be scheduled when you call this method. 68a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate */ 69a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate public void dataChanged() { 70a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate try { 71a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate mService.dataChanged(mContext.getPackageName()); 72a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate } catch (RemoteException e) { 73a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate } 74a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate } 75a8bf815c6153290b173f34b071dddb0a0034a115Christopher Tate} 76