Loading res/xml/ambient_display_settings.xml +2 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,8 @@ <SwitchPreference android:key="ambient_display_notification" android:title="@string/doze_title" android:summary="@string/doze_summary" /> android:summary="@string/doze_summary" settings:controller="com.android.settings.display.AmbientDisplayNotificationsPreferenceController"/> </PreferenceCategory> Loading src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java +22 −21 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ package com.android.settings.display; import static android.provider.Settings.Secure.DOZE_ENABLED; import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY; import android.content.Context; Loading @@ -21,21 +22,19 @@ import android.content.Intent; import android.os.UserHandle; import android.provider.Settings; import android.support.annotation.VisibleForTesting; import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.settings.R; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.TogglePreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.DatabaseIndexingUtils; import com.android.settings.search.InlineSwitchPayload; import com.android.settings.search.ResultPayload; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; public class AmbientDisplayNotificationsPreferenceController extends AbstractPreferenceController implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener { TogglePreferenceController implements Preference.OnPreferenceChangeListener { private final int ON = 1; private final int OFF = 0; Loading @@ -45,18 +44,20 @@ public class AmbientDisplayNotificationsPreferenceController extends private static final int MY_USER = UserHandle.myUserId(); private final MetricsFeatureProvider mMetricsFeatureProvider; private final AmbientDisplayConfiguration mConfig; private AmbientDisplayConfiguration mConfig; public AmbientDisplayNotificationsPreferenceController(Context context, AmbientDisplayConfiguration config, MetricsFeatureProvider metricsFeatureProvider) { super(context); mMetricsFeatureProvider = metricsFeatureProvider; mConfig = config; public AmbientDisplayNotificationsPreferenceController(Context context, String key) { super(context, key); mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); } @Override public String getPreferenceKey() { return KEY_AMBIENT_DISPLAY_NOTIFICATIONS; /** * Set AmbientDisplayConfiguration for this controller, please call in onAttach of fragment * * @param config AmbientDisplayConfiguration for this controller */ public void setConfig(AmbientDisplayConfiguration config) { mConfig = config; } @Override Loading @@ -68,23 +69,23 @@ public class AmbientDisplayNotificationsPreferenceController extends } @Override public void updateState(Preference preference) { ((SwitchPreference) preference).setChecked(mConfig.pulseOnNotificationEnabled(MY_USER)); public boolean isChecked() { return mConfig.pulseOnNotificationEnabled(MY_USER); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean value = (Boolean) newValue; Settings.Secure.putInt(mContext.getContentResolver(), DOZE_ENABLED, value ? ON : OFF); public boolean setChecked(boolean isChecked) { Settings.Secure.putInt(mContext.getContentResolver(), DOZE_ENABLED, isChecked ? ON : OFF); return true; } @Override public boolean isAvailable() { return mConfig.pulseOnNotificationAvailable(); public int getAvailabilityStatus() { return mConfig.pulseOnNotificationAvailable() ? AVAILABLE : DISABLED_UNSUPPORTED; } @Override //TODO (b/69808376): Remove result payload public ResultPayload getResultPayload() { final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext, AmbientDisplaySettings.class.getName(), KEY_AMBIENT_DISPLAY_NOTIFICATIONS, Loading src/com/android/settings/display/AmbientDisplaySettings.java +8 −7 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.gestures.DoubleTapScreenPreferenceController; import com.android.settings.gestures.PickupGesturePreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settingslib.core.AbstractPreferenceController; Loading @@ -52,11 +53,9 @@ public class AmbientDisplaySettings extends DashboardFragment { private AmbientDisplayConfiguration mConfig; private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, Lifecycle lifecycle, AmbientDisplayConfiguration config, MetricsFeatureProvider metricsFeatureProvider) { Lifecycle lifecycle, AmbientDisplayConfiguration config) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AmbientDisplayNotificationsPreferenceController(context, config, metricsFeatureProvider)); controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle, config, MY_USER_ID, KEY_AMBIENT_DISPLAY_DOUBLE_TAP)); controllers.add(new PickupGesturePreferenceController(context, lifecycle, config, Loading @@ -71,6 +70,9 @@ public class AmbientDisplaySettings extends DashboardFragment { AmbientDisplayAlwaysOnPreferenceController.class); controller.setConfig(getConfig(context)); controller.setCallback(this::updatePreferenceStates); final AmbientDisplayNotificationsPreferenceController notificationController = use( AmbientDisplayNotificationsPreferenceController.class); notificationController.setConfig(getConfig(context)); } @Override Loading @@ -85,8 +87,7 @@ public class AmbientDisplaySettings extends DashboardFragment { @Override protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { return buildPreferenceControllers(context, getLifecycle(), getConfig(context), mMetricsFeatureProvider); return buildPreferenceControllers(context, getLifecycle(), getConfig(context)); } @Override Loading @@ -111,7 +112,7 @@ public class AmbientDisplaySettings extends DashboardFragment { public List<AbstractPreferenceController> createPreferenceControllers( Context context) { return buildPreferenceControllers(context, null, new AmbientDisplayConfiguration(context), null); new AmbientDisplayConfiguration(context)); } }; Loading tests/robotests/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceControllerTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; import android.os.UserHandle; import android.provider.Settings; import android.support.v14.preference.SwitchPreference; Loading @@ -44,6 +45,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.util.ReflectionHelpers; @RunWith(SettingsRobolectricTestRunner.class) @Config(shadows = ShadowSecureSettings.class) Loading @@ -67,8 +69,10 @@ public class AmbientDisplayNotificationsPreferenceControllerTest { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mContentResolver = mContext.getContentResolver(); mController = new AmbientDisplayNotificationsPreferenceController(mContext, mConfig, mMetricsFeatureProvider); mController = new AmbientDisplayNotificationsPreferenceController(mContext, AmbientDisplayNotificationsPreferenceController.KEY_AMBIENT_DISPLAY_NOTIFICATIONS); mController.setConfig(mConfig); ReflectionHelpers.setField(mController, "mMetricsFeatureProvider", mMetricsFeatureProvider); } @Test Loading Loading @@ -119,6 +123,20 @@ public class AmbientDisplayNotificationsPreferenceControllerTest { assertThat(mController.isAvailable()).isFalse(); } @Test public void isChecked_checked_shouldReturnTrue() { when(mConfig.pulseOnNotificationEnabled(UserHandle.myUserId())).thenReturn(true); assertThat(mController.isChecked()).isTrue(); } @Test public void isChecked_checked_shouldReturnFalse() { when(mConfig.pulseOnNotificationEnabled(UserHandle.myUserId())).thenReturn(false); assertThat(mController.isChecked()).isFalse(); } @Test public void handlePreferenceTreeClick_reportsEventForItsPreference() { when(mSwitchPreference.getKey()).thenReturn( Loading Loading
res/xml/ambient_display_settings.xml +2 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,8 @@ <SwitchPreference android:key="ambient_display_notification" android:title="@string/doze_title" android:summary="@string/doze_summary" /> android:summary="@string/doze_summary" settings:controller="com.android.settings.display.AmbientDisplayNotificationsPreferenceController"/> </PreferenceCategory> Loading
src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java +22 −21 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ package com.android.settings.display; import static android.provider.Settings.Secure.DOZE_ENABLED; import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY; import android.content.Context; Loading @@ -21,21 +22,19 @@ import android.content.Intent; import android.os.UserHandle; import android.provider.Settings; import android.support.annotation.VisibleForTesting; import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.settings.R; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.TogglePreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.DatabaseIndexingUtils; import com.android.settings.search.InlineSwitchPayload; import com.android.settings.search.ResultPayload; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; public class AmbientDisplayNotificationsPreferenceController extends AbstractPreferenceController implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener { TogglePreferenceController implements Preference.OnPreferenceChangeListener { private final int ON = 1; private final int OFF = 0; Loading @@ -45,18 +44,20 @@ public class AmbientDisplayNotificationsPreferenceController extends private static final int MY_USER = UserHandle.myUserId(); private final MetricsFeatureProvider mMetricsFeatureProvider; private final AmbientDisplayConfiguration mConfig; private AmbientDisplayConfiguration mConfig; public AmbientDisplayNotificationsPreferenceController(Context context, AmbientDisplayConfiguration config, MetricsFeatureProvider metricsFeatureProvider) { super(context); mMetricsFeatureProvider = metricsFeatureProvider; mConfig = config; public AmbientDisplayNotificationsPreferenceController(Context context, String key) { super(context, key); mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); } @Override public String getPreferenceKey() { return KEY_AMBIENT_DISPLAY_NOTIFICATIONS; /** * Set AmbientDisplayConfiguration for this controller, please call in onAttach of fragment * * @param config AmbientDisplayConfiguration for this controller */ public void setConfig(AmbientDisplayConfiguration config) { mConfig = config; } @Override Loading @@ -68,23 +69,23 @@ public class AmbientDisplayNotificationsPreferenceController extends } @Override public void updateState(Preference preference) { ((SwitchPreference) preference).setChecked(mConfig.pulseOnNotificationEnabled(MY_USER)); public boolean isChecked() { return mConfig.pulseOnNotificationEnabled(MY_USER); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean value = (Boolean) newValue; Settings.Secure.putInt(mContext.getContentResolver(), DOZE_ENABLED, value ? ON : OFF); public boolean setChecked(boolean isChecked) { Settings.Secure.putInt(mContext.getContentResolver(), DOZE_ENABLED, isChecked ? ON : OFF); return true; } @Override public boolean isAvailable() { return mConfig.pulseOnNotificationAvailable(); public int getAvailabilityStatus() { return mConfig.pulseOnNotificationAvailable() ? AVAILABLE : DISABLED_UNSUPPORTED; } @Override //TODO (b/69808376): Remove result payload public ResultPayload getResultPayload() { final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext, AmbientDisplaySettings.class.getName(), KEY_AMBIENT_DISPLAY_NOTIFICATIONS, Loading
src/com/android/settings/display/AmbientDisplaySettings.java +8 −7 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.gestures.DoubleTapScreenPreferenceController; import com.android.settings.gestures.PickupGesturePreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settingslib.core.AbstractPreferenceController; Loading @@ -52,11 +53,9 @@ public class AmbientDisplaySettings extends DashboardFragment { private AmbientDisplayConfiguration mConfig; private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, Lifecycle lifecycle, AmbientDisplayConfiguration config, MetricsFeatureProvider metricsFeatureProvider) { Lifecycle lifecycle, AmbientDisplayConfiguration config) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AmbientDisplayNotificationsPreferenceController(context, config, metricsFeatureProvider)); controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle, config, MY_USER_ID, KEY_AMBIENT_DISPLAY_DOUBLE_TAP)); controllers.add(new PickupGesturePreferenceController(context, lifecycle, config, Loading @@ -71,6 +70,9 @@ public class AmbientDisplaySettings extends DashboardFragment { AmbientDisplayAlwaysOnPreferenceController.class); controller.setConfig(getConfig(context)); controller.setCallback(this::updatePreferenceStates); final AmbientDisplayNotificationsPreferenceController notificationController = use( AmbientDisplayNotificationsPreferenceController.class); notificationController.setConfig(getConfig(context)); } @Override Loading @@ -85,8 +87,7 @@ public class AmbientDisplaySettings extends DashboardFragment { @Override protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { return buildPreferenceControllers(context, getLifecycle(), getConfig(context), mMetricsFeatureProvider); return buildPreferenceControllers(context, getLifecycle(), getConfig(context)); } @Override Loading @@ -111,7 +112,7 @@ public class AmbientDisplaySettings extends DashboardFragment { public List<AbstractPreferenceController> createPreferenceControllers( Context context) { return buildPreferenceControllers(context, null, new AmbientDisplayConfiguration(context), null); new AmbientDisplayConfiguration(context)); } }; Loading
tests/robotests/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceControllerTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; import android.os.UserHandle; import android.provider.Settings; import android.support.v14.preference.SwitchPreference; Loading @@ -44,6 +45,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.util.ReflectionHelpers; @RunWith(SettingsRobolectricTestRunner.class) @Config(shadows = ShadowSecureSettings.class) Loading @@ -67,8 +69,10 @@ public class AmbientDisplayNotificationsPreferenceControllerTest { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mContentResolver = mContext.getContentResolver(); mController = new AmbientDisplayNotificationsPreferenceController(mContext, mConfig, mMetricsFeatureProvider); mController = new AmbientDisplayNotificationsPreferenceController(mContext, AmbientDisplayNotificationsPreferenceController.KEY_AMBIENT_DISPLAY_NOTIFICATIONS); mController.setConfig(mConfig); ReflectionHelpers.setField(mController, "mMetricsFeatureProvider", mMetricsFeatureProvider); } @Test Loading Loading @@ -119,6 +123,20 @@ public class AmbientDisplayNotificationsPreferenceControllerTest { assertThat(mController.isAvailable()).isFalse(); } @Test public void isChecked_checked_shouldReturnTrue() { when(mConfig.pulseOnNotificationEnabled(UserHandle.myUserId())).thenReturn(true); assertThat(mController.isChecked()).isTrue(); } @Test public void isChecked_checked_shouldReturnFalse() { when(mConfig.pulseOnNotificationEnabled(UserHandle.myUserId())).thenReturn(false); assertThat(mController.isChecked()).isFalse(); } @Test public void handlePreferenceTreeClick_reportsEventForItsPreference() { when(mSwitchPreference.getKey()).thenReturn( Loading