Search in sources :

Example 6 with IPackageManager

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

the class ActivityManagerService method clearApplicationUserData.

public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer, int userId) {
    enforceNotIsolatedCaller("clearApplicationUserData");
    int uid = Binder.getCallingUid();
    int pid = Binder.getCallingPid();
    userId = handleIncomingUser(pid, uid, userId, false, true, "clearApplicationUserData", null);
    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);
                if (observer != null) {
                    try {
                        observer.onRemoveCompleted(packageName, false);
                    } catch (RemoteException e) {
                        Slog.i(TAG, "Observer no longer exists.");
                    }
                }
                return false;
            }
            if (uid == pkgUid || checkComponentPermission(android.Manifest.permission.CLEAR_APP_USER_DATA, pid, uid, -1, true) == PackageManager.PERMISSION_GRANTED) {
                forceStopPackageLocked(packageName, pkgUid);
            } else {
                throw new SecurityException(pid + " does not have permission:" + android.Manifest.permission.CLEAR_APP_USER_DATA + " to clear data" + "for process:" + packageName);
            }
        }
        try {
            //clear application user data
            pm.clearApplicationUserData(packageName, observer, userId);
            Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null));
            intent.putExtra(Intent.EXTRA_UID, pkgUid);
            broadcastIntentInPackage("android", Process.SYSTEM_UID, intent, null, null, 0, null, null, null, false, false, userId);
        } catch (RemoteException e) {
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
    return true;
}
Also used : IPackageManager(android.content.pm.IPackageManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 7 with IPackageManager

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

the class ActivityManagerService method getRecentTasks.

public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, int userId) {
    userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, true, "getRecentTasks", null);
    synchronized (this) {
        enforceCallingPermission(android.Manifest.permission.GET_TASKS, "getRecentTasks()");
        final boolean detailed = checkCallingPermission(android.Manifest.permission.GET_DETAILED_TASKS) == PackageManager.PERMISSION_GRANTED;
        IPackageManager pm = AppGlobals.getPackageManager();
        final int N = mRecentTasks.size();
        ArrayList<ActivityManager.RecentTaskInfo> res = new ArrayList<ActivityManager.RecentTaskInfo>(maxNum < N ? maxNum : N);
        for (int i = 0; i < N && maxNum > 0; i++) {
            TaskRecord tr = mRecentTasks.get(i);
            // Only add calling user's recent tasks
            if (tr.userId != userId)
                continue;
            if (i == 0 || ((flags & ActivityManager.RECENT_WITH_EXCLUDED) != 0) || (tr.intent == null) || ((tr.intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0)) {
                ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo();
                rti.id = tr.numActivities > 0 ? tr.taskId : -1;
                rti.persistentId = tr.taskId;
                rti.baseIntent = new Intent(tr.intent != null ? tr.intent : tr.affinityIntent);
                if (!detailed) {
                    rti.baseIntent.replaceExtras((Bundle) null);
                }
                rti.origActivity = tr.origActivity;
                rti.description = tr.lastDescription;
                if ((flags & ActivityManager.RECENT_IGNORE_UNAVAILABLE) != 0) {
                    // Check whether this activity is currently available.
                    try {
                        if (rti.origActivity != null) {
                            if (pm.getActivityInfo(rti.origActivity, 0, userId) == null) {
                                continue;
                            }
                        } else if (rti.baseIntent != null) {
                            if (pm.queryIntentActivities(rti.baseIntent, null, 0, userId) == null) {
                                continue;
                            }
                        }
                    } catch (RemoteException e) {
                    // Will never happen.
                    }
                }
                res.add(rti);
                maxNum--;
            }
        }
        return res;
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager) RemoteException(android.os.RemoteException)

Example 8 with IPackageManager

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

the class ActivityManagerService method revokeUriPermission.

public void revokeUriPermission(IApplicationThread caller, Uri uri, int modeFlags) {
    enforceNotIsolatedCaller("revokeUriPermission");
    synchronized (this) {
        final ProcessRecord r = getRecordForAppLocked(caller);
        if (r == null) {
            throw new SecurityException("Unable to find app for caller " + caller + " when revoking permission to uri " + uri);
        }
        if (uri == null) {
            Slog.w(TAG, "revokeUriPermission: null uri");
            return;
        }
        modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        if (modeFlags == 0) {
            return;
        }
        final IPackageManager pm = AppGlobals.getPackageManager();
        final String authority = uri.getAuthority();
        ProviderInfo pi = null;
        ContentProviderRecord cpr = mProviderMap.getProviderByName(authority, r.userId);
        if (cpr != null) {
            pi = cpr.info;
        } else {
            try {
                pi = pm.resolveContentProvider(authority, PackageManager.GET_URI_PERMISSION_PATTERNS, r.userId);
            } catch (RemoteException ex) {
            }
        }
        if (pi == null) {
            Slog.w(TAG, "No content provider found for permission revoke: " + uri.toSafeString());
            return;
        }
        revokeUriPermissionLocked(r.uid, uri, modeFlags);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) ProviderInfo(android.content.pm.ProviderInfo) RemoteException(android.os.RemoteException)

Example 9 with IPackageManager

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

the class CompatModePackages method saveCompatModes.

void saveCompatModes() {
    HashMap<String, Integer> pkgs;
    synchronized (mService) {
        pkgs = new HashMap<String, Integer>(mPackages);
    }
    FileOutputStream fos = null;
    try {
        fos = mFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, "utf-8");
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        out.startTag(null, "compat-packages");
        final IPackageManager pm = AppGlobals.getPackageManager();
        final int screenLayout = mService.mConfiguration.screenLayout;
        final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
        final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Integer> entry = it.next();
            String pkg = entry.getKey();
            int mode = entry.getValue();
            if (mode == 0) {
                continue;
            }
            ApplicationInfo ai = null;
            try {
                ai = pm.getApplicationInfo(pkg, 0, 0);
            } catch (RemoteException e) {
            }
            if (ai == null) {
                continue;
            }
            CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, smallestScreenWidthDp, false);
            if (info.alwaysSupportsScreen()) {
                continue;
            }
            if (info.neverSupportsScreen()) {
                continue;
            }
            out.startTag(null, "pkg");
            out.attribute(null, "name", pkg);
            out.attribute(null, "mode", Integer.toString(mode));
            out.endTag(null, "pkg");
        }
        out.endTag(null, "compat-packages");
        out.endDocument();
        mFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing compat packages", e1);
        if (fos != null) {
            mFile.failWrite(fos);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageManager(android.content.pm.IPackageManager) FileOutputStream(java.io.FileOutputStream) RemoteException(android.os.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 10 with IPackageManager

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

the class ActivityManagerService method killBackgroundProcesses.

public void killBackgroundProcesses(final String packageName, int userId) {
    if (checkCallingPermission(android.Manifest.permission.KILL_BACKGROUND_PROCESSES) != PackageManager.PERMISSION_GRANTED && checkCallingPermission(android.Manifest.permission.RESTART_PACKAGES) != PackageManager.PERMISSION_GRANTED) {
        String msg = "Permission Denial: killBackgroundProcesses() from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " requires " + android.Manifest.permission.KILL_BACKGROUND_PROCESSES;
        Slog.w(TAG, msg);
        throw new SecurityException(msg);
    }
    userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, true, true, "killBackgroundProcesses", null);
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        synchronized (this) {
            int appId = -1;
            try {
                appId = UserHandle.getAppId(pm.getPackageUid(packageName, 0));
            } catch (RemoteException e) {
            }
            if (appId == -1) {
                Slog.w(TAG, "Invalid packageName: " + packageName);
                return;
            }
            killPackageProcessesLocked(packageName, appId, userId, ProcessList.SERVICE_ADJ, false, true, true, false, "kill background");
        }
    } 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