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

Commit ae5020ba authored by Liana Kazanova (xWF)'s avatar Liana Kazanova (xWF) Committed by Android (Google) Code Review
Browse files

Merge "Revert "Backup & restore for ringtone vibrations"" into main

parents b44f6299 ae2441e2
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ android_library {
        "configinfra_framework_flags_java_lib",
        "device_config_service_flags_java",
        "libaconfig_java_proto_lite",
        "notification_flags_lib",
        "SettingsLibDeviceStateRotationLock",
        "SettingsLibDisplayUtils",
    ],
+0 −30
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.hardware.display.ColorDisplayManager;
import android.icu.util.ULocale;
import android.media.AudioManager;
import android.media.RingtoneManager;
import android.media.Utils;
import android.net.Uri;
import android.os.LocaleList;
import android.os.RemoteException;
@@ -310,13 +309,6 @@ public class SettingsHelper {
                    return SILENT_RINGTONE;
                }
            } else {
                // If the ringtone/notification support the vibration, use the original value.
                final int ringtoneType = getRingtoneType(name);
                if ((Settings.System.RINGTONE.equals(name)
                        || Settings.System.NOTIFICATION_SOUND.equals(name))
                        && hasVibrationSettings(value, ringtoneType)) {
                    return value;
                }
                return getCanonicalRingtoneValue(value);
            }
        }
@@ -370,15 +362,6 @@ public class SettingsHelper {
            return;
        }

        // If the ringtone/notification has vibration, we backup original value in onBackupValue.
        // So use the value directly for restoring.
        if ((ringtoneType == RingtoneManager.TYPE_RINGTONE
                || ringtoneType == RingtoneManager.TYPE_NOTIFICATION)
                && hasVibrationSettings(value, ringtoneType)) {
            RingtoneManager.setActualDefaultRingtoneUri(mContext, ringtoneType, Uri.parse(value));
            return;
        }

        Uri ringtoneUri = null;
        try {
            ringtoneUri =
@@ -634,19 +617,6 @@ public class SettingsHelper {
        return allLocales.remove(toFullLocale(filteredLocale));
    }

    private boolean hasVibrationSettings(String value, int type) {
        if (Utils.hasVibration(Uri.parse(value)) && mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported)) {
            if (type == RingtoneManager.TYPE_RINGTONE) {
                return android.media.audio.Flags.enableRingtoneHapticsCustomization();
            }
            if (type == RingtoneManager.TYPE_NOTIFICATION) {
                return com.android.server.notification.Flags.notificationVibrationInSoundUri();
            }
        }
        return false;
    }

    /**
     * Sets the locale specified. Input data is the byte representation of comma separated
     * multiple BCP-47 language tags. For backwards compatibility, strings of the form
+0 −69
Original line number Diff line number Diff line
@@ -37,12 +37,9 @@ import android.content.res.Resources;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.media.AudioManager;
import android.media.Utils;
import android.net.Uri;
import android.os.Bundle;
import android.os.LocaleList;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.provider.Settings;
@@ -57,7 +54,6 @@ import com.android.internal.R;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -78,13 +74,9 @@ public class SettingsHelperTest {
            "content://media/internal/audio/media/20?title=DefaultNotification&canonical=1";
    private static final String DEFAULT_ALARM_VALUE =
            "content://media/internal/audio/media/30?title=DefaultAlarm&canonical=1";
    private static final String VIBRATION_FILE_NAME = "haptics.xml";

    private SettingsHelper mSettingsHelper;

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Mock private Context mContext;
    @Mock private Resources mResources;
    @Mock private AudioManager mAudioManager;
@@ -127,22 +119,6 @@ public class SettingsHelperTest {
        assertEquals(SETTING_REAL_VALUE, mSettingsHelper.onBackupValue(SETTING_KEY, SETTING_VALUE));
    }

    @Test
    @EnableFlags({android.media.audio.Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION,
            com.android.server.notification.Flags.FLAG_NOTIFICATION_VIBRATION_IN_SOUND_URI})
    public void testOnBackupValue_ringtoneVibrationSupport_returnsSameValue() {
        when(mResources.getBoolean(
                com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported)).thenReturn(
                true);
        String testRingtoneVibrationValue = createUriWithVibration(DEFAULT_RINGTONE_VALUE);
        String testNotificationVibrationValue = createUriWithVibration(DEFAULT_NOTIFICATION_VALUE);

        assertEquals(testRingtoneVibrationValue, mSettingsHelper.onBackupValue(
                Settings.System.RINGTONE, testRingtoneVibrationValue));
        assertEquals(testNotificationVibrationValue, mSettingsHelper.onBackupValue(
                Settings.System.NOTIFICATION_SOUND, testNotificationVibrationValue));
    }

    @Test
    public void testGetRealValue_settingNotReplaced_returnsSameValue() {
        when(mSettingsHelper.isReplacedSystemSetting(eq(SETTING_KEY))).thenReturn(false);
@@ -699,30 +675,6 @@ public class SettingsHelperTest {
                .isEqualTo(null);
    }

    @Test
    @EnableFlags({android.media.audio.Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION,
            com.android.server.notification.Flags.FLAG_NOTIFICATION_VIBRATION_IN_SOUND_URI})
    public void testRestoreValue_ringtoneVibrationSupport_restoreValue() {
        when(mResources.getBoolean(
                com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported)).thenReturn(
                true);
        String testRingtoneVibrationValue = createUriWithVibration(DEFAULT_RINGTONE_VALUE);
        String testNotificationVibrationValue = createUriWithVibration(DEFAULT_NOTIFICATION_VALUE);
        ContentProvider mockMediaContentProvider =
                new MockContentProvider(mContext) {
                    @Override
                    public String getType(Uri url) {
                        return "audio/ogg";
                    }
                };
        mContentResolver.addProvider(MediaStore.AUTHORITY, mockMediaContentProvider);
        resetRingtoneSettingsToDefault();

        assertRingtoneSettingsRestoring(Settings.System.RINGTONE, testRingtoneVibrationValue);
        assertRingtoneSettingsRestoring(
                Settings.System.NOTIFICATION_SOUND, testNotificationVibrationValue);
    }

    private static class MockSettingsProvider extends MockContentProvider {
        private final ArrayMap<String, String> mKeyValueStore = new ArrayMap<>();
        MockSettingsProvider(Context context) {
@@ -814,25 +766,4 @@ public class SettingsHelperTest {
        assertThat(Settings.System.getString(mContentResolver, Settings.System.ALARM_ALERT))
                .isEqualTo(DEFAULT_ALARM_VALUE);
    }

    private String createUriWithVibration(String defaultUriString) {
        return Uri.parse(defaultUriString).buildUpon()
                .appendQueryParameter(
                        Utils.VIBRATION_URI_PARAM, VIBRATION_FILE_NAME).build().toString();
    }

    private void assertRingtoneSettingsRestoring(
            String settings, String testRingtoneSettingsValue) {
        mSettingsHelper.restoreValue(
                mContext,
                mContentResolver,
                new ContentValues(),
                Uri.EMPTY,
                settings,
                testRingtoneSettingsValue,
                0);

        assertThat(Settings.System.getString(mContentResolver, settings))
                .isEqualTo(testRingtoneSettingsValue);
    }
}