Merge change 6437 into donut
* changes: Backup / Restore locale preference.
This commit is contained in:
@ -1359,8 +1359,21 @@ public final class Settings {
|
|||||||
SCREEN_BRIGHTNESS,
|
SCREEN_BRIGHTNESS,
|
||||||
VIBRATE_ON,
|
VIBRATE_ON,
|
||||||
NOTIFICATIONS_USE_RING_VOLUME,
|
NOTIFICATIONS_USE_RING_VOLUME,
|
||||||
RINGTONE,
|
MODE_RINGER,
|
||||||
NOTIFICATION_SOUND,
|
MODE_RINGER_STREAMS_AFFECTED,
|
||||||
|
MUTE_STREAMS_AFFECTED,
|
||||||
|
VOLUME_VOICE,
|
||||||
|
VOLUME_SYSTEM,
|
||||||
|
VOLUME_RING,
|
||||||
|
VOLUME_MUSIC,
|
||||||
|
VOLUME_ALARM,
|
||||||
|
VOLUME_NOTIFICATION,
|
||||||
|
VOLUME_VOICE + APPEND_FOR_LAST_AUDIBLE,
|
||||||
|
VOLUME_SYSTEM + APPEND_FOR_LAST_AUDIBLE,
|
||||||
|
VOLUME_RING + APPEND_FOR_LAST_AUDIBLE,
|
||||||
|
VOLUME_MUSIC + APPEND_FOR_LAST_AUDIBLE,
|
||||||
|
VOLUME_ALARM + APPEND_FOR_LAST_AUDIBLE,
|
||||||
|
VOLUME_NOTIFICATION + APPEND_FOR_LAST_AUDIBLE,
|
||||||
TEXT_AUTO_REPLACE,
|
TEXT_AUTO_REPLACE,
|
||||||
TEXT_AUTO_CAPS,
|
TEXT_AUTO_CAPS,
|
||||||
TEXT_AUTO_PUNCTUATE,
|
TEXT_AUTO_PUNCTUATE,
|
||||||
@ -2299,6 +2312,8 @@ public final class Settings {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final String[] SETTINGS_TO_BACKUP = {
|
public static final String[] SETTINGS_TO_BACKUP = {
|
||||||
|
ADB_ENABLED,
|
||||||
|
ALLOW_MOCK_LOCATION,
|
||||||
INSTALL_NON_MARKET_APPS,
|
INSTALL_NON_MARKET_APPS,
|
||||||
PARENTAL_CONTROL_ENABLED,
|
PARENTAL_CONTROL_ENABLED,
|
||||||
PARENTAL_CONTROL_REDIRECT_URL,
|
PARENTAL_CONTROL_REDIRECT_URL,
|
||||||
|
@ -50,6 +50,7 @@ public class SettingsBackupAgent extends BackupHelperAgent {
|
|||||||
private static final String KEY_SYSTEM = "system";
|
private static final String KEY_SYSTEM = "system";
|
||||||
private static final String KEY_SECURE = "secure";
|
private static final String KEY_SECURE = "secure";
|
||||||
private static final String KEY_SYNC = "sync_providers";
|
private static final String KEY_SYNC = "sync_providers";
|
||||||
|
private static final String KEY_LOCALE = "locale";
|
||||||
|
|
||||||
private static String[] sortedSystemKeys = null;
|
private static String[] sortedSystemKeys = null;
|
||||||
private static String[] sortedSecureKeys = null;
|
private static String[] sortedSecureKeys = null;
|
||||||
@ -85,6 +86,7 @@ public class SettingsBackupAgent extends BackupHelperAgent {
|
|||||||
byte[] systemSettingsData = getSystemSettings();
|
byte[] systemSettingsData = getSystemSettings();
|
||||||
byte[] secureSettingsData = getSecureSettings();
|
byte[] secureSettingsData = getSecureSettings();
|
||||||
byte[] syncProviders = mSettingsHelper.getSyncProviders();
|
byte[] syncProviders = mSettingsHelper.getSyncProviders();
|
||||||
|
byte[] locale = mSettingsHelper.getLocaleData();
|
||||||
|
|
||||||
data.writeEntityHeader(KEY_SYSTEM, systemSettingsData.length);
|
data.writeEntityHeader(KEY_SYSTEM, systemSettingsData.length);
|
||||||
data.writeEntityData(systemSettingsData, systemSettingsData.length);
|
data.writeEntityData(systemSettingsData, systemSettingsData.length);
|
||||||
@ -95,6 +97,9 @@ public class SettingsBackupAgent extends BackupHelperAgent {
|
|||||||
data.writeEntityHeader(KEY_SYNC, syncProviders.length);
|
data.writeEntityHeader(KEY_SYNC, syncProviders.length);
|
||||||
data.writeEntityData(syncProviders, syncProviders.length);
|
data.writeEntityData(syncProviders, syncProviders.length);
|
||||||
|
|
||||||
|
data.writeEntityHeader(KEY_LOCALE, locale.length);
|
||||||
|
data.writeEntityData(locale, locale.length);
|
||||||
|
|
||||||
backupFile(FILE_WIFI_SUPPLICANT, data);
|
backupFile(FILE_WIFI_SUPPLICANT, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,14 +112,20 @@ public class SettingsBackupAgent extends BackupHelperAgent {
|
|||||||
|
|
||||||
while (data.readNextHeader()) {
|
while (data.readNextHeader()) {
|
||||||
final String key = data.getKey();
|
final String key = data.getKey();
|
||||||
|
final int size = data.getDataSize();
|
||||||
if (KEY_SYSTEM.equals(key)) {
|
if (KEY_SYSTEM.equals(key)) {
|
||||||
restoreSettings(data, Settings.System.CONTENT_URI);
|
restoreSettings(data, Settings.System.CONTENT_URI);
|
||||||
} else if (KEY_SECURE.equals(key)) {
|
} else if (KEY_SECURE.equals(key)) {
|
||||||
restoreSettings(data, Settings.Secure.CONTENT_URI);
|
restoreSettings(data, Settings.Secure.CONTENT_URI);
|
||||||
} else if (FILE_WIFI_SUPPLICANT.equals(key)) {
|
// TODO: Re-enable WIFI restore when we figure out a solution for the permissions
|
||||||
restoreFile(FILE_WIFI_SUPPLICANT, data);
|
// } else if (FILE_WIFI_SUPPLICANT.equals(key)) {
|
||||||
|
// restoreFile(FILE_WIFI_SUPPLICANT, data);
|
||||||
} else if (KEY_SYNC.equals(key)) {
|
} else if (KEY_SYNC.equals(key)) {
|
||||||
mSettingsHelper.setSyncProviders(data);
|
mSettingsHelper.setSyncProviders(data);
|
||||||
|
} else if (KEY_LOCALE.equals(key)) {
|
||||||
|
byte[] localeData = new byte[size];
|
||||||
|
data.readEntityData(localeData, 0, size);
|
||||||
|
mSettingsHelper.setLocaleData(localeData);
|
||||||
} else {
|
} else {
|
||||||
data.skipEntityData();
|
data.skipEntityData();
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,22 @@
|
|||||||
|
|
||||||
package com.android.providers.settings;
|
package com.android.providers.settings;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import android.app.ActivityManagerNative;
|
||||||
|
import android.app.IActivityManager;
|
||||||
import android.backup.BackupDataInput;
|
import android.backup.BackupDataInput;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.IContentService;
|
import android.content.IContentService;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.IHardwareService;
|
import android.os.IHardwareService;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class SettingsHelper {
|
public class SettingsHelper {
|
||||||
@ -110,7 +116,6 @@ public class SettingsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Get a list of all sync providers and save/restore the settings */
|
|
||||||
byte[] getSyncProviders() {
|
byte[] getSyncProviders() {
|
||||||
byte[] sync = new byte[1 + PROVIDERS.length];
|
byte[] sync = new byte[1 + PROVIDERS.length];
|
||||||
try {
|
try {
|
||||||
@ -141,4 +146,53 @@ public class SettingsHelper {
|
|||||||
Log.w(TAG, "Unable to read sync settings");
|
Log.w(TAG, "Unable to read sync settings");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte[] getLocaleData() {
|
||||||
|
Configuration conf = mContext.getResources().getConfiguration();
|
||||||
|
final Locale loc = conf.locale;
|
||||||
|
String localeString = loc.getLanguage();
|
||||||
|
String country = loc.getCountry();
|
||||||
|
if (!TextUtils.isEmpty(country)) {
|
||||||
|
localeString += "_" + country;
|
||||||
|
}
|
||||||
|
return localeString.getBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the locale specified. Input data is the equivalent of "ll_cc".getBytes(), where
|
||||||
|
* "ll" is the language code and "cc" is the country code.
|
||||||
|
* @param data the locale string in bytes.
|
||||||
|
*/
|
||||||
|
void setLocaleData(byte[] data) {
|
||||||
|
// Check if locale was set by the user:
|
||||||
|
Configuration conf = mContext.getResources().getConfiguration();
|
||||||
|
Locale loc = conf.locale;
|
||||||
|
if (conf.userSetLocale) return; // Don't change if user set it in the SetupWizard
|
||||||
|
|
||||||
|
final String[] availableLocales = mContext.getAssets().getLocales();
|
||||||
|
String localeCode = new String(data);
|
||||||
|
String language = new String(data, 0, 2);
|
||||||
|
String country = data.length > 4 ? new String(data, 3, 2) : "";
|
||||||
|
loc = null;
|
||||||
|
for (int i = 0; i < availableLocales.length; i++) {
|
||||||
|
if (availableLocales[i].equals(localeCode)) {
|
||||||
|
loc = new Locale(language, country);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (loc == null) return; // Couldn't find the saved locale in this version of the software
|
||||||
|
|
||||||
|
try {
|
||||||
|
IActivityManager am = ActivityManagerNative.getDefault();
|
||||||
|
Configuration config = am.getConfiguration();
|
||||||
|
config.locale = loc;
|
||||||
|
// indicate this isn't some passing default - the user wants this remembered
|
||||||
|
config.userSetLocale = true;
|
||||||
|
|
||||||
|
am.updateConfiguration(config);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// Intentionally left blank
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package com.android.providers.settings;
|
|||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
import android.backup.IBackupManager;
|
import android.backup.BackupManager;
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@ -47,6 +47,8 @@ public class SettingsProvider extends ContentProvider {
|
|||||||
|
|
||||||
private DatabaseHelper mOpenHelper;
|
private DatabaseHelper mOpenHelper;
|
||||||
|
|
||||||
|
private BackupManager mBackupManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode a content URL into the table, projection, and arguments
|
* Decode a content URL into the table, projection, and arguments
|
||||||
* used to access the corresponding database rows.
|
* used to access the corresponding database rows.
|
||||||
@ -140,16 +142,7 @@ public class SettingsProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inform the backup manager about a data change
|
// Inform the backup manager about a data change
|
||||||
IBackupManager ibm = IBackupManager.Stub.asInterface(
|
mBackupManager.dataChanged();
|
||||||
ServiceManager.getService(Context.BACKUP_SERVICE));
|
|
||||||
if (ibm != null) {
|
|
||||||
try {
|
|
||||||
ibm.dataChanged(getContext().getPackageName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Try again later
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now send the notification through the content framework.
|
// Now send the notification through the content framework.
|
||||||
|
|
||||||
String notify = uri.getQueryParameter("notify");
|
String notify = uri.getQueryParameter("notify");
|
||||||
@ -189,6 +182,7 @@ public class SettingsProvider extends ContentProvider {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
mOpenHelper = new DatabaseHelper(getContext());
|
mOpenHelper = new DatabaseHelper(getContext());
|
||||||
|
mBackupManager = new BackupManager(getContext());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user