Merge "Show setting for work profile lock screen notification" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5bb87f9f34
@@ -15,21 +15,32 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/lockscreen_settings_title">
|
android:title="@string/lockscreen_settings_title">
|
||||||
|
|
||||||
|
<com.android.settings.notification.RestrictedDropDownPreference
|
||||||
|
android:key="security_setting_lock_screen_notif"
|
||||||
|
android:title="@string/lock_screen_notifications_title"
|
||||||
|
android:summary="@string/summary_placeholder" />
|
||||||
|
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="add_users_when_locked"
|
||||||
|
android:title="@string/user_add_on_lockscreen_menu" />
|
||||||
|
|
||||||
|
<com.android.settingslib.RestrictedPreference
|
||||||
|
android:key="owner_info_settings"
|
||||||
|
android:title="@string/owner_info_settings_title"
|
||||||
|
android:summary="@string/owner_info_settings_summary" />
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="security_setting_lock_screen_notif_work_header"
|
||||||
|
android:title="@string/profile_section_header">
|
||||||
|
|
||||||
<com.android.settings.notification.RestrictedDropDownPreference
|
<com.android.settings.notification.RestrictedDropDownPreference
|
||||||
android:key="lock_screen_notifications"
|
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" />
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
</PreferenceCategory>
|
||||||
android:key="add_users_when_locked"
|
|
||||||
android:title="@string/user_add_on_lockscreen_menu"/>
|
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
|
||||||
android:key="owner_info_settings"
|
|
||||||
android:title="@string/owner_info_settings_title"
|
|
||||||
android:summary="@string/owner_info_settings_summary"/>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -65,7 +65,10 @@ public class ConfigureNotificationSettings extends DashboardFragment {
|
|||||||
final PulseNotificationPreferenceController pulseController =
|
final PulseNotificationPreferenceController pulseController =
|
||||||
new PulseNotificationPreferenceController(context);
|
new PulseNotificationPreferenceController(context);
|
||||||
final LockScreenNotificationPreferenceController lockScreenNotificationController =
|
final LockScreenNotificationPreferenceController lockScreenNotificationController =
|
||||||
new LockScreenNotificationPreferenceController(context);
|
new LockScreenNotificationPreferenceController(context,
|
||||||
|
"lock_screen_notifications",
|
||||||
|
"lock_screen_notifications_profile_header",
|
||||||
|
"lock_screen_notifications_profile");
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(pulseController);
|
lifecycle.addObserver(pulseController);
|
||||||
lifecycle.addObserver(lockScreenNotificationController);
|
lifecycle.addObserver(lockScreenNotificationController);
|
||||||
|
@@ -26,6 +26,7 @@ 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.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
@@ -46,11 +47,10 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro
|
|||||||
Preference.OnPreferenceChangeListener, LifecycleObserver, OnResume, OnPause {
|
Preference.OnPreferenceChangeListener, LifecycleObserver, OnResume, OnPause {
|
||||||
|
|
||||||
private static final String TAG = "LockScreenNotifPref";
|
private static final String TAG = "LockScreenNotifPref";
|
||||||
private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications";
|
|
||||||
private static final String KEY_LOCK_SCREEN_PROFILE_HEADER =
|
private final String mSettingKey;
|
||||||
"lock_screen_notifications_profile_header";
|
private final String mWorkSettingCategoryKey;
|
||||||
private static final String KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS =
|
private final String mWorkSettingKey;
|
||||||
"lock_screen_notifications_profile";
|
|
||||||
|
|
||||||
private RestrictedDropDownPreference mLockscreen;
|
private RestrictedDropDownPreference mLockscreen;
|
||||||
private RestrictedDropDownPreference mLockscreenProfile;
|
private RestrictedDropDownPreference mLockscreenProfile;
|
||||||
@@ -64,7 +64,16 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro
|
|||||||
private int mLockscreenSelectedValueProfile;
|
private int mLockscreenSelectedValueProfile;
|
||||||
|
|
||||||
public LockScreenNotificationPreferenceController(Context context) {
|
public LockScreenNotificationPreferenceController(Context context) {
|
||||||
|
this(context, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LockScreenNotificationPreferenceController(Context context,
|
||||||
|
String settingKey, String workSettingCategoryKey, String workSettingKey) {
|
||||||
super(context);
|
super(context);
|
||||||
|
mSettingKey = settingKey;
|
||||||
|
mWorkSettingCategoryKey = workSettingCategoryKey;
|
||||||
|
mWorkSettingKey = workSettingKey;
|
||||||
|
|
||||||
mProfileChallengeUserId = Utils.getManagedProfileId(
|
mProfileChallengeUserId = Utils.getManagedProfileId(
|
||||||
UserManager.get(context), UserHandle.myUserId());
|
UserManager.get(context), UserHandle.myUserId());
|
||||||
final LockPatternUtils utils = new LockPatternUtils(context);
|
final LockPatternUtils utils = new LockPatternUtils(context);
|
||||||
@@ -79,17 +88,17 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro
|
|||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mLockscreen =
|
mLockscreen =
|
||||||
(RestrictedDropDownPreference) screen.findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS);
|
(RestrictedDropDownPreference) screen.findPreference(mSettingKey);
|
||||||
if (mLockscreen == null) {
|
if (mLockscreen == null) {
|
||||||
Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_NOTIFICATIONS);
|
Log.i(TAG, "Preference not found: " + mSettingKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
|
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
|
||||||
mLockscreenProfile = (RestrictedDropDownPreference) screen.findPreference(
|
mLockscreenProfile = (RestrictedDropDownPreference) screen.findPreference(
|
||||||
KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
|
mWorkSettingKey);
|
||||||
} else {
|
} else {
|
||||||
removePreference(screen, KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
|
removePreference(screen, mWorkSettingKey);
|
||||||
removePreference(screen, KEY_LOCK_SCREEN_PROFILE_HEADER);
|
removePreference(screen, mWorkSettingCategoryKey);
|
||||||
}
|
}
|
||||||
mSettingObserver = new SettingObserver();
|
mSettingObserver = new SettingObserver();
|
||||||
initLockScreenNotificationPrefDisplay();
|
initLockScreenNotificationPrefDisplay();
|
||||||
@@ -136,7 +145,7 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro
|
|||||||
|
|
||||||
private void initLockscreenNotificationPrefForProfile() {
|
private void initLockscreenNotificationPrefForProfile() {
|
||||||
if (mLockscreenProfile == null) {
|
if (mLockscreenProfile == null) {
|
||||||
Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
|
Log.i(TAG, "Preference not found: " + mWorkSettingKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArrayList<CharSequence> entries = new ArrayList<>();
|
ArrayList<CharSequence> entries = new ArrayList<>();
|
||||||
@@ -205,8 +214,8 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
switch (preference.getKey()) {
|
final String key = preference.getKey();
|
||||||
case KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS: {
|
if (TextUtils.equals(mWorkSettingKey, key)) {
|
||||||
final int val = Integer.parseInt((String) newValue);
|
final int val = Integer.parseInt((String) newValue);
|
||||||
if (val == mLockscreenSelectedValueProfile) {
|
if (val == mLockscreenSelectedValueProfile) {
|
||||||
return false;
|
return false;
|
||||||
@@ -223,8 +232,7 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro
|
|||||||
enabled ? 1 : 0, mProfileChallengeUserId);
|
enabled ? 1 : 0, mProfileChallengeUserId);
|
||||||
mLockscreenSelectedValueProfile = val;
|
mLockscreenSelectedValueProfile = val;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (TextUtils.equals(mSettingKey, key)) {
|
||||||
case KEY_LOCK_SCREEN_NOTIFICATIONS: {
|
|
||||||
final int val = Integer.parseInt((String) newValue);
|
final int val = Integer.parseInt((String) newValue);
|
||||||
if (val == mLockscreenSelectedValue) {
|
if (val == mLockscreenSelectedValue) {
|
||||||
return false;
|
return false;
|
||||||
@@ -238,10 +246,8 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro
|
|||||||
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;
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
|
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
|
||||||
@@ -295,6 +301,7 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro
|
|||||||
final boolean enabled = getLockscreenNotificationsEnabled(mProfileChallengeUserId);
|
final boolean enabled = getLockscreenNotificationsEnabled(mProfileChallengeUserId);
|
||||||
final boolean allowPrivate = !mSecureProfile
|
final boolean allowPrivate = !mSecureProfile
|
||||||
|| getLockscreenAllowPrivateNotifications(mProfileChallengeUserId);
|
|| getLockscreenAllowPrivateNotifications(mProfileChallengeUserId);
|
||||||
|
mLockscreenProfile.setSummary("%s");
|
||||||
mLockscreenSelectedValueProfile = !enabled
|
mLockscreenSelectedValueProfile = !enabled
|
||||||
? R.string.lock_screen_notifications_summary_disable_profile
|
? R.string.lock_screen_notifications_summary_disable_profile
|
||||||
: (allowPrivate ? R.string.lock_screen_notifications_summary_show_profile
|
: (allowPrivate ? R.string.lock_screen_notifications_summary_show_profile
|
||||||
|
@@ -18,6 +18,8 @@ package com.android.settings.security;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.accounts.AddUserWhenLockedPreferenceController;
|
import com.android.settings.accounts.AddUserWhenLockedPreferenceController;
|
||||||
@@ -26,6 +28,7 @@ import com.android.settings.core.lifecycle.Lifecycle;
|
|||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
import com.android.settings.notification.LockScreenNotificationPreferenceController;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -38,6 +41,15 @@ public class LockscreenDashboardFragment extends DashboardFragment
|
|||||||
|
|
||||||
private static final String TAG = "LockscreenDashboardFragment";
|
private static final String TAG = "LockscreenDashboardFragment";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_LOCK_SCREEN_NOTIFICATON = "security_setting_lock_screen_notif";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER =
|
||||||
|
"security_setting_lock_screen_notif_work_header";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE =
|
||||||
|
"security_setting_lock_screen_notif_work";
|
||||||
|
|
||||||
private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
|
private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -60,7 +72,10 @@ public class LockscreenDashboardFragment extends DashboardFragment
|
|||||||
final List<PreferenceController> controllers = new ArrayList<>();
|
final List<PreferenceController> controllers = new ArrayList<>();
|
||||||
final Lifecycle lifecycle = getLifecycle();
|
final Lifecycle lifecycle = getLifecycle();
|
||||||
final LockScreenNotificationPreferenceController notificationController =
|
final LockScreenNotificationPreferenceController notificationController =
|
||||||
new LockScreenNotificationPreferenceController(context);
|
new LockScreenNotificationPreferenceController(context,
|
||||||
|
KEY_LOCK_SCREEN_NOTIFICATON,
|
||||||
|
KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER,
|
||||||
|
KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE);
|
||||||
lifecycle.addObserver(notificationController);
|
lifecycle.addObserver(notificationController);
|
||||||
controllers.add(notificationController);
|
controllers.add(notificationController);
|
||||||
final AddUserWhenLockedPreferenceController addUserWhenLockedController =
|
final AddUserWhenLockedPreferenceController addUserWhenLockedController =
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
add_users_when_locked
|
add_users_when_locked
|
||||||
additional_system_update_settings
|
additional_system_update_settings
|
||||||
dashboard_tile_placeholder
|
dashboard_tile_placeholder
|
||||||
lock_screen_notifications
|
|
||||||
screen_zoom
|
screen_zoom
|
||||||
usage_access
|
usage_access
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.security;
|
||||||
|
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.XmlTestUtils;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class LockscreenDashboardFragmentTest {
|
||||||
|
|
||||||
|
private LockscreenDashboardFragment mFragment;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void containsNotificationSettingsForPrimaryUserAndWorkProfile() {
|
||||||
|
mFragment = new LockscreenDashboardFragment();
|
||||||
|
|
||||||
|
List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(RuntimeEnvironment.application,
|
||||||
|
mFragment.getPreferenceScreenResId());
|
||||||
|
|
||||||
|
assertThat(keys).containsAllOf(LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON,
|
||||||
|
LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE,
|
||||||
|
LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user