Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fc50725 authored by Marvin Paul's avatar Marvin Paul
Browse files

Don't backup ringtone on non-telephony devices.

Restoring a device that supports telephony using the backup set of
a non-telephony device would cause the ringtone to be set to "None"
instead of the default value. This was due to the fact that on
non-telephony devices, the ringtone value was being backed up as
"_silent" instead of null.

Bug: 18777629

Change-Id: Idece1f874438a895169dbba7df1d716adea6660e
parent 45c6ae56
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import java.util.Locale;
@@ -38,11 +39,14 @@ public class SettingsHelper {
    private static final String SILENT_RINGTONE = "_silent";
    private Context mContext;
    private AudioManager mAudioManager;
    private TelephonyManager mTelephonyManager;

    public SettingsHelper(Context context) {
        mContext = context;
        mAudioManager = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
        mTelephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
    }

    /**
@@ -75,12 +79,23 @@ public class SettingsHelper {
    }

    public String onBackupValue(String name, String value) {
        // Special processing for backing up ringtones
        // Special processing for backing up ringtones & notification sounds
        if (Settings.System.RINGTONE.equals(name)
                || Settings.System.NOTIFICATION_SOUND.equals(name)) {
            if (value == null) {
                // Silent ringtone
                if (Settings.System.RINGTONE.equals(name)) {
                    // For ringtones, we need to distinguish between non-telephony vs telephony
                    if (mTelephonyManager != null && mTelephonyManager.isVoiceCapable()) {
                        // Backup a null ringtone as silent on voice-capable devices
                        return SILENT_RINGTONE;
                    } else {
                        // Skip backup of ringtone on non-telephony devices.
                        return null;
                    }
                } else {
                    // Backup a null notification sound as silent
                    return SILENT_RINGTONE;
                }
            } else {
                return getCanonicalRingtoneValue(value);
            }