Search in sources :

Example 6 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project platform_frameworks_base by android.

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

use of android.app.ActivityManager.RunningTaskInfo in project platform_frameworks_base by android.

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.
            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 8 with RunningTaskInfo

use of android.app.ActivityManager.RunningTaskInfo in project Lazy by l123456789jy.

the class AppUtils method isApplicationInBackground.

/**
     * whether application is in background
     * <ul>
     * <li>need use permission android.permission.GET_TASKS in Manifest.xml</li>
     * </ul>
     *
     * @param context 上下文
     * @return if application is in background return true, otherwise return
     * false
     */
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)

Example 9 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 10 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)

Aggregations

RunningTaskInfo (android.app.ActivityManager.RunningTaskInfo)25 ActivityManager (android.app.ActivityManager)12 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