summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2009-04-29 14:03:25 -0700
committerChristopher Tate <ctate@google.com>2009-04-29 14:49:30 -0700
commit487529a70cd1479ae8d6bbfb356be7e72542c185 (patch)
treeca19a948a28e9d4eb7b4c9890b006e43b89d7a6d /core/java/android
parentdc67739af90aa31a0b546c14bf1e68e6acbb8375 (diff)
downloadframeworks_base-487529a70cd1479ae8d6bbfb356be7e72542c185.zip
frameworks_base-487529a70cd1479ae8d6bbfb356be7e72542c185.tar.gz
frameworks_base-487529a70cd1479ae8d6bbfb356be7e72542c185.tar.bz2
First baby steps towards settings backup
This change adds a sketched outline of the backup system architecture, with all of the major pieces represented other than client-side helpers for specific types of data. IBackupManager and BackupService are public so that we can write test apps against SDK-domain symbols from the outset. What code exists in this change hasn't been tested and may crash. It's the beginnings of the real implementation but of course is barely begun.
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/backup/BackupService.java106
-rw-r--r--core/java/android/backup/IBackupManager.aidl32
-rw-r--r--core/java/android/backup/IBackupService.aidl53
-rw-r--r--core/java/android/content/Context.java9
4 files changed, 200 insertions, 0 deletions
diff --git a/core/java/android/backup/BackupService.java b/core/java/android/backup/BackupService.java
new file mode 100644
index 0000000..5cfa4f2
--- /dev/null
+++ b/core/java/android/backup/BackupService.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.backup;
+
+import android.annotation.SdkConstant;
+import android.annotation.SdkConstant.SdkConstantType;
+import android.app.Service;
+import android.backup.IBackupService;
+import android.content.Intent;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Log;
+
+/**
+ * This is the central interface between an application and Android's
+ * settings backup mechanism.
+ *
+ * <p><em>Not hidden but API subject to change and should not be published</em>
+ */
+
+public abstract class BackupService extends Service {
+ /**
+ * Service Action: Participate in the backup infrastructure. Applications
+ * that wish to use the Android backup mechanism must provide an exported
+ * subclass of BackupService and give it an {@link android.content.IntentFilter
+ * IntentFilter} that accepts this action.
+ */
+ @SdkConstant(SdkConstantType.SERVICE_ACTION)
+ public static final String SERVICE_ACTION = "android.service.action.BACKUP";
+
+ /**
+ * The application is being asked to write any data changed since the
+ * last time it performed a backup operation. The state data recorded
+ * during the last backup pass is provided in the oldStateFd file descriptor.
+ * If oldStateFd is negative, no old state is available and the application
+ * should perform a full backup. In both cases, a representation of the
+ * final backup state after this pass should be written to the file pointed
+ * to by the newStateFd file descriptor.
+ *
+ * @param oldStateFd An open, read-only file descriptor pointing to the last
+ * backup state provided by the application. May be negative,
+ * in which case no prior state is being provided and the
+ * application should perform a full backup.
+ * @param dataFd An open, read/write file descriptor pointing to the backup data
+ * destination. Typically the application will use backup helper
+ * classes to write to this file.
+ * @param newStateFd An open, read/write file descriptor pointing to an empty
+ * file. The application should record the final backup state
+ * here after writing the requested data to dataFd.
+ */
+ public abstract void onBackup(int oldStateFd, int dataFd, int newStateFd);
+
+ /**
+ * The application is being restored from backup, and should replace any
+ * existing data with the contents of the backup. The backup data is
+ * provided in the file pointed to by the dataFd file descriptor. Once
+ * the restore is finished, the application should write a representation
+ * of the final state to the newStateFd file descriptor,
+ *
+ * @param dataFd An open, read-only file descriptor pointing to a full snapshot
+ * of the application's data.
+ * @param newStateFd An open, read/write file descriptor pointing to an empty
+ * file. The application should record the final backup state
+ * here after restoring its data from dataFd.
+ */
+ public abstract void onRestore(int dataFd, int newStateFd);
+
+
+ // ----- Core implementation -----
+
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+
+ private final IBinder mBinder = new BackupServiceBinder().asBinder();
+
+ // ----- IBackupService binder interface -----
+ private class BackupServiceBinder extends IBackupService.Stub {
+ public void doBackup(int oldStateFd, int dataFd, int newStateFd)
+ throws RemoteException {
+ // !!! TODO - real implementation; for now just invoke the callbacks directly
+ Log.v("BackupServiceBinder", "doBackup() invoked");
+ BackupService.this.onBackup(oldStateFd, dataFd, newStateFd);
+ }
+
+ public void doRestore(int dataFd, int newStateFd) throws RemoteException {
+ // !!! TODO - real implementation; for now just invoke the callbacks directly
+ Log.v("BackupServiceBinder", "doRestore() invoked");
+ BackupService.this.onRestore(dataFd, newStateFd);
+ }
+ }
+}
diff --git a/core/java/android/backup/IBackupManager.aidl b/core/java/android/backup/IBackupManager.aidl
new file mode 100644
index 0000000..40cebdd
--- /dev/null
+++ b/core/java/android/backup/IBackupManager.aidl
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.backup;
+
+/**
+ * Direct interface to the Backup Manager Service that applications invoke on. The only
+ * operation currently needed is a simple notification that the app has made changes to
+ * data it wishes to back up, so the system should run a backup pass.
+ *
+ * {@hide pending API solidification}
+ */
+interface IBackupManager {
+ /**
+ * Tell the system service that the caller has made changes to its
+ * data, and therefore needs to undergo a backup pass.
+ */
+ oneway void dataChanged();
+}
diff --git a/core/java/android/backup/IBackupService.aidl b/core/java/android/backup/IBackupService.aidl
new file mode 100644
index 0000000..24544bd
--- /dev/null
+++ b/core/java/android/backup/IBackupService.aidl
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.backup;
+
+/**
+ * Interface presented by applications being asked to participate in the
+ * backup & restore mechanism. End user code does not typically implement
+ * this interface; they subclass BackupService instead.
+ *
+ * {@hide}
+ */
+interface IBackupService {
+ /**
+ * Request that the app perform an incremental backup.
+ *
+ * @param oldStateFd Read-only file containing the description blob of the
+ * app's data state as of the last backup operation's completion.
+ *
+ * @param dataFd Read-write file, empty when onBackup() is called, that
+ * is the data destination for this backup pass's incrementals.
+ *
+ * @param newStateFd Read-write file, empty when onBackup() is called,
+ * where the new state blob is to be recorded.
+ */
+ void doBackup(int oldStateFd, int dataFd, int newStateFd);
+
+ /**
+ * Restore an entire data snapshot to the application.
+ *
+ * @param dataFd Read-only file containing the full data snapshot of the
+ * app's backup. This is to be a <i>replacement</i> of the app's
+ * current data, not to be merged into it.
+ *
+ * @param newStateFd Read-write file, empty when onRestore() is called,
+ * that is to be written with the state description that holds after
+ * the restore has been completed.
+ */
+ void doRestore(int dataFd, int newStateFd);
+}
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index a301449..f2ad248 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -1269,6 +1269,15 @@ public abstract class Context {
public static final String APPWIDGET_SERVICE = "appwidget";
/**
+ * Use with {@link #getSystemService} to retrieve an
+ * {@blink android.backup.IBackupManager IBackupManager} for communicating
+ * with the backup mechanism.
+ *
+ * @see #getSystemService
+ */
+ public static final String BACKUP_SERVICE = "backup";
+
+ /**
* Determine whether the given permission is allowed for a particular
* process and user ID running in the system.
*