Search in sources :

Example 11 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project android_frameworks_base by DirtyUnicorns.

the class ActivityManagerService method getTasks.

@Override
public List<RunningTaskInfo> getTasks(int maxNum, int flags) {
    final int callingUid = Binder.getCallingUid();
    ArrayList<RunningTaskInfo> list = new ArrayList<RunningTaskInfo>();
    synchronized (this) {
        if (DEBUG_ALL)
            Slog.v(TAG, "getTasks: max=" + maxNum + ", flags=" + flags);
        final boolean allowed = isGetTasksAllowed("getTasks", Binder.getCallingPid(), callingUid);
        // TODO: Improve with MRU list from all ActivityStacks.
        mStackSupervisor.getTasksLocked(maxNum, list, callingUid, allowed);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo) Point(android.graphics.Point)

Example 12 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project android_frameworks_base by DirtyUnicorns.

the class ActivityStack method getTasksLocked.

void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) {
    boolean focusedStack = mStackSupervisor.getFocusedStack() == this;
    boolean topTask = true;
    for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
        final TaskRecord task = mTaskHistory.get(taskNdx);
        if (task.getTopActivity() == null) {
            continue;
        }
        ActivityRecord r = null;
        ActivityRecord top = null;
        ActivityRecord tmp;
        int numActivities = 0;
        int numRunning = 0;
        final ArrayList<ActivityRecord> activities = task.mActivities;
        if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) {
            continue;
        }
        for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
            tmp = activities.get(activityNdx);
            if (tmp.finishing) {
                continue;
            }
            r = tmp;
            // Initialize state for next task if needed.
            if (top == null || (top.state == ActivityState.INITIALIZING)) {
                top = r;
                numActivities = numRunning = 0;
            }
            // Add 'r' into the current task.
            numActivities++;
            if (r.app != null && r.app.thread != null) {
                numRunning++;
            }
            if (DEBUG_ALL)
                Slog.v(TAG, r.intent.getComponent().flattenToShortString() + ": task=" + r.task);
        }
        RunningTaskInfo ci = new RunningTaskInfo();
        ci.id = task.taskId;
        ci.stackId = mStackId;
        ci.baseActivity = r.intent.getComponent();
        ci.topActivity = top.intent.getComponent();
        ci.lastActiveTime = task.lastActiveTime;
        if (focusedStack && topTask) {
            // Give the latest time to ensure foreground task can be sorted
            // at the first, because lastActiveTime of creating task is 0.
            // Only do this if the clock didn't run backwards, though.
            ci.lastActiveTime = Math.max(ci.lastActiveTime, System.currentTimeMillis());
            topTask = false;
        }
        if (top.task != null) {
            ci.description = top.task.lastDescription;
        }
        ci.numActivities = numActivities;
        ci.numRunning = numRunning;
        ci.isDockable = task.canGoInDockedStack();
        ci.resizeMode = task.mResizeMode;
        list.add(ci);
    }
}
Also used : RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo) Point(android.graphics.Point)

Example 13 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project UltimateAndroid by cymcsg.

the class PackageUtils method isTopActivity.

/**
     * whether the app whost package's name is packageName is on the top of the stack
     * <ul>
     * Attentions:
     * <li>You should add android.permission.GET_TASKS in manifest</li>
     * </ul>
     *
     * @param context
     * @param packageName
     * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
     * stack
     */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || !BasicUtils.judgeNotNull(packageName)) {
        return null;
    }
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (!BasicUtils.judgeNotNull(tasksInfo)) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : ActivityManager(android.app.ActivityManager) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 14 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project android_frameworks_base by crdroidandroid.

the class PipManager method isSettingsShown.

private boolean isSettingsShown() {
    List<RunningTaskInfo> runningTasks;
    try {
        runningTasks = mActivityManager.getTasks(1, 0);
        if (runningTasks == null || runningTasks.size() == 0) {
            return false;
        }
    } catch (RemoteException e) {
        Log.d(TAG, "Failed to detect top activity", e);
        return false;
    }
    ComponentName topActivity = runningTasks.get(0).topActivity;
    for (Pair<String, String> componentName : sSettingsPackageAndClassNamePairList) {
        String packageName = componentName.first;
        if (topActivity.getPackageName().equals(packageName)) {
            String className = componentName.second;
            if (className == null || topActivity.getClassName().equals(className)) {
                return true;
            }
        }
    }
    return false;
}
Also used : ComponentName(android.content.ComponentName) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo) RemoteException(android.os.RemoteException)

Example 15 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project android_frameworks_base by AOSPA.

the class PipManager method isSettingsShown.

private boolean isSettingsShown() {
    List<RunningTaskInfo> runningTasks;
    try {
        runningTasks = mActivityManager.getTasks(1, 0);
        if (runningTasks == null || runningTasks.size() == 0) {
            return false;
        }
    } catch (RemoteException e) {
        Log.d(TAG, "Failed to detect top activity", e);
        return false;
    }
    ComponentName topActivity = runningTasks.get(0).topActivity;
    for (Pair<String, String> componentName : sSettingsPackageAndClassNamePairList) {
        String packageName = componentName.first;
        if (topActivity.getPackageName().equals(packageName)) {
            String className = componentName.second;
            if (className == null || topActivity.getClassName().equals(className)) {
                return true;
            }
        }
    }
    return false;
}
Also used : ComponentName(android.content.ComponentName) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo) RemoteException(android.os.RemoteException)

Aggregations

RunningTaskInfo (android.app.ActivityManager.RunningTaskInfo)26 ActivityManager (android.app.ActivityManager)13 ComponentName (android.content.ComponentName)11 Point (android.graphics.Point)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 RemoteException (android.os.RemoteException)5 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 ResolveInfo (android.content.pm.ResolveInfo)1