Search in sources :

Example 81 with IActivityManager

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

the class BroadcastReceiver method peekService.

/**
     * Provide a binder to an already-bound 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}.
     *
     * For peekService() to return a non null {@link android.os.IBinder} interface
     * the service must have published it before. In other words some component
     * must have called {@link android.content.Context#bindService(Intent, ServiceConnection, int)} on it.
     *
     * @param myContext The Context that had been passed to {@link #onReceive(Context, Intent)}
     * @param service Identifies the already-bound service you wish to use. See
     * {@link android.content.Context#bindService(Intent, ServiceConnection, int)}
     * 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 82 with IActivityManager

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

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)

Example 83 with IActivityManager

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

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) {
                if (e instanceof DeadObjectException) {
                // System process is dead; ignore
                } else {
                    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)

Example 84 with IActivityManager

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

the class ActionUtils method killForegroundAppInternal.

private static boolean killForegroundAppInternal(Context context, int userId) throws RemoteException {
    try {
        final Intent intent = new Intent(Intent.ACTION_MAIN);
        String defaultHomePackage = "com.android.launcher";
        intent.addCategory(Intent.CATEGORY_HOME);
        final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
        if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
            defaultHomePackage = res.activityInfo.packageName;
        }
        IActivityManager am = ActivityManagerNative.getDefault();
        List<ActivityManager.RunningAppProcessInfo> apps = am.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo appInfo : apps) {
            int uid = appInfo.uid;
            // root, phone, etc.)
            if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID && appInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                if (appInfo.pkgList != null && (appInfo.pkgList.length > 0)) {
                    for (String pkg : appInfo.pkgList) {
                        if (!pkg.equals("com.android.systemui") && !pkg.equals(defaultHomePackage)) {
                            am.forceStopPackage(pkg, UserHandle.USER_CURRENT);
                            return true;
                        }
                    }
                } else {
                    Process.killProcess(appInfo.pid);
                    return true;
                }
            }
        }
    } catch (RemoteException remoteException) {
    // Do nothing; just let it go.
    }
    return false;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 85 with IActivityManager

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

the class PhoneStatusBar method handleLongPressBackRecents.

/**
     * This handles long-press of both back and recents.  They are
     * handled together to capture them both being long-pressed
     * at the same time to exit screen pinning (lock task).
     *
     * When accessibility mode is on, only a long-press from recents
     * is required to exit.
     *
     * In all other circumstances we try to pass through long-press events
     * for Back, so that apps can still use it.  Which can be from two things.
     * 1) Not currently in screen pinning (lock task).
     * 2) Back is long-pressed without recents.
     */
private boolean handleLongPressBackRecents(View v) {
    try {
        boolean sendBackLongPress = false;
        IActivityManager activityManager = ActivityManagerNative.getDefault();
        boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
        boolean inLockTaskMode = activityManager.isInLockTaskMode();
        if (inLockTaskMode && !touchExplorationEnabled) {
            long time = System.currentTimeMillis();
            // long-pressed 'together'
            if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
                activityManager.stopLockTaskMode();
                return true;
            } else if (v.getId() == R.id.back) {
                // If we aren't pressing recents right now then they presses
                // won't be together, so send the standard long-press action.
                sendBackLongPress = true;
            }
            mLastLockToAppLongPress = time;
        } else {
            // If this is back still need to handle sending the long-press event.
            if (v.getId() == R.id.back) {
                sendBackLongPress = true;
            } else if (touchExplorationEnabled && inLockTaskMode) {
                // When in accessibility mode a long press that is recents (not back)
                // should stop lock task.
                activityManager.stopLockTaskMode();
                return true;
            } else if (v.getId() == R.id.recent_apps) {
                return handleLongPressRecents();
            }
        }
        if (sendBackLongPress) {
            KeyButtonView keyButtonView = (KeyButtonView) v;
            keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
            keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
            return true;
        }
    } catch (RemoteException e) {
        Log.d(TAG, "Unable to reach activity manager", e);
    }
    return false;
}
Also used : KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView) 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