summaryrefslogtreecommitdiffstats
path: root/packages/SettingsProvider
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2013-09-10 17:08:45 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-09-10 17:08:45 -0700
commit41be933285e29bd6968ee31591279b21df67a6ce (patch)
treeb426f5f712825d94650401abaa5e5c13a950d3d4 /packages/SettingsProvider
parentd7ae1474465357e40d2c4c1141258dc06308beb5 (diff)
parent485d9afe60c2e42ccccd95d7934c24c5c8b2c995 (diff)
downloadframeworks_base-41be933285e29bd6968ee31591279b21df67a6ce.zip
frameworks_base-41be933285e29bd6968ee31591279b21df67a6ce.tar.gz
frameworks_base-41be933285e29bd6968ee31591279b21df67a6ce.tar.bz2
am 485d9afe: am a0a47c73: Merge "Backup and restore ringtone and notification ringtone" into klp-dev
* commit '485d9afe60c2e42ccccd95d7934c24c5c8b2c995': Backup and restore ringtone and notification ringtone
Diffstat (limited to 'packages/SettingsProvider')
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java4
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java49
2 files changed, 52 insertions, 1 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
index 3f04470..344446f 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
@@ -738,10 +738,12 @@ public class SettingsBackupAgent extends BackupAgentHelper {
}
}
+ // Intercept the keys and see if they need special handling
+ value = mSettingsHelper.onBackupValue(key, value);
+
if (value == null) {
continue;
}
-
// Write the key and value in the intermediary array.
byte[] keyBytes = key.getBytes();
totalSize += INTEGER_BYTE_COUNT + keyBytes.length;
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index a446e40..080290c 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -23,6 +23,8 @@ import android.content.Context;
import android.content.res.Configuration;
import android.location.LocationManager;
import android.media.AudioManager;
+import android.media.RingtoneManager;
+import android.net.Uri;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -33,6 +35,7 @@ import android.text.TextUtils;
import java.util.Locale;
public class SettingsHelper {
+ private static final String SILENT_RINGTONE = "_silent";
private Context mContext;
private AudioManager mAudioManager;
@@ -63,10 +66,56 @@ public class SettingsHelper {
setAutoRestore(Integer.parseInt(value) == 1);
} else if (isAlreadyConfiguredCriticalAccessibilitySetting(name)) {
return false;
+ } else if (Settings.System.RINGTONE.equals(name)
+ || Settings.System.NOTIFICATION_SOUND.equals(name)) {
+ setRingtone(name, value);
+ return false;
}
return true;
}
+ public String onBackupValue(String name, String value) {
+ // Special processing for backing up ringtones
+ if (Settings.System.RINGTONE.equals(name)
+ || Settings.System.NOTIFICATION_SOUND.equals(name)) {
+ if (value == null) {
+ // Silent ringtone
+ return SILENT_RINGTONE;
+ } else {
+ return getCanonicalRingtoneValue(value);
+ }
+ }
+ // Return the original value
+ return value;
+ }
+
+ /**
+ * Sets the ringtone of type specified by the name.
+ *
+ * @param name should be Settings.System.RINGTONE or Settings.System.NOTIFICATION_SOUND.
+ * @param value can be a canonicalized uri or "_silent" to indicate a silent (null) ringtone.
+ */
+ private void setRingtone(String name, String value) {
+ // If it's null, don't change the default
+ if (value == null) return;
+ Uri ringtoneUri = null;
+ if (SILENT_RINGTONE.equals(value)) {
+ ringtoneUri = null;
+ } else {
+ Uri canonicalUri = Uri.parse(value);
+ ringtoneUri = mContext.getContentResolver().uncanonicalize(canonicalUri);
+ }
+ final int ringtoneType = Settings.System.RINGTONE.equals(name)
+ ? RingtoneManager.TYPE_RINGTONE : RingtoneManager.TYPE_NOTIFICATION;
+ RingtoneManager.setActualDefaultRingtoneUri(mContext, ringtoneType, ringtoneUri);
+ }
+
+ private String getCanonicalRingtoneValue(String value) {
+ final Uri ringtoneUri = Uri.parse(value);
+ final Uri canonicalUri = mContext.getContentResolver().canonicalize(ringtoneUri);
+ return canonicalUri == null ? null : canonicalUri.toString();
+ }
+
private boolean isAlreadyConfiguredCriticalAccessibilitySetting(String name) {
// These are the critical accessibility settings that are required for a
// blind user to be able to interact with the device. If these settings are