Search in sources :

Example 61 with IPackageManager

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

the class ActivityManagerService method checkGrantUriPermissionFromIntentLocked.

/**
     * Like checkGrantUriPermissionLocked, but takes an Intent.
     */
NeededUriGrants checkGrantUriPermissionFromIntentLocked(int callingUid, String targetPkg, Intent intent, int mode, NeededUriGrants needed, int targetUserId) {
    if (DEBUG_URI_PERMISSION)
        Slog.v(TAG_URI_PERMISSION, "Checking URI perm to data=" + (intent != null ? intent.getData() : null) + " clip=" + (intent != null ? intent.getClipData() : null) + " from " + intent + "; flags=0x" + Integer.toHexString(intent != null ? intent.getFlags() : 0));
    if (targetPkg == null) {
        throw new NullPointerException("targetPkg");
    }
    if (intent == null) {
        return null;
    }
    Uri data = intent.getData();
    ClipData clip = intent.getClipData();
    if (data == null && clip == null) {
        return null;
    }
    // Default userId for uris in the intent (if they don't specify it themselves)
    int contentUserHint = intent.getContentUserHint();
    if (contentUserHint == UserHandle.USER_CURRENT) {
        contentUserHint = UserHandle.getUserId(callingUid);
    }
    final IPackageManager pm = AppGlobals.getPackageManager();
    int targetUid;
    if (needed != null) {
        targetUid = needed.targetUid;
    } else {
        try {
            targetUid = pm.getPackageUid(targetPkg, MATCH_DEBUG_TRIAGED_MISSING, targetUserId);
        } catch (RemoteException ex) {
            return null;
        }
        if (targetUid < 0) {
            if (DEBUG_URI_PERMISSION)
                Slog.v(TAG_URI_PERMISSION, "Can't grant URI permission no uid for: " + targetPkg + " on user " + targetUserId);
            return null;
        }
    }
    if (data != null) {
        GrantUri grantUri = GrantUri.resolve(contentUserHint, data);
        targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, grantUri, mode, targetUid);
        if (targetUid > 0) {
            if (needed == null) {
                needed = new NeededUriGrants(targetPkg, targetUid, mode);
            }
            needed.add(grantUri);
        }
    }
    if (clip != null) {
        for (int i = 0; i < clip.getItemCount(); i++) {
            Uri uri = clip.getItemAt(i).getUri();
            if (uri != null) {
                GrantUri grantUri = GrantUri.resolve(contentUserHint, uri);
                targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, grantUri, mode, targetUid);
                if (targetUid > 0) {
                    if (needed == null) {
                        needed = new NeededUriGrants(targetPkg, targetUid, mode);
                    }
                    needed.add(grantUri);
                }
            } else {
                Intent clipIntent = clip.getItemAt(i).getIntent();
                if (clipIntent != null) {
                    NeededUriGrants newNeeded = checkGrantUriPermissionFromIntentLocked(callingUid, targetPkg, clipIntent, mode, needed, targetUserId);
                    if (newNeeded != null) {
                        needed = newNeeded;
                    }
                }
            }
        }
    }
    return needed;
}
Also used : IPackageManager(android.content.pm.IPackageManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException) Uri(android.net.Uri) ClipData(android.content.ClipData) Point(android.graphics.Point)

Example 62 with IPackageManager

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

the class ActivityManagerService method killBackgroundProcesses.

@Override
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 = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, true, ALLOW_FULL_ONLY, "killBackgroundProcesses", null);
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        synchronized (this) {
            int appId = -1;
            try {
                appId = UserHandle.getAppId(pm.getPackageUid(packageName, MATCH_DEBUG_TRIAGED_MISSING, userId));
            } 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) Point(android.graphics.Point)

Example 63 with IPackageManager

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

the class ActivityManagerService method appendDropBoxProcessHeaders.

/**
     * Utility function for addErrorToDropBox and handleStrictModeViolation's logging
     * to append various headers to the dropbox log text.
     */
private void appendDropBoxProcessHeaders(ProcessRecord process, String processName, StringBuilder sb) {
    // would prevent watchdog from killing system_server.
    if (process == null) {
        sb.append("Process: ").append(processName).append("\n");
        return;
    }
    // concurrently during execution of this method)
    synchronized (this) {
        sb.append("Process: ").append(processName).append("\n");
        int flags = process.info.flags;
        IPackageManager pm = AppGlobals.getPackageManager();
        sb.append("Flags: 0x").append(Integer.toHexString(flags)).append("\n");
        for (int ip = 0; ip < process.pkgList.size(); ip++) {
            String pkg = process.pkgList.keyAt(ip);
            sb.append("Package: ").append(pkg);
            try {
                PackageInfo pi = pm.getPackageInfo(pkg, 0, UserHandle.getCallingUserId());
                if (pi != null) {
                    sb.append(" v").append(pi.versionCode);
                    if (pi.versionName != null) {
                        sb.append(" (").append(pi.versionName).append(")");
                    }
                }
            } catch (RemoteException e) {
                Slog.e(TAG, "Error getting package info: " + pkg, e);
            }
            sb.append("\n");
        }
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 64 with IPackageManager

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

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

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

the class ActivityManagerService method startProcessLocked.

private final void startProcessLocked(ProcessRecord app, String hostingType, String hostingNameStr, String abiOverride, String entryPoint, String[] entryPointArgs) {
    long startTime = SystemClock.elapsedRealtime();
    if (app.pid > 0 && app.pid != MY_PID) {
        checkTime(startTime, "startProcess: removing from pids map");
        synchronized (mPidsSelfLocked) {
            mPidsSelfLocked.remove(app.pid);
            mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
        }
        checkTime(startTime, "startProcess: done removing from pids map");
        app.setPid(0);
    }
    if (DEBUG_PROCESSES && mProcessesOnHold.contains(app))
        Slog.v(TAG_PROCESSES, "startProcessLocked removing on hold: " + app);
    mProcessesOnHold.remove(app);
    checkTime(startTime, "startProcess: starting to update cpu stats");
    updateCpuStats();
    checkTime(startTime, "startProcess: done updating cpu stats");
    try {
        try {
            final int userId = UserHandle.getUserId(app.uid);
            AppGlobals.getPackageManager().checkPackageStartable(app.info.packageName, userId);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
        int uid = app.uid;
        int[] gids = null;
        int mountExternal = Zygote.MOUNT_EXTERNAL_NONE;
        if (!app.isolated) {
            int[] permGids = null;
            try {
                checkTime(startTime, "startProcess: getting gids from package manager");
                final IPackageManager pm = AppGlobals.getPackageManager();
                permGids = pm.getPackageGids(app.info.packageName, MATCH_DEBUG_TRIAGED_MISSING, app.userId);
                MountServiceInternal mountServiceInternal = LocalServices.getService(MountServiceInternal.class);
                mountExternal = mountServiceInternal.getExternalStorageMountMode(uid, app.info.packageName);
            } catch (RemoteException e) {
                throw e.rethrowAsRuntimeException();
            }
            /*
                 * Add shared application and profile GIDs so applications can share some
                 * resources like shared libraries and access user-wide resources
                 */
            if (ArrayUtils.isEmpty(permGids)) {
                gids = new int[2];
            } else {
                gids = new int[permGids.length + 2];
                System.arraycopy(permGids, 0, gids, 2, permGids.length);
            }
            gids[0] = UserHandle.getSharedAppGid(UserHandle.getAppId(uid));
            gids[1] = UserHandle.getUserGid(UserHandle.getUserId(uid));
        }
        checkTime(startTime, "startProcess: building args");
        if (mFactoryTest != FactoryTest.FACTORY_TEST_OFF) {
            if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL && mTopComponent != null && app.processName.equals(mTopComponent.getPackageName())) {
                uid = 0;
            }
            if (mFactoryTest == FactoryTest.FACTORY_TEST_HIGH_LEVEL && (app.info.flags & ApplicationInfo.FLAG_FACTORY_TEST) != 0) {
                uid = 0;
            }
        }
        int debugFlags = 0;
        if ((app.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            debugFlags |= Zygote.DEBUG_ENABLE_DEBUGGER;
            // Also turn on CheckJNI for debuggable apps. It's quite
            // awkward to turn on otherwise.
            debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI;
        }
        // system is booted in safe mode.
        if ((app.info.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0 || mSafeMode == true) {
            debugFlags |= Zygote.DEBUG_ENABLE_SAFEMODE;
        }
        if ("1".equals(SystemProperties.get("debug.checkjni"))) {
            debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI;
        }
        String genDebugInfoProperty = SystemProperties.get("debug.generate-debug-info");
        if ("true".equals(genDebugInfoProperty)) {
            debugFlags |= Zygote.DEBUG_GENERATE_DEBUG_INFO;
        }
        if ("1".equals(SystemProperties.get("debug.jni.logging"))) {
            debugFlags |= Zygote.DEBUG_ENABLE_JNI_LOGGING;
        }
        if ("1".equals(SystemProperties.get("debug.assert"))) {
            debugFlags |= Zygote.DEBUG_ENABLE_ASSERT;
        }
        if (mNativeDebuggingApp != null && mNativeDebuggingApp.equals(app.processName)) {
            // Enable all debug flags required by the native debugger.
            // Don't interpret anything
            debugFlags |= Zygote.DEBUG_ALWAYS_JIT;
            // Generate debug info
            debugFlags |= Zygote.DEBUG_GENERATE_DEBUG_INFO;
            // Disbale optimizations
            debugFlags |= Zygote.DEBUG_NATIVE_DEBUGGABLE;
            mNativeDebuggingApp = null;
        }
        //Check if zygote should refresh its fonts
        boolean refreshTheme = false;
        if (SystemProperties.getBoolean(PROP_REFRESH_THEME, false)) {
            SystemProperties.set(PROP_REFRESH_THEME, "false");
            refreshTheme = true;
        }
        String requiredAbi = (abiOverride != null) ? abiOverride : app.info.primaryCpuAbi;
        if (requiredAbi == null) {
            requiredAbi = Build.SUPPORTED_ABIS[0];
        }
        String instructionSet = null;
        if (app.info.primaryCpuAbi != null) {
            instructionSet = VMRuntime.getInstructionSet(app.info.primaryCpuAbi);
        }
        app.gids = gids;
        app.requiredAbi = requiredAbi;
        app.instructionSet = instructionSet;
        // Start the process.  It will either succeed and return a result containing
        // the PID of the new process, or else throw a RuntimeException.
        boolean isActivityProcess = (entryPoint == null);
        if (entryPoint == null)
            entryPoint = "android.app.ActivityThread";
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Start proc: " + app.processName);
        checkTime(startTime, "startProcess: asking zygote to start proc");
        Process.ProcessStartResult startResult = Process.start(entryPoint, app.processName, uid, uid, gids, debugFlags, mountExternal, app.info.targetSdkVersion, app.info.seinfo, requiredAbi, instructionSet, app.info.dataDir, refreshTheme, entryPointArgs);
        checkTime(startTime, "startProcess: returned from zygote!");
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        mBatteryStatsService.noteProcessStart(app.processName, app.info.uid);
        checkTime(startTime, "startProcess: done updating battery stats");
        EventLog.writeEvent(EventLogTags.AM_PROC_START, UserHandle.getUserId(uid), startResult.pid, uid, app.processName, hostingType, hostingNameStr != null ? hostingNameStr : "");
        try {
            AppGlobals.getPackageManager().logAppProcessStartIfNeeded(app.processName, app.uid, app.info.seinfo, app.info.sourceDir, startResult.pid);
        } catch (RemoteException ex) {
        // Ignore
        }
        if (app.persistent) {
            Watchdog.getInstance().processStarted(app.processName, startResult.pid);
        }
        checkTime(startTime, "startProcess: building log message");
        StringBuilder buf = mStringBuilder;
        buf.setLength(0);
        buf.append("Start proc ");
        buf.append(startResult.pid);
        buf.append(':');
        buf.append(app.processName);
        buf.append('/');
        UserHandle.formatUid(buf, uid);
        if (!isActivityProcess) {
            buf.append(" [");
            buf.append(entryPoint);
            buf.append("]");
        }
        buf.append(" for ");
        buf.append(hostingType);
        if (hostingNameStr != null) {
            buf.append(" ");
            buf.append(hostingNameStr);
        }
        Slog.i(TAG, buf.toString());
        app.setPid(startResult.pid);
        app.usingWrapper = startResult.usingWrapper;
        app.removed = false;
        app.killed = false;
        app.killedByAm = false;
        checkTime(startTime, "startProcess: starting to update pids map");
        ProcessRecord oldApp;
        synchronized (mPidsSelfLocked) {
            oldApp = mPidsSelfLocked.get(startResult.pid);
        }
        // If there is already an app occupying that pid that hasn't been cleaned up
        if (oldApp != null && !app.isolated) {
            // Clean up anything relating to this pid first
            Slog.w(TAG, "Reusing pid " + startResult.pid + " while app is still mapped to it");
            cleanUpApplicationRecordLocked(oldApp, false, false, -1, true);
        }
        synchronized (mPidsSelfLocked) {
            this.mPidsSelfLocked.put(startResult.pid, app);
            if (isActivityProcess) {
                Message msg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG);
                msg.obj = app;
                mHandler.sendMessageDelayed(msg, startResult.usingWrapper ? PROC_START_TIMEOUT_WITH_WRAPPER : PROC_START_TIMEOUT);
            }
        }
        checkTime(startTime, "startProcess: done updating pids map");
    } catch (RuntimeException e) {
        Slog.e(TAG, "Failure starting process " + app.processName, e);
        // Something went very wrong while trying to start this process; one
        // common case is when the package is frozen due to an active
        // upgrade. To recover, clean up any active bookkeeping related to
        // starting this process. (We already invoked this method once when
        // the package was initially frozen through KILL_APPLICATION_MSG, so
        // it doesn't hurt to use it again.)
        forceStopPackageLocked(app.info.packageName, UserHandle.getAppId(app.uid), false, false, true, false, false, UserHandle.getUserId(app.userId), "start failure");
    }
}
Also used : MountServiceInternal(android.os.storage.MountServiceInternal) Message(android.os.Message) Process(android.os.Process) Point(android.graphics.Point) 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