Search in sources :

Example 21 with IPackageManager

use of android.content.pm.IPackageManager in project platform_frameworks_base by android.

the class WallpaperBackupAgent method servicePackageExists.

private boolean servicePackageExists(ComponentName comp) {
    try {
        if (comp != null) {
            final IPackageManager pm = AppGlobals.getPackageManager();
            final PackageInfo info = pm.getPackageInfo(comp.getPackageName(), 0, UserHandle.USER_SYSTEM);
            return (info != null);
        }
    } catch (RemoteException e) {
        Slog.e(TAG, "Unable to contact package manager");
    }
    return false;
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Example 22 with IPackageManager

use of android.content.pm.IPackageManager in project platform_frameworks_base by android.

the class ActivityManagerService method getRunningExternalApplications.

@Override
public List<ApplicationInfo> getRunningExternalApplications() {
    enforceNotIsolatedCaller("getRunningExternalApplications");
    List<ActivityManager.RunningAppProcessInfo> runningApps = getRunningAppProcesses();
    List<ApplicationInfo> retList = new ArrayList<ApplicationInfo>();
    if (runningApps != null && runningApps.size() > 0) {
        Set<String> extList = new HashSet<String>();
        for (ActivityManager.RunningAppProcessInfo app : runningApps) {
            if (app.pkgList != null) {
                for (String pkg : app.pkgList) {
                    extList.add(pkg);
                }
            }
        }
        IPackageManager pm = AppGlobals.getPackageManager();
        for (String pkg : extList) {
            try {
                ApplicationInfo info = pm.getApplicationInfo(pkg, 0, UserHandle.getCallingUserId());
                if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
                    retList.add(info);
                }
            } catch (RemoteException e) {
            }
        }
    }
    return retList;
}
Also used : IPackageManager(android.content.pm.IPackageManager) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) ActivityManager(android.app.ActivityManager) RemoteException(android.os.RemoteException) HashSet(java.util.HashSet)

Example 23 with IPackageManager

use of android.content.pm.IPackageManager in project platform_frameworks_base by android.

the class RecentTasks method cleanupLocked.

/**
     * Update the recent tasks lists: make sure tasks should still be here (their
     * applications / activities still exist), update their availability, fix-up ordering
     * of affiliations.
     */
void cleanupLocked(int userId) {
    int recentsCount = size();
    if (recentsCount == 0) {
        // or just any empty list.
        return;
    }
    final IPackageManager pm = AppGlobals.getPackageManager();
    for (int i = recentsCount - 1; i >= 0; i--) {
        final TaskRecord task = get(i);
        if (userId != UserHandle.USER_ALL && task.userId != userId) {
            // Only look at tasks for the user ID of interest.
            continue;
        }
        if (task.autoRemoveRecents && task.getTopActivity() == null) {
            // This situation is broken, and we should just get rid of it now.
            remove(i);
            task.removedFromRecents();
            Slog.w(TAG, "Removing auto-remove without activity: " + task);
            continue;
        }
        // Check whether this activity is currently available.
        if (task.realActivity != null) {
            ActivityInfo ai = mTmpAvailActCache.get(task.realActivity);
            if (ai == null) {
                try {
                    // At this first cut, we're only interested in
                    // activities that are fully runnable based on
                    // current system state.
                    ai = pm.getActivityInfo(task.realActivity, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId);
                } catch (RemoteException e) {
                    // Will never happen.
                    continue;
                }
                if (ai == null) {
                    ai = mTmpActivityInfo;
                }
                mTmpAvailActCache.put(task.realActivity, ai);
            }
            if (ai == mTmpActivityInfo) {
                // This could be either because the activity no longer exists, or the
                // app is temporarily gone. For the former we want to remove the recents
                // entry; for the latter we want to mark it as unavailable.
                ApplicationInfo app = mTmpAvailAppCache.get(task.realActivity.getPackageName());
                if (app == null) {
                    try {
                        app = pm.getApplicationInfo(task.realActivity.getPackageName(), PackageManager.MATCH_UNINSTALLED_PACKAGES, userId);
                    } catch (RemoteException e) {
                        // Will never happen.
                        continue;
                    }
                    if (app == null) {
                        app = mTmpAppInfo;
                    }
                    mTmpAvailAppCache.put(task.realActivity.getPackageName(), app);
                }
                if (app == mTmpAppInfo || (app.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
                    // Doesn't exist any more! Good-bye.
                    remove(i);
                    task.removedFromRecents();
                    Slog.w(TAG, "Removing no longer valid recent: " + task);
                    continue;
                } else {
                    // Otherwise just not available for now.
                    if (DEBUG_RECENTS && task.isAvailable)
                        Slog.d(TAG_RECENTS, "Making recent unavailable: " + task);
                    task.isAvailable = false;
                }
            } else {
                if (!ai.enabled || !ai.applicationInfo.enabled || (ai.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
                    if (DEBUG_RECENTS && task.isAvailable)
                        Slog.d(TAG_RECENTS, "Making recent unavailable: " + task + " (enabled=" + ai.enabled + "/" + ai.applicationInfo.enabled + " flags=" + Integer.toHexString(ai.applicationInfo.flags) + ")");
                    task.isAvailable = false;
                } else {
                    if (DEBUG_RECENTS && !task.isAvailable)
                        Slog.d(TAG_RECENTS, "Making recent available: " + task);
                    task.isAvailable = true;
                }
            }
        }
    }
    // Verify the affiliate chain for each task.
    int i = 0;
    recentsCount = size();
    while (i < recentsCount) {
        i = processNextAffiliateChainLocked(i);
    }
// recent tasks are now in sorted, affiliated order.
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 24 with IPackageManager

use of android.content.pm.IPackageManager in project platform_frameworks_base by android.

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, StandardCharsets.UTF_8.name());
        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 25 with IPackageManager

use of android.content.pm.IPackageManager in project platform_frameworks_base by android.

the class ActivityManagerService method forceStopPackage.

@Override
public void forceStopPackage(final String packageName, int userId) {
    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 callingPid = Binder.getCallingPid();
    userId = mUserController.handleIncomingUser(callingPid, Binder.getCallingUid(), userId, true, ALLOW_FULL_ONLY, "forceStopPackage", null);
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        synchronized (this) {
            int[] users = userId == UserHandle.USER_ALL ? mUserController.getUsers() : new int[] { userId };
            for (int user : users) {
                int pkgUid = -1;
                try {
                    pkgUid = pm.getPackageUid(packageName, MATCH_DEBUG_TRIAGED_MISSING, user);
                } catch (RemoteException e) {
                }
                if (pkgUid == -1) {
                    Slog.w(TAG, "Invalid packageName: " + packageName);
                    continue;
                }
                try {
                    pm.setPackageStoppedState(packageName, true, user);
                } catch (RemoteException e) {
                } catch (IllegalArgumentException e) {
                    Slog.w(TAG, "Failed trying to unstop package " + packageName + ": " + e);
                }
                if (mUserController.isUserRunningLocked(user, 0)) {
                    forceStopPackageLocked(packageName, pkgUid, "from pid " + callingPid);
                    finishForceStopPackageLocked(packageName, pkgUid);
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

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