Search in sources :

Example 71 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by AOSPA.

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;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ConnectivityManager(android.net.ConnectivityManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Example 72 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by AOSPA.

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;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) Drawable(android.graphics.drawable.Drawable) AppOpsManager(android.app.AppOpsManager) IPackageManager(android.content.pm.IPackageManager) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException)

Example 73 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by AOSPA.

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;
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Example 74 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by AOSPA.

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);
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Example 75 with IPackageManager

use of android.content.pm.IPackageManager in project cornerstone by Onskreen.

the class ActivityManagerService method forceStopPackage.

public void forceStopPackage(final String packageName) {
    if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES) != PackageManager.PERMISSION_GRANTED) {
        String msg = "Permission Denial: forceStopPackage() from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
        Slog.w(TAG, msg);
        throw new SecurityException(msg);
    }
    final int userId = UserId.getCallingUserId();
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        int pkgUid = -1;
        synchronized (this) {
            try {
                pkgUid = pm.getPackageUid(packageName, userId);
            } catch (RemoteException e) {
            }
            if (pkgUid == -1) {
                Slog.w(TAG, "Invalid packageName: " + packageName);
                return;
            }
            forceStopPackageLocked(packageName, pkgUid);
            try {
                pm.setPackageStoppedState(packageName, true, userId);
            } catch (RemoteException e) {
            } catch (IllegalArgumentException e) {
                Slog.w(TAG, "Failed trying to unstop package " + packageName + ": " + e);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Aggregations

IPackageManager (android.content.pm.IPackageManager)192 RemoteException (android.os.RemoteException)182 ApplicationInfo (android.content.pm.ApplicationInfo)58 Point (android.graphics.Point)33 PackageInfo (android.content.pm.PackageInfo)32 ComponentName (android.content.ComponentName)29 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)20 PackageManager (android.content.pm.PackageManager)18 UserHandle (android.os.UserHandle)13 Context (android.content.Context)12 HashMap (java.util.HashMap)12 ProviderInfo (android.content.pm.ProviderInfo)10 PendingIntent (android.app.PendingIntent)9 HashSet (java.util.HashSet)9 UserManager (android.os.UserManager)8 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 ResolveInfo (android.content.pm.ResolveInfo)7 ActivityManager (android.app.ActivityManager)6 SpannableString (android.text.SpannableString)6