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