Merge change 6287 into donut

* changes:
  Restore GPS state and ringer/vibrate toggles.
This commit is contained in:
Android (Google) Code Review
2009-07-06 17:32:09 -07:00
3 changed files with 73 additions and 20 deletions

View File

@@ -24,6 +24,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer; import org.xmlpull.v1.XmlSerializer;
import android.backup.IBackupManager;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
@@ -35,6 +36,7 @@ import android.os.Message;
import android.os.Parcel; import android.os.Parcel;
import android.os.RemoteCallbackList; import android.os.RemoteCallbackList;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.Xml; import android.util.Xml;
@@ -351,8 +353,18 @@ public class SyncStorageEngine extends Handler {
} }
} }
} }
// Inform the backup manager about a data change
IBackupManager ibm = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
if (ibm != null) {
try {
ibm.dataChanged("com.android.providers.settings");
} catch (RemoteException e) {
// Try again later
}
}
} }
public boolean getSyncProviderAutomatically(String account, String providerName) { public boolean getSyncProviderAutomatically(String account, String providerName) {
synchronized (mAuthorities) { synchronized (mAuthorities) {
if (account != null) { if (account != null) {

View File

@@ -166,11 +166,12 @@ public class SettingsBackupAgent extends BackupHelperAgent {
pos += length; pos += length;
if (!TextUtils.isEmpty(settingName) && !TextUtils.isEmpty(settingValue)) { if (!TextUtils.isEmpty(settingName) && !TextUtils.isEmpty(settingValue)) {
//Log.i(TAG, "Restore " + settingName + " = " + settingValue); //Log.i(TAG, "Restore " + settingName + " = " + settingValue);
cv.clear(); if (mSettingsHelper.restoreValue(settingName, settingValue)) {
cv.put(Settings.NameValueTable.NAME, settingName); cv.clear();
cv.put(Settings.NameValueTable.VALUE, settingValue); cv.put(Settings.NameValueTable.NAME, settingName);
getContentResolver().insert(contentUri, cv); cv.put(Settings.NameValueTable.VALUE, settingValue);
mSettingsHelper.restoreValue(settingName, settingValue); getContentResolver().insert(contentUri, cv);
}
} }
} }
} }

View File

@@ -19,12 +19,13 @@ package com.android.providers.settings;
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.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.content.IContentService;
import android.util.Log; import android.util.Log;
public class SettingsHelper { public class SettingsHelper {
@@ -33,10 +34,10 @@ public class SettingsHelper {
private Context mContext; private Context mContext;
private AudioManager mAudioManager; private AudioManager mAudioManager;
private IContentService mContentService; private IContentService mContentService;
private static final String SYNC_AUTO = "auto_sync"; private static final String[] PROVIDERS = { "gmail-ls", "calendar", "contacts" };
private static final String SYNC_MAIL = "gmail-ls_sync";
private static final String SYNC_CALENDAR = "calendar_sync"; private boolean mSilent;
private static final String SYNC_CONTACTS = "contacts_sync"; private boolean mVibrate;
public SettingsHelper(Context context) { public SettingsHelper(Context context) {
mContext = context; mContext = context;
@@ -45,15 +46,43 @@ public class SettingsHelper {
mContentService = ContentResolver.getContentService(); mContentService = ContentResolver.getContentService();
} }
public void restoreValue(String name, String value) { /**
* Sets the property via a call to the appropriate API, if any, and returns
* whether or not the setting should be saved to the database as well.
* @param name the name of the setting
* @param value the string value of the setting
* @return whether to continue with writing the value to the database. In
* some cases the data will be written by the call to the appropriate API,
* and in some cases the property value needs to be modified before setting.
*/
public boolean restoreValue(String name, String value) {
if (Settings.System.SCREEN_BRIGHTNESS.equals(name)) { if (Settings.System.SCREEN_BRIGHTNESS.equals(name)) {
setBrightness(Integer.parseInt(value)); setBrightness(Integer.parseInt(value));
} else if (Settings.System.SOUND_EFFECTS_ENABLED.equals(name)) { } else if (Settings.System.SOUND_EFFECTS_ENABLED.equals(name)) {
if (Integer.parseInt(value) == 1) { setSoundEffects(Integer.parseInt(value) == 1);
mAudioManager.loadSoundEffects(); } else if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) {
} else { setGpsLocation(value);
mAudioManager.unloadSoundEffects(); return false;
} }
return true;
}
private void setGpsLocation(String value) {
final String GPS = LocationManager.GPS_PROVIDER;
boolean enabled =
GPS.equals(value) ||
value.startsWith(GPS + ",") ||
value.endsWith("," + GPS) ||
value.contains("," + GPS + ",");
Settings.Secure.setLocationProviderEnabled(
mContext.getContentResolver(), GPS, enabled);
}
private void setSoundEffects(boolean enable) {
if (enable) {
mAudioManager.loadSoundEffects();
} else {
mAudioManager.unloadSoundEffects();
} }
} }
@@ -69,8 +98,19 @@ public class SettingsHelper {
} }
} }
static final String[] PROVIDERS = { "gmail-ls", "calendar", "contacts" }; private void setRingerMode() {
if (mSilent) {
mAudioManager.setRingerMode(mVibrate ? AudioManager.RINGER_MODE_VIBRATE :
AudioManager.RINGER_MODE_SILENT);
} else {
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
mVibrate ? AudioManager.VIBRATE_SETTING_ON
: AudioManager.VIBRATE_SETTING_OFF);
}
}
/* 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 {
@@ -85,7 +125,7 @@ public class SettingsHelper {
} }
return sync; return sync;
} }
void setSyncProviders(BackupDataInput backup) { void setSyncProviders(BackupDataInput backup) {
byte[] sync = new byte[backup.getDataSize()]; byte[] sync = new byte[backup.getDataSize()];