Search in sources :

Example 21 with RunningTaskInfo

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

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.
            long currentTime = System.currentTimeMillis();
            // This FIXes the recents app not launching issue.
            if (ci.lastActiveTime < currentTime) {
                ci.lastActiveTime = currentTime;
            }
            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 22 with RunningTaskInfo

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

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 23 with RunningTaskInfo

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

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 24 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project LshUtils by SenhLinsh.

the class PackageUtils method isTopActivity.

/**
     * 判断应用是否在栈顶
     * <ul>
     * <strong>注意:</strong>
     * <li>你应用在清单文件中添加权限 <strong>android.permission.GET_TASKS</strong> </li>
     * </ul>
     * 
     * @param context
     * @param packageName
     * @return 如果参数为null或者任务为null,返回null,其他返回是否在栈顶
     */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || StringUtils.isEmpty(packageName)) {
        return null;
    }
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (ListUtils.isEmpty(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 25 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project LshUtils by SenhLinsh.

the class AppUtils method isApplicationInBackground.

/**
     * 判断应用是否正在后台运行
     * <ul>
     * <li>需要在清单文件添加权限: android.permission.GET_TASKS</li>
     * </ul>
     */
public static boolean isApplicationInBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskList = am.getRunningTasks(1);
    if (taskList != null && !taskList.isEmpty()) {
        ComponentName topActivity = taskList.get(0).topActivity;
        if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }
    }
    return false;
}
Also used : ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo)

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