Search in sources :

Example 56 with IActivityManager

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

the class PackageManagerService method setPermissionEnforced.

@Override
public void setPermissionEnforced(String permission, boolean enforced) {
    mContext.enforceCallingOrSelfPermission(GRANT_REVOKE_PERMISSIONS, null);
    if (READ_EXTERNAL_STORAGE.equals(permission)) {
        synchronized (mPackages) {
            if (mSettings.mReadExternalStorageEnforced == null || mSettings.mReadExternalStorageEnforced != enforced) {
                mSettings.mReadExternalStorageEnforced = enforced;
                mSettings.writeLPr();
            }
        }
        // kill any non-foreground processes so we restart them and
        // grant/revoke the GID.
        final IActivityManager am = ActivityManagerNative.getDefault();
        if (am != null) {
            final long token = Binder.clearCallingIdentity();
            try {
                am.killProcessesBelowForeground("setPermissionEnforcement");
            } catch (RemoteException e) {
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }
    } else {
        throw new IllegalArgumentException("No selective enforcement for " + permission);
    }
}
Also used : RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 57 with IActivityManager

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

the class PackageManagerService method startCleaningPackages.

void startCleaningPackages() {
    // reader
    synchronized (mPackages) {
        if (!isExternalMediaAvailable()) {
            return;
        }
        if (mSettings.mPackagesToBeCleaned.isEmpty()) {
            return;
        }
    }
    Intent intent = new Intent(PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE);
    intent.setComponent(DEFAULT_CONTAINER_COMPONENT);
    IActivityManager am = ActivityManagerNative.getDefault();
    if (am != null) {
        try {
            am.startService(null, intent, null, UserHandle.USER_OWNER);
        } catch (RemoteException e) {
        }
    }
}
Also used : Intent(android.content.Intent) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 58 with IActivityManager

use of android.app.IActivityManager in project platform_frameworks_base by android.

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(myContext);
        binder = am.peekService(service, service.resolveTypeIfNeeded(myContext.getContentResolver()), myContext.getOpPackageName());
    } catch (RemoteException e) {
    }
    return binder;
}
Also used : IBinder(android.os.IBinder) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 59 with IActivityManager

use of android.app.IActivityManager in project platform_frameworks_base by android.

the class SettingsCmd method run.

public void run() {
    boolean valid = false;
    String arg;
    try {
        while ((arg = nextArg()) != null) {
            if ("--user".equals(arg)) {
                if (mUser != -1) {
                    // --user specified more than once; invalid
                    break;
                }
                arg = nextArg();
                if ("current".equals(arg) || "cur".equals(arg)) {
                    mUser = UserHandle.USER_CURRENT;
                } else {
                    mUser = Integer.parseInt(arg);
                }
            } else if (mVerb == CommandVerb.UNSPECIFIED) {
                if ("get".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.GET;
                } else if ("put".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.PUT;
                } else if ("delete".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.DELETE;
                } else if ("list".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.LIST;
                } else {
                    // invalid
                    System.err.println("Invalid command: " + arg);
                    break;
                }
            } else if (mTable == null) {
                if (!"system".equalsIgnoreCase(arg) && !"secure".equalsIgnoreCase(arg) && !"global".equalsIgnoreCase(arg)) {
                    System.err.println("Invalid namespace '" + arg + "'");
                    // invalid
                    break;
                }
                mTable = arg.toLowerCase();
                if (mVerb == CommandVerb.LIST) {
                    valid = true;
                    break;
                }
            } else if (mVerb == CommandVerb.GET || mVerb == CommandVerb.DELETE) {
                mKey = arg;
                if (mNextArg >= mArgs.length) {
                    valid = true;
                } else {
                    System.err.println("Too many arguments");
                }
                break;
            } else if (mKey == null) {
                mKey = arg;
            // keep going; there's another PUT arg
            } else {
                // PUT, final arg
                mValue = arg;
                if (mNextArg >= mArgs.length) {
                    valid = true;
                } else {
                    System.err.println("Too many arguments");
                }
                break;
            }
        }
    } catch (Exception e) {
        valid = false;
    }
    if (valid) {
        try {
            IActivityManager activityManager = ActivityManagerNative.getDefault();
            if (mUser == UserHandle.USER_CURRENT) {
                mUser = activityManager.getCurrentUser().id;
            }
            if (mUser < 0) {
                mUser = UserHandle.USER_SYSTEM;
            }
            IContentProvider provider = null;
            IBinder token = new Binder();
            try {
                ContentProviderHolder holder = activityManager.getContentProviderExternal("settings", UserHandle.USER_SYSTEM, token);
                if (holder == null) {
                    throw new IllegalStateException("Could not find settings provider");
                }
                provider = holder.provider;
                switch(mVerb) {
                    case GET:
                        System.out.println(getForUser(provider, mUser, mTable, mKey));
                        break;
                    case PUT:
                        putForUser(provider, mUser, mTable, mKey, mValue);
                        break;
                    case DELETE:
                        System.out.println("Deleted " + deleteForUser(provider, mUser, mTable, mKey) + " rows");
                        break;
                    case LIST:
                        for (String line : listForUser(provider, mUser, mTable)) {
                            System.out.println(line);
                        }
                        break;
                    default:
                        System.err.println("Unspecified command");
                        break;
                }
            } finally {
                if (provider != null) {
                    activityManager.removeContentProviderExternal("settings", token);
                }
            }
        } catch (Exception e) {
            System.err.println("Error while accessing settings provider");
            e.printStackTrace();
        }
    } else {
        printUsage();
    }
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) IBinder(android.os.IBinder) IContentProvider(android.content.IContentProvider) ContentProviderHolder(android.app.IActivityManager.ContentProviderHolder) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 60 with IActivityManager

use of android.app.IActivityManager in project platform_frameworks_base by android.

the class ShellUiAutomatorBridge method getSystemLongPressTime.

public long getSystemLongPressTime() {
    // Read the long press timeout setting.
    long longPressTimeout = 0;
    try {
        IContentProvider provider = null;
        Cursor cursor = null;
        IActivityManager activityManager = ActivityManagerNative.getDefault();
        String providerName = Settings.Secure.CONTENT_URI.getAuthority();
        IBinder token = new Binder();
        try {
            ContentProviderHolder holder = activityManager.getContentProviderExternal(providerName, UserHandle.USER_SYSTEM, token);
            if (holder == null) {
                throw new IllegalStateException("Could not find provider: " + providerName);
            }
            provider = holder.provider;
            cursor = provider.query(null, Settings.Secure.CONTENT_URI, new String[] { Settings.Secure.VALUE }, "name=?", new String[] { Settings.Secure.LONG_PRESS_TIMEOUT }, null, null);
            if (cursor.moveToFirst()) {
                longPressTimeout = cursor.getInt(0);
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (provider != null) {
                activityManager.removeContentProviderExternal(providerName, token);
            }
        }
    } catch (RemoteException e) {
        String message = "Error reading long press timeout setting.";
        Log.e(LOG_TAG, message, e);
        throw new RuntimeException(message, e);
    }
    return longPressTimeout;
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) IBinder(android.os.IBinder) IContentProvider(android.content.IContentProvider) ContentProviderHolder(android.app.IActivityManager.ContentProviderHolder) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Aggregations

IActivityManager (android.app.IActivityManager)85 RemoteException (android.os.RemoteException)72 Intent (android.content.Intent)21 IBinder (android.os.IBinder)18 Configuration (android.content.res.Configuration)14 ContentProviderHolder (android.app.IActivityManager.ContentProviderHolder)11 IContentProvider (android.content.IContentProvider)11 Binder (android.os.Binder)11 ActivityThread (android.app.ActivityThread)7 Locale (java.util.Locale)7 BroadcastReceiver (android.content.BroadcastReceiver)6 Context (android.content.Context)6 IMountService (android.os.storage.IMountService)6 IMountShutdownObserver (android.os.storage.IMountShutdownObserver)6 Cursor (android.database.Cursor)5 ComponentName (android.content.ComponentName)4 PackageManagerInternal (android.content.pm.PackageManagerInternal)4 UserInfo (android.content.pm.UserInfo)4 ErrnoException (android.system.ErrnoException)4 ArrayMap (android.util.ArrayMap)4