Notification settings updates
- remove duplicate settings - move recent app list to bottom of the screen - change dropdown fields to dialogs Test: manual, make RunSettingsRoboTests Change-Id: Ia07d56e39be10c7b8be58f9ec35114ca2eab7d5c Fixes: 72402499
This commit is contained in:
@@ -2689,8 +2689,6 @@
|
||||
<intent-filter android:priority="150">
|
||||
<action android:name="com.android.settings.action.SETTINGS" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.notifications" />
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.applications.NotificationApps" />
|
||||
</activity>
|
||||
|
@@ -53,7 +53,7 @@
|
||||
settings:useAdditionalSummary="true" />
|
||||
|
||||
<!-- Visibility Override -->
|
||||
<com.android.settings.notification.RestrictedDropDownPreference
|
||||
<com.android.settings.RestrictedListPreference
|
||||
android:key="visibility_override"
|
||||
android:title="@string/app_notification_visibility_override_title"/>
|
||||
|
||||
|
@@ -15,39 +15,27 @@
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/configure_notification_settings"
|
||||
android:key="configure_notification_settings">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="recent_notifications_category"
|
||||
android:title="@string/recent_notifications"
|
||||
android:order="-200">
|
||||
<!-- Placeholder for a list of recent apps -->
|
||||
|
||||
<!-- See all apps button -->
|
||||
<Preference
|
||||
android:title="@string/notifications_title"
|
||||
android:key="all_notifications"
|
||||
android:order="20">
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.settings"
|
||||
android:targetClass="com.android.settings.Settings$NotificationAppListActivity">
|
||||
</intent>
|
||||
</Preference>
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- Empty category to draw divider -->
|
||||
<PreferenceCategory
|
||||
android:key="all_notifications_divider"
|
||||
android:order="-190"/>
|
||||
|
||||
<!-- When device is locked -->
|
||||
<com.android.settings.notification.RestrictedDropDownPreference
|
||||
<com.android.settings.RestrictedListPreference
|
||||
android:key="lock_screen_notifications"
|
||||
android:title="@string/lock_screen_notifications_title"
|
||||
android:summary="@string/summary_placeholder"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="lock_screen_notifications_profile_header"
|
||||
android:title="@string/profile_section_header">
|
||||
|
||||
<com.android.settings.RestrictedListPreference
|
||||
android:key="lock_screen_notifications_profile"
|
||||
android:title="@string/lock_screen_notifications_title"
|
||||
android:summary="@string/summary_placeholder"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- Notification badging -->
|
||||
<SwitchPreference
|
||||
android:key="notification_badging"
|
||||
@@ -71,14 +59,30 @@
|
||||
android:title="@string/fingerprint_swipe_for_notifications_title"
|
||||
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings" />
|
||||
|
||||
<!-- Empty category to draw divider -->
|
||||
<PreferenceCategory
|
||||
android:key="lock_screen_notifications_profile_header"
|
||||
android:title="@string/profile_section_header">
|
||||
android:key="all_notifications_divider"
|
||||
android:order="20"/>
|
||||
|
||||
<com.android.settings.notification.RestrictedDropDownPreference
|
||||
android:key="lock_screen_notifications_profile"
|
||||
android:title="@string/lock_screen_notifications_title"
|
||||
android:summary="@string/summary_placeholder"/>
|
||||
<PreferenceCategory
|
||||
android:key="recent_notifications_category"
|
||||
android:title="@string/recent_notifications"
|
||||
settings:allowDividerAbove="false"
|
||||
android:order="21">
|
||||
<!-- Placeholder for a list of recent apps -->
|
||||
|
||||
<!-- See all apps button -->
|
||||
<Preference
|
||||
android:title="@string/notifications_title"
|
||||
android:key="all_notifications"
|
||||
android:order="22">
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.settings"
|
||||
android:targetClass="com.android.settings.Settings$NotificationAppListActivity">
|
||||
</intent>
|
||||
</Preference>
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -19,7 +19,7 @@
|
||||
android:key="security_lockscreen_settings_screen"
|
||||
android:title="@string/lockscreen_settings_title">
|
||||
|
||||
<com.android.settings.notification.RestrictedDropDownPreference
|
||||
<com.android.settings.RestrictedListPreference
|
||||
android:key="security_setting_lock_screen_notif"
|
||||
android:title="@string/lock_screen_notifications_title"
|
||||
android:summary="@string/summary_placeholder" />
|
||||
@@ -42,7 +42,7 @@
|
||||
android:key="security_setting_lock_screen_notif_work_header"
|
||||
android:title="@string/profile_section_header">
|
||||
|
||||
<com.android.settings.notification.RestrictedDropDownPreference
|
||||
<com.android.settings.RestrictedListPreference
|
||||
android:key="security_setting_lock_screen_notif_work"
|
||||
android:title="@string/lock_screen_notifications_title"
|
||||
android:summary="@string/summary_placeholder" />
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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<RestrictedItem> 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<String> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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<CharSequence> entries = new ArrayList<>();
|
||||
ArrayList<CharSequence> 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);
|
||||
}
|
||||
}
|
||||
|
@@ -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<CharSequence[]> 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<CharSequence[]> 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<CharSequence[]> 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<String> 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<String> 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));
|
||||
|
Reference in New Issue
Block a user