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;
}
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;
}
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.
}
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);
}
}
}
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);
}
}
Aggregations