Search in sources :

Example 11 with MutableBoolean

use of android.util.MutableBoolean in project android_frameworks_base by DirtyUnicorns.

the class EventBus method registerSubscriber.

/**
     * Registers a new subscriber.
     */
private void registerSubscriber(Object subscriber, int priority, MutableBoolean hasInterprocessEventsChangedOut) {
    // Fail immediately if we are being called from the non-main thread
    long callingThreadId = Thread.currentThread().getId();
    if (callingThreadId != mHandler.getLooper().getThread().getId()) {
        throw new RuntimeException("Can not register() a subscriber from a non-main thread.");
    }
    // Return immediately if this exact subscriber is already registered
    if (findRegisteredSubscriber(subscriber, false)) {
        return;
    }
    long t1 = 0;
    if (DEBUG_TRACE_ALL) {
        t1 = SystemClock.currentTimeMicro();
        logWithPid("registerSubscriber(" + subscriber.getClass().getSimpleName() + ")");
    }
    Subscriber sub = new Subscriber(subscriber, SystemClock.uptimeMillis());
    Class<?> subscriberType = subscriber.getClass();
    ArrayList<EventHandlerMethod> subscriberMethods = mSubscriberTypeMap.get(subscriberType);
    if (subscriberMethods != null) {
        if (DEBUG_TRACE_ALL) {
            logWithPid("Subscriber class type already registered");
        }
        // events
        for (EventHandlerMethod method : subscriberMethods) {
            ArrayList<EventHandler> eventTypeHandlers = mEventTypeMap.get(method.eventType);
            eventTypeHandlers.add(new EventHandler(sub, method, priority));
            sortEventHandlersByPriority(eventTypeHandlers);
        }
        mSubscribers.add(sub);
        return;
    } else {
        if (DEBUG_TRACE_ALL) {
            logWithPid("Subscriber class type requires registration");
        }
        // If we are parsing this type from scratch, ensure we add it to the subscriber type
        // map, and pull out he handler methods below
        subscriberMethods = new ArrayList<>();
        mSubscriberTypeMap.put(subscriberType, subscriberMethods);
        mSubscribers.add(sub);
    }
    // Find all the valid event bus handler methods of the subscriber
    MutableBoolean isInterprocessEvent = new MutableBoolean(false);
    Method[] methods = subscriberType.getDeclaredMethods();
    for (Method m : methods) {
        Class<?>[] parameterTypes = m.getParameterTypes();
        isInterprocessEvent.value = false;
        if (isValidEventBusHandlerMethod(m, parameterTypes, isInterprocessEvent)) {
            Class<? extends Event> eventType = (Class<? extends Event>) parameterTypes[0];
            ArrayList<EventHandler> eventTypeHandlers = mEventTypeMap.get(eventType);
            if (eventTypeHandlers == null) {
                eventTypeHandlers = new ArrayList<>();
                mEventTypeMap.put(eventType, eventTypeHandlers);
            }
            if (isInterprocessEvent.value) {
                try {
                    // Enforce that the event must have a Bundle constructor
                    eventType.getConstructor(Bundle.class);
                    mInterprocessEventNameMap.put(eventType.getName(), (Class<? extends InterprocessEvent>) eventType);
                    if (hasInterprocessEventsChangedOut != null) {
                        hasInterprocessEventsChangedOut.value = true;
                    }
                } catch (NoSuchMethodException e) {
                    throw new RuntimeException("Expected InterprocessEvent to have a Bundle constructor");
                }
            }
            EventHandlerMethod method = new EventHandlerMethod(m, eventType);
            EventHandler handler = new EventHandler(sub, method, priority);
            eventTypeHandlers.add(handler);
            subscriberMethods.add(method);
            sortEventHandlersByPriority(eventTypeHandlers);
            if (DEBUG_TRACE_ALL) {
                logWithPid("  * Method: " + m.getName() + " event: " + parameterTypes[0].getSimpleName() + " interprocess? " + isInterprocessEvent.value);
            }
        }
    }
    if (DEBUG_TRACE_ALL) {
        logWithPid("Registered " + subscriber.getClass().getSimpleName() + " in " + (SystemClock.currentTimeMicro() - t1) + " microseconds");
    }
}
Also used : MutableBoolean(android.util.MutableBoolean) Method(java.lang.reflect.Method)

Example 12 with MutableBoolean

use of android.util.MutableBoolean in project android_frameworks_base by DirtyUnicorns.

the class EventBus method registerInterprocessAsCurrentUser.

/**
     * Registers a subscriber to receive interprocess events with the given priority.
     *
     * @param subscriber the subscriber to handle events.  If this is the first instance of the
     *                   subscriber's class type that has been registered, the class's methods will
     *                   be scanned for appropriate event handler methods.
     * @param priority the priority that this subscriber will receive events relative to other
     *                 subscribers
     */
public void registerInterprocessAsCurrentUser(Context context, Object subscriber, int priority) {
    if (DEBUG_TRACE_ALL) {
        logWithPid("registerInterprocessAsCurrentUser(" + subscriber.getClass().getSimpleName() + ")");
    }
    // Register the subscriber normally, and update the broadcast receiver filter if this is
    // a new subscriber type with interprocess events
    MutableBoolean hasInterprocessEventsChanged = new MutableBoolean(false);
    registerSubscriber(subscriber, priority, hasInterprocessEventsChanged);
    if (DEBUG_TRACE_ALL) {
        logWithPid("hasInterprocessEventsChanged: " + hasInterprocessEventsChanged.value);
    }
    if (hasInterprocessEventsChanged.value) {
        registerReceiverForInterprocessEvents(context);
    }
}
Also used : MutableBoolean(android.util.MutableBoolean)

Example 13 with MutableBoolean

use of android.util.MutableBoolean in project android_frameworks_base by DirtyUnicorns.

the class BatteryStats method dumpCheckinLocked.

@SuppressWarnings("unused")
public void dumpCheckinLocked(Context context, PrintWriter pw, List<ApplicationInfo> apps, int flags, long histStart) {
    prepareForDumpLocked();
    dumpLine(pw, 0, /* uid */
    "i", /* category */
    VERSION_DATA, CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), getEndPlatformVersion());
    long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
    final boolean filtering = (flags & (DUMP_HISTORY_ONLY | DUMP_CHARGED_ONLY | DUMP_DAILY_ONLY)) != 0;
    if ((flags & DUMP_INCLUDE_HISTORY) != 0 || (flags & DUMP_HISTORY_ONLY) != 0) {
        if (startIteratingHistoryLocked()) {
            try {
                for (int i = 0; i < getHistoryStringPoolSize(); i++) {
                    pw.print(BATTERY_STATS_CHECKIN_VERSION);
                    pw.print(',');
                    pw.print(HISTORY_STRING_POOL);
                    pw.print(',');
                    pw.print(i);
                    pw.print(",");
                    pw.print(getHistoryTagPoolUid(i));
                    pw.print(",\"");
                    String str = getHistoryTagPoolString(i);
                    str = str.replace("\\", "\\\\");
                    str = str.replace("\"", "\\\"");
                    pw.print(str);
                    pw.print("\"");
                    pw.println();
                }
                dumpHistoryLocked(pw, flags, histStart, true);
            } finally {
                finishIteratingHistoryLocked();
            }
        }
    }
    if (filtering && (flags & (DUMP_CHARGED_ONLY | DUMP_DAILY_ONLY)) == 0) {
        return;
    }
    if (apps != null) {
        SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
        for (int i = 0; i < apps.size(); i++) {
            ApplicationInfo ai = apps.get(i);
            Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(UserHandle.getAppId(ai.uid));
            if (pkgs == null) {
                pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
                uids.put(UserHandle.getAppId(ai.uid), pkgs);
            }
            pkgs.first.add(ai.packageName);
        }
        SparseArray<? extends Uid> uidStats = getUidStats();
        final int NU = uidStats.size();
        String[] lineArgs = new String[2];
        for (int i = 0; i < NU; i++) {
            int uid = UserHandle.getAppId(uidStats.keyAt(i));
            Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
            if (pkgs != null && !pkgs.second.value) {
                pkgs.second.value = true;
                for (int j = 0; j < pkgs.first.size(); j++) {
                    lineArgs[0] = Integer.toString(uid);
                    lineArgs[1] = pkgs.first.get(j);
                    dumpLine(pw, 0, /* uid */
                    "i", /* category */
                    UID_DATA, (Object[]) lineArgs);
                }
            }
        }
    }
    if (!filtering || (flags & DUMP_CHARGED_ONLY) != 0) {
        dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
        String[] lineArgs = new String[1];
        long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
        if (timeRemaining >= 0) {
            lineArgs[0] = Long.toString(timeRemaining);
            dumpLine(pw, 0, /* uid */
            "i", /* category */
            DISCHARGE_TIME_REMAIN_DATA, (Object[]) lineArgs);
        }
        dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
        timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
        if (timeRemaining >= 0) {
            lineArgs[0] = Long.toString(timeRemaining);
            dumpLine(pw, 0, /* uid */
            "i", /* category */
            CHARGE_TIME_REMAIN_DATA, (Object[]) lineArgs);
        }
        dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, (flags & DUMP_DEVICE_WIFI_ONLY) != 0);
    }
}
Also used : MutableBoolean(android.util.MutableBoolean) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) SparseArray(android.util.SparseArray) LongSparseArray(android.util.LongSparseArray) Pair(android.util.Pair)

Example 14 with MutableBoolean

use of android.util.MutableBoolean in project android_frameworks_base by AOSPA.

the class RecentsImpl method preloadRecents.

public void preloadRecents() {
    // Preload only the raw task list into a new load plan (which will be consumed by the
    // RecentsActivity) only if there is a task to animate to.
    SystemServicesProxy ssp = Recents.getSystemServices();
    MutableBoolean isHomeStackVisible = new MutableBoolean(true);
    if (!ssp.isRecentsActivityVisible(isHomeStackVisible)) {
        ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask();
        RecentsTaskLoader loader = Recents.getTaskLoader();
        sInstanceLoadPlan = loader.createLoadPlan(mContext);
        sInstanceLoadPlan.preloadRawTasks(!isHomeStackVisible.value);
        loader.preloadTasks(sInstanceLoadPlan, runningTask.id, !isHomeStackVisible.value);
        TaskStack stack = sInstanceLoadPlan.getTaskStack();
        if (stack.getTaskCount() > 0) {
            // Only preload the icon (but not the thumbnail since it may not have been taken for
            // the pausing activity)
            preloadIcon(runningTask.id);
            // At this point, we don't know anything about the stack state.  So only calculate
            // the dimensions of the thumbnail that we need for the transition into Recents, but
            // do not draw it until we construct the activity options when we start Recents
            updateHeaderBarLayout(stack, null);
        }
    }
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) TaskStack(com.android.systemui.recents.model.TaskStack) MutableBoolean(android.util.MutableBoolean) RecentsTaskLoader(com.android.systemui.recents.model.RecentsTaskLoader) ActivityManager(android.app.ActivityManager)

Example 15 with MutableBoolean

use of android.util.MutableBoolean in project android_frameworks_base by AOSPA.

the class RecentsImpl method showRecents.

public void showRecents(boolean triggeredFromAltTab, boolean draggingInRecents, boolean animate, boolean launchedWhileDockingTask, boolean fromHome, int growTarget) {
    mTriggeredFromAltTab = triggeredFromAltTab;
    mDraggingInRecents = draggingInRecents;
    mLaunchedWhileDocking = launchedWhileDockingTask;
    if (mFastAltTabTrigger.isAsleep()) {
        // Fast alt-tab duration has elapsed, fall through to showing Recents and reset
        mFastAltTabTrigger.stopDozing();
    } else if (mFastAltTabTrigger.isDozing()) {
        //       is inversely proportional to the FAST_ALT_TAB_DELAY_MS duration though.
        if (!triggeredFromAltTab) {
            return;
        }
        mFastAltTabTrigger.stopDozing();
    } else if (triggeredFromAltTab) {
        // The fast alt-tab detector is not yet running, so start the trigger and wait for the
        // hideRecents() call, or for the fast alt-tab duration to elapse
        mFastAltTabTrigger.startDozing();
        return;
    }
    try {
        // Check if the top task is in the home stack, and start the recents activity
        SystemServicesProxy ssp = Recents.getSystemServices();
        boolean forceVisible = launchedWhileDockingTask || draggingInRecents;
        MutableBoolean isHomeStackVisible = new MutableBoolean(forceVisible);
        if (forceVisible || !ssp.isRecentsActivityVisible(isHomeStackVisible)) {
            ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask();
            startRecentsActivity(runningTask, isHomeStackVisible.value || fromHome, animate, growTarget);
        }
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Failed to launch RecentsActivity", e);
    }
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) ActivityNotFoundException(android.content.ActivityNotFoundException) MutableBoolean(android.util.MutableBoolean) ActivityManager(android.app.ActivityManager)

Aggregations

MutableBoolean (android.util.MutableBoolean)38 ActivityManager (android.app.ActivityManager)15 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)15 ActivityNotFoundException (android.content.ActivityNotFoundException)10 ApplicationInfo (android.content.pm.ApplicationInfo)5 LongSparseArray (android.util.LongSparseArray)5 Pair (android.util.Pair)5 SparseArray (android.util.SparseArray)5 ViewParent (android.view.ViewParent)5 IterateRecentsEvent (com.android.systemui.recents.events.activity.IterateRecentsEvent)5 LaunchNextTaskRequestEvent (com.android.systemui.recents.events.activity.LaunchNextTaskRequestEvent)5 ToggleRecentsEvent (com.android.systemui.recents.events.activity.ToggleRecentsEvent)5 RecentsTaskLoader (com.android.systemui.recents.model.RecentsTaskLoader)5 Task (com.android.systemui.recents.model.Task)5 TaskStack (com.android.systemui.recents.model.TaskStack)5 Method (java.lang.reflect.Method)5 ArrayList (java.util.ArrayList)5 LaunchMostRecentTaskRequestEvent (com.android.systemui.recents.events.activity.LaunchMostRecentTaskRequestEvent)4 CursorWindow (android.database.CursorWindow)1 DbStats (android.database.sqlite.SQLiteDebug.DbStats)1