diff options
| -rw-r--r-- | api/current.xml | 76 | ||||
| -rw-r--r-- | core/java/android/backup/BackupManager.java | 69 | ||||
| -rw-r--r-- | core/java/android/backup/BackupService.java | 30 | ||||
| -rw-r--r-- | core/java/android/backup/IBackupManager.aidl | 7 | ||||
| -rw-r--r-- | core/java/com/android/internal/os/BatteryStatsImpl.java | 6 | ||||
| -rw-r--r-- | core/jni/android_location_GpsLocationProvider.cpp | 1 | ||||
| -rw-r--r-- | services/java/com/android/server/BackupManagerService.java | 12 |
7 files changed, 114 insertions, 87 deletions
diff --git a/api/current.xml b/api/current.xml index 75eec10b4beb..c732c30d6404 100644 --- a/api/current.xml +++ b/api/current.xml @@ -21740,82 +21740,6 @@ </field> </class> </package> -<package name="android.backup" -> -<class name="BackupService" - extends="android.app.Service" - abstract="true" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<constructor name="BackupService" - type="android.backup.BackupService" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -</constructor> -<method name="onBackup" - return="void" - abstract="true" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="oldStateFd" type="int"> -</parameter> -<parameter name="dataFd" type="int"> -</parameter> -<parameter name="newStateFd" type="int"> -</parameter> -</method> -<method name="onBind" - return="android.os.IBinder" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="intent" type="android.content.Intent"> -</parameter> -</method> -<method name="onRestore" - return="void" - abstract="true" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="dataFd" type="int"> -</parameter> -<parameter name="newStateFd" type="int"> -</parameter> -</method> -<field name="SERVICE_ACTION" - type="java.lang.String" - transient="false" - volatile="false" - value=""android.service.action.BACKUP"" - static="true" - final="true" - deprecated="not deprecated" - visibility="public" -> -</field> -</class> -</package> <package name="android.content" > <class name="ActivityNotFoundException" diff --git a/core/java/android/backup/BackupManager.java b/core/java/android/backup/BackupManager.java new file mode 100644 index 000000000000..6f0b2eef603f --- /dev/null +++ b/core/java/android/backup/BackupManager.java @@ -0,0 +1,69 @@ +/* + * 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.content.Context; +import android.os.RemoteException; +import android.os.ServiceManager; + +/** + * BackupManager is the interface to the system's backup service. + * Applications simply instantiate one, and then use that instance + * to communicate with the backup infrastructure. + * + * <p>When your application has made changes to data it wishes to have + * backed up, call {@link #dataChanged()} to notify the backup service. + * The system will then schedule a backup operation to occur in the near + * future. Repeated calls to {@link #dataChanged()} have no further effect + * until the backup operation actually occurs. + * + * <p>The backup operation itself begins with the system launching the + * {@link BackupService} subclass declared in your manifest. See the documentation + * for {@link BackupService} for a detailed description of how the backup then proceeds. + * + * @hide pending API solidification + */ +public class BackupManager { + private Context mContext; + private IBackupManager mService; + + /** + * Constructs a BackupManager object through which the application can + * communicate with the Android backup system. + * + * @param context The {@link android.content.Context} that was provided when + * one of your application's {@link android.app.Activity Activities} + * was created. + */ + public BackupManager(Context context) { + mContext = context; + mService = IBackupManager.Stub.asInterface( + ServiceManager.getService(Context.BACKUP_SERVICE)); + } + + /** + * Notifies the Android backup system that your application wishes to back up + * new changes to its data. A backup operation using your application's + * {@link BackupService} subclass will be scheduled when you call this method. + */ + public void dataChanged() { + try { + mService.dataChanged(mContext.getPackageName()); + } catch (RemoteException e) { + } + } +} diff --git a/core/java/android/backup/BackupService.java b/core/java/android/backup/BackupService.java index 5cfa4f273620..d912d8c6e7d0 100644 --- a/core/java/android/backup/BackupService.java +++ b/core/java/android/backup/BackupService.java @@ -29,7 +29,20 @@ 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> + * In order to use the backup service, your application must implement a + * subclass of BackupService, and declare an intent filter + * in the application manifest specifying that your BackupService subclass + * handles the {link #SERVICE_ACTION} intent action. For example: + * + * <pre class="prettyprint"> + * <!-- Use the class "MyBackupService" to perform backups for my app --> + * <service android:name=".MyBackupService"> + * <intent-filter> + * <action android:name="android.service.action.BACKUP"> + * </intent-filter> + * </service></pre> + * + * @hide pending API solidification */ public abstract class BackupService extends Service { @@ -40,7 +53,7 @@ public abstract class BackupService extends Service { * IntentFilter} that accepts this action. */ @SdkConstant(SdkConstantType.SERVICE_ACTION) - public static final String SERVICE_ACTION = "android.service.action.BACKUP"; + public static final String SERVICE_ACTION = "android.backup.BackupService"; /** * The application is being asked to write any data changed since the @@ -50,7 +63,7 @@ public abstract class BackupService extends Service { * 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 @@ -70,7 +83,7 @@ public abstract class BackupService extends Service { * 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 @@ -82,8 +95,15 @@ public abstract class BackupService extends Service { // ----- Core implementation ----- + /** + * Returns the private interface called by the backup system. Applications will + * not typically override this. + */ public IBinder onBind(Intent intent) { - return mBinder; + if (intent.getAction().equals(SERVICE_ACTION)) { + return mBinder; + } + return null; } private final IBinder mBinder = new BackupServiceBinder().asBinder(); diff --git a/core/java/android/backup/IBackupManager.aidl b/core/java/android/backup/IBackupManager.aidl index 40cebddedc79..7efaf589526b 100644 --- a/core/java/android/backup/IBackupManager.aidl +++ b/core/java/android/backup/IBackupManager.aidl @@ -21,12 +21,15 @@ package android.backup; * 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} + * Apps will use the {@link android.backup.BackupManager} class rather than going through + * this Binder interface directly. + * + * {@hide} */ 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(); + oneway void dataChanged(String packageName); } diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 77649f0bab0c..1218fe37cf7f 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -2360,6 +2360,12 @@ public final class BatteryStatsImpl extends BatteryStats { public void updateKernelWakelocksLocked() { Map<String, KernelWakelockStats> m = readKernelWakelockStats(); + if (m == null) { + // Not crashing might make board bringup easier. + Log.w(TAG, "Couldn't get kernel wake lock stats"); + return; + } + for (Map.Entry<String, KernelWakelockStats> ent : m.entrySet()) { String name = ent.getKey(); KernelWakelockStats kws = ent.getValue(); diff --git a/core/jni/android_location_GpsLocationProvider.cpp b/core/jni/android_location_GpsLocationProvider.cpp index bbde8d50f3df..9c63fd2e36eb 100644 --- a/core/jni/android_location_GpsLocationProvider.cpp +++ b/core/jni/android_location_GpsLocationProvider.cpp @@ -155,6 +155,7 @@ static jboolean android_location_GpsLocationProvider_init(JNIEnv* env, jobject o sGpsSuplInterface = (const GpsSuplInterface*)sGpsInterface->get_extension(GPS_SUPL_INTERFACE); if (sGpsSuplInterface) sGpsSuplInterface->init(&sGpsSuplCallbacks); + return true; } static void android_location_GpsLocationProvider_disable(JNIEnv* env, jobject obj) diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java index de14c337d989..0f953180f806 100644 --- a/services/java/com/android/server/BackupManagerService.java +++ b/services/java/com/android/server/BackupManagerService.java @@ -164,7 +164,7 @@ class BackupManagerService extends IBackupManager.Stub { // ----- IBackupManager binder interface ----- - public void dataChanged() throws RemoteException { + public void dataChanged(String packageName) throws RemoteException { // Record that we need a backup pass for the caller. Since multiple callers // may share a uid, we need to note all candidates within that uid and schedule // a backup pass for each of them. @@ -173,10 +173,14 @@ class BackupManagerService extends IBackupManager.Stub { if (targets != null) { synchronized (mQueueLock) { // Note that this client has made data changes that need to be backed up - // !!! add them to the set of pending packages for (ServiceInfo service : targets) { - if (mPendingBackups.add(service)) { - // !!! TODO: write to the pending-backup journal file in case of crash + // validate the caller-supplied package name against the known set of + // packages associated with this uid + if (service.packageName.equals(packageName)) { + // add the caller to the set of pending backups + if (mPendingBackups.add(service)) { + // !!! TODO: write to the pending-backup journal file in case of crash + } } } |