Merge change 5317 into donut

* changes:
  Start backing up wallpaper
This commit is contained in:
Android (Google) Code Review
2009-06-24 18:46:59 -07:00
5 changed files with 117 additions and 4 deletions

View File

@ -0,0 +1,66 @@
/*
* 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.ParcelFileDescriptor;
import android.util.Log;
import java.io.File;
import java.io.FileDescriptor;
/**
* Like FileBackupHelper, but takes absolute paths for the files instead of
* subpaths of getFilesDir()
*
* @hide
*/
public class AbsoluteFileBackupHelper extends FileBackupHelperBase implements BackupHelper {
private static final String TAG = "AbsoluteFileBackupHelper";
Context mContext;
String[] mFiles;
public AbsoluteFileBackupHelper(Context context, String... files) {
super(context);
mContext = context;
mFiles = files;
}
/**
* Based on oldState, determine which of the files from the application's data directory
* need to be backed up, write them to the data stream, and fill in newState with the
* state as it exists now.
*/
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) {
// use the file paths as the keys, too
performBackup_checked(oldState, data, newState, mFiles, mFiles);
}
public void restoreEntity(BackupDataInputStream data) {
// TODO: turn this off before ship
Log.d(TAG, "got entity '" + data.getKey() + "' size=" + data.size());
String key = data.getKey();
if (isKeyInList(key, mFiles)) {
File f = new File(key);
writeFile(f, data);
}
}
}

View File

@ -0,0 +1,35 @@
/*
* 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 com.android.internal.backup;
import android.backup.AbsoluteFileBackupHelper;
import android.backup.BackupHelperAgent;
/**
* Backup agent for various system-managed data
*/
public class SystemBackupAgent extends BackupHelperAgent {
// the set of files that we back up whole, as absolute paths
String[] mFiles = {
/* WallpaperService.WALLPAPER_FILE */
"/data/data/com.android.settings/files/wallpaper",
};
public void onCreate() {
addHelper("system_files", new AbsoluteFileBackupHelper(this, mFiles));
}
}

View File

@ -1000,6 +1000,7 @@
android:hasCode="false"
android:label="@string/android_system_label"
android:allowClearUserData="false"
android:backupAgent="com.android.internal.backup.SystemBackupAgent"
android:icon="@drawable/ic_launcher_android">
<activity android:name="com.android.internal.app.ChooserActivity"
android:theme="@style/Theme.Dialog.Alert"

View File

@ -76,8 +76,7 @@ class BackupManagerService extends IBackupManager.Stub {
private static final boolean DEBUG = true;
// Default time to wait after data changes before we back up the data
private static final long COLLECTION_INTERVAL = 1000;
//private static final long COLLECTION_INTERVAL = 3 * 60 * 1000;
private static final long COLLECTION_INTERVAL = 3 * 60 * 1000;
private static final int MSG_RUN_BACKUP = 1;
private static final int MSG_RUN_FULL_BACKUP = 2;
@ -360,7 +359,8 @@ class BackupManagerService extends IBackupManager.Stub {
if (DEBUG) {
Log.v(TAG, "Adding " + targetPkgs.size() + " backup participants:");
for (PackageInfo p : targetPkgs) {
Log.v(TAG, " " + p + " agent=" + p.applicationInfo.backupAgentName);
Log.v(TAG, " " + p + " agent=" + p.applicationInfo.backupAgentName
+ " uid=" + p.applicationInfo.uid);
}
}

View File

@ -18,8 +18,10 @@ package com.android.server;
import static android.os.FileObserver.*;
import static android.os.ParcelFileDescriptor.*;
import android.app.IWallpaperService;
import android.app.IWallpaperServiceCallback;
import android.backup.BackupManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -154,7 +156,16 @@ class WallpaperService extends IWallpaperService.Stub {
public ParcelFileDescriptor setWallpaper() {
checkPermission(android.Manifest.permission.SET_WALLPAPER);
try {
return ParcelFileDescriptor.open(WALLPAPER_FILE, MODE_CREATE|MODE_READ_WRITE);
ParcelFileDescriptor fd = ParcelFileDescriptor.open(WALLPAPER_FILE,
MODE_CREATE|MODE_READ_WRITE);
// changing the wallpaper means we'll need to back up the new one
long origId = Binder.clearCallingIdentity();
BackupManager bm = new BackupManager(mContext);
bm.dataChanged();
Binder.restoreCallingIdentity(origId);
return fd;
} catch (FileNotFoundException e) {
if (Config.LOGD) Log.d(TAG, "Error setting wallpaper", e);
}