Search in sources :

Example 1 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.

the class PackageManagerService method installExistingPackageAsUser.

/**
     * @hide
     */
@Override
public int installExistingPackageAsUser(String packageName, int userId) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.INSTALL_PACKAGES, null);
    PackageSetting pkgSetting;
    final int uid = Binder.getCallingUid();
    if (UserHandle.getUserId(uid) != userId) {
        mContext.enforceCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, "installExistingPackage for user " + userId);
    }
    if (isUserRestricted(userId, UserManager.DISALLOW_INSTALL_APPS)) {
        return PackageManager.INSTALL_FAILED_USER_RESTRICTED;
    }
    long callingId = Binder.clearCallingIdentity();
    try {
        boolean sendAdded = false;
        Bundle extras = new Bundle(1);
        // writer
        synchronized (mPackages) {
            pkgSetting = mSettings.mPackages.get(packageName);
            if (pkgSetting == null) {
                return PackageManager.INSTALL_FAILED_INVALID_URI;
            }
            if (!pkgSetting.getInstalled(userId)) {
                pkgSetting.setInstalled(true, userId);
                mSettings.writePackageRestrictionsLPr(userId);
                extras.putInt(Intent.EXTRA_UID, UserHandle.getUid(userId, pkgSetting.appId));
                sendAdded = true;
            }
        }
        if (sendAdded) {
            sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, null, packageName, extras, null, null, new int[] { userId });
            try {
                IActivityManager am = ActivityManagerNative.getDefault();
                final boolean isSystem = isSystemApp(pkgSetting) || isUpdatedSystemApp(pkgSetting);
                if (isSystem && am.isUserRunning(userId, false)) {
                    // The just-installed/enabled app is bundled on the system, so presumed
                    // to be able to run automatically without needing an explicit launch.
                    // Send it a BOOT_COMPLETED if it would ordinarily have gotten one.
                    Intent bcIntent = new Intent(Intent.ACTION_BOOT_COMPLETED).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).setPackage(packageName);
                    am.broadcastIntent(null, bcIntent, null, null, 0, null, null, null, android.app.AppOpsManager.OP_NONE, false, false, userId);
                }
            } catch (RemoteException e) {
                // shouldn't happen
                Slog.w(TAG, "Unable to bootstrap installed package", e);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
    return PackageManager.INSTALL_SUCCEEDED;
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 2 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.

the class PackageManagerService method revokePermission.

public void revokePermission(String packageName, String permissionName) {
    int changedAppId = -1;
    synchronized (mPackages) {
        final PackageParser.Package pkg = mPackages.get(packageName);
        if (pkg == null) {
            throw new IllegalArgumentException("Unknown package: " + packageName);
        }
        if (pkg.applicationInfo.uid != Binder.getCallingUid()) {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.GRANT_REVOKE_PERMISSIONS, null);
        }
        final BasePermission bp = mSettings.mPermissions.get(permissionName);
        if (bp == null) {
            throw new IllegalArgumentException("Unknown permission: " + permissionName);
        }
        checkGrantRevokePermissions(pkg, bp);
        final PackageSetting ps = (PackageSetting) pkg.mExtras;
        if (ps == null) {
            return;
        }
        final GrantedPermissions gp = (ps.sharedUser != null) ? ps.sharedUser : ps;
        if (gp.grantedPermissions.remove(permissionName)) {
            gp.grantedPermissions.remove(permissionName);
            if (ps.haveGids) {
                gp.gids = removeInts(gp.gids, bp.gids);
            }
            mSettings.writeLPr();
            changedAppId = ps.appId;
        }
    }
    if (changedAppId >= 0) {
        // We changed the perm on someone, kill its processes.
        IActivityManager am = ActivityManagerNative.getDefault();
        if (am != null) {
            final int callingUserId = UserHandle.getCallingUserId();
            final long ident = Binder.clearCallingIdentity();
            try {
                //XXX we should only revoke for the calling user's app permissions,
                // but for now we impact all users.
                //am.killUid(UserHandle.getUid(callingUserId, changedAppId),
                //        "revoke " + permissionName);
                int[] users = sUserManager.getUserIds();
                for (int user : users) {
                    am.killUid(UserHandle.getUid(user, changedAppId), "revoke " + permissionName);
                }
            } catch (RemoteException e) {
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
    }
}
Also used : PackageParser(android.content.pm.PackageParser) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 3 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.

the class ShutdownThread method run.

/**
     * Makes sure we handle the shutdown gracefully.
     * Shuts off power regardless of radio and bluetooth state if the alloted time has passed.
     */
public void run() {
    BroadcastReceiver br = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // We don't allow apps to cancel this, so ignore the result.
            actionDone();
        }
    };
    /*
         * Write a system property in case the system_server reboots before we
         * get to the actual hardware restart. If that happens, we'll retry at
         * the beginning of the SystemServer startup.
         */
    {
        String reason = (mReboot ? "1" : "0") + (mRebootReason != null ? mRebootReason : "");
        SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason);
    }
    /*
         * If we are rebooting into safe mode, write a system property
         * indicating so.
         */
    if (mRebootSafeMode) {
        SystemProperties.set(REBOOT_SAFEMODE_PROPERTY, "1");
    }
    Log.i(TAG, "Sending shutdown broadcast...");
    // First send the high-level shut down broadcast.
    mActionDone = false;
    Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, null, br, mHandler, 0, null, null);
    final long endTime = SystemClock.elapsedRealtime() + MAX_BROADCAST_TIME;
    synchronized (mActionDoneSync) {
        while (!mActionDone) {
            long delay = endTime - SystemClock.elapsedRealtime();
            if (delay <= 0) {
                Log.w(TAG, "Shutdown broadcast timed out");
                break;
            }
            try {
                mActionDoneSync.wait(delay);
            } catch (InterruptedException e) {
            }
        }
    }
    Log.i(TAG, "Shutting down activity manager...");
    final IActivityManager am = ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
    if (am != null) {
        try {
            am.shutdown(MAX_BROADCAST_TIME);
        } catch (RemoteException e) {
        }
    }
    // Shutdown radios.
    shutdownRadios(MAX_RADIO_WAIT_TIME);
    // Shutdown MountService to ensure media is in a safe state
    IMountShutdownObserver observer = new IMountShutdownObserver.Stub() {

        public void onShutDownComplete(int statusCode) throws RemoteException {
            Log.w(TAG, "Result code " + statusCode + " from MountService.shutdown");
            actionDone();
        }
    };
    Log.i(TAG, "Shutting down MountService");
    // Set initial variables and time out time.
    mActionDone = false;
    final long endShutTime = SystemClock.elapsedRealtime() + MAX_SHUTDOWN_WAIT_TIME;
    synchronized (mActionDoneSync) {
        try {
            final IMountService mount = IMountService.Stub.asInterface(ServiceManager.checkService("mount"));
            if (mount != null) {
                mount.shutdown(observer);
            } else {
                Log.w(TAG, "MountService unavailable for shutdown");
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception during MountService shutdown", e);
        }
        while (!mActionDone) {
            long delay = endShutTime - SystemClock.elapsedRealtime();
            if (delay <= 0) {
                Log.w(TAG, "Shutdown wait timed out");
                break;
            }
            try {
                mActionDoneSync.wait(delay);
            } catch (InterruptedException e) {
            }
        }
    }
    rebootOrShutdown(mReboot, mRebootReason);
}
Also used : Context(android.content.Context) IMountShutdownObserver(android.os.storage.IMountShutdownObserver) IMountService(android.os.storage.IMountService) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) RemoteException(android.os.RemoteException) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 4 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.

the class BroadcastReceiver method peekService.

/**
     * Provide a binder to an already-running service.  This method is synchronous
     * and will not start the target service if it is not present, so it is safe
     * to call from {@link #onReceive}.
     * 
     * @param myContext The Context that had been passed to {@link #onReceive(Context, Intent)}
     * @param service The Intent indicating the service you wish to use.  See {@link
     * Context#startService(Intent)} for more information.
     */
public IBinder peekService(Context myContext, Intent service) {
    IActivityManager am = ActivityManagerNative.getDefault();
    IBinder binder = null;
    try {
        service.prepareToLeaveProcess();
        binder = am.peekService(service, service.resolveTypeIfNeeded(myContext.getContentResolver()));
    } catch (RemoteException e) {
    }
    return binder;
}
Also used : IBinder(android.os.IBinder) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 5 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.

the class StrictMode method dropboxViolationAsync.

/**
     * In the common case, as set by conditionallyEnableDebugLogging,
     * we're just dropboxing any violations but not showing a dialog,
     * not loggging, and not killing the process.  In these cases we
     * don't need to do a synchronous call to the ActivityManager.
     * This is used by both per-thread and vm-wide violations when
     * applicable.
     */
private static void dropboxViolationAsync(final int violationMaskSubset, final ViolationInfo info) {
    int outstanding = sDropboxCallsInFlight.incrementAndGet();
    if (outstanding > 20) {
        // What's going on?  Let's not make make the situation
        // worse and just not log.
        sDropboxCallsInFlight.decrementAndGet();
        return;
    }
    if (LOG_V)
        Log.d(TAG, "Dropboxing async; in-flight=" + outstanding);
    new Thread("callActivityManagerForStrictModeDropbox") {

        public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            try {
                IActivityManager am = ActivityManagerNative.getDefault();
                if (am == null) {
                    Log.d(TAG, "No activity manager; failed to Dropbox violation.");
                } else {
                    am.handleApplicationStrictModeViolation(RuntimeInit.getApplicationObject(), violationMaskSubset, info);
                }
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException handling StrictMode violation", e);
            }
            int outstanding = sDropboxCallsInFlight.decrementAndGet();
            if (LOG_V)
                Log.d(TAG, "Dropbox complete; in-flight=" + outstanding);
        }
    }.start();
}
Also used : ActivityThread(android.app.ActivityThread) IActivityManager(android.app.IActivityManager)

Aggregations

IActivityManager (android.app.IActivityManager)112 RemoteException (android.os.RemoteException)93 Intent (android.content.Intent)23 IBinder (android.os.IBinder)20 Configuration (android.content.res.Configuration)15 UserHandle (android.os.UserHandle)14 ContentProviderHolder (android.app.IActivityManager.ContentProviderHolder)11 IContentProvider (android.content.IContentProvider)11 Binder (android.os.Binder)11 ActivityOptions (android.app.ActivityOptions)9 ActivityThread (android.app.ActivityThread)9 Context (android.content.Context)8 IntentSender (android.content.IntentSender)8 Point (android.graphics.Point)7 SpannableString (android.text.SpannableString)7 BroadcastReceiver (android.content.BroadcastReceiver)6 ComponentName (android.content.ComponentName)6 IMountService (android.os.storage.IMountService)6 IMountShutdownObserver (android.os.storage.IMountShutdownObserver)6 Locale (java.util.Locale)6