diff options
| author | 2009-07-06 17:32:09 -0700 | |
|---|---|---|
| committer | 2009-07-06 17:32:09 -0700 | |
| commit | b71951591d72cddb4dbc3d39778dfcb5597a5733 (patch) | |
| tree | 0ff9f834f3ec48179ab2413532105aa5e3f4b273 | |
| parent | 870e09fcd2dfdc12ac318962efd28b0420c562bb (diff) | |
| parent | 70c874ba20b586712a7550b6c5efeb6dc0fdf9fa (diff) | |
Merge change 6287 into donut
* changes:
Restore GPS state and ringer/vibrate toggles.
3 files changed, 73 insertions, 20 deletions
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java index 9c25e73b0cf3..f781e0d0e12d 100644 --- a/core/java/android/content/SyncStorageEngine.java +++ b/core/java/android/content/SyncStorageEngine.java @@ -24,6 +24,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; +import android.backup.IBackupManager; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; @@ -35,6 +36,7 @@ import android.os.Message; import android.os.Parcel; import android.os.RemoteCallbackList; import android.os.RemoteException; +import android.os.ServiceManager; import android.util.Log; import android.util.SparseArray; 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) { synchronized (mAuthorities) { if (account != null) { diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java index 16be668c0d00..f9e98ef67d90 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java @@ -166,11 +166,12 @@ public class SettingsBackupAgent extends BackupHelperAgent { pos += length; if (!TextUtils.isEmpty(settingName) && !TextUtils.isEmpty(settingValue)) { //Log.i(TAG, "Restore " + settingName + " = " + settingValue); - cv.clear(); - cv.put(Settings.NameValueTable.NAME, settingName); - cv.put(Settings.NameValueTable.VALUE, settingValue); - getContentResolver().insert(contentUri, cv); - mSettingsHelper.restoreValue(settingName, settingValue); + if (mSettingsHelper.restoreValue(settingName, settingValue)) { + cv.clear(); + cv.put(Settings.NameValueTable.NAME, settingName); + cv.put(Settings.NameValueTable.VALUE, settingValue); + getContentResolver().insert(contentUri, cv); + } } } } diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java index b0655872df29..5f3fba815898 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java @@ -19,12 +19,13 @@ package com.android.providers.settings; import android.backup.BackupDataInput; import android.content.ContentResolver; import android.content.Context; +import android.content.IContentService; +import android.location.LocationManager; import android.media.AudioManager; import android.os.IHardwareService; import android.os.RemoteException; import android.os.ServiceManager; import android.provider.Settings; -import android.content.IContentService; import android.util.Log; public class SettingsHelper { @@ -33,10 +34,10 @@ public class SettingsHelper { private Context mContext; private AudioManager mAudioManager; private IContentService mContentService; - private static final String SYNC_AUTO = "auto_sync"; - private static final String SYNC_MAIL = "gmail-ls_sync"; - private static final String SYNC_CALENDAR = "calendar_sync"; - private static final String SYNC_CONTACTS = "contacts_sync"; + private static final String[] PROVIDERS = { "gmail-ls", "calendar", "contacts" }; + + private boolean mSilent; + private boolean mVibrate; public SettingsHelper(Context context) { mContext = context; @@ -45,15 +46,43 @@ public class SettingsHelper { 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)) { setBrightness(Integer.parseInt(value)); } else if (Settings.System.SOUND_EFFECTS_ENABLED.equals(name)) { - if (Integer.parseInt(value) == 1) { - mAudioManager.loadSoundEffects(); - } else { - mAudioManager.unloadSoundEffects(); - } + setSoundEffects(Integer.parseInt(value) == 1); + } else if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) { + setGpsLocation(value); + 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[] sync = new byte[1 + PROVIDERS.length]; try { @@ -85,7 +125,7 @@ public class SettingsHelper { } return sync; } - + void setSyncProviders(BackupDataInput backup) { byte[] sync = new byte[backup.getDataSize()]; |