summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2013-07-05 15:05:46 +0200
committerDanny Baumann <dannybaumann@web.de>2013-07-10 14:38:50 +0200
commit416f0d447c9d341170ea8d033642a02c478e9095 (patch)
tree384a0c4e1cc3da5a290f2cff00f9732accb7a0b7 /services
parenta48d4ed29fa904f065786f9b773b605ad9638e6f (diff)
downloadframeworks_base-416f0d447c9d341170ea8d033642a02c478e9095.zip
frameworks_base-416f0d447c9d341170ea8d033642a02c478e9095.tar.gz
frameworks_base-416f0d447c9d341170ea8d033642a02c478e9095.tar.bz2
Also backup profiles file via backup manager.
Change-Id: Id70cb1bce15b7de127e4291e9482ab3fd7270f9f
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/ProfileManagerService.java32
-rw-r--r--services/java/com/android/server/SystemBackupAgent.java31
2 files changed, 55 insertions, 8 deletions
diff --git a/services/java/com/android/server/ProfileManagerService.java b/services/java/com/android/server/ProfileManagerService.java
index 3c3bfb3..a6f269f 100644
--- a/services/java/com/android/server/ProfileManagerService.java
+++ b/services/java/com/android/server/ProfileManagerService.java
@@ -25,6 +25,7 @@ import android.app.IProfileManager;
import android.app.NotificationGroup;
import android.app.Profile;
import android.app.ProfileGroup;
+import android.app.backup.BackupManager;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -34,12 +35,14 @@ import android.content.res.XmlResourceParser;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiSsid;
import android.net.wifi.WifiInfo;
+import android.os.Environment;
import android.os.RemoteException;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import android.os.ParcelUuid;
+import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@@ -70,7 +73,8 @@ public class ProfileManagerService extends IProfileManager.Stub {
public static final String PERMISSION_CHANGE_SETTINGS = "android.permission.WRITE_SETTINGS";
- private static final String PROFILE_FILENAME = "/data/system/profiles.xml";
+ /* package */ static final File PROFILE_FILE =
+ new File(Environment.getSystemSecureDirectory(), "profiles.xml");
private static final String TAG = "ProfileService";
@@ -89,7 +93,7 @@ public class ProfileManagerService extends IProfileManager.Stub {
private Context mContext;
private boolean mDirty;
-
+ private BackupManager mBackupManager;
private WifiManager mWifiManager;
private String mLastConnectedSSID;
@@ -142,7 +146,8 @@ public class ProfileManagerService extends IProfileManager.Stub {
public ProfileManagerService(Context context) {
mContext = context;
- mWifiManager = (WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
+ mBackupManager = new BackupManager(mContext);
+ mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mLastConnectedSSID = getActiveSSID();
mWildcardGroup = new NotificationGroup(
@@ -173,7 +178,7 @@ public class ProfileManagerService extends IProfileManager.Stub {
boolean init = skipFile;
- if (! skipFile) {
+ if (!skipFile) {
try {
loadFromFile();
} catch (RemoteException e) {
@@ -498,10 +503,19 @@ public class ProfileManagerService extends IProfileManager.Stub {
return null;
}
+ // Called by SystemBackupAgent after files are restored to disk.
+ void settingsRestored() {
+ initialize();
+ for (Profile p : mProfiles.values()) {
+ p.validateRingtones(mContext);
+ }
+ persistIfDirty();
+ }
+
private void loadFromFile() throws RemoteException, XmlPullParserException, IOException {
XmlPullParserFactory xppf = XmlPullParserFactory.newInstance();
XmlPullParser xpp = xppf.newPullParser();
- FileReader fr = new FileReader(PROFILE_FILENAME);
+ FileReader fr = new FileReader(PROFILE_FILE);
xpp.setInput(fr);
loadXml(xpp, mContext);
fr.close();
@@ -530,7 +544,7 @@ public class ProfileManagerService extends IProfileManager.Stub {
addNotificationGroupInternal(ng);
}
} else if (event == XmlPullParser.END_DOCUMENT) {
- throw new IOException("Premature end of file while reading " + PROFILE_FILENAME);
+ throw new IOException("Premature end of file while reading " + PROFILE_FILE);
}
event = xpp.next();
}
@@ -609,11 +623,15 @@ public class ProfileManagerService extends IProfileManager.Stub {
if (dirty) {
try {
Log.d(TAG, "Saving profile data...");
- FileWriter fw = new FileWriter(PROFILE_FILENAME);
+ FileWriter fw = new FileWriter(PROFILE_FILE);
fw.write(getXmlString());
fw.close();
Log.d(TAG, "Save completed.");
mDirty = false;
+
+ long token = clearCallingIdentity();
+ mBackupManager.dataChanged();
+ restoreCallingIdentity(token);
} catch (Throwable e) {
e.printStackTrace();
}
diff --git a/services/java/com/android/server/SystemBackupAgent.java b/services/java/com/android/server/SystemBackupAgent.java
index 8cf273d..eeeec83 100644
--- a/services/java/com/android/server/SystemBackupAgent.java
+++ b/services/java/com/android/server/SystemBackupAgent.java
@@ -17,6 +17,7 @@
package com.android.server;
+import android.app.backup.AbsoluteFileBackupHelper;
import android.app.backup.BackupDataInput;
import android.app.backup.BackupDataOutput;
import android.app.backup.BackupAgentHelper;
@@ -46,6 +47,11 @@ public class SystemBackupAgent extends BackupAgentHelper {
private static final String WALLPAPER_IMAGE_FILENAME = "wallpaper";
private static final String WALLPAPER_INFO_FILENAME = "wallpaper_info.xml";
+ private static final String PROFILES_FILENAME =
+ ProfileManagerService.PROFILE_FILE.getName();
+ private static final String PROFILES_FILE_DIRECTORY =
+ ProfileManagerService.PROFILE_FILE.getParentFile().getAbsolutePath();
+
// TODO: Will need to change if backing up non-primary user's wallpaper
private static final String WALLPAPER_IMAGE_DIR =
Environment.getUserSystemDirectory(UserHandle.USER_OWNER).getAbsolutePath();
@@ -75,13 +81,16 @@ public class SystemBackupAgent extends BackupAgentHelper {
keys = new String[] { WALLPAPER_INFO_KEY };
}
addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files, keys));
+ addHelper("profiles", new AbsoluteFileBackupHelper(SystemBackupAgent.this,
+ ProfileManagerService.PROFILE_FILE.getAbsolutePath()));
super.onBackup(oldState, data, newState);
}
@Override
public void onFullBackup(FullBackupDataOutput data) throws IOException {
- // At present we back up only the wallpaper
+ // At present we back up only the wallpaper and profiles
fullWallpaperBackup(data);
+ fullProfilesBackup(data);
}
private void fullWallpaperBackup(FullBackupDataOutput output) {
@@ -95,6 +104,11 @@ public class SystemBackupAgent extends BackupAgentHelper {
WALLPAPER_IMAGE_DIR, WALLPAPER_IMAGE, output.getData());
}
+ private void fullProfilesBackup(FullBackupDataOutput output) {
+ FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
+ PROFILES_FILE_DIRECTORY, PROFILES_FILENAME, output.getData());
+ }
+
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
throws IOException {
@@ -105,13 +119,19 @@ public class SystemBackupAgent extends BackupAgentHelper {
addHelper("system_files", new WallpaperBackupHelper(SystemBackupAgent.this,
new String[] { WALLPAPER_IMAGE },
new String[] { WALLPAPER_IMAGE_KEY} ));
+ addHelper("profiles", new AbsoluteFileBackupHelper(SystemBackupAgent.this,
+ ProfileManagerService.PROFILE_FILE.getAbsolutePath()));
try {
super.onRestore(data, appVersionCode, newState);
WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService(
Context.WALLPAPER_SERVICE);
+ ProfileManagerService profiles = (ProfileManagerService)ServiceManager.getService(
+ Context.PROFILE_SERVICE);
+
wallpaper.settingsRestored();
+ profiles.settingsRestored();
} catch (IOException ex) {
// If there was a failure, delete everything for the wallpaper, this is too aggressive,
// but this is hopefully a rare failure.
@@ -129,6 +149,7 @@ public class SystemBackupAgent extends BackupAgentHelper {
// Bits to indicate postprocessing we may need to perform
boolean restoredWallpaper = false;
+ boolean restoredProfiles = false;
File outFile = null;
// Various domain+files we understand a priori
@@ -139,6 +160,9 @@ public class SystemBackupAgent extends BackupAgentHelper {
} else if (path.equals(WALLPAPER_IMAGE_FILENAME)) {
outFile = new File(WALLPAPER_IMAGE);
restoredWallpaper = true;
+ } else if (path.equals(PROFILES_FILENAME)) {
+ outFile = ProfileManagerService.PROFILE_FILE;
+ restoredProfiles = true;
}
}
@@ -154,6 +178,11 @@ public class SystemBackupAgent extends BackupAgentHelper {
Context.WALLPAPER_SERVICE);
wallpaper.settingsRestored();
}
+ if (restoredProfiles) {
+ ProfileManagerService profiles = (ProfileManagerService)
+ ServiceManager.getService(Context.PROFILE_SERVICE);
+ profiles.settingsRestored();
+ }
} catch (IOException e) {
if (restoredWallpaper) {
// Make sure we wind up in a good state