use of android.provider.Settings in project android_frameworks_base by ParanoidAndroid.
the class WifiSettingsStore method testAndClearWifiSavedState.
/* After a reboot, we restore wi-fi to be on if it was turned off temporarily for tethering.
* The settings app tracks the saved state, but the framework has to check it at boot to
* make sure the wi-fi is turned on in case it was turned off for the purpose of tethering.
*
* Note that this is not part of the regular WIFI_ON setting because this only needs to
* be controlled through the settings app and not the Wi-Fi public API.
*/
private boolean testAndClearWifiSavedState() {
final ContentResolver cr = mContext.getContentResolver();
int wifiSavedState = 0;
try {
wifiSavedState = Settings.Global.getInt(cr, Settings.Global.WIFI_SAVED_STATE);
if (wifiSavedState == 1)
Settings.Global.putInt(cr, Settings.Global.WIFI_SAVED_STATE, 0);
} catch (Settings.SettingNotFoundException e) {
;
}
return (wifiSavedState == 1);
}
use of android.provider.Settings in project actor-platform by actorapp.
the class ProfileFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
uid = getArguments().getInt(EXTRA_UID);
final UserVM user = users().get(uid);
ArrayList<UserPhone> phones = user.getPhones().get();
ArrayList<UserEmail> emails = user.getEmails().get();
String about = user.getAbout().get();
final String userName = user.getNick().get();
final View res = inflater.inflate(R.layout.fragment_profile, container, false);
//
// Style Background
//
res.findViewById(R.id.container).setBackgroundColor(style.getMainBackgroundColor());
res.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
//
// User Avatar
//
avatarView = (AvatarView) res.findViewById(R.id.avatar);
avatarView.init(Screen.dp(48), 22);
avatarView.bind(user.getAvatar().get(), user.getName().get(), user.getId());
avatarView.setOnClickListener(v -> {
startActivity(ViewAvatarActivity.viewAvatar(user.getId(), getActivity()));
});
//
// User Name
//
TextView nameText = (TextView) res.findViewById(R.id.name);
nameText.setTextColor(style.getProfileTitleColor());
bind(nameText, user.getName());
//
// User Last Seen
//
TextView lastSeen = (TextView) res.findViewById(R.id.lastSeen);
lastSeen.setTextColor(style.getProfileSubtitleColor());
bind(lastSeen, user);
//
// Fab
//
FloatingActionButton fab = (FloatingActionButton) res.findViewById(R.id.fab);
fab.setBackgroundTintList(new ColorStateList(new int[][] { new int[] { android.R.attr.state_pressed }, StateSet.WILD_CARD }, new int[] { ActorSDK.sharedActor().style.getFabPressedColor(), ActorSDK.sharedActor().style.getFabColor() }));
fab.setRippleColor(ActorSDK.sharedActor().style.getFabPressedColor());
fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), ComposeActivity.class)));
//
// Remove Contact
//
final View removeContact = res.findViewById(R.id.addContact);
final TextView addContactTitle = (TextView) removeContact.findViewById(R.id.addContactTitle);
addContactTitle.setText(getString(R.string.profile_contacts_added));
addContactTitle.setTextColor(style.getTextPrimaryColor());
removeContact.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().removeContact(user.getId()));
});
bind(user.isContact(), (isContact, valueModel) -> {
if (isContact) {
removeContact.setVisibility(View.VISIBLE);
//fab
fab.setImageResource(R.drawable.ic_message_white_24dp);
fab.setOnClickListener(view -> startActivity(Intents.openPrivateDialog(user.getId(), true, getActivity())));
} else {
removeContact.setVisibility(View.GONE);
//fab
fab.setImageResource(R.drawable.ic_person_add_white_24dp);
fab.setOnClickListener(view -> execute(ActorSDK.sharedActor().getMessenger().addContact(user.getId())));
}
});
//
// New Message
//
View newMessageView = res.findViewById(R.id.newMessage);
ImageView newMessageIcon = (ImageView) newMessageView.findViewById(R.id.newMessageIcon);
TextView newMessageTitle = (TextView) newMessageView.findViewById(R.id.newMessageText);
{
Drawable drawable = getResources().getDrawable(R.drawable.ic_chat_black_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
newMessageIcon.setImageDrawable(drawable);
newMessageTitle.setTextColor(style.getTextPrimaryColor());
}
newMessageView.setOnClickListener(v -> {
startActivity(Intents.openPrivateDialog(user.getId(), true, getActivity()));
});
//
// Voice Call
//
View voiceCallDivider = res.findViewById(R.id.voiceCallDivider);
View voiceCallView = res.findViewById(R.id.voiceCall);
if (ActorSDK.sharedActor().isCallsEnabled() && !user.isBot()) {
ImageView voiceViewIcon = (ImageView) voiceCallView.findViewById(R.id.actionIcon);
TextView voiceViewTitle = (TextView) voiceCallView.findViewById(R.id.actionText);
Drawable drawable = getResources().getDrawable(R.drawable.ic_phone_white_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
voiceViewIcon.setImageDrawable(drawable);
voiceViewTitle.setTextColor(style.getTextPrimaryColor());
voiceCallView.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().doCall(user.getId()));
});
} else {
voiceCallView.setVisibility(View.GONE);
voiceCallDivider.setVisibility(View.GONE);
}
//
// Video Call
//
View videoCallDivider = res.findViewById(R.id.videoCallDivider);
View videoCallView = res.findViewById(R.id.videoCall);
if (ActorSDK.sharedActor().isCallsEnabled() && !user.isBot()) {
ImageView voiceViewIcon = (ImageView) videoCallView.findViewById(R.id.videoCallIcon);
TextView voiceViewTitle = (TextView) videoCallView.findViewById(R.id.videoCallText);
Drawable drawable = getResources().getDrawable(R.drawable.ic_videocam_white_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
voiceViewIcon.setImageDrawable(drawable);
voiceViewTitle.setTextColor(style.getTextPrimaryColor());
videoCallView.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().doVideoCall(user.getId()));
});
} else {
videoCallView.setVisibility(View.GONE);
videoCallDivider.setVisibility(View.GONE);
}
//
// Contact Information
//
final LinearLayout contactsContainer = (LinearLayout) res.findViewById(R.id.contactsContainer);
String aboutString = user.getAbout().get();
boolean isFirstContact = aboutString == null || aboutString.isEmpty();
//
// About
//
bind(user.getAbout(), new ValueChangedListener<String>() {
private View userAboutRecord;
@Override
public void onChanged(final String newUserAbout, Value<String> valueModel) {
if (newUserAbout != null && newUserAbout.length() > 0) {
if (userAboutRecord == null) {
userAboutRecord = buildRecordBig(newUserAbout, R.drawable.ic_info_outline_black_24dp, true, false, inflater, contactsContainer);
} else {
((TextView) userAboutRecord.findViewById(R.id.value)).setText(newUserAbout);
}
if (recordFieldWithIcon != null) {
recordFieldWithIcon.findViewById(R.id.recordIcon).setVisibility(View.INVISIBLE);
}
}
}
});
if (!ActorSDK.sharedActor().isOnClientPrivacyEnabled() || user.isInPhoneBook().get()) {
for (int i = 0; i < phones.size(); i++) {
final UserPhone userPhone = phones.get(i);
// Formatting Phone Number
String _phoneNumber;
try {
Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + userPhone.getPhone(), "us");
_phoneNumber = PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
_phoneNumber = "+" + userPhone.getPhone();
}
final String phoneNumber = _phoneNumber;
String phoneTitle = userPhone.getTitle();
// Trying to localize this
if (phoneTitle.toLowerCase().equals("mobile phone")) {
phoneTitle = getString(R.string.settings_mobile_phone);
}
View view = buildRecord(phoneTitle, phoneNumber, R.drawable.ic_import_contacts_black_24dp, isFirstContact, false, inflater, contactsContainer);
if (isFirstContact) {
recordFieldWithIcon = view;
}
view.setOnClickListener(v -> {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.phone_menu_call).replace("{0}", phoneNumber), getString(R.string.phone_menu_sms).replace("{0}", phoneNumber), getString(R.string.phone_menu_share).replace("{0}", phoneNumber), getString(R.string.phone_menu_copy) }, (dialog, which) -> {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:+" + userPhone.getPhone())));
} else if (which == 1) {
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("sms:+" + userPhone.getPhone())));
} else if (which == 2) {
startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text).replace("{0}", phoneNumber).replace("{1}", user.getName().get())));
} else if (which == 3) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", phoneNumber);
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_phone_copied, Snackbar.LENGTH_SHORT).show();
}
}).show().setCanceledOnTouchOutside(true);
});
view.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", "+" + userPhone.getPhone());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_phone_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
isFirstContact = false;
}
for (int i = 0; i < emails.size(); i++) {
final UserEmail userEmail = emails.get(i);
View view = buildRecord(userEmail.getTitle(), userEmail.getEmail(), R.drawable.ic_import_contacts_black_24dp, isFirstContact, false, inflater, contactsContainer);
if (isFirstContact) {
recordFieldWithIcon = view;
}
view.setOnClickListener(v -> {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.email_menu_email).replace("{0}", userEmail.getEmail()), getString(R.string.phone_menu_copy) }, (dialog, which) -> {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", userEmail.getEmail(), null)));
} else if (which == 1) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", userEmail.getEmail());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_email_copied, Snackbar.LENGTH_SHORT).show();
}
}).show().setCanceledOnTouchOutside(true);
});
view.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", "+" + userEmail.getEmail());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_email_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
isFirstContact = false;
}
}
//
// Username
//
final boolean finalIsFirstContact = isFirstContact;
bind(user.getNick(), new ValueChangedListener<String>() {
private View userNameRecord;
@Override
public void onChanged(final String newUserName, Value<String> valueModel) {
if (newUserName != null && newUserName.length() > 0) {
if (userNameRecord == null) {
userNameRecord = buildRecord(getString(R.string.nickname), "@" + newUserName, R.drawable.ic_import_contacts_black_24dp, finalIsFirstContact, false, inflater, contactsContainer);
} else {
((TextView) userNameRecord.findViewById(R.id.value)).setText(newUserName);
}
userNameRecord.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Username", newUserName);
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_nickname_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
if (finalIsFirstContact) {
recordFieldWithIcon = userNameRecord;
}
}
}
});
//
// Settings
//
{
//
// Notifications
//
View notificationContainer = res.findViewById(R.id.notificationsCont);
View notificationPickerContainer = res.findViewById(R.id.notificationsPickerCont);
((TextView) notificationContainer.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
final SwitchCompat notificationEnable = (SwitchCompat) res.findViewById(R.id.enableNotifications);
Peer peer = Peer.user(user.getId());
notificationEnable.setChecked(messenger().isNotificationsEnabled(peer));
if (messenger().isNotificationsEnabled(peer)) {
ViewUtils.showView(notificationPickerContainer, false);
} else {
ViewUtils.goneView(notificationPickerContainer, false);
}
notificationEnable.setOnCheckedChangeListener((buttonView, isChecked) -> {
messenger().changeNotificationsEnabled(Peer.user(user.getId()), isChecked);
if (isChecked) {
ViewUtils.showView(notificationPickerContainer, false);
} else {
ViewUtils.goneView(notificationPickerContainer, false);
}
});
notificationContainer.setOnClickListener(v -> notificationEnable.setChecked(!notificationEnable.isChecked()));
ImageView iconView = (ImageView) res.findViewById(R.id.settings_notification_icon);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_list_black_24dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
iconView.setImageDrawable(drawable);
((TextView) notificationPickerContainer.findViewById(R.id.settings_notifications_picker_title)).setTextColor(style.getTextPrimaryColor());
notificationPickerContainer.setOnClickListener(view -> {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
Uri currentSound = null;
String defaultPath = null;
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
if (defaultUri != null) {
defaultPath = defaultUri.getPath();
}
String path = messenger().getPreferences().getString("userNotificationSound_" + uid);
if (path == null) {
path = defaultPath;
}
if (path != null && !path.equals("none")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
}
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
startActivityForResult(intent, SOUND_PICKER_REQUEST_CODE);
});
//
// Block
//
View blockContainer = res.findViewById(R.id.blockCont);
final TextView blockTitle = (TextView) blockContainer.findViewById(R.id.settings_block_title);
blockTitle.setTextColor(style.getTextPrimaryColor());
bind(user.getIsBlocked(), (val, valueModel) -> {
blockTitle.setText(val ? R.string.profile_settings_unblock : R.string.profile_settings_block);
});
blockContainer.setOnClickListener(v -> {
if (!user.getIsBlocked().get()) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.profile_settings_block_confirm).replace("{user}", user.getName().get())).setPositiveButton(R.string.dialog_yes, (dialog, which) -> {
execute(messenger().blockUser(user.getId()));
dialog.dismiss();
}).setNegativeButton(R.string.dialog_cancel, (dialog, which) -> {
dialog.dismiss();
}).show();
} else {
execute(messenger().unblockUser(user.getId()));
}
});
ImageView blockIconView = (ImageView) res.findViewById(R.id.settings_block_icon);
Drawable blockDrawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_block_white_24dp));
drawable.mutate();
DrawableCompat.setTint(blockDrawable, style.getSettingsIconColor());
blockIconView.setImageDrawable(blockDrawable);
}
//
// Scroll Coordinate
//
final ScrollView scrollView = ((ScrollView) res.findViewById(R.id.scrollContainer));
scrollView.getViewTreeObserver().addOnScrollChangedListener(() -> updateBar(scrollView.getScrollY()));
updateBar(scrollView.getScrollY());
return res;
}
use of android.provider.Settings in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SecuritySettings method createPreferenceHierarchy.
/**
* Important!
*
* Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
* logic or adding/removing preferences here.
*/
private PreferenceScreen createPreferenceHierarchy() {
PreferenceScreen root = getPreferenceScreen();
if (root != null) {
root.removeAll();
}
addPreferencesFromResource(R.xml.security_settings);
root = getPreferenceScreen();
// Add options for lock/unlock screen
final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, MY_USER_ID);
addPreferencesFromResource(resid);
// DO or PO installed in the user may disallow to change password.
disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, MY_USER_ID);
mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
if (mProfileChallengeUserId != UserHandle.USER_NULL && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
addPreferencesFromResource(R.xml.security_settings_profile);
addPreferencesFromResource(R.xml.security_settings_unification);
final int profileResid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, mProfileChallengeUserId);
addPreferencesFromResource(profileResid);
maybeAddFingerprintPreference(root, mProfileChallengeUserId);
if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
final Preference lockPreference = root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
final String summary = getContext().getString(R.string.lock_settings_profile_unified_summary);
lockPreference.setSummary(summary);
lockPreference.setEnabled(false);
// PO may disallow to change password for the profile, but screen lock and managed
// profile's lock is the same. Disable main "Screen lock" menu.
disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, mProfileChallengeUserId);
} else {
// PO may disallow to change profile password, and the profile's password is
// separated from screen lock password. Disable profile specific "Screen lock" menu.
disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE_PROFILE, mProfileChallengeUserId);
}
}
Preference unlockSetOrChange = findPreference(KEY_UNLOCK_SET_OR_CHANGE);
if (unlockSetOrChange instanceof GearPreference) {
((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
}
// Add options for device encryption
mIsAdmin = mUm.isAdminUser();
if (mIsAdmin) {
if (LockPatternUtils.isDeviceEncryptionEnabled()) {
// The device is currently encrypted.
addPreferencesFromResource(R.xml.security_settings_encrypted);
} else {
// This device supports encryption but isn't encrypted.
addPreferencesFromResource(R.xml.security_settings_unencrypted);
}
}
// Fingerprint and trust agents
PreferenceGroup securityCategory = (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
if (securityCategory != null) {
maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
addTrustAgentSettings(securityCategory);
}
mVisiblePatternProfile = (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
mUnifyProfile = (SwitchPreference) root.findPreference(KEY_UNIFICATION);
// Append the rest of the settings
addPreferencesFromResource(R.xml.security_settings_misc);
// Do not display SIM lock for devices without an Icc card
CarrierConfigManager cfgMgr = (CarrierConfigManager) getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE);
PersistableBundle b = cfgMgr.getConfig();
PreferenceGroup iccLockGroup = (PreferenceGroup) root.findPreference(KEY_SIM_LOCK);
Preference iccLock = root.findPreference(KEY_SIM_LOCK_SETTINGS);
if (!mIsAdmin || b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
root.removePreference(iccLockGroup);
} else {
SubscriptionManager subMgr = SubscriptionManager.from(getActivity());
TelephonyManager tm = TelephonyManager.getDefault();
int numPhones = tm.getPhoneCount();
boolean hasAnySim = false;
for (int i = 0; i < numPhones; i++) {
final Preference pref;
if (numPhones > 1) {
SubscriptionInfo sir = subMgr.getActiveSubscriptionInfoForSimSlotIndex(i);
if (sir == null) {
continue;
}
pref = new Preference(getActivity());
pref.setOrder(iccLock.getOrder());
pref.setTitle(getString(R.string.sim_card_lock_settings_title, i + 1));
pref.setSummary(sir.getDisplayName());
Intent intent = new Intent(getActivity(), com.android.settings.Settings.IccLockSettingsActivity.class);
intent.putExtra(IccLockSettings.EXTRA_SUB_ID, sir.getSubscriptionId());
intent.putExtra(IccLockSettings.EXTRA_SUB_DISPLAY_NAME, sir.getDisplayName());
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
pref.setIntent(intent);
iccLockGroup.addPreference(pref);
} else {
pref = iccLock;
}
// Do not display SIM lock for devices without an Icc card
hasAnySim |= tm.hasIccCard(i);
int simState = tm.getSimState(i);
boolean simPresent = simState != TelephonyManager.SIM_STATE_ABSENT && simState != TelephonyManager.SIM_STATE_UNKNOWN && simState != TelephonyManager.SIM_STATE_CARD_IO_ERROR;
if (!simPresent) {
pref.setEnabled(false);
}
}
if (!hasAnySim) {
root.removePreference(iccLockGroup);
} else if (numPhones > 1) {
iccLockGroup.removePreference(iccLock);
}
}
if (Settings.System.getInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
root.findPreference(KEY_SCREEN_PINNING).setSummary(getResources().getString(R.string.switch_on_text));
}
// Show password
mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD);
mResetCredentials = (RestrictedPreference) root.findPreference(KEY_RESET_CREDENTIALS);
// Credential storage
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
// needs to be initialized for onResume()
mKeyStore = KeyStore.getInstance();
if (!RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_CONFIG_CREDENTIALS, MY_USER_ID)) {
RestrictedPreference userCredentials = (RestrictedPreference) root.findPreference(KEY_USER_CREDENTIALS);
userCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
RestrictedPreference credentialStorageType = (RestrictedPreference) root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE);
credentialStorageType.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
RestrictedPreference installCredentials = (RestrictedPreference) root.findPreference(KEY_CREDENTIALS_INSTALL);
installCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
mResetCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
final int storageSummaryRes = mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware : R.string.credential_storage_type_software;
credentialStorageType.setSummary(storageSummaryRes);
} else {
PreferenceGroup credentialsManager = (PreferenceGroup) root.findPreference(KEY_CREDENTIALS_MANAGER);
credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS));
credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL));
credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE));
credentialsManager.removePreference(root.findPreference(KEY_USER_CREDENTIALS));
}
// Application install
PreferenceGroup deviceAdminCategory = (PreferenceGroup) root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
mToggleAppInstallation = (RestrictedSwitchPreference) findPreference(KEY_TOGGLE_INSTALL_APPLICATIONS);
mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
// Side loading of apps.
// Disable for restricted profiles. For others, check if policy disallows it.
mToggleAppInstallation.setEnabled(!um.getUserInfo(MY_USER_ID).isRestricted());
if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, MY_USER_ID) || RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_INSTALL_APPS, MY_USER_ID)) {
mToggleAppInstallation.setEnabled(false);
}
if (mToggleAppInstallation.isEnabled()) {
mToggleAppInstallation.checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
if (!mToggleAppInstallation.isDisabledByAdmin()) {
mToggleAppInstallation.checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_APPS);
}
}
// Advanced Security features
PreferenceGroup advancedCategory = (PreferenceGroup) root.findPreference(KEY_ADVANCED_SECURITY);
if (advancedCategory != null) {
Preference manageAgents = advancedCategory.findPreference(KEY_MANAGE_TRUST_AGENTS);
if (manageAgents != null && !mLockPatternUtils.isSecure(MY_USER_ID)) {
manageAgents.setEnabled(false);
manageAgents.setSummary(R.string.disabled_because_no_backup_security);
}
}
// The above preferences come and go based on security state, so we need to update
// the index. This call is expected to be fairly cheap, but we may want to do something
// smarter in the future.
Index.getInstance(getActivity()).updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
if (pref != null)
pref.setOnPreferenceChangeListener(this);
}
return root;
}
Aggregations