use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.
the class RecentLocationApps method getAppList.
/**
* Fills a list of applications which queried location recently within specified time.
*/
public List<Request> getAppList() {
// Retrieve a location usage list from AppOps
AppOpsManager aoManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(LOCATION_OPS);
final int appOpsCount = appOps != null ? appOps.size() : 0;
// Process the AppOps list and generate a preference list.
ArrayList<Request> requests = new ArrayList<>(appOpsCount);
final long now = System.currentTimeMillis();
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
final List<UserHandle> profiles = um.getUserProfiles();
for (int i = 0; i < appOpsCount; ++i) {
AppOpsManager.PackageOps ops = appOps.get(i);
// Don't show the Android System in the list - it's not actionable for the user.
// Also don't show apps belonging to background users except managed users.
String packageName = ops.getPackageName();
int uid = ops.getUid();
int userId = UserHandle.getUserId(uid);
boolean isAndroidOs = (uid == Process.SYSTEM_UID) && ANDROID_SYSTEM_PACKAGE_NAME.equals(packageName);
if (isAndroidOs || !profiles.contains(new UserHandle(userId))) {
continue;
}
Request request = getRequestFromOps(now, ops);
if (request != null) {
requests.add(request);
}
}
return requests;
}
use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.
the class RecentLocationApps method getRequestFromOps.
/**
* Creates a Request entry for the given PackageOps.
*
* This method examines the time interval of the PackageOps first. If the PackageOps is older
* than the designated interval, this method ignores the PackageOps object and returns null.
* When the PackageOps is fresh enough, this method returns a Request object for the package
*/
private Request getRequestFromOps(long now, AppOpsManager.PackageOps ops) {
String packageName = ops.getPackageName();
List<AppOpsManager.OpEntry> entries = ops.getOps();
boolean highBattery = false;
boolean normalBattery = false;
// Earliest time for a location request to end and still be shown in list.
long recentLocationCutoffTime = now - RECENT_TIME_INTERVAL_MILLIS;
for (AppOpsManager.OpEntry entry : entries) {
if (entry.isRunning() || entry.getTime() >= recentLocationCutoffTime) {
switch(entry.getOp()) {
case AppOpsManager.OP_MONITOR_LOCATION:
normalBattery = true;
break;
case AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION:
highBattery = true;
break;
default:
break;
}
}
}
if (!highBattery && !normalBattery) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, packageName + " hadn't used location within the time interval.");
}
return null;
}
// The package is fresh enough, continue.
int uid = ops.getUid();
int userId = UserHandle.getUserId(uid);
Request request = null;
try {
IPackageManager ipm = AppGlobals.getPackageManager();
ApplicationInfo appInfo = ipm.getApplicationInfo(packageName, PackageManager.GET_META_DATA, userId);
if (appInfo == null) {
Log.w(TAG, "Null application info retrieved for package " + packageName + ", userId " + userId);
return null;
}
final UserHandle userHandle = new UserHandle(userId);
Drawable appIcon = mPackageManager.getApplicationIcon(appInfo);
Drawable icon = mPackageManager.getUserBadgedIcon(appIcon, userHandle);
CharSequence appLabel = mPackageManager.getApplicationLabel(appInfo);
CharSequence badgedAppLabel = mPackageManager.getUserBadgedLabel(appLabel, userHandle);
if (appLabel.toString().contentEquals(badgedAppLabel)) {
// If badged label is not different from original then no need for it as
// a separate content description.
badgedAppLabel = null;
}
request = new Request(packageName, userHandle, icon, appLabel, highBattery, badgedAppLabel);
} catch (RemoteException e) {
Log.w(TAG, "Error while retrieving application info for package " + packageName + ", userId " + userId, e);
}
return request;
}
use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.
the class UidDetailProvider method buildUidDetail.
/**
* Build {@link UidDetail} object, blocking until all {@link Drawable}
* lookup is finished.
*/
private UidDetail buildUidDetail(int uid) {
final Resources res = mContext.getResources();
final PackageManager pm = mContext.getPackageManager();
final UidDetail detail = new UidDetail();
detail.label = pm.getNameForUid(uid);
detail.icon = pm.getDefaultActivityIcon();
// handle special case labels
switch(uid) {
case android.os.Process.SYSTEM_UID:
detail.label = res.getString(R.string.process_kernel_label);
detail.icon = pm.getDefaultActivityIcon();
return detail;
case TrafficStats.UID_REMOVED:
detail.label = res.getString(UserManager.supportsMultipleUsers() ? R.string.data_usage_uninstalled_apps_users : R.string.data_usage_uninstalled_apps);
detail.icon = pm.getDefaultActivityIcon();
return detail;
case TrafficStats.UID_TETHERING:
final ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
detail.label = res.getString(Utils.getTetheringLabel(cm));
detail.icon = pm.getDefaultActivityIcon();
return detail;
}
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
// Handle keys that are actually user handles
if (isKeyForUser(uid)) {
final int userHandle = getUserIdForKey(uid);
final UserInfo info = um.getUserInfo(userHandle);
if (info != null) {
detail.label = Utils.getUserLabel(mContext, info);
detail.icon = Utils.getUserIcon(mContext, um, info);
return detail;
}
}
// otherwise fall back to using packagemanager labels
final String[] packageNames = pm.getPackagesForUid(uid);
final int length = packageNames != null ? packageNames.length : 0;
try {
final int userId = UserHandle.getUserId(uid);
UserHandle userHandle = new UserHandle(userId);
IPackageManager ipm = AppGlobals.getPackageManager();
if (length == 1) {
final ApplicationInfo info = ipm.getApplicationInfo(packageNames[0], 0, /* no flags */
userId);
if (info != null) {
detail.label = info.loadLabel(pm).toString();
detail.icon = um.getBadgedIconForUser(info.loadIcon(pm), new UserHandle(userId));
}
} else if (length > 1) {
detail.detailLabels = new CharSequence[length];
detail.detailContentDescriptions = new CharSequence[length];
for (int i = 0; i < length; i++) {
final String packageName = packageNames[i];
final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
final ApplicationInfo appInfo = ipm.getApplicationInfo(packageName, 0, /* no flags */
userId);
if (appInfo != null) {
detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
detail.detailContentDescriptions[i] = um.getBadgedLabelForUser(detail.detailLabels[i], userHandle);
if (packageInfo.sharedUserLabel != 0) {
detail.label = pm.getText(packageName, packageInfo.sharedUserLabel, packageInfo.applicationInfo).toString();
detail.icon = um.getBadgedIconForUser(appInfo.loadIcon(pm), userHandle);
}
}
}
}
detail.contentDescription = um.getBadgedLabelForUser(detail.label, userHandle);
} catch (NameNotFoundException e) {
Log.w(TAG, "Error while building UI detail for uid " + uid, e);
} catch (RemoteException e) {
Log.w(TAG, "Error while building UI detail for uid " + uid, e);
}
if (TextUtils.isEmpty(detail.label)) {
detail.label = Integer.toString(uid);
}
return detail;
}
use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.
the class AccountManagerService method removeAccountAsUser.
@Override
public void removeAccountAsUser(IAccountManagerResponse response, Account account, boolean expectActivityLaunch, int userId) {
final int callingUid = Binder.getCallingUid();
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "removeAccount: " + account + ", response " + response + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid() + ", for user id " + userId);
}
if (response == null)
throw new IllegalArgumentException("response is null");
if (account == null)
throw new IllegalArgumentException("account is null");
// Only allow the system process to modify accounts of other users
if (isCrossUser(callingUid, userId)) {
throw new SecurityException(String.format("User %s tying remove account for %s", UserHandle.getCallingUserId(), userId));
}
/*
* Only the system or authenticator should be allowed to remove accounts for that
* authenticator. This will let users remove accounts (via Settings in the system) but not
* arbitrary applications (like competing authenticators).
*/
UserHandle user = UserHandle.of(userId);
if (!isAccountManagedByCaller(account.type, callingUid, user.getIdentifier()) && !isSystemUid(callingUid)) {
String msg = String.format("uid %s cannot remove accounts of type: %s", callingUid, account.type);
throw new SecurityException(msg);
}
if (!canUserModifyAccounts(userId, callingUid)) {
try {
response.onError(AccountManager.ERROR_CODE_USER_RESTRICTED, "User cannot modify accounts");
} catch (RemoteException re) {
}
return;
}
if (!canUserModifyAccountsForType(userId, account.type, callingUid)) {
try {
response.onError(AccountManager.ERROR_CODE_MANAGEMENT_DISABLED_FOR_ACCOUNT_TYPE, "User cannot modify accounts of this type (policy).");
} catch (RemoteException re) {
}
return;
}
long identityToken = clearCallingIdentity();
UserAccounts accounts = getUserAccounts(userId);
cancelNotification(getSigninRequiredNotificationId(accounts, account), user);
synchronized (accounts.credentialsPermissionNotificationIds) {
for (Pair<Pair<Account, String>, Integer> pair : accounts.credentialsPermissionNotificationIds.keySet()) {
if (account.equals(pair.first.first)) {
int id = accounts.credentialsPermissionNotificationIds.get(pair);
cancelNotification(id, user);
}
}
}
SQLiteDatabase db = accounts.openHelper.getReadableDatabase();
final long accountId = getAccountIdLocked(db, account);
logRecord(db, DebugDbHelper.ACTION_CALLED_ACCOUNT_REMOVE, TABLE_ACCOUNTS, accountId, accounts, callingUid);
try {
new RemoveAccountSession(accounts, response, account, expectActivityLaunch).bind();
} finally {
restoreCallingIdentity(identityToken);
}
}
use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.
the class AccountManagerService method revokeAppPermission.
/**
* Don't allow callers with the given uid permission to get credentials for
* account/authTokenType.
* <p>
* Although this is public it can only be accessed via the AccountManagerService object
* which is in the system. This means we don't need to protect it with permissions.
* @hide
*/
private void revokeAppPermission(Account account, String authTokenType, int uid) {
if (account == null || authTokenType == null) {
Log.e(TAG, "revokeAppPermission: called with invalid arguments", new Exception());
return;
}
UserAccounts accounts = getUserAccounts(UserHandle.getUserId(uid));
synchronized (accounts.cacheLock) {
final SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
db.beginTransaction();
try {
long accountId = getAccountIdLocked(db, account);
if (accountId >= 0) {
db.delete(TABLE_GRANTS, GRANTS_ACCOUNTS_ID + "=? AND " + GRANTS_AUTH_TOKEN_TYPE + "=? AND " + GRANTS_GRANTEE_UID + "=?", new String[] { String.valueOf(accountId), authTokenType, String.valueOf(uid) });
db.setTransactionSuccessful();
}
} finally {
db.endTransaction();
}
cancelNotification(getCredentialPermissionNotificationId(account, authTokenType, uid), new UserHandle(accounts.userId));
}
// Listeners are a final CopyOnWriteArrayList, hence no lock needed.
for (AccountManagerInternal.OnAppPermissionChangeListener listener : mAppPermissionChangeListeners) {
mMessageHandler.post(() -> listener.onAppPermissionChanged(account, uid));
}
}
Aggregations