Search in sources :

Example 26 with IPackageManager

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

the class ActivityManagerService method dumpAssociationsLocked.

void dumpAssociationsLocked(FileDescriptor fd, PrintWriter pw, String[] args, int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) {
    pw.println("ACTIVITY MANAGER ASSOCIATIONS (dumpsys activity associations)");
    int dumpUid = 0;
    if (dumpPackage != null) {
        IPackageManager pm = AppGlobals.getPackageManager();
        try {
            dumpUid = pm.getPackageUid(dumpPackage, MATCH_UNINSTALLED_PACKAGES, 0);
        } catch (RemoteException e) {
        }
    }
    boolean printedAnything = false;
    final long now = SystemClock.uptimeMillis();
    for (int i1 = 0, N1 = mAssociations.size(); i1 < N1; i1++) {
        ArrayMap<ComponentName, SparseArray<ArrayMap<String, Association>>> targetComponents = mAssociations.valueAt(i1);
        for (int i2 = 0, N2 = targetComponents.size(); i2 < N2; i2++) {
            SparseArray<ArrayMap<String, Association>> sourceUids = targetComponents.valueAt(i2);
            for (int i3 = 0, N3 = sourceUids.size(); i3 < N3; i3++) {
                ArrayMap<String, Association> sourceProcesses = sourceUids.valueAt(i3);
                for (int i4 = 0, N4 = sourceProcesses.size(); i4 < N4; i4++) {
                    Association ass = sourceProcesses.valueAt(i4);
                    if (dumpPackage != null) {
                        if (!ass.mTargetComponent.getPackageName().equals(dumpPackage) && UserHandle.getAppId(ass.mSourceUid) != dumpUid) {
                            continue;
                        }
                    }
                    printedAnything = true;
                    pw.print("  ");
                    pw.print(ass.mTargetProcess);
                    pw.print("/");
                    UserHandle.formatUid(pw, ass.mTargetUid);
                    pw.print(" <- ");
                    pw.print(ass.mSourceProcess);
                    pw.print("/");
                    UserHandle.formatUid(pw, ass.mSourceUid);
                    pw.println();
                    pw.print("    via ");
                    pw.print(ass.mTargetComponent.flattenToShortString());
                    pw.println();
                    pw.print("    ");
                    long dur = ass.mTime;
                    if (ass.mNesting > 0) {
                        dur += now - ass.mStartTime;
                    }
                    TimeUtils.formatDuration(dur, pw);
                    pw.print(" (");
                    pw.print(ass.mCount);
                    pw.print(" times)");
                    pw.print("  ");
                    for (int i = 0; i < ass.mStateTimes.length; i++) {
                        long amt = ass.mStateTimes[i];
                        if (ass.mLastState - ActivityManager.MIN_PROCESS_STATE == i) {
                            amt += now - ass.mLastStateUptime;
                        }
                        if (amt != 0) {
                            pw.print(" ");
                            pw.print(ProcessList.makeProcStateString(i + ActivityManager.MIN_PROCESS_STATE));
                            pw.print("=");
                            TimeUtils.formatDuration(amt, pw);
                            if (ass.mLastState - ActivityManager.MIN_PROCESS_STATE == i) {
                                pw.print("*");
                            }
                        }
                    }
                    pw.println();
                    if (ass.mNesting > 0) {
                        pw.print("    Currently active: ");
                        TimeUtils.formatDuration(now - ass.mStartTime, pw);
                        pw.println();
                    }
                }
            }
        }
    }
    if (!printedAnything) {
        pw.println("  (nothing)");
    }
}
Also used : ArrayMap(android.util.ArrayMap) Point(android.graphics.Point) SparseArray(android.util.SparseArray) IPackageManager(android.content.pm.IPackageManager) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 27 with IPackageManager

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

the class ActivityManagerService method grantUriPermissionLocked.

void grantUriPermissionLocked(int callingUid, String targetPkg, GrantUri grantUri, final int modeFlags, UriPermissionOwner owner, int targetUserId) {
    if (targetPkg == null) {
        throw new NullPointerException("targetPkg");
    }
    int targetUid;
    final IPackageManager pm = AppGlobals.getPackageManager();
    try {
        targetUid = pm.getPackageUid(targetPkg, MATCH_DEBUG_TRIAGED_MISSING, targetUserId);
    } catch (RemoteException ex) {
        return;
    }
    targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, grantUri, modeFlags, targetUid);
    if (targetUid < 0) {
        return;
    }
    grantUriPermissionUncheckedLocked(targetUid, targetPkg, grantUri, modeFlags, owner);
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 28 with IPackageManager

use of android.content.pm.IPackageManager in project XobotOS by xamarin.

the class LoadedApk method initializeJavaContextClassLoader.

/**
     * Setup value for Thread.getContextClassLoader(). If the
     * package will not run in in a VM with other packages, we set
     * the Java context ClassLoader to the
     * PackageInfo.getClassLoader value. However, if this VM can
     * contain multiple packages, we intead set the Java context
     * ClassLoader to a proxy that will warn about the use of Java
     * context ClassLoaders and then fall through to use the
     * system ClassLoader.
     *
     * <p> Note that this is similar to but not the same as the
     * android.content.Context.getClassLoader(). While both
     * context class loaders are typically set to the
     * PathClassLoader used to load the package archive in the
     * single application per VM case, a single Android process
     * may contain several Contexts executing on one thread with
     * their own logical ClassLoaders while the Java context
     * ClassLoader is a thread local. This is why in the case when
     * we have multiple packages per VM we do not set the Java
     * context ClassLoader to an arbitrary but instead warn the
     * user to set their own if we detect that they are using a
     * Java library that expects it to be set.
     */
private void initializeJavaContextClassLoader() {
    IPackageManager pm = ActivityThread.getPackageManager();
    android.content.pm.PackageInfo pi;
    try {
        pi = pm.getPackageInfo(mPackageName, 0);
    } catch (RemoteException e) {
        throw new AssertionError(e);
    }
    /*
         * Two possible indications that this package could be
         * sharing its virtual machine with other packages:
         *
         * 1.) the sharedUserId attribute is set in the manifest,
         *     indicating a request to share a VM with other
         *     packages with the same sharedUserId.
         *
         * 2.) the application element of the manifest has an
         *     attribute specifying a non-default process name,
         *     indicating the desire to run in another packages VM.
         */
    boolean sharedUserIdSet = (pi.sharedUserId != null);
    boolean processNameNotDefault = (pi.applicationInfo != null && !mPackageName.equals(pi.applicationInfo.processName));
    boolean sharable = (sharedUserIdSet || processNameNotDefault);
    ClassLoader contextClassLoader = (sharable) ? new WarningContextClassLoader() : mClassLoader;
    Thread.currentThread().setContextClassLoader(contextClassLoader);
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Example 29 with IPackageManager

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

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")) {
            Op op = new Op(uid, pkgName, Integer.parseInt(parser.getAttributeValue(null, "n")));
            String mode = parser.getAttributeValue(null, "m");
            if (mode != null) {
                op.mode = Integer.parseInt(mode);
            }
            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;
            }
            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 30 with IPackageManager

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

the class RetailDemoModeService method isDemoLauncherDisabled.

boolean isDemoLauncherDisabled() {
    int enabledState = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
    try {
        final IPackageManager iPm = AppGlobals.getPackageManager();
        final String demoLauncherComponent = getContext().getString(R.string.config_demoModeLauncherComponent);
        enabledState = iPm.getComponentEnabledSetting(ComponentName.unflattenFromString(demoLauncherComponent), mCurrentUserId);
    } catch (RemoteException re) {
        Slog.e(TAG, "Error retrieving demo launcher enabled setting", re);
    }
    return enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}
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