Loading res/values/strings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -11795,6 +11795,11 @@ <!-- Summary for the top level Privacy Settings [CHAR LIMIT=NONE]--> <string name="privacy_dashboard_summary">Permissions, account activity, personal data</string> <!-- UI debug setting: show media player on quick settings title [CHAR LIMIT=60] --> <string name="quick_settings_media_player">Media resumption</string> <!-- UI debug setting: show media player on quick settings summary [CHAR_LIMIT=NONE] --> <string name="quick_settings_media_player_summary">Shows and persists media player in Quick Settings. Requires reboot.</string> <!-- Label for button in contextual card for users to remove the card [CHAR LIMIT=30] --> <string name="contextual_card_dismiss_remove">Remove</string> <!-- Label for button in contextual card for users to keep the card [CHAR LIMIT=30] --> res/xml/development_settings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -525,6 +525,11 @@ android:title="@string/usb_audio_disable_routing" android:summary="@string/usb_audio_disable_routing_summary" /> <SwitchPreference android:key="quick_settings_media_player" android:title="@string/quick_settings_media_player" android:summary="@string/quick_settings_media_player_summary" /> </PreferenceCategory> <PreferenceCategory Loading src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -491,6 +491,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new DebugNonRectClipOperationsPreferenceController(context)); controllers.add(new ForceDarkPreferenceController(context)); controllers.add(new EnableBlursPreferenceController(context)); controllers.add(new QuickSettingsMediaPlayerPreferenceController(context)); controllers.add(new ForceMSAAPreferenceController(context)); controllers.add(new HardwareOverlaysPreferenceController(context)); controllers.add(new SimulateColorSpacePreferenceController(context)); Loading src/com/android/settings/development/QuickSettingsMediaPlayerPreferenceController.java 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.development; import android.content.Context; import android.provider.Settings; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.SwitchPreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; /** * Controls whether the media player should be visible in quick settings. */ public class QuickSettingsMediaPlayerPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { private static final String PREFERENCE_KEY = "quick_settings_media_player"; @VisibleForTesting static final String SETTING_NAME = Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS; @VisibleForTesting static final int SETTING_VALUE_ON = 1; @VisibleForTesting static final int SETTING_VALUE_OFF = 0; public QuickSettingsMediaPlayerPreferenceController(Context context) { super(context); } @Override public String getPreferenceKey() { return PREFERENCE_KEY; } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean isEnabled = (Boolean) newValue; Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF); return true; } @Override public void updateState(Preference preference) { final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_OFF); ((SwitchPreference) mPreference).setChecked(mode != SETTING_VALUE_OFF); } @Override protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_OFF); ((SwitchPreference) mPreference).setChecked(false); } } tests/robotests/src/com/android/settings/development/QuickSettingsMediaPlayerPreferenceControllerTest.java 0 → 100644 +111 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.development; import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_NAME; import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_VALUE_OFF; import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_VALUE_ON; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.provider.Settings; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class QuickSettingsMediaPlayerPreferenceControllerTest { @Mock private SwitchPreference mPreference; @Mock private PreferenceScreen mPreferenceScreen; @Rule public MockitoRule mMockitoRule = MockitoJUnit.rule(); private Context mContext; private QuickSettingsMediaPlayerPreferenceController mController; @Before public void setup() { mContext = RuntimeEnvironment.application; mController = new QuickSettingsMediaPlayerPreferenceController(mContext); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) .thenReturn(mPreference); mController.displayPreference(mPreferenceScreen); } @Test public void onPreferenceChanged_turnOnPreference_shouldEnable() { mController.onPreferenceChange(mPreference, true /* new value */); final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_ON); } @Test public void onPreferenceChanged_turnOffPreference_shouldDisable() { mController.onPreferenceChange(mPreference, false /* new value */); final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_OFF); } @Test public void updateState_settingEnabled_preferenceShouldBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_ON); mController.updateState(mPreference); verify(mPreference).setChecked(true); } @Test public void updateState_settingDisabled_preferenceShouldNotBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_OFF); mController.updateState(mPreference); verify(mPreference).setChecked(false); } @Test public void onDeveloperOptionsSwitchDisabled_shouldDisable() { mController.onDeveloperOptionsSwitchDisabled(); final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_OFF); verify(mPreference).setEnabled(false); verify(mPreference).setChecked(false); } } Loading
res/values/strings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -11795,6 +11795,11 @@ <!-- Summary for the top level Privacy Settings [CHAR LIMIT=NONE]--> <string name="privacy_dashboard_summary">Permissions, account activity, personal data</string> <!-- UI debug setting: show media player on quick settings title [CHAR LIMIT=60] --> <string name="quick_settings_media_player">Media resumption</string> <!-- UI debug setting: show media player on quick settings summary [CHAR_LIMIT=NONE] --> <string name="quick_settings_media_player_summary">Shows and persists media player in Quick Settings. Requires reboot.</string> <!-- Label for button in contextual card for users to remove the card [CHAR LIMIT=30] --> <string name="contextual_card_dismiss_remove">Remove</string> <!-- Label for button in contextual card for users to keep the card [CHAR LIMIT=30] -->
res/xml/development_settings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -525,6 +525,11 @@ android:title="@string/usb_audio_disable_routing" android:summary="@string/usb_audio_disable_routing_summary" /> <SwitchPreference android:key="quick_settings_media_player" android:title="@string/quick_settings_media_player" android:summary="@string/quick_settings_media_player_summary" /> </PreferenceCategory> <PreferenceCategory Loading
src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -491,6 +491,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new DebugNonRectClipOperationsPreferenceController(context)); controllers.add(new ForceDarkPreferenceController(context)); controllers.add(new EnableBlursPreferenceController(context)); controllers.add(new QuickSettingsMediaPlayerPreferenceController(context)); controllers.add(new ForceMSAAPreferenceController(context)); controllers.add(new HardwareOverlaysPreferenceController(context)); controllers.add(new SimulateColorSpacePreferenceController(context)); Loading
src/com/android/settings/development/QuickSettingsMediaPlayerPreferenceController.java 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.development; import android.content.Context; import android.provider.Settings; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.SwitchPreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; /** * Controls whether the media player should be visible in quick settings. */ public class QuickSettingsMediaPlayerPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { private static final String PREFERENCE_KEY = "quick_settings_media_player"; @VisibleForTesting static final String SETTING_NAME = Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS; @VisibleForTesting static final int SETTING_VALUE_ON = 1; @VisibleForTesting static final int SETTING_VALUE_OFF = 0; public QuickSettingsMediaPlayerPreferenceController(Context context) { super(context); } @Override public String getPreferenceKey() { return PREFERENCE_KEY; } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean isEnabled = (Boolean) newValue; Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF); return true; } @Override public void updateState(Preference preference) { final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_OFF); ((SwitchPreference) mPreference).setChecked(mode != SETTING_VALUE_OFF); } @Override protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_OFF); ((SwitchPreference) mPreference).setChecked(false); } }
tests/robotests/src/com/android/settings/development/QuickSettingsMediaPlayerPreferenceControllerTest.java 0 → 100644 +111 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.development; import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_NAME; import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_VALUE_OFF; import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_VALUE_ON; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.provider.Settings; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class QuickSettingsMediaPlayerPreferenceControllerTest { @Mock private SwitchPreference mPreference; @Mock private PreferenceScreen mPreferenceScreen; @Rule public MockitoRule mMockitoRule = MockitoJUnit.rule(); private Context mContext; private QuickSettingsMediaPlayerPreferenceController mController; @Before public void setup() { mContext = RuntimeEnvironment.application; mController = new QuickSettingsMediaPlayerPreferenceController(mContext); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) .thenReturn(mPreference); mController.displayPreference(mPreferenceScreen); } @Test public void onPreferenceChanged_turnOnPreference_shouldEnable() { mController.onPreferenceChange(mPreference, true /* new value */); final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_ON); } @Test public void onPreferenceChanged_turnOffPreference_shouldDisable() { mController.onPreferenceChange(mPreference, false /* new value */); final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_OFF); } @Test public void updateState_settingEnabled_preferenceShouldBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_ON); mController.updateState(mPreference); verify(mPreference).setChecked(true); } @Test public void updateState_settingDisabled_preferenceShouldNotBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_OFF); mController.updateState(mPreference); verify(mPreference).setChecked(false); } @Test public void onDeveloperOptionsSwitchDisabled_shouldDisable() { mController.onDeveloperOptionsSwitchDisabled(); final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_OFF); verify(mPreference).setEnabled(false); verify(mPreference).setChecked(false); } }