use of android.content.pm.IPackageManager in project android_frameworks_base by ResurrectionRemix.
the class IntentFirewall method logIntent.
private static void logIntent(int intentType, Intent intent, int callerUid, String resolvedType) {
// The component shouldn't be null, but let's double check just to be safe
ComponentName cn = intent.getComponent();
String shortComponent = null;
if (cn != null) {
shortComponent = cn.flattenToShortString();
}
String callerPackages = null;
int callerPackageCount = 0;
IPackageManager pm = AppGlobals.getPackageManager();
if (pm != null) {
try {
String[] callerPackagesArray = pm.getPackagesForUid(callerUid);
if (callerPackagesArray != null) {
callerPackageCount = callerPackagesArray.length;
callerPackages = joinPackages(callerPackagesArray);
}
} catch (RemoteException ex) {
Slog.e(TAG, "Remote exception while retrieving packages", ex);
}
}
EventLogTags.writeIfwIntentMatched(intentType, shortComponent, callerUid, callerPackageCount, callerPackages, intent.getAction(), resolvedType, intent.getDataString(), intent.getFlags());
}
use of android.content.pm.IPackageManager in project android_frameworks_base by ResurrectionRemix.
the class SenderPackageFilter method matches.
@Override
public boolean matches(IntentFirewall ifw, ComponentName resolvedComponent, Intent intent, int callerUid, int callerPid, String resolvedType, int receivingUid) {
IPackageManager pm = AppGlobals.getPackageManager();
int packageUid = -1;
try {
// USER_SYSTEM here is not important. Only app id is used and getPackageUid() will
// return a uid whether the app is installed for a user or not.
packageUid = pm.getPackageUid(mPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, UserHandle.USER_SYSTEM);
} catch (RemoteException ex) {
// handled below
}
if (packageUid == -1) {
return false;
}
return UserHandle.isSameApp(packageUid, callerUid);
}
use of android.content.pm.IPackageManager 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.content.pm.IPackageManager 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.content.pm.IPackageManager in project android_frameworks_base by ResurrectionRemix.
the class AccountManagerService method checkUidPermission.
private boolean checkUidPermission(String permission, int uid, String opPackageName) {
final long identity = Binder.clearCallingIdentity();
try {
IPackageManager pm = ActivityThread.getPackageManager();
if (pm.checkUidPermission(permission, uid) != PackageManager.PERMISSION_GRANTED) {
return false;
}
final int opCode = AppOpsManager.permissionToOpCode(permission);
return (opCode == AppOpsManager.OP_NONE || mAppOpsManager.noteOpNoThrow(opCode, uid, opPackageName) == AppOpsManager.MODE_ALLOWED);
} catch (RemoteException e) {
/* ignore - local call */
} finally {
Binder.restoreCallingIdentity(identity);
}
return false;
}
Aggregations