Search in sources :

Example 86 with IPackageManager

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

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 87 with IPackageManager

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

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 88 with IPackageManager

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

the class RecentTasks method cleanupProtectedComponentTasksLocked.

/**
     * Clear out protected tasks from the list
     */
void cleanupProtectedComponentTasksLocked(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;
        }
        try {
            if (task.realActivity != null && pm.isComponentProtected(null, -1, task.realActivity, userId)) {
                remove(i);
                task.removedFromRecents();
            }
        } catch (RemoteException e) {
        }
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Example 89 with IPackageManager

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

the class AppOpsService method readUid.

void readUid(XmlPullParser parser, String pkgName) throws NumberFormatException, XmlPullParserException, IOException {
    int uid = Integer.parseInt(parser.getAttributeValue(null, "n"));
    String isPrivilegedString = parser.getAttributeValue(null, "p");
    boolean isPrivileged = false;
    if (isPrivilegedString == null) {
        try {
            IPackageManager packageManager = ActivityThread.getPackageManager();
            if (packageManager != null) {
                ApplicationInfo appInfo = ActivityThread.getPackageManager().getApplicationInfo(pkgName, 0, UserHandle.getUserId(uid));
                if (appInfo != null) {
                    isPrivileged = (appInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
                }
            } else {
                // Could not load data, don't add to cache so it will be loaded later.
                return;
            }
        } catch (RemoteException e) {
            Slog.w(TAG, "Could not contact PackageManager", e);
        }
    } else {
        isPrivileged = Boolean.parseBoolean(isPrivilegedString);
    }
    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        String tagName = parser.getName();
        if (tagName.equals("op")) {
            int code = Integer.parseInt(parser.getAttributeValue(null, "n"));
            // use op name string if it exists
            String codeNameStr = parser.getAttributeValue(null, "ns");
            if (codeNameStr != null) {
                // returns OP_NONE if it could not be mapped
                code = AppOpsManager.nameToOp(codeNameStr);
            }
            // skip op codes that are out of bounds
            if (code == AppOpsManager.OP_NONE || code >= AppOpsManager._NUM_OP) {
                continue;
            }
            Op op = new Op(uid, pkgName, code, AppOpsManager.MODE_ERRORED);
            String mode = parser.getAttributeValue(null, "m");
            if (mode != null) {
                op.mode = Integer.parseInt(mode);
            } else {
                String sDefualtMode = parser.getAttributeValue(null, "dm");
                int defaultMode;
                if (sDefualtMode != null) {
                    defaultMode = Integer.parseInt(sDefualtMode);
                } else {
                    defaultMode = getDefaultMode(code, uid, pkgName);
                }
                op.mode = defaultMode;
            }
            String time = parser.getAttributeValue(null, "t");
            if (time != null) {
                op.time = Long.parseLong(time);
            }
            time = parser.getAttributeValue(null, "r");
            if (time != null) {
                op.rejectTime = Long.parseLong(time);
            }
            String dur = parser.getAttributeValue(null, "d");
            if (dur != null) {
                op.duration = Integer.parseInt(dur);
            }
            String proxyUid = parser.getAttributeValue(null, "pu");
            if (proxyUid != null) {
                op.proxyUid = Integer.parseInt(proxyUid);
            }
            String proxyPackageName = parser.getAttributeValue(null, "pp");
            if (proxyPackageName != null) {
                op.proxyPackageName = proxyPackageName;
            }
            String allowed = parser.getAttributeValue(null, "ac");
            if (allowed != null) {
                op.allowedCount = Integer.parseInt(allowed);
            }
            String ignored = parser.getAttributeValue(null, "ic");
            if (ignored != null) {
                op.ignoredCount = Integer.parseInt(ignored);
            }
            UidState uidState = getUidStateLocked(uid, true);
            if (uidState.pkgOps == null) {
                uidState.pkgOps = new ArrayMap<>();
            }
            Ops ops = uidState.pkgOps.get(pkgName);
            if (ops == null) {
                ops = new Ops(pkgName, uidState, isPrivileged);
                uidState.pkgOps.put(pkgName, ops);
            }
            ops.put(op.op, op);
        } else {
            Slog.w(TAG, "Unknown element under <pkg>: " + parser.getName());
            XmlUtils.skipCurrentTag(parser);
        }
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 90 with IPackageManager

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

the class ClipboardService method addActiveOwnerLocked.

private final void addActiveOwnerLocked(int uid, String pkg) {
    final IPackageManager pm = AppGlobals.getPackageManager();
    final int targetUserHandle = UserHandle.getCallingUserId();
    final long oldIdentity = Binder.clearCallingIdentity();
    try {
        PackageInfo pi = pm.getPackageInfo(pkg, 0, targetUserHandle);
        if (pi == null) {
            throw new IllegalArgumentException("Unknown package " + pkg);
        }
        if (!UserHandle.isSameApp(pi.applicationInfo.uid, uid)) {
            throw new SecurityException("Calling uid " + uid + " does not own package " + pkg);
        }
    } catch (RemoteException e) {
    // Can't happen; the package manager is in the same process
    } finally {
        Binder.restoreCallingIdentity(oldIdentity);
    }
    PerUserClipboard clipboard = getClipboard();
    if (clipboard.primaryClip != null && !clipboard.activePermissionOwners.contains(pkg)) {
        final int N = clipboard.primaryClip.getItemCount();
        for (int i = 0; i < N; i++) {
            grantItemLocked(clipboard.primaryClip.getItemAt(i), pkg, UserHandle.getUserId(uid));
        }
        clipboard.activePermissionOwners.add(pkg);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageInfo(android.content.pm.PackageInfo) 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