use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.
the class AccountManagerService method isPrivileged.
private boolean isPrivileged(int callingUid) {
final int callingUserId = UserHandle.getUserId(callingUid);
final PackageManager userPackageManager;
try {
userPackageManager = mContext.createPackageContextAsUser("android", 0, new UserHandle(callingUserId)).getPackageManager();
} catch (NameNotFoundException e) {
return false;
}
String[] packages = userPackageManager.getPackagesForUid(callingUid);
for (String name : packages) {
try {
PackageInfo packageInfo = userPackageManager.getPackageInfo(name, 0);
if (packageInfo != null && (packageInfo.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
return false;
}
use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.
the class DpmMockContext method addUser.
public File addUser(int userId, int flags) {
// Set up (default) UserInfo for CALLER_USER_HANDLE.
final UserInfo uh = new UserInfo(userId, "user" + userId, flags);
when(userManager.getUserInfo(eq(userId))).thenReturn(uh);
mUserInfos.add(uh);
when(userManager.getUsers()).thenReturn(mUserInfos);
when(userManager.getUsers(anyBoolean())).thenReturn(mUserInfos);
when(userManager.isUserRunning(eq(new UserHandle(userId)))).thenReturn(true);
when(userManager.getUserInfo(anyInt())).thenAnswer(new Answer<UserInfo>() {
@Override
public UserInfo answer(InvocationOnMock invocation) throws Throwable {
final int userId = (int) invocation.getArguments()[0];
for (UserInfo ui : mUserInfos) {
if (ui.id == userId) {
return ui;
}
}
return null;
}
});
when(userManager.getProfiles(anyInt())).thenAnswer(new Answer<List<UserInfo>>() {
@Override
public List<UserInfo> answer(InvocationOnMock invocation) throws Throwable {
final int userId = (int) invocation.getArguments()[0];
return getProfiles(userId);
}
});
when(userManager.getProfileIdsWithDisabled(anyInt())).thenAnswer(new Answer<int[]>() {
@Override
public int[] answer(InvocationOnMock invocation) throws Throwable {
final int userId = (int) invocation.getArguments()[0];
List<UserInfo> profiles = getProfiles(userId);
int[] results = new int[profiles.size()];
for (int i = 0; i < results.length; i++) {
results[i] = profiles.get(i).id;
}
return results;
}
});
when(accountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]);
// Create a data directory.
final File dir = new File(dataDir, "user" + userId);
DpmTestUtils.clearDir(dir);
when(environment.getUserSystemDirectory(eq(userId))).thenReturn(dir);
return dir;
}
use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AccountSettings method onPrepareOptionsMenu.
@Override
public void onPrepareOptionsMenu(Menu menu) {
final UserHandle currentProfile = Process.myUserHandle();
if (mProfiles.size() == 1) {
menu.findItem(R.id.account_settings_menu_auto_sync).setVisible(true).setOnMenuItemClickListener(new MasterSyncStateClickListener(currentProfile)).setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(currentProfile.getIdentifier()));
menu.findItem(R.id.account_settings_menu_auto_sync_personal).setVisible(false);
menu.findItem(R.id.account_settings_menu_auto_sync_work).setVisible(false);
} else if (mProfiles.size() > 1) {
// We assume there's only one managed profile, otherwise UI needs to change
final UserHandle managedProfile = mProfiles.valueAt(1).userInfo.getUserHandle();
menu.findItem(R.id.account_settings_menu_auto_sync_personal).setVisible(true).setOnMenuItemClickListener(new MasterSyncStateClickListener(currentProfile)).setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(currentProfile.getIdentifier()));
menu.findItem(R.id.account_settings_menu_auto_sync_work).setVisible(true).setOnMenuItemClickListener(new MasterSyncStateClickListener(managedProfile)).setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(managedProfile.getIdentifier()));
menu.findItem(R.id.account_settings_menu_auto_sync).setVisible(false);
} else {
Log.w(TAG, "Method onPrepareOptionsMenu called before mProfiles was initialized");
}
}
use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ProtectedAccountView method findIntendedAccount.
/**
* Given the string the user entered in the 'username' field, find
* the stored account that they probably intended. Prefer, in order:
*
* - an exact match for what was typed, or
* - a case-insensitive match for what was typed, or
* - if they didn't include a domain, an exact match of the username, or
* - if they didn't include a domain, a case-insensitive
* match of the username.
*
* If there is a tie for the best match, choose neither --
* the user needs to be more specific.
*
* @return an account name from the database, or null if we can't
* find a single best match.
*/
private Account findIntendedAccount(String username) {
Account[] accounts = AccountManager.get(mContext).getAccountsByTypeAsUser("com.google", new UserHandle(ActivityManager.getCurrentUser()));
// Try to figure out which account they meant if they
// typed only the username (and not the domain), or got
// the case wrong.
Account bestAccount = null;
int bestScore = 0;
for (Account a : accounts) {
int score = 0;
if (username.equals(a.name)) {
score = 4;
} else if (username.equalsIgnoreCase(a.name)) {
score = 3;
} else if (username.indexOf('@') < 0) {
int i = a.name.indexOf('@');
if (i >= 0) {
String aUsername = a.name.substring(0, i);
if (username.equals(aUsername)) {
score = 2;
} else if (username.equalsIgnoreCase(aUsername)) {
score = 1;
}
}
}
if (score > bestScore) {
bestAccount = a;
bestScore = score;
} else if (score == bestScore) {
bestAccount = null;
}
}
return bestAccount;
}
use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.
the class SearchableInfo method getActivityMetaData.
/**
* Gets search information for the given activity.
*
* @param context Context to use for reading activity resources.
* @param activityInfo Activity to get search information from.
* @return Search information about the given activity, or {@code null} if
* the activity has no or invalid searchability meta-data.
*
* @hide For use by SearchManagerService.
*/
public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo, int userId) {
Context userContext = null;
try {
userContext = context.createPackageContextAsUser("system", 0, new UserHandle(userId));
} catch (NameNotFoundException nnfe) {
Log.e(LOG_TAG, "Couldn't create package context for user " + userId);
return null;
}
// for each component, try to find metadata
XmlResourceParser xml = activityInfo.loadXmlMetaData(userContext.getPackageManager(), MD_LABEL_SEARCHABLE);
if (xml == null) {
return null;
}
ComponentName cName = new ComponentName(activityInfo.packageName, activityInfo.name);
SearchableInfo searchable = getActivityMetaData(userContext, xml, cName);
xml.close();
if (DBG) {
if (searchable != null) {
Log.d(LOG_TAG, "Checked " + activityInfo.name + ",label=" + searchable.getLabelId() + ",icon=" + searchable.getIconId() + ",suggestAuthority=" + searchable.getSuggestAuthority() + ",target=" + searchable.getSearchActivity().getClassName() + ",global=" + searchable.shouldIncludeInGlobalSearch() + ",settingsDescription=" + searchable.getSettingsDescriptionId() + ",threshold=" + searchable.getSuggestThreshold());
} else {
Log.d(LOG_TAG, "Checked " + activityInfo.name + ", no searchable meta-data");
}
}
return searchable;
}
Aggregations