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:
@@ -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.settingslib.drawer.CategoryKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserAndAccountDashboardFragment extends DashboardFragment {
|
||||
@@ -46,12 +47,18 @@ public class UserAndAccountDashboardFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.account_settings;
|
||||
return R.xml.user_and_accounts_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
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.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
|
||||
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)
|
||||
*/
|
||||
|
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);
|
||||
}
|
||||
|
||||
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 final Context mContext;
|
||||
|
Reference in New Issue
Block a user