Add Emergency info and Add user when locked to account dashboard.
Add two items to User & accounts dashboard, and refractor UserCapabilities so that it can be accessed in the new controller. Test: RunSettingsRoboTests Bug: 31801423 Change-Id: Ib446ad6c99d4cc6405a17cf82d2d86e044870b73
This commit is contained in:
@@ -7932,4 +7932,11 @@
|
|||||||
|
|
||||||
<!-- Warning when activating the automatic storage manager on legacy devices. [CHAR LIMIT=NONE] -->
|
<!-- Warning when activating the automatic storage manager on legacy devices. [CHAR LIMIT=NONE] -->
|
||||||
<string name="automatic_storage_manager_activation_warning">Your storage is now being managed by the storage manager</string>
|
<string name="automatic_storage_manager_activation_warning">Your storage is now being managed by the storage manager</string>
|
||||||
|
|
||||||
|
<!-- Accounts for section header [CHAR LIMIT=30] -->
|
||||||
|
<string name="account_for_section_header">Accounts</string>
|
||||||
|
|
||||||
|
<!-- Configure section header [CHAR LIMIT=30] -->
|
||||||
|
<string name="configure_section_header">Configure</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
43
res/xml/user_and_accounts_settings.xml
Normal file
43
res/xml/user_and_accounts_settings.xml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2014 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:key="account"
|
||||||
|
android:title="@string/account_settings_title"
|
||||||
|
settings:keywords="@string/keywords_accounts">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="account_for_header"
|
||||||
|
android:title="@string/account_for_section_header" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="emergency_info"
|
||||||
|
android:title="@string/emergency_info_title" />
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="account_configuration_header"
|
||||||
|
android:title="@string/configure_section_header">
|
||||||
|
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="add_users_when_locked"
|
||||||
|
android:title="@string/user_add_on_lockscreen_menu"
|
||||||
|
android:summary="@string/user_add_on_lockscreen_menu_summary"
|
||||||
|
settings:useAdditionalSummary="true" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* 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.accounts;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings.Global;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceController;
|
||||||
|
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settings.core.lifecycle.events.OnPause;
|
||||||
|
import com.android.settings.core.lifecycle.events.OnResume;
|
||||||
|
import com.android.settings.users.UserCapabilities;
|
||||||
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
public class AddUserWhenLockedPreferenceController extends PreferenceController
|
||||||
|
implements Preference.OnPreferenceChangeListener, LifecycleObserver, OnPause, OnResume {
|
||||||
|
|
||||||
|
private static final String KEY_ADD_USER_WHEN_LOCKED = "add_users_when_locked";
|
||||||
|
|
||||||
|
private RestrictedSwitchPreference mAddUserWhenLocked;
|
||||||
|
private UserCapabilities mUserCaps;
|
||||||
|
private boolean mShouldUpdateUserList;
|
||||||
|
|
||||||
|
public AddUserWhenLockedPreferenceController(Context context) {
|
||||||
|
super(context);
|
||||||
|
mUserCaps = UserCapabilities.create(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
RestrictedSwitchPreference restrictedSwitchPreference =
|
||||||
|
(RestrictedSwitchPreference) preference;
|
||||||
|
int value = Global.getInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 0);
|
||||||
|
restrictedSwitchPreference.setChecked(value == 1);
|
||||||
|
restrictedSwitchPreference.setDisabledByAdmin(
|
||||||
|
mUserCaps.disallowAddUser() ? mUserCaps.getEnforcedAdmin() : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
Boolean value = (Boolean) newValue;
|
||||||
|
Global.putInt(mContext.getContentResolver(),
|
||||||
|
Global.ADD_USERS_WHEN_LOCKED, value != null && value ? 1 : 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
mShouldUpdateUserList = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
if (mShouldUpdateUserList) {
|
||||||
|
mUserCaps.updateAddUserCapabilities(mContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return mUserCaps.isAdmin() &&
|
||||||
|
(!mUserCaps.disallowAddUser() || mUserCaps.disallowAddUserSetByAdmin());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_ADD_USER_WHEN_LOCKED;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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.accounts;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceController;
|
||||||
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EmergencyInfoPreferenceController extends PreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_EMERGENCY_INFO = "emergency_info";
|
||||||
|
private static final String ACTION_EDIT_EMERGENCY_INFO = "android.settings.EDIT_EMERGENGY_INFO";
|
||||||
|
private static final String PACKAGE_NAME_EMERGENCY = "com.android.emergency";
|
||||||
|
|
||||||
|
public EmergencyInfoPreferenceController(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||||
|
if (isAvailable()) {
|
||||||
|
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
|
||||||
|
final Resources res = mContext.getResources();
|
||||||
|
data.title = res.getString(com.android.settings.R.string.emergency_info_title);
|
||||||
|
data.screenTitle = res.getString(com.android.settings.R.string.emergency_info_title);
|
||||||
|
rawData.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
|
if (KEY_EMERGENCY_INFO.equals(preference.getKey())) {
|
||||||
|
Intent intent = new Intent(ACTION_EDIT_EMERGENCY_INFO);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
Intent intent = new Intent(ACTION_EDIT_EMERGENCY_INFO).setPackage(PACKAGE_NAME_EMERGENCY);
|
||||||
|
List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(intent, 0);
|
||||||
|
return infos != null && !infos.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_EMERGENCY_INFO;
|
||||||
|
}
|
||||||
|
}
|
@@ -23,6 +23,7 @@ import com.android.settings.core.PreferenceController;
|
|||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UserAndAccountDashboardFragment extends DashboardFragment {
|
public class UserAndAccountDashboardFragment extends DashboardFragment {
|
||||||
@@ -46,12 +47,18 @@ public class UserAndAccountDashboardFragment extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getPreferenceScreenResId() {
|
protected int getPreferenceScreenResId() {
|
||||||
return R.xml.account_settings;
|
return R.xml.user_and_accounts_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||||
return null;
|
final List<PreferenceController> controllers = new ArrayList<>();
|
||||||
|
controllers.add(new EmergencyInfoPreferenceController(context));
|
||||||
|
AddUserWhenLockedPreferenceController addUserWhenLockedPrefController =
|
||||||
|
new AddUserWhenLockedPreferenceController(context);
|
||||||
|
controllers.add(addUserWhenLockedPrefController);
|
||||||
|
getLifecycle().addObserver(addUserWhenLockedPrefController);
|
||||||
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,6 +18,7 @@ package com.android.settings.core;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
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 com.android.settings.search.SearchIndexableRaw;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -65,6 +66,14 @@ public abstract class PreferenceController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates raw data for search provider.
|
||||||
|
*
|
||||||
|
* Called by SearchIndexProvider#getRawDataToIndex
|
||||||
|
*/
|
||||||
|
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if preference is available (should be displayed)
|
* Returns true if preference is available (should be displayed)
|
||||||
*/
|
*/
|
||||||
|
113
src/com/android/settings/users/UserCapabilities.java
Normal file
113
src/com/android/settings/users/UserCapabilities.java
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* 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.users;
|
||||||
|
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
|
public class UserCapabilities {
|
||||||
|
boolean mEnabled = true;
|
||||||
|
boolean mCanAddUser = true;
|
||||||
|
boolean mCanAddRestrictedProfile = true;
|
||||||
|
boolean mIsAdmin;
|
||||||
|
boolean mIsGuest;
|
||||||
|
boolean mCanAddGuest;
|
||||||
|
boolean mDisallowAddUser;
|
||||||
|
boolean mDisallowAddUserSetByAdmin;
|
||||||
|
RestrictedLockUtils.EnforcedAdmin mEnforcedAdmin;
|
||||||
|
|
||||||
|
private UserCapabilities() {}
|
||||||
|
|
||||||
|
public static UserCapabilities create(Context context) {
|
||||||
|
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
|
UserCapabilities caps = new UserCapabilities();
|
||||||
|
if (!UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) {
|
||||||
|
caps.mEnabled = false;
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId());
|
||||||
|
caps.mIsGuest = myUserInfo.isGuest();
|
||||||
|
caps.mIsAdmin = myUserInfo.isAdmin();
|
||||||
|
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
|
||||||
|
Context.DEVICE_POLICY_SERVICE);
|
||||||
|
// No restricted profiles for tablets with a device owner, or phones.
|
||||||
|
if (dpm.isDeviceManaged() || Utils.isVoiceCapable(context)) {
|
||||||
|
caps.mCanAddRestrictedProfile = false;
|
||||||
|
}
|
||||||
|
caps.updateAddUserCapabilities(context);
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateAddUserCapabilities(Context context) {
|
||||||
|
mEnforcedAdmin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
|
||||||
|
UserManager.DISALLOW_ADD_USER, UserHandle.myUserId());
|
||||||
|
final boolean hasBaseUserRestriction = RestrictedLockUtils.hasBaseUserRestriction(
|
||||||
|
context, UserManager.DISALLOW_ADD_USER, UserHandle.myUserId());
|
||||||
|
mDisallowAddUserSetByAdmin =
|
||||||
|
mEnforcedAdmin != null && !hasBaseUserRestriction;
|
||||||
|
mDisallowAddUser =
|
||||||
|
(mEnforcedAdmin != null || hasBaseUserRestriction);
|
||||||
|
mCanAddUser = true;
|
||||||
|
if (!mIsAdmin || UserManager.getMaxSupportedUsers() < 2
|
||||||
|
|| !UserManager.supportsMultipleUsers()
|
||||||
|
|| mDisallowAddUser) {
|
||||||
|
mCanAddUser = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean canAddUsersWhenLocked = mIsAdmin || Settings.Global.getInt(
|
||||||
|
context.getContentResolver(), Settings.Global.ADD_USERS_WHEN_LOCKED, 0) == 1;
|
||||||
|
mCanAddGuest = !mIsGuest && !mDisallowAddUser && canAddUsersWhenLocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdmin() {
|
||||||
|
return mIsAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean disallowAddUser() {
|
||||||
|
return mDisallowAddUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean disallowAddUserSetByAdmin() {
|
||||||
|
return mDisallowAddUserSetByAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RestrictedLockUtils.EnforcedAdmin getEnforcedAdmin() {
|
||||||
|
return mEnforcedAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "UserCapabilities{" +
|
||||||
|
"mEnabled=" + mEnabled +
|
||||||
|
", mCanAddUser=" + mCanAddUser +
|
||||||
|
", mCanAddRestrictedProfile=" + mCanAddRestrictedProfile +
|
||||||
|
", mIsAdmin=" + mIsAdmin +
|
||||||
|
", mIsGuest=" + mIsGuest +
|
||||||
|
", mCanAddGuest=" + mCanAddGuest +
|
||||||
|
", mDisallowAddUser=" + mDisallowAddUser +
|
||||||
|
", mEnforcedAdmin=" + mEnforcedAdmin +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@@ -1058,76 +1058,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
mMePreference.setTitle(label);
|
mMePreference.setTitle(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class UserCapabilities {
|
|
||||||
boolean mEnabled = true;
|
|
||||||
boolean mCanAddUser = true;
|
|
||||||
boolean mCanAddRestrictedProfile = true;
|
|
||||||
boolean mIsAdmin;
|
|
||||||
boolean mIsGuest;
|
|
||||||
boolean mCanAddGuest;
|
|
||||||
boolean mDisallowAddUser;
|
|
||||||
boolean mDisallowAddUserSetByAdmin;
|
|
||||||
EnforcedAdmin mEnforcedAdmin;
|
|
||||||
|
|
||||||
private UserCapabilities() {}
|
|
||||||
|
|
||||||
public static UserCapabilities create(Context context) {
|
|
||||||
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
|
||||||
UserCapabilities caps = new UserCapabilities();
|
|
||||||
if (!UserManager.supportsMultipleUsers() || Utils.isMonkeyRunning()) {
|
|
||||||
caps.mEnabled = false;
|
|
||||||
return caps;
|
|
||||||
}
|
|
||||||
|
|
||||||
final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId());
|
|
||||||
caps.mIsGuest = myUserInfo.isGuest();
|
|
||||||
caps.mIsAdmin = myUserInfo.isAdmin();
|
|
||||||
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
|
|
||||||
Context.DEVICE_POLICY_SERVICE);
|
|
||||||
// No restricted profiles for tablets with a device owner, or phones.
|
|
||||||
if (dpm.isDeviceManaged() || Utils.isVoiceCapable(context)) {
|
|
||||||
caps.mCanAddRestrictedProfile = false;
|
|
||||||
}
|
|
||||||
caps.updateAddUserCapabilities(context);
|
|
||||||
return caps;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAddUserCapabilities(Context context) {
|
|
||||||
mEnforcedAdmin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
|
|
||||||
UserManager.DISALLOW_ADD_USER, UserHandle.myUserId());
|
|
||||||
final boolean hasBaseUserRestriction = RestrictedLockUtils.hasBaseUserRestriction(
|
|
||||||
context, UserManager.DISALLOW_ADD_USER, UserHandle.myUserId());
|
|
||||||
mDisallowAddUserSetByAdmin =
|
|
||||||
mEnforcedAdmin != null && !hasBaseUserRestriction;
|
|
||||||
mDisallowAddUser =
|
|
||||||
(mEnforcedAdmin != null || hasBaseUserRestriction);
|
|
||||||
mCanAddUser = true;
|
|
||||||
if (!mIsAdmin || UserManager.getMaxSupportedUsers() < 2
|
|
||||||
|| !UserManager.supportsMultipleUsers()
|
|
||||||
|| mDisallowAddUser) {
|
|
||||||
mCanAddUser = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean canAddUsersWhenLocked = mIsAdmin || Settings.Global.getInt(
|
|
||||||
context.getContentResolver(), Settings.Global.ADD_USERS_WHEN_LOCKED, 0) == 1;
|
|
||||||
mCanAddGuest = !mIsGuest && !mDisallowAddUser && canAddUsersWhenLocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "UserCapabilities{" +
|
|
||||||
"mEnabled=" + mEnabled +
|
|
||||||
", mCanAddUser=" + mCanAddUser +
|
|
||||||
", mCanAddRestrictedProfile=" + mCanAddRestrictedProfile +
|
|
||||||
", mIsAdmin=" + mIsAdmin +
|
|
||||||
", mIsGuest=" + mIsGuest +
|
|
||||||
", mCanAddGuest=" + mCanAddGuest +
|
|
||||||
", mDisallowAddUser=" + mDisallowAddUser +
|
|
||||||
", mEnforcedAdmin=" + mEnforcedAdmin +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* 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.accounts;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.provider.Settings.Global;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class AddUserWhenLockedPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
|
private UserInfo mUserInfo;
|
||||||
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
|
private UserManager mUserManager;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private AddUserWhenLockedPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
ShadowApplication shadowContext = ShadowApplication.getInstance();
|
||||||
|
shadowContext.setSystemService(Context.USER_SERVICE, mUserManager);
|
||||||
|
mContext = shadowContext.getApplicationContext();
|
||||||
|
mController = new AddUserWhenLockedPreferenceController(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPref_NotAdmin_shouldNotDisplay() {
|
||||||
|
when(mUserManager.getUserInfo(anyInt())).thenReturn(mUserInfo);
|
||||||
|
when(mUserInfo.isAdmin()).thenReturn(false);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mScreen).removePreference(any(Preference.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||||
|
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
||||||
|
Global.putInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 1);
|
||||||
|
|
||||||
|
mController.updateState(preference);
|
||||||
|
|
||||||
|
verify(preference).setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
||||||
|
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
||||||
|
Global.putInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 0);
|
||||||
|
|
||||||
|
mController.updateState(preference);
|
||||||
|
|
||||||
|
verify(preference).setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_SettingIsOnWhenPreferenceChecked() {
|
||||||
|
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
||||||
|
preference.setChecked(true);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(preference, Boolean.TRUE);
|
||||||
|
|
||||||
|
assertThat(Global.getInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 0))
|
||||||
|
.isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChange_SettingIsOffWhenPreferenceNotChecked() {
|
||||||
|
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
||||||
|
preference.setChecked(false);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(preference, Boolean.FALSE);
|
||||||
|
|
||||||
|
assertThat(Global.getInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 0))
|
||||||
|
.isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* 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.accounts;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class EmergencyInfoPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private EmergencyInfoPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mController = new EmergencyInfoPreferenceController(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateRawDataToIndex_prefUnavaiable_shouldNotUpdate() {
|
||||||
|
final List<SearchIndexableRaw> data = new ArrayList<>();
|
||||||
|
when(mContext.getPackageManager().queryIntentActivities(
|
||||||
|
any(Intent.class), anyInt()))
|
||||||
|
.thenReturn(null);
|
||||||
|
|
||||||
|
mController.updateRawDataToIndex(data);
|
||||||
|
|
||||||
|
assertThat(data).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateRawDataToIndex_prefAvaiable_shouldUpdate() {
|
||||||
|
final List<SearchIndexableRaw> data = new ArrayList<>();
|
||||||
|
final List<ResolveInfo> infos = new ArrayList<>();
|
||||||
|
infos.add(new ResolveInfo());
|
||||||
|
when(mContext.getPackageManager().queryIntentActivities(
|
||||||
|
any(Intent.class), anyInt()))
|
||||||
|
.thenReturn(infos);
|
||||||
|
|
||||||
|
mController.updateRawDataToIndex(data);
|
||||||
|
|
||||||
|
assertThat(data).isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPref_prefUnAvaiable_shouldNotDisplay() {
|
||||||
|
when(mContext.getPackageManager().queryIntentActivities(
|
||||||
|
any(Intent.class), anyInt()))
|
||||||
|
.thenReturn(null);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mScreen).removePreference(any(Preference.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPref_prefAvaiable_shouldDisplay() {
|
||||||
|
final List<SearchIndexableRaw> data = new ArrayList<>();
|
||||||
|
final List<ResolveInfo> infos = new ArrayList<>();
|
||||||
|
infos.add(new ResolveInfo());
|
||||||
|
when(mContext.getPackageManager().queryIntentActivities(
|
||||||
|
any(Intent.class), anyInt()))
|
||||||
|
.thenReturn(infos);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlePreferenceTreeClick_shouldStartActivity() {
|
||||||
|
final Preference preference = mock(Preference.class);
|
||||||
|
final ShadowApplication application = ShadowApplication.getInstance();
|
||||||
|
final Context context = application.getApplicationContext();
|
||||||
|
mController = new EmergencyInfoPreferenceController(context);
|
||||||
|
|
||||||
|
mController.handlePreferenceTreeClick(preference);
|
||||||
|
|
||||||
|
assertThat(application.getNextStartedActivity().getAction())
|
||||||
|
.isEqualTo("android.settings.EDIT_EMERGENGY_INFO");
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user