@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "Referrer: " + getReferrer()); mAm = (ActivityManager) getSystemService(ACTIVITY_SERVICE); if (savedInstanceState != null) { mOverrideConfig = savedInstanceState.getParcelable(KEY_CONFIGURATION); if (mOverrideConfig != null) { applyOverrideConfiguration(mOverrideConfig); } } UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); List<UserInfo> users = um.getUsers(); mSecondUser = Integer.MAX_VALUE; for (UserInfo ui : users) { if (ui.id != 0 && mSecondUser > ui.id) { mSecondUser = ui.id; } } /* AlertDialog ad = new AlertDialog.Builder(this).setTitle("title").setMessage("message").create(); ad.getWindow().getAttributes().type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; ad.show(); */ }
private void cleanUpRemovedUsersLocked() { final List<UserInfo> users = mUserManager.getUsers(true); if (users == null || users.size() == 0) { throw new IllegalStateException("There can't be no users"); } ArraySet<String> toDelete = new ArraySet<>(); String[] fileNames = mUsageStatsDir.list(); if (fileNames == null) { // No users to delete. return; } toDelete.addAll(Arrays.asList(fileNames)); final int userCount = users.size(); for (int i = 0; i < userCount; i++) { final UserInfo userInfo = users.get(i); toDelete.remove(Integer.toString(userInfo.id)); } final int deleteCount = toDelete.size(); for (int i = 0; i < deleteCount; i++) { deleteRecursively(new File(mUsageStatsDir, toDelete.valueAt(i))); } }
/** Return list of other users, excluding the current user. */ private List<UserInfo> getUsersExcluding(UserInfo excluding) { final List<UserInfo> users = mUserManager.getUsers(); final Iterator<UserInfo> i = users.iterator(); while (i.hasNext()) { if (i.next().id == excluding.id) { i.remove(); } } return users; }
// Intended to be called only once at startup, after the system is ready. Installs a broadcast // receiver to monitor ongoing UID changes, so this shouldn't/needn't be called again. public synchronized void startMonitoring() { log("Monitoring"); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_USER_ADDED); intentFilter.addAction(Intent.ACTION_USER_REMOVED); mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, intentFilter, null, null); intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addDataScheme("package"); mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, intentFilter, null, null); List<PackageInfo> apps = mPackageManager.getInstalledPackages(GET_PERMISSIONS); if (apps == null) { loge("No apps"); return; } for (PackageInfo app : apps) { int uid = app.applicationInfo != null ? app.applicationInfo.uid : -1; if (uid < 0) { continue; } boolean isNetwork = hasNetworkPermission(app); boolean isSystem = hasSystemPermission(app); if (isNetwork || isSystem) { Boolean permission = mApps.get(uid); // If multiple packages share a UID (cf: android:sharedUserId) and ask for different // permissions, don't downgrade (i.e., if it's already SYSTEM, leave it as is). if (permission == null || permission == NETWORK) { mApps.put(uid, isSystem); } } } List<UserInfo> users = mUserManager.getUsers(true); // exclude dying users if (users != null) { for (UserInfo user : users) { mUsers.add(user.id); } } log("Users: " + mUsers.size() + ", Apps: " + mApps.size()); update(mUsers, mApps, true); }
/** * * Disables preferences that are less secure than required quality. * * @param quality the requested quality. */ private void disableUnusablePreferences(final int quality, MutableBoolean allowBiometric) { final PreferenceScreen entries = getPreferenceScreen(); final boolean onlyShowFallback = getActivity() .getIntent() .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false); final boolean weakBiometricAvailable = mChooseLockSettingsHelper.utils().isBiometricWeakInstalled(); // if there are multiple users, disable "None" setting UserManager mUm = (UserManager) getSystemService(Context.USER_SERVICE); List<UserInfo> users = mUm.getUsers(true); final boolean singleUser = users.size() == 1; for (int i = entries.getPreferenceCount() - 1; i >= 0; --i) { Preference pref = entries.getPreference(i); if (pref instanceof PreferenceScreen) { final String key = ((PreferenceScreen) pref).getKey(); boolean enabled = true; boolean visible = true; if (KEY_UNLOCK_SET_OFF.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; visible = singleUser; // don't show when there's more than 1 user } else if (KEY_UNLOCK_SET_NONE.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; } else if (KEY_UNLOCK_SET_BIOMETRIC_WEAK.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK || allowBiometric.value; visible = weakBiometricAvailable; // If not available, then don't show it. } else if (KEY_UNLOCK_SET_PATTERN.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING; } else if (KEY_UNLOCK_SET_PIN.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; } if (!visible || (onlyShowFallback && !allowedForFallback(key))) { entries.removePreference(pref); } else if (!enabled) { pref.setSummary(R.string.unlock_set_unlock_disabled_summary); pref.setEnabled(false); } } } }