diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 29459a0e7b5..afa9188b5d6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2689,8 +2689,6 @@ - diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml index c799c8b3948..6d2057108a6 100644 --- a/res/xml/channel_notification_settings.xml +++ b/res/xml/channel_notification_settings.xml @@ -53,7 +53,7 @@ settings:useAdditionalSummary="true" /> - diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml index 520ebaa5fa8..e080be4dc6e 100644 --- a/res/xml/configure_notification_settings.xml +++ b/res/xml/configure_notification_settings.xml @@ -15,39 +15,27 @@ --> - - - - - - - - - - - - - - + + + + + + + + android:key="all_notifications_divider" + android:order="20"/> - + + + + + + + + + diff --git a/res/xml/security_lockscreen_settings.xml b/res/xml/security_lockscreen_settings.xml index 6faedd72972..1da1de5eccf 100644 --- a/res/xml/security_lockscreen_settings.xml +++ b/res/xml/security_lockscreen_settings.xml @@ -19,7 +19,7 @@ android:key="security_lockscreen_settings_screen" android:title="@string/lockscreen_settings_title"> - @@ -42,7 +42,7 @@ android:key="security_setting_lock_screen_notif_work_header" android:title="@string/profile_section_header"> - diff --git a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java index d56febb1544..bf821db860e 100644 --- a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java +++ b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java @@ -34,6 +34,7 @@ import android.util.Log; import com.android.internal.widget.LockPatternUtils; import com.android.settings.R; +import com.android.settings.RestrictedListPreference; import com.android.settings.Utils; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.overlay.FeatureFactory; @@ -55,8 +56,8 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen private final String mWorkSettingCategoryKey; private final String mWorkSettingKey; - private RestrictedDropDownPreference mLockscreen; - private RestrictedDropDownPreference mLockscreenProfile; + private RestrictedListPreference mLockscreen; + private RestrictedListPreference mLockscreenProfile; private final int mProfileChallengeUserId; private final boolean mSecure; @@ -92,13 +93,13 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mLockscreen = - (RestrictedDropDownPreference) screen.findPreference(mSettingKey); + (RestrictedListPreference) screen.findPreference(mSettingKey); if (mLockscreen == null) { Log.i(TAG, "Preference not found: " + mSettingKey); return; } if (mProfileChallengeUserId != UserHandle.USER_NULL) { - mLockscreenProfile = (RestrictedDropDownPreference) screen.findPreference( + mLockscreenProfile = (RestrictedListPreference) screen.findPreference( mWorkSettingKey); } else { setVisible(screen, mWorkSettingKey, false /* visible */); @@ -180,11 +181,6 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen entries.add(mContext.getString(R.string.lock_screen_notifications_summary_disable_profile)); values.add(Integer.toString(R.string.lock_screen_notifications_summary_disable_profile)); - mLockscreenProfile.setOnPreClickListener( - (Preference p) -> Utils.startQuietModeDialogIfNecessary(mContext, - UserManager.get(mContext), mProfileChallengeUserId) - ); - mLockscreenProfile.setEntries(entries.toArray(new CharSequence[entries.size()])); mLockscreenProfile.setEntryValues(values.toArray(new CharSequence[values.size()])); updateLockscreenNotificationsForProfile(); @@ -224,36 +220,40 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen public boolean onPreferenceChange(Preference preference, Object newValue) { final String key = preference.getKey(); if (TextUtils.equals(mWorkSettingKey, key)) { - final int val = Integer.parseInt((String) newValue); - if (val == mLockscreenSelectedValueProfile) { - return false; - } - final boolean enabled = - val != R.string.lock_screen_notifications_summary_disable_profile; - final boolean show = - val == R.string.lock_screen_notifications_summary_show_profile; - Settings.Secure.putIntForUser(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, - show ? 1 : 0, mProfileChallengeUserId); - Settings.Secure.putIntForUser(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, - enabled ? 1 : 0, mProfileChallengeUserId); - mLockscreenSelectedValueProfile = val; - return true; + if (Utils.startQuietModeDialogIfNecessary(mContext, UserManager.get(mContext), + mProfileChallengeUserId)) { + return false; + } + final int val = Integer.parseInt((String) newValue); + if (val == mLockscreenSelectedValueProfile) { + return false; + } + final boolean enabled = + val != R.string.lock_screen_notifications_summary_disable_profile; + final boolean show = + val == R.string.lock_screen_notifications_summary_show_profile; + Settings.Secure.putIntForUser(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, + show ? 1 : 0, mProfileChallengeUserId); + Settings.Secure.putIntForUser(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, + enabled ? 1 : 0, mProfileChallengeUserId); + mLockscreenSelectedValueProfile = val; + return true; } else if (TextUtils.equals(mSettingKey, key)) { - final int val = Integer.parseInt((String) newValue); - if (val == mLockscreenSelectedValue) { - return false; - } - final boolean enabled = - val != R.string.lock_screen_notifications_summary_disable; - final boolean show = val == R.string.lock_screen_notifications_summary_show; - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0); - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0); - mLockscreenSelectedValue = val; - return true; + final int val = Integer.parseInt((String) newValue); + if (val == mLockscreenSelectedValue) { + return false; + } + final boolean enabled = + val != R.string.lock_screen_notifications_summary_disable; + final boolean show = val == R.string.lock_screen_notifications_summary_show; + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0); + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0); + mLockscreenSelectedValue = val; + return true; } return false; } @@ -264,8 +264,8 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( mContext, keyguardNotificationFeatures, UserHandle.myUserId()); if (admin != null && mLockscreen != null) { - RestrictedDropDownPreference.RestrictedItem item = - new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin); + RestrictedListPreference.RestrictedItem item = + new RestrictedListPreference.RestrictedItem(entry, entryValue, admin); mLockscreen.addRestrictedItem(item); } if (mProfileChallengeUserId != UserHandle.USER_NULL) { @@ -273,8 +273,8 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( mContext, keyguardNotificationFeatures, mProfileChallengeUserId); if (profileAdmin != null && mLockscreenProfile != null) { - RestrictedDropDownPreference.RestrictedItem item = - new RestrictedDropDownPreference.RestrictedItem( + RestrictedListPreference.RestrictedItem item = + new RestrictedListPreference.RestrictedItem( entry, entryValue, profileAdmin); mLockscreenProfile.addRestrictedItem(item); } diff --git a/src/com/android/settings/notification/RestrictedDropDownPreference.java b/src/com/android/settings/notification/RestrictedDropDownPreference.java deleted file mode 100644 index d19cf8d7c9f..00000000000 --- a/src/com/android/settings/notification/RestrictedDropDownPreference.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2016 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; -import android.graphics.drawable.Drawable; -import android.support.v7.preference.DropDownPreference; -import android.support.v7.preference.PreferenceViewHolder; -import android.util.AttributeSet; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemSelectedListener; -import android.widget.ArrayAdapter; -import android.widget.Spinner; -import android.widget.TextView; - -import com.android.settings.R; -import com.android.settingslib.RestrictedLockUtils; -import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; -import com.android.settingslib.RestrictedPreferenceHelper; - -import java.util.ArrayList; -import java.util.List; - -public class RestrictedDropDownPreference extends DropDownPreference { - private final RestrictedPreferenceHelper mHelper; - private ReselectionSpinner mSpinner; - private List mRestrictedItems = new ArrayList<>(); - private boolean mUserClicked = false; - private OnPreferenceClickListener mPreClickListener; - - public RestrictedDropDownPreference(Context context, AttributeSet attrs) { - super(context, attrs); - setLayoutResource(R.layout.restricted_preference_dropdown); - setWidgetLayoutResource(R.layout.restricted_icon); - mHelper = new RestrictedPreferenceHelper(context, this, attrs); - } - - @Override - protected ArrayAdapter createAdapter() { - return new RestrictedArrayItemAdapter(getContext()); - } - - @Override - public void setValue(String value) { - if (getRestrictedItemForEntryValue(value) != null) { - return; - } - super.setValue(value); - } - - @Override - public void onBindViewHolder(PreferenceViewHolder view) { - mSpinner = (ReselectionSpinner) view.itemView.findViewById(R.id.spinner); - mSpinner.setPreference(this); - super.onBindViewHolder(view); - mHelper.onBindViewHolder(view); - mSpinner.setOnItemSelectedListener(mItemSelectedListener); - final View restrictedIcon = view.findViewById(R.id.restricted_icon); - if (restrictedIcon != null) { - restrictedIcon.setVisibility(isDisabledByAdmin() ? View.VISIBLE : View.GONE); - } - } - - private boolean isRestrictedForEntry(CharSequence entry) { - if (entry == null) { - return false; - } - for (RestrictedItem item : mRestrictedItems) { - if (entry.equals(item.entry)) { - return true; - } - } - return false; - } - - private RestrictedItem getRestrictedItemForEntryValue(CharSequence entryValue) { - if (entryValue == null) { - return null; - } - for (RestrictedItem item : mRestrictedItems) { - if (entryValue.equals(item.entryValue)) { - return item; - } - } - return null; - } - - private RestrictedItem getRestrictedItemForPosition(int position) { - if (position < 0 || position >= getEntryValues().length) { - return null; - } - CharSequence entryValue = getEntryValues()[position]; - return getRestrictedItemForEntryValue(entryValue); - } - - public void addRestrictedItem(RestrictedItem item) { - mRestrictedItems.add(item); - } - - public void clearRestrictedItems() { - mRestrictedItems.clear(); - } - - @Override - public void performClick() { - if (mPreClickListener != null && mPreClickListener.onPreferenceClick(this)) { - return; - } - if (!mHelper.performClick()) { - mUserClicked = true; - super.performClick(); - } - } - - @Override - public void setEnabled(boolean enabled) { - if (enabled && isDisabledByAdmin()) { - mHelper.setDisabledByAdmin(null); - return; - } - super.setEnabled(enabled); - } - - public void setDisabledByAdmin(EnforcedAdmin admin) { - if (mHelper.setDisabledByAdmin(admin)) { - notifyChanged(); - } - } - - /** - * Similar to {@link #setOnPreferenceClickListener(OnPreferenceClickListener)}, but can - * preempt {@link #onClick()}. - */ - public void setOnPreClickListener(OnPreferenceClickListener l) { - mPreClickListener = l; - } - - public boolean isDisabledByAdmin() { - return mHelper.isDisabledByAdmin(); - } - - private void setUserClicked(boolean userClicked) { - mUserClicked = userClicked; - } - - private boolean isUserClicked() { - return mUserClicked; - } - - private final OnItemSelectedListener mItemSelectedListener = new OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View v, int position, long id) { - if (mUserClicked) { - mUserClicked = false; - } else { - return; - } - if (position >= 0 && position < getEntryValues().length) { - String value = getEntryValues()[position].toString(); - RestrictedItem item = getRestrictedItemForEntryValue(value); - if (item != null) { - RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), - item.enforcedAdmin); - mSpinner.setSelection(findIndexOfValue(getValue())); - } else if (!value.equals(getValue()) && callChangeListener(value)) { - setValue(value); - } - } - } - - @Override - public void onNothingSelected(AdapterView parent) { - // noop - } - }; - - /** - * Extension of {@link ArrayAdapter} which updates the state of the dropdown item - * depending on whether it is restricted by the admin. - */ - private class RestrictedArrayItemAdapter extends ArrayAdapter { - private static final int TEXT_RES_ID = android.R.id.text1; - public RestrictedArrayItemAdapter(Context context) { - super(context, R.layout.spinner_dropdown_restricted_item, TEXT_RES_ID); - } - - @Override - public View getDropDownView(int position, View convertView, ViewGroup parent) { - View rootView = super.getView(position, convertView, parent); - CharSequence entry = getItem(position); - boolean isEntryRestricted = isRestrictedForEntry(entry); - TextView text = (TextView) rootView.findViewById(TEXT_RES_ID); - if (text != null) { - text.setEnabled(!isEntryRestricted); - } - View restrictedIcon = rootView.findViewById(R.id.restricted_icon); - if (restrictedIcon != null) { - restrictedIcon.setVisibility(isEntryRestricted ? View.VISIBLE : View.GONE); - } - return rootView; - } - } - - /** - * Extension of {@link Spinner} which triggers the admin support dialog on user clicking a - * restricted item even if was already selected. - */ - public static class ReselectionSpinner extends Spinner { - private RestrictedDropDownPreference pref; - - public ReselectionSpinner(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public void setPreference(RestrictedDropDownPreference pref) { - this.pref = pref; - } - - @Override - public void setSelection(int position) { - int previousSelectedPosition = getSelectedItemPosition(); - super.setSelection(position); - if (position == previousSelectedPosition && pref.isUserClicked()) { - pref.setUserClicked(false); - RestrictedItem item = pref.getRestrictedItemForPosition(position); - if (item != null) { - RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), - item.enforcedAdmin); - } - } - } - } - - public static class RestrictedItem { - public final CharSequence entry; - public final CharSequence entryValue; - public final EnforcedAdmin enforcedAdmin; - - public RestrictedItem(CharSequence entry, CharSequence entryValue, - EnforcedAdmin enforcedAdmin) { - this.entry = entry; - this.entryValue = entryValue; - this.enforcedAdmin = enforcedAdmin; - } - } -} \ No newline at end of file diff --git a/src/com/android/settings/notification/VisibilityPreferenceController.java b/src/com/android/settings/notification/VisibilityPreferenceController.java index 76caac0c852..62ca183ccc4 100644 --- a/src/com/android/settings/notification/VisibilityPreferenceController.java +++ b/src/com/android/settings/notification/VisibilityPreferenceController.java @@ -29,6 +29,7 @@ import android.support.v7.preference.Preference; import com.android.internal.widget.LockPatternUtils; import com.android.settings.R; +import com.android.settings.RestrictedListPreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.RestrictedLockUtils; @@ -65,7 +66,7 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro public void updateState(Preference preference) { if (mChannel != null && mAppRow != null) { - RestrictedDropDownPreference pref = (RestrictedDropDownPreference) preference; + RestrictedListPreference pref = (RestrictedListPreference) preference; ArrayList entries = new ArrayList<>(); ArrayList values = new ArrayList<>(); @@ -120,14 +121,14 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro return true; } - private void setRestrictedIfNotificationFeaturesDisabled(RestrictedDropDownPreference pref, + private void setRestrictedIfNotificationFeaturesDisabled(RestrictedListPreference pref, CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) { RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( mContext, keyguardNotificationFeatures, mAppRow.userId); if (admin != null) { - RestrictedDropDownPreference.RestrictedItem item = - new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin); + RestrictedListPreference.RestrictedItem item = + new RestrictedListPreference.RestrictedItem(entry, entryValue, admin); pref.addRestrictedItem(item); } } diff --git a/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java index c18372c78bf..25dba80ef1c 100644 --- a/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java @@ -47,6 +47,7 @@ import android.provider.Settings; import android.support.v7.preference.PreferenceScreen; import com.android.internal.widget.LockPatternUtils; +import com.android.settings.RestrictedListPreference; import com.android.settings.TestConfig; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.shadow.ShadowRestrictionUtils; @@ -115,8 +116,8 @@ public class VisibilityPreferenceControllerTest { @Test public void testNoCrashIfNoOnResume() throws Exception { mController.isAvailable(); - mController.updateState(mock(RestrictedDropDownPreference.class)); - mController.onPreferenceChange(mock(RestrictedDropDownPreference.class), true); + mController.updateState(mock(RestrictedListPreference.class)); + mController.onPreferenceChange(mock(RestrictedListPreference.class), true); } @Test @@ -165,7 +166,7 @@ public class VisibilityPreferenceControllerTest { mController.onResume(new NotificationBackend.AppRow(), channel, null, mock( RestrictedLockUtils.EnforcedAdmin.class)); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); verify(pref, times(2)).addRestrictedItem(any()); @@ -187,7 +188,7 @@ public class VisibilityPreferenceControllerTest { mController.onResume(new NotificationBackend.AppRow(), channel, null, mock( RestrictedLockUtils.EnforcedAdmin.class)); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); verify(pref, times(1)).addRestrictedItem(any()); @@ -202,7 +203,7 @@ public class VisibilityPreferenceControllerTest { NotificationChannel channel = mock(NotificationChannel.class); mController.onResume(appRow, channel, null, null); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); ArgumentCaptor argumentCaptor = @@ -221,7 +222,7 @@ public class VisibilityPreferenceControllerTest { NotificationChannel channel = mock(NotificationChannel.class); mController.onResume(appRow, channel, null, null); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); ArgumentCaptor argumentCaptor = @@ -237,7 +238,7 @@ public class VisibilityPreferenceControllerTest { NotificationChannel channel = mock(NotificationChannel.class); mController.onResume(appRow, channel, null, null); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); ArgumentCaptor argumentCaptor = @@ -268,7 +269,7 @@ public class VisibilityPreferenceControllerTest { when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE); mController.onResume(appRow, channel, null, null); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(String.class); @@ -287,7 +288,7 @@ public class VisibilityPreferenceControllerTest { when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET); mController.onResume(appRow, channel, null, null); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(String.class); @@ -306,7 +307,7 @@ public class VisibilityPreferenceControllerTest { channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET); mController.onResume(appRow, channel, null, null); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_PRIVATE)); @@ -325,7 +326,7 @@ public class VisibilityPreferenceControllerTest { channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE); mController.onResume(appRow, channel, null, null); - RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); + RestrictedListPreference pref = mock(RestrictedListPreference.class); mController.updateState(pref); mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_SECRET));