android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS源码实例Demo

下面列出了android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: RecentTasks.java
/**
 * @return whether the given visible task is within the policy range.
 */
private boolean isInVisibleRange(TaskRecord task, int numVisibleTasks) {
    // Keep the last most task even if it is excluded from recents
    final boolean isExcludeFromRecents =
            (task.getBaseIntent().getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
                    == Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
    if (isExcludeFromRecents) {
        if (DEBUG_RECENTS_TRIM_TASKS) Slog.d(TAG, "\texcludeFromRecents=true");
        return numVisibleTasks == 1;
    }

    if (mMinNumVisibleTasks >= 0 && numVisibleTasks <= mMinNumVisibleTasks) {
        // Always keep up to the min number of recent tasks, after that fall through to the
        // checks below
        return true;
    }

    if (mMaxNumVisibleTasks >= 0) {
        // Always keep up to the max number of recent tasks, but return false afterwards
        return numVisibleTasks <= mMaxNumVisibleTasks;
    }

    if (mActiveTasksSessionDurationMs > 0) {
        // Keep the task if the inactive time is within the session window, this check must come
        // after the checks for the min/max visible task range
        if (task.getInactiveDuration() <= mActiveTasksSessionDurationMs) {
            return true;
        }
    }

    return false;
}
 
源代码2 项目: android_9.0.0_r45   文件: TaskRecord.java
void setRootProcess(ProcessRecord proc) {
    clearRootProcess();
    if (intent != null &&
            (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0) {
        mRootProcess = proc;
        proc.recentTasks.add(this);
    }
}
 
源代码3 项目: OPFIab   文件: OPFIabActivity.java
/**
 * Start new instance of this activity.
 *
 * @param context Can't be null. Context object witch will be used to start new instance of
 *                {@link OPFIabActivity}. If passed object is not <code>instanceof</code>
 *                {@link Activity}, new activity will be started with
 *                {@link Intent#FLAG_ACTIVITY_NEW_TASK} flag.
 */
public static void start(@NonNull final Context context) {
    final Intent intent = new Intent(context, OPFIabActivity.class);
    final int flags = Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
            | Intent.FLAG_ACTIVITY_NO_ANIMATION;
    if (context instanceof Activity) {
        intent.setFlags(flags);
    } else {
        intent.setFlags(flags | Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    OPFLog.d("Starting OPFIabActivity with " + context + " as context");
    context.startActivity(intent);
}
 
源代码4 项目: android_9.0.0_r45   文件: RecentTasks.java
/**
 * @return the list of recent tasks for presentation.
 */
ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags,
        boolean getTasksAllowed, boolean getDetailedTasks, int userId, int callingUid) {
    final boolean withExcluded = (flags & RECENT_WITH_EXCLUDED) != 0;

    if (!mService.isUserRunning(userId, FLAG_AND_UNLOCKED)) {
        Slog.i(TAG, "user " + userId + " is still locked. Cannot load recents");
        return ParceledListSlice.emptyList();
    }
    loadUserRecentsLocked(userId);

    final Set<Integer> includedUsers = mUserController.getProfileIds(userId);
    includedUsers.add(Integer.valueOf(userId));

    final ArrayList<ActivityManager.RecentTaskInfo> res = new ArrayList<>();
    final int size = mTasks.size();
    int numVisibleTasks = 0;
    for (int i = 0; i < size; i++) {
        final TaskRecord tr = mTasks.get(i);

        if (isVisibleRecentTask(tr)) {
            numVisibleTasks++;
            if (isInVisibleRange(tr, numVisibleTasks)) {
                // Fall through
            } else {
                // Not in visible range
                continue;
            }
        } else {
            // Not visible
            continue;
        }

        // Skip remaining tasks once we reach the requested size
        if (res.size() >= maxNum) {
            continue;
        }

        // Only add calling user or related users recent tasks
        if (!includedUsers.contains(Integer.valueOf(tr.userId))) {
            if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Skipping, not user: " + tr);
            continue;
        }

        if (tr.realActivitySuspended) {
            if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Skipping, activity suspended: " + tr);
            continue;
        }

        // Return the entry if desired by the caller.  We always return
        // the first entry, because callers always expect this to be the
        // foreground app.  We may filter others if the caller has
        // not supplied RECENT_WITH_EXCLUDED and there is some reason
        // we should exclude the entry.

        if (i == 0
                || withExcluded
                || (tr.intent == null)
                || ((tr.intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
                == 0)) {
            if (!getTasksAllowed) {
                // If the caller doesn't have the GET_TASKS permission, then only
                // allow them to see a small subset of tasks -- their own and home.
                if (!tr.isActivityTypeHome() && tr.effectiveUid != callingUid) {
                    if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "Skipping, not allowed: " + tr);
                    continue;
                }
            }
            if (tr.autoRemoveRecents && tr.getTopActivity() == null) {
                // Don't include auto remove tasks that are finished or finishing.
                if (DEBUG_RECENTS) Slog.d(TAG_RECENTS,
                        "Skipping, auto-remove without activity: " + tr);
                continue;
            }
            if ((flags & RECENT_IGNORE_UNAVAILABLE) != 0 && !tr.isAvailable) {
                if (DEBUG_RECENTS) Slog.d(TAG_RECENTS,
                        "Skipping, unavail real act: " + tr);
                continue;
            }

            if (!tr.mUserSetupComplete) {
                // Don't include task launched while user is not done setting-up.
                if (DEBUG_RECENTS) Slog.d(TAG_RECENTS,
                        "Skipping, user setup not complete: " + tr);
                continue;
            }

            final ActivityManager.RecentTaskInfo rti = createRecentTaskInfo(tr);
            if (!getDetailedTasks) {
                rti.baseIntent.replaceExtras((Bundle)null);
            }

            res.add(rti);
        }
    }
    return new ParceledListSlice<>(res);
}
 
源代码5 项目: android_9.0.0_r45   文件: RecentTasks.java
/**
 * @return whether the given active task should be presented to the user through SystemUI.
 */
private boolean isVisibleRecentTask(TaskRecord task) {
    if (DEBUG_RECENTS_TRIM_TASKS) Slog.d(TAG, "isVisibleRecentTask: task=" + task
            + " minVis=" + mMinNumVisibleTasks + " maxVis=" + mMaxNumVisibleTasks
            + " sessionDuration=" + mActiveTasksSessionDurationMs
            + " inactiveDuration=" + task.getInactiveDuration()
            + " activityType=" + task.getActivityType()
            + " windowingMode=" + task.getWindowingMode()
            + " intentFlags=" + task.getBaseIntent().getFlags());

    switch (task.getActivityType()) {
        case ACTIVITY_TYPE_HOME:
        case ACTIVITY_TYPE_RECENTS:
            // Ignore certain activity types completely
            return false;
        case ACTIVITY_TYPE_ASSISTANT:
            // Ignore assistant that chose to be excluded from Recents, even if it's a top
            // task.
            if ((task.getBaseIntent().getFlags()
                    & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
                    == Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) {
                return false;
            }
    }

    // Ignore certain windowing modes
    switch (task.getWindowingMode()) {
        case WINDOWING_MODE_PINNED:
            return false;
        case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY:
            if (DEBUG_RECENTS_TRIM_TASKS) Slog.d(TAG, "\ttop=" + task.getStack().topTask());
            final ActivityStack stack = task.getStack();
            if (stack != null && stack.topTask() == task) {
                // Only the non-top task of the primary split screen mode is visible
                return false;
            }
    }

    // If we're in lock task mode, ignore the root task
    if (task == mService.getLockTaskController().getRootTask()) {
        return false;
    }

    return true;
}
 
 方法所在类
 同类方法