Wake notifications to TogglePreferenceController
Convert Wake for new notifications to TogglePreferenceController Because Slice controller only support Constructor(context) Move other parameter to setAmbientDisplayConfiguration Change-Id: I01042b84217ad9592fece966374140dffaf813e4 Fixes:67997460 Test: make RunSettingsRoboTests -j
This commit is contained in:
@@ -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>
|
||||
|
||||
|
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
@@ -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;
|
||||
@@ -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,
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -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(
|
||||
|
Reference in New Issue
Block a user