Merge "Notification settings updates"
This commit is contained in:
committed by
Android (Google) Code Review
commit
905221568e
@@ -2689,8 +2689,6 @@
|
|||||||
<intent-filter android:priority="150">
|
<intent-filter android:priority="150">
|
||||||
<action android:name="com.android.settings.action.SETTINGS" />
|
<action android:name="com.android.settings.action.SETTINGS" />
|
||||||
</intent-filter>
|
</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"
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
android:value="com.android.settings.applications.NotificationApps" />
|
android:value="com.android.settings.applications.NotificationApps" />
|
||||||
</activity>
|
</activity>
|
||||||
|
@@ -53,7 +53,7 @@
|
|||||||
settings:useAdditionalSummary="true" />
|
settings:useAdditionalSummary="true" />
|
||||||
|
|
||||||
<!-- Visibility Override -->
|
<!-- Visibility Override -->
|
||||||
<com.android.settings.notification.RestrictedDropDownPreference
|
<com.android.settings.RestrictedListPreference
|
||||||
android:key="visibility_override"
|
android:key="visibility_override"
|
||||||
android:title="@string/app_notification_visibility_override_title"/>
|
android:title="@string/app_notification_visibility_override_title"/>
|
||||||
|
|
||||||
|
@@ -15,39 +15,27 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<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:title="@string/configure_notification_settings"
|
||||||
android:key="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 -->
|
<!-- When device is locked -->
|
||||||
<com.android.settings.notification.RestrictedDropDownPreference
|
<com.android.settings.RestrictedListPreference
|
||||||
android:key="lock_screen_notifications"
|
android:key="lock_screen_notifications"
|
||||||
android:title="@string/lock_screen_notifications_title"
|
android:title="@string/lock_screen_notifications_title"
|
||||||
android:summary="@string/summary_placeholder"/>
|
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 -->
|
<!-- Notification badging -->
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="notification_badging"
|
android:key="notification_badging"
|
||||||
@@ -71,14 +59,30 @@
|
|||||||
android:title="@string/fingerprint_swipe_for_notifications_title"
|
android:title="@string/fingerprint_swipe_for_notifications_title"
|
||||||
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings" />
|
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings" />
|
||||||
|
|
||||||
|
<!-- Empty category to draw divider -->
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="lock_screen_notifications_profile_header"
|
android:key="all_notifications_divider"
|
||||||
android:title="@string/profile_section_header">
|
android:order="20"/>
|
||||||
|
|
||||||
<com.android.settings.notification.RestrictedDropDownPreference
|
<PreferenceCategory
|
||||||
android:key="lock_screen_notifications_profile"
|
android:key="recent_notifications_category"
|
||||||
android:title="@string/lock_screen_notifications_title"
|
android:title="@string/recent_notifications"
|
||||||
android:summary="@string/summary_placeholder"/>
|
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>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
android:key="security_lockscreen_settings_screen"
|
android:key="security_lockscreen_settings_screen"
|
||||||
android:title="@string/lockscreen_settings_title">
|
android:title="@string/lockscreen_settings_title">
|
||||||
|
|
||||||
<com.android.settings.notification.RestrictedDropDownPreference
|
<com.android.settings.RestrictedListPreference
|
||||||
android:key="security_setting_lock_screen_notif"
|
android:key="security_setting_lock_screen_notif"
|
||||||
android:title="@string/lock_screen_notifications_title"
|
android:title="@string/lock_screen_notifications_title"
|
||||||
android:summary="@string/summary_placeholder" />
|
android:summary="@string/summary_placeholder" />
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
android:key="security_setting_lock_screen_notif_work_header"
|
android:key="security_setting_lock_screen_notif_work_header"
|
||||||
android:title="@string/profile_section_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:key="security_setting_lock_screen_notif_work"
|
||||||
android:title="@string/lock_screen_notifications_title"
|
android:title="@string/lock_screen_notifications_title"
|
||||||
android:summary="@string/summary_placeholder" />
|
android:summary="@string/summary_placeholder" />
|
||||||
|
@@ -34,6 +34,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.RestrictedListPreference;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
@@ -55,8 +56,8 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
|
|||||||
private final String mWorkSettingCategoryKey;
|
private final String mWorkSettingCategoryKey;
|
||||||
private final String mWorkSettingKey;
|
private final String mWorkSettingKey;
|
||||||
|
|
||||||
private RestrictedDropDownPreference mLockscreen;
|
private RestrictedListPreference mLockscreen;
|
||||||
private RestrictedDropDownPreference mLockscreenProfile;
|
private RestrictedListPreference mLockscreenProfile;
|
||||||
|
|
||||||
private final int mProfileChallengeUserId;
|
private final int mProfileChallengeUserId;
|
||||||
private final boolean mSecure;
|
private final boolean mSecure;
|
||||||
@@ -92,13 +93,13 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
|
|||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mLockscreen =
|
mLockscreen =
|
||||||
(RestrictedDropDownPreference) screen.findPreference(mSettingKey);
|
(RestrictedListPreference) screen.findPreference(mSettingKey);
|
||||||
if (mLockscreen == null) {
|
if (mLockscreen == null) {
|
||||||
Log.i(TAG, "Preference not found: " + mSettingKey);
|
Log.i(TAG, "Preference not found: " + mSettingKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
|
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
|
||||||
mLockscreenProfile = (RestrictedDropDownPreference) screen.findPreference(
|
mLockscreenProfile = (RestrictedListPreference) screen.findPreference(
|
||||||
mWorkSettingKey);
|
mWorkSettingKey);
|
||||||
} else {
|
} else {
|
||||||
setVisible(screen, mWorkSettingKey, false /* visible */);
|
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));
|
entries.add(mContext.getString(R.string.lock_screen_notifications_summary_disable_profile));
|
||||||
values.add(Integer.toString(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.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
||||||
mLockscreenProfile.setEntryValues(values.toArray(new CharSequence[values.size()]));
|
mLockscreenProfile.setEntryValues(values.toArray(new CharSequence[values.size()]));
|
||||||
updateLockscreenNotificationsForProfile();
|
updateLockscreenNotificationsForProfile();
|
||||||
@@ -224,36 +220,40 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
|
|||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final String key = preference.getKey();
|
final String key = preference.getKey();
|
||||||
if (TextUtils.equals(mWorkSettingKey, key)) {
|
if (TextUtils.equals(mWorkSettingKey, key)) {
|
||||||
final int val = Integer.parseInt((String) newValue);
|
if (Utils.startQuietModeDialogIfNecessary(mContext, UserManager.get(mContext),
|
||||||
if (val == mLockscreenSelectedValueProfile) {
|
mProfileChallengeUserId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final boolean enabled =
|
final int val = Integer.parseInt((String) newValue);
|
||||||
val != R.string.lock_screen_notifications_summary_disable_profile;
|
if (val == mLockscreenSelectedValueProfile) {
|
||||||
final boolean show =
|
return false;
|
||||||
val == R.string.lock_screen_notifications_summary_show_profile;
|
}
|
||||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
final boolean enabled =
|
||||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
|
val != R.string.lock_screen_notifications_summary_disable_profile;
|
||||||
show ? 1 : 0, mProfileChallengeUserId);
|
final boolean show =
|
||||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
val == R.string.lock_screen_notifications_summary_show_profile;
|
||||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||||
enabled ? 1 : 0, mProfileChallengeUserId);
|
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
|
||||||
mLockscreenSelectedValueProfile = val;
|
show ? 1 : 0, mProfileChallengeUserId);
|
||||||
return true;
|
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)) {
|
} else if (TextUtils.equals(mSettingKey, key)) {
|
||||||
final int val = Integer.parseInt((String) newValue);
|
final int val = Integer.parseInt((String) newValue);
|
||||||
if (val == mLockscreenSelectedValue) {
|
if (val == mLockscreenSelectedValue) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final boolean enabled =
|
final boolean enabled =
|
||||||
val != R.string.lock_screen_notifications_summary_disable;
|
val != R.string.lock_screen_notifications_summary_disable;
|
||||||
final boolean show = val == R.string.lock_screen_notifications_summary_show;
|
final boolean show = val == R.string.lock_screen_notifications_summary_show;
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0);
|
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0);
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
|
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
|
||||||
mLockscreenSelectedValue = val;
|
mLockscreenSelectedValue = val;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -264,8 +264,8 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
|
|||||||
RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
||||||
mContext, keyguardNotificationFeatures, UserHandle.myUserId());
|
mContext, keyguardNotificationFeatures, UserHandle.myUserId());
|
||||||
if (admin != null && mLockscreen != null) {
|
if (admin != null && mLockscreen != null) {
|
||||||
RestrictedDropDownPreference.RestrictedItem item =
|
RestrictedListPreference.RestrictedItem item =
|
||||||
new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin);
|
new RestrictedListPreference.RestrictedItem(entry, entryValue, admin);
|
||||||
mLockscreen.addRestrictedItem(item);
|
mLockscreen.addRestrictedItem(item);
|
||||||
}
|
}
|
||||||
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
|
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
|
||||||
@@ -273,8 +273,8 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
|
|||||||
RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
||||||
mContext, keyguardNotificationFeatures, mProfileChallengeUserId);
|
mContext, keyguardNotificationFeatures, mProfileChallengeUserId);
|
||||||
if (profileAdmin != null && mLockscreenProfile != null) {
|
if (profileAdmin != null && mLockscreenProfile != null) {
|
||||||
RestrictedDropDownPreference.RestrictedItem item =
|
RestrictedListPreference.RestrictedItem item =
|
||||||
new RestrictedDropDownPreference.RestrictedItem(
|
new RestrictedListPreference.RestrictedItem(
|
||||||
entry, entryValue, profileAdmin);
|
entry, entryValue, profileAdmin);
|
||||||
mLockscreenProfile.addRestrictedItem(item);
|
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.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.RestrictedListPreference;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro
|
|||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mChannel != null && mAppRow != null) {
|
if (mChannel != null && mAppRow != null) {
|
||||||
RestrictedDropDownPreference pref = (RestrictedDropDownPreference) preference;
|
RestrictedListPreference pref = (RestrictedListPreference) preference;
|
||||||
ArrayList<CharSequence> entries = new ArrayList<>();
|
ArrayList<CharSequence> entries = new ArrayList<>();
|
||||||
ArrayList<CharSequence> values = new ArrayList<>();
|
ArrayList<CharSequence> values = new ArrayList<>();
|
||||||
|
|
||||||
@@ -120,14 +121,14 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRestrictedIfNotificationFeaturesDisabled(RestrictedDropDownPreference pref,
|
private void setRestrictedIfNotificationFeaturesDisabled(RestrictedListPreference pref,
|
||||||
CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) {
|
CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) {
|
||||||
RestrictedLockUtils.EnforcedAdmin admin =
|
RestrictedLockUtils.EnforcedAdmin admin =
|
||||||
RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
|
||||||
mContext, keyguardNotificationFeatures, mAppRow.userId);
|
mContext, keyguardNotificationFeatures, mAppRow.userId);
|
||||||
if (admin != null) {
|
if (admin != null) {
|
||||||
RestrictedDropDownPreference.RestrictedItem item =
|
RestrictedListPreference.RestrictedItem item =
|
||||||
new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin);
|
new RestrictedListPreference.RestrictedItem(entry, entryValue, admin);
|
||||||
pref.addRestrictedItem(item);
|
pref.addRestrictedItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,7 @@ import android.provider.Settings;
|
|||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.RestrictedListPreference;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.ShadowRestrictionUtils;
|
import com.android.settings.testutils.shadow.ShadowRestrictionUtils;
|
||||||
@@ -115,8 +116,8 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNoCrashIfNoOnResume() throws Exception {
|
public void testNoCrashIfNoOnResume() throws Exception {
|
||||||
mController.isAvailable();
|
mController.isAvailable();
|
||||||
mController.updateState(mock(RestrictedDropDownPreference.class));
|
mController.updateState(mock(RestrictedListPreference.class));
|
||||||
mController.onPreferenceChange(mock(RestrictedDropDownPreference.class), true);
|
mController.onPreferenceChange(mock(RestrictedListPreference.class), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -165,7 +166,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class));
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
verify(pref, times(2)).addRestrictedItem(any());
|
verify(pref, times(2)).addRestrictedItem(any());
|
||||||
@@ -187,7 +188,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class));
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
verify(pref, times(1)).addRestrictedItem(any());
|
verify(pref, times(1)).addRestrictedItem(any());
|
||||||
@@ -202,7 +203,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
ArgumentCaptor<CharSequence[]> argumentCaptor =
|
ArgumentCaptor<CharSequence[]> argumentCaptor =
|
||||||
@@ -221,7 +222,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
ArgumentCaptor<CharSequence[]> argumentCaptor =
|
ArgumentCaptor<CharSequence[]> argumentCaptor =
|
||||||
@@ -237,7 +238,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
ArgumentCaptor<CharSequence[]> argumentCaptor =
|
ArgumentCaptor<CharSequence[]> argumentCaptor =
|
||||||
@@ -268,7 +269,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
|
when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
@@ -287,7 +288,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET);
|
when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
@@ -306,7 +307,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
|
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_PRIVATE));
|
mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_PRIVATE));
|
||||||
@@ -325,7 +326,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
|
channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_SECRET));
|
mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_SECRET));
|
||||||
|
Reference in New Issue
Block a user