Clean up DND slice in search.

- Remove the controller in SoundSettings, just use the common one.
- Update a bunch of IDs so ZenModeSliceBuilder maps to the toggle
  button in zen_mode_settings.xml

This is needed so the slice intent (left target when shown in search)
is the same as what we index from search side. Previously the search
indexer is finding zen_mode from sound page but the slice itself is
reporting a deep link into zenModeSettings page.

Fixes: 130437726
Test: robotest

Change-Id: Ic41d2d93afa1f748e3282e23010199a0fa078645
This commit is contained in:
Fan Zhang
2019-04-12 15:31:25 -07:00
parent 76ffb2df02
commit 7df6445c3e
8 changed files with 19 additions and 100 deletions

View File

@@ -103,7 +103,7 @@
settings:useAdminDisabledSummary="true"
settings:keywords="@string/keywords_sounds_and_notifications_interruptions"
settings:allowDividerAbove="true"
settings:controller="com.android.settings.notification.ZenModeSoundSettingsPreferenceController"/>
settings:controller="com.android.settings.notification.ZenModePreferenceController"/>
<Preference
android:key="gesture_prevent_ringing_sound"

View File

@@ -20,7 +20,7 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="zen_mode_settings"
android:title="@string/zen_mode_settings_title"
settings:keywords="@string/keywords_zen_mode_settings">
settings:searchable="false">
<PreferenceCategory
android:key="zen_mode_settings_category_behavior"
@@ -66,11 +66,13 @@
<!-- Turn on DND button -->
<com.android.settingslib.widget.LayoutPreference
android:key="zen_mode_settings_button_container"
android:key="zen_mode_toggle"
android:title="@string/zen_mode_settings_title"
android:selectable="false"
android:layout="@layout/zen_mode_settings_button"
settings:allowDividerAbove="true"
settings:allowDividerBelow="true"/>
settings:allowDividerBelow="true"
settings:keywords="@string/keywords_zen_mode_settings"/>
<!-- Footer that shows if user is put into alarms only or total silence mode by an app -->
<com.android.settingslib.widget.FooterPreference/>

View File

@@ -33,11 +33,12 @@ import com.android.settingslib.widget.LayoutPreference;
public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController
implements PreferenceControllerMixin {
public static final String KEY = "zen_mode_toggle";
private static final String TAG = "EnableZenModeButton";
protected static final String KEY = "zen_mode_settings_button_container";
private final FragmentManager mFragment;
private Button mZenButtonOn;
private Button mZenButtonOff;
private FragmentManager mFragment;
public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
fragment) {
@@ -60,13 +61,13 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference
super.updateState(preference);
if (null == mZenButtonOn) {
mZenButtonOn = (Button) ((LayoutPreference) preference)
mZenButtonOn = ((LayoutPreference) preference)
.findViewById(R.id.zen_mode_settings_turn_on_button);
updateZenButtonOnClickListener();
}
if (null == mZenButtonOff) {
mZenButtonOff = (Button) ((LayoutPreference) preference)
mZenButtonOff = ((LayoutPreference) preference)
.findViewById(R.id.zen_mode_settings_turn_off_button);
mZenButtonOff.setOnClickListener(v -> {
mMetricsFeatureProvider.action(mContext,

View File

@@ -328,7 +328,6 @@ public class ZenModeSettings extends ZenModeSettingsBase {
public List<String> getNonIndexableKeys(Context context) {
List<String> keys = super.getNonIndexableKeys(context);
keys.add(ZenModeDurationPreferenceController.KEY);
keys.add(ZenModeButtonPreferenceController.KEY);
return keys;
}

View File

@@ -18,8 +18,6 @@ package com.android.settings.notification;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static com.android.settings.notification.ZenModeSoundSettingsPreferenceController.ZEN_MODE_KEY;
import android.annotation.ColorInt;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -47,6 +45,8 @@ public class ZenModeSliceBuilder {
private static final String TAG = "ZenModeSliceBuilder";
private static final String ZEN_MODE_SLICE_KEY = ZenModeButtonPreferenceController.KEY;
/**
* Action notifying a change on the Zen Mode Slice.
*/
@@ -78,7 +78,8 @@ public class ZenModeSliceBuilder {
final PendingIntent primaryAction = getPrimaryAction(context);
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction,
(IconCompat) null /* icon */, ListBuilder.ICON_IMAGE, title);
final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction, null /* actionTitle */,
final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction,
null /* actionTitle */,
isZenModeEnabled);
return new ListBuilder(context, CustomSliceRegistry.ZEN_MODE_SLICE_URI,
@@ -110,10 +111,10 @@ public class ZenModeSliceBuilder {
}
public static Intent getIntent(Context context) {
final Uri contentUri = new Uri.Builder().appendPath(ZEN_MODE_KEY).build();
final Uri contentUri = new Uri.Builder().appendPath(ZEN_MODE_SLICE_KEY).build();
final String screenTitle = context.getText(R.string.zen_mode_settings_title).toString();
return SliceBuilderUtils.buildSearchResultPageIntent(context,
ZenModeSettings.class.getName(), ZEN_MODE_KEY, screenTitle,
ZenModeSettings.class.getName(), ZEN_MODE_SLICE_KEY, screenTitle,
SettingsEnums.NOTIFICATION_ZEN_MODE)
.setClassName(context.getPackageName(), SubSettings.class.getName())
.setData(contentUri);

View File

@@ -1,33 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import android.content.Context;
public class ZenModeSoundSettingsPreferenceController extends ZenModePreferenceController {
public static final String ZEN_MODE_KEY = "zen_mode";
public ZenModeSoundSettingsPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}

View File

@@ -19,8 +19,6 @@ package com.android.settings.slices;
import static android.provider.SettingsSlicesContract.KEY_LOCATION;
import static android.provider.SettingsSlicesContract.KEY_WIFI;
import static com.android.settings.notification.ZenModeSoundSettingsPreferenceController.ZEN_MODE_KEY;
import android.content.ContentResolver;
import android.net.Uri;
import android.provider.SettingsSlicesContract;
@@ -43,6 +41,7 @@ import com.android.settings.location.LocationSlice;
import com.android.settings.media.MediaOutputIndicatorSlice;
import com.android.settings.media.MediaOutputSlice;
import com.android.settings.network.telephony.MobileDataSlice;
import com.android.settings.notification.ZenModeButtonPreferenceController;
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
import com.android.settings.wifi.slice.ContextualWifiSlice;
import com.android.settings.wifi.slice.WifiSlice;
@@ -298,7 +297,7 @@ public class CustomSliceRegistry {
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath(ZEN_MODE_KEY)
.appendPath(ZenModeButtonPreferenceController.KEY)
.build();
/**

View File

@@ -1,50 +0,0 @@
/*
* Copyright (C) 2019 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.notification;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class ZenModeSoundSettingsPreferenceControllerTest {
private Context mContext;
private ZenModeSoundSettingsPreferenceController mController;
private static final String KEY_ZEN_MODE = "zen_mode";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new ZenModeSoundSettingsPreferenceController(mContext, KEY_ZEN_MODE);
}
@Test
public void getAvailabilityStatus_available() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
}