Add Work Challenge Notifications Setting

Bug: 26844582
Change-Id: Ib1eb28cfebcc0c8d23ec8669f2777ccb822d7bf3
This commit is contained in:
Clara Bayarri
2016-02-18 12:09:21 +00:00
parent eb8962d273
commit 462cce1a4c
6 changed files with 174 additions and 30 deletions

View File

@@ -5903,6 +5903,9 @@
<!-- Configure Notifications: Advanced section header [CHAR LIMIT=30] --> <!-- Configure Notifications: Advanced section header [CHAR LIMIT=30] -->
<string name="advanced_section_header">Advanced</string> <string name="advanced_section_header">Advanced</string>
<!-- Configure Notifications: Work profile section header [CHAR LIMIT=30] -->
<string name="profile_section_header">Work notifications</string>
<!-- Configure Notifications: Title for the pulse notification light option. [CHAR LIMIT=30] --> <!-- Configure Notifications: Title for the pulse notification light option. [CHAR LIMIT=30] -->
<string name="notification_pulse_title">Pulse notification light</string> <string name="notification_pulse_title">Pulse notification light</string>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:title="@string/configure_notification_settings" >
<PreferenceCategory
android:title="@string/profile_section_header" >
<com.android.settingslib.RestrictedDropDownPreference
android:key="lock_screen_notifications_profile"
android:title="@string/lock_screen_notifications_title"
android:summary="%s" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -36,7 +36,6 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -224,7 +223,7 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
} }
protected boolean isProfileChallenge() { protected boolean isProfileChallenge() {
return UserHandle.myUserId() != mEffectiveUserId; return Utils.isManagedProfile(UserManager.get(getContext()));
} }
protected void reportSuccessfullAttempt() { protected void reportSuccessfullAttempt() {

View File

@@ -228,7 +228,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, MY_USER_ID); final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, MY_USER_ID);
addPreferencesFromResource(resid); addPreferencesFromResource(resid);
mProfileChallengeUserId = getManagedProfileId(mUm); mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
if (mProfileChallengeUserId != UserHandle.USER_NULL if (mProfileChallengeUserId != UserHandle.USER_NULL
&& mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) { && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
addPreferencesFromResource(R.xml.security_settings_profile); addPreferencesFromResource(R.xml.security_settings_profile);
@@ -726,21 +726,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
return R.string.help_url_security; return R.string.help_url_security;
} }
private static int getManagedProfileId(UserManager um) {
List<UserInfo> profiles = um.getProfiles(MY_USER_ID);
int numProfiles = profiles.size();
if (numProfiles == 1) {
return UserHandle.USER_NULL;
}
for (int i = 0; i < numProfiles; ++i) {
UserInfo profile = profiles.get(i);
if (profile.id != MY_USER_ID) {
return profile.id;
}
}
return UserHandle.USER_NULL;
}
/** /**
* For Search. Please keep it in sync when updating "createPreferenceHierarchy()" * For Search. Please keep it in sync when updating "createPreferenceHierarchy()"
*/ */
@@ -764,7 +749,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
result.add(sir); result.add(sir);
final UserManager um = UserManager.get(context); final UserManager um = UserManager.get(context);
final int profileUserId = getManagedProfileId(um); final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID);
if (profileUserId != UserHandle.USER_NULL if (profileUserId != UserHandle.USER_NULL
&& lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) { && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) {
sir = new SearchIndexableResource(context); sir = new SearchIndexableResource(context);
@@ -847,7 +832,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
} }
final LockPatternUtils lockPatternUtils = new LockPatternUtils(context); final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
final int profileUserId = getManagedProfileId(um); final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID);
if (profileUserId != UserHandle.USER_NULL if (profileUserId != UserHandle.USER_NULL
&& lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) { && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) {
if (lockPatternUtils.getKeyguardStoredPasswordQuality(profileUserId) if (lockPatternUtils.getKeyguardStoredPasswordQuality(profileUserId)

View File

@@ -595,6 +595,23 @@ public final class Utils extends com.android.settingslib.Utils {
return isManagedProfile(userManager, UserHandle.myUserId()); return isManagedProfile(userManager, UserHandle.myUserId());
} }
/**
* Retrieves the id for the given user's managed profile.
*
* @return the managed profile id or UserHandle.USER_NULL if there is none.
*/
public static int getManagedProfileId(UserManager um, int parentUserId) {
List<UserInfo> profiles = um.getProfiles(parentUserId);
int numProfiles = profiles.size();
for (int i = 0; i < numProfiles; ++i) {
UserInfo profile = profiles.get(i);
if (profile.id != parentUserId) {
return profile.id;
}
}
return UserHandle.USER_NULL;
}
/** /**
* Returns true if the userId passed in is a managed profile. * Returns true if the userId passed in is a managed profile.
* *

View File

@@ -23,6 +23,7 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener; import android.support.v7.preference.Preference.OnPreferenceChangeListener;
@@ -34,6 +35,7 @@ import com.android.settings.InstrumentedFragment;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.RestrictedListPreference.RestrictedItem; import com.android.settings.RestrictedListPreference.RestrictedItem;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
import java.util.ArrayList; import java.util.ArrayList;
@@ -48,6 +50,8 @@ public class ConfigureNotificationSettings extends SettingsPreferenceFragment {
private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; private static final String KEY_NOTIFICATION_PULSE = "notification_pulse";
private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications"; private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications";
private static final String KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS =
"lock_screen_notifications_profile";
private final SettingsObserver mSettingsObserver = new SettingsObserver(); private final SettingsObserver mSettingsObserver = new SettingsObserver();
@@ -55,8 +59,12 @@ public class ConfigureNotificationSettings extends SettingsPreferenceFragment {
private TwoStatePreference mNotificationPulse; private TwoStatePreference mNotificationPulse;
private NotificationLockscreenPreference mLockscreen; private NotificationLockscreenPreference mLockscreen;
private NotificationLockscreenPreference mLockscreenProfile;
private boolean mSecure; private boolean mSecure;
private boolean mSecureProfile;
private int mLockscreenSelectedValue; private int mLockscreenSelectedValue;
private int mLockscreenSelectedValueProfile;
private int mProfileChallengeUserId;
@Override @Override
protected int getMetricsCategory() { protected int getMetricsCategory() {
@@ -67,13 +75,22 @@ public class ConfigureNotificationSettings extends SettingsPreferenceFragment {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mContext = getActivity(); mContext = getActivity();
mProfileChallengeUserId = Utils.getManagedProfileId(
UserManager.get(mContext), UserHandle.myUserId());
mSecure = new LockPatternUtils(getActivity()).isSecure(UserHandle.myUserId()); mSecure = new LockPatternUtils(getActivity()).isSecure(UserHandle.myUserId());
mSecureProfile = (mProfileChallengeUserId != UserHandle.USER_NULL)
&& new LockPatternUtils(getActivity()).isSecure(mProfileChallengeUserId);
addPreferencesFromResource(R.xml.configure_notification_settings); addPreferencesFromResource(R.xml.configure_notification_settings);
initPulse(); initPulse();
initLockscreenNotifications(); initLockscreenNotifications();
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
addPreferencesFromResource(R.xml.configure_notification_settings_profile);
initLockscreenNotificationsForProfile();
}
} }
@Override @Override
@@ -126,8 +143,6 @@ public class ConfigureNotificationSettings extends SettingsPreferenceFragment {
} }
} }
// === Lockscreen (public / private) notifications ===
private void initLockscreenNotifications() { private void initLockscreenNotifications() {
mLockscreen = (NotificationLockscreenPreference) getPreferenceScreen().findPreference( mLockscreen = (NotificationLockscreenPreference) getPreferenceScreen().findPreference(
KEY_LOCK_SCREEN_NOTIFICATIONS); KEY_LOCK_SCREEN_NOTIFICATIONS);
@@ -187,6 +202,71 @@ public class ConfigureNotificationSettings extends SettingsPreferenceFragment {
} }
} }
// === Lockscreen (public / private) notifications ===
private void initLockscreenNotificationsForProfile() {
mLockscreenProfile = (NotificationLockscreenPreference) getPreferenceScreen()
.findPreference(KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
if (mLockscreenProfile == null) {
Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
return;
}
ArrayList<CharSequence> entries = new ArrayList<>();
ArrayList<CharSequence> values = new ArrayList<>();
entries.add(getString(R.string.lock_screen_notifications_summary_disable_profile));
values.add(Integer.toString(R.string.lock_screen_notifications_summary_disable_profile));
String summaryShowEntry = getString(
R.string.lock_screen_notifications_summary_show_profile);
String summaryShowEntryValue = Integer.toString(
R.string.lock_screen_notifications_summary_show_profile);
entries.add(summaryShowEntry);
values.add(summaryShowEntryValue);
setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue,
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
if (mSecureProfile) {
String summaryHideEntry = getString(
R.string.lock_screen_notifications_summary_hide_profile);
String summaryHideEntryValue = Integer.toString(
R.string.lock_screen_notifications_summary_hide_profile);
entries.add(summaryHideEntry);
values.add(summaryHideEntryValue);
setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue,
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
}
mLockscreenProfile.setEntries(entries.toArray(new CharSequence[entries.size()]));
mLockscreenProfile.setEntryValues(values.toArray(new CharSequence[values.size()]));
updateLockscreenNotificationsForProfile();
if (mLockscreenProfile.getEntries().length > 1) {
mLockscreenProfile.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
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(getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
show ? 1 : 0, mProfileChallengeUserId);
Settings.Secure.putIntForUser(getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
enabled ? 1 : 0, mProfileChallengeUserId);
mLockscreenSelectedValueProfile = val;
return true;
}
});
} else {
// There is one or less option for the user, disable the drop down.
mLockscreenProfile.setEnabled(false);
}
}
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry, private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
CharSequence entryValue, int keyguardNotificationFeatures) { CharSequence entryValue, int keyguardNotificationFeatures) {
EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
@@ -195,28 +275,54 @@ public class ConfigureNotificationSettings extends SettingsPreferenceFragment {
RestrictedItem item = new RestrictedItem(entry, entryValue, admin); RestrictedItem item = new RestrictedItem(entry, entryValue, admin);
mLockscreen.addRestrictedItem(item); mLockscreen.addRestrictedItem(item);
} }
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
EnforcedAdmin profileAdmin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
mContext, keyguardNotificationFeatures, mProfileChallengeUserId);
if (profileAdmin != null) {
RestrictedItem item = new RestrictedItem(entry, entryValue, profileAdmin);
mLockscreenProfile.addRestrictedItem(item);
}
}
} }
private void updateLockscreenNotifications() { private void updateLockscreenNotifications() {
if (mLockscreen == null) { if (mLockscreen == null) {
return; return;
} }
final boolean enabled = getLockscreenNotificationsEnabled(); final boolean enabled = getLockscreenNotificationsEnabled(UserHandle.myUserId());
final boolean allowPrivate = !mSecure || getLockscreenAllowPrivateNotifications(); final boolean allowPrivate = !mSecure
|| getLockscreenAllowPrivateNotifications(UserHandle.myUserId());
mLockscreenSelectedValue = !enabled ? R.string.lock_screen_notifications_summary_disable : mLockscreenSelectedValue = !enabled ? R.string.lock_screen_notifications_summary_disable :
allowPrivate ? R.string.lock_screen_notifications_summary_show : allowPrivate ? R.string.lock_screen_notifications_summary_show :
R.string.lock_screen_notifications_summary_hide; R.string.lock_screen_notifications_summary_hide;
mLockscreen.setValue(Integer.toString(mLockscreenSelectedValue)); mLockscreen.setValue(Integer.toString(mLockscreenSelectedValue));
} }
private boolean getLockscreenNotificationsEnabled() { private void updateLockscreenNotificationsForProfile() {
return Settings.Secure.getInt(getContentResolver(), if (mProfileChallengeUserId == UserHandle.USER_NULL) {
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; return;
}
if (mLockscreenProfile == null) {
return;
}
final boolean enabled = getLockscreenNotificationsEnabled(mProfileChallengeUserId);
final boolean allowPrivate = !mSecureProfile
|| getLockscreenAllowPrivateNotifications(mProfileChallengeUserId);
mLockscreenSelectedValueProfile = !enabled
? R.string.lock_screen_notifications_summary_disable_profile
: (allowPrivate ? R.string.lock_screen_notifications_summary_show_profile
: R.string.lock_screen_notifications_summary_hide_profile);
mLockscreenProfile.setValue(Integer.toString(mLockscreenSelectedValueProfile));
} }
private boolean getLockscreenAllowPrivateNotifications() { private boolean getLockscreenNotificationsEnabled(int userId) {
return Settings.Secure.getInt(getContentResolver(), return Settings.Secure.getIntForUser(getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0; Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userId) != 0;
}
private boolean getLockscreenAllowPrivateNotifications(int userId) {
return Settings.Secure.getIntForUser(getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userId) != 0;
} }
@@ -253,6 +359,9 @@ public class ConfigureNotificationSettings extends SettingsPreferenceFragment {
} }
if (LOCK_SCREEN_PRIVATE_URI.equals(uri) || LOCK_SCREEN_SHOW_URI.equals(uri)) { if (LOCK_SCREEN_PRIVATE_URI.equals(uri) || LOCK_SCREEN_SHOW_URI.equals(uri)) {
updateLockscreenNotifications(); updateLockscreenNotifications();
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
updateLockscreenNotificationsForProfile();
}
} }
} }
} }