Java Code Examples for org.chromium.chrome.browser.document.DocumentUtils#getTaskInfoFromTask()

The following examples show how to use org.chromium.chrome.browser.document.DocumentUtils#getTaskInfoFromTask() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncognitoNotificationService.java    From delion with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = getPackageManager();

    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        String className = DocumentUtils.getTaskClassName(task, pm);

        // It is not easily possible to distinguish between tasks sitting on top of
        // ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
        // close them to be on the cautious side of things.
        if ((TextUtils.equals(className, ChromeTabbedActivity.class.getName())
                || TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
                && !visibleTaskIds.contains(info.id)) {
            task.finishAndRemoveTask();
        }
    }
}
 
Example 2
Source File: IncognitoNotificationService.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = getPackageManager();

    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        String className = DocumentUtils.getTaskClassName(task, pm);

        // It is not easily possible to distinguish between tasks sitting on top of
        // ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
        // close them to be on the cautious side of things.
        if ((TextUtils.equals(className, ChromeTabbedActivity.class.getName())
                || TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
                && !visibleTaskIds.contains(info.id)) {
            task.finishAndRemoveTask();
        }
    }
}
 
Example 3
Source File: IncognitoNotificationService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = getPackageManager();

    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        String className = DocumentUtils.getTaskClassName(task, pm);

        // It is not easily possible to distinguish between tasks sitting on top of
        // ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
        // close them to be on the cautious side of things.
        if ((ChromeTabbedActivity.isTabbedModeClassName(className)
                || TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
                && !visibleTaskIds.contains(info.id)) {
            task.finishAndRemoveTask();
        }
    }
}
 
Example 4
Source File: DocumentTabModelSelector.java    From delion with Apache License 2.0 5 votes vote down vote up
private int getLargestTaskIdFromRecents() {
    int biggestId = Tab.INVALID_TAB_ID;
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        biggestId = Math.max(biggestId, info.persistentId);
    }
    return biggestId;
}
 
Example 5
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private boolean isMergedInstanceTaskRunning() {
    if (!FeatureUtilities.isTabModelMergingEnabled() || sMergedInstanceTaskId == 0) {
        return false;
    }

    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        if (info.id == sMergedInstanceTaskId) return true;
    }
    return false;
}
 
Example 6
Source File: DocumentTabModelSelector.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private int getLargestTaskIdFromRecents() {
    int biggestId = Tab.INVALID_TAB_ID;
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        biggestId = Math.max(biggestId, info.persistentId);
    }
    return biggestId;
}
 
Example 7
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private boolean isMergedInstanceTaskRunning() {
    if (!FeatureUtilities.isTabModelMergingEnabled() || sMergedInstanceTaskId == 0) {
        return false;
    }

    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        if (info.id == sMergedInstanceTaskId) return true;
    }
    return false;
}
 
Example 8
Source File: DocumentTabModelSelector.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private int getLargestTaskIdFromRecents() {
    int biggestId = Tab.INVALID_TAB_ID;
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        biggestId = Math.max(biggestId, info.persistentId);
    }
    return biggestId;
}
 
Example 9
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Determine whether the incognito profile needs to be destroyed as part of startup.  This is
 * only needed on L+ when it is possible to swipe away tasks from Android recents without
 * killing the process.  When this occurs, the normal incognito profile shutdown does not
 * happen, which can leave behind incognito cookies from an existing session.
 */
@SuppressLint("NewApi")
private boolean shouldDestroyIncognitoProfile() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return false;

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = context.getPackageManager();

    Set<Integer> tabbedModeTaskIds = new HashSet<>();
    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        String className = DocumentUtils.getTaskClassName(task, pm);

        if (isTabbedModeClassName(className)) {
            tabbedModeTaskIds.add(info.id);
        }
    }

    if (tabbedModeTaskIds.size() == 0) {
        return Profile.getLastUsedProfile().hasOffTheRecordProfile();
    }

    List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
    for (int i = 0; i < activities.size(); i++) {
        Activity activity = activities.get(i).get();
        if (activity == null) continue;
        tabbedModeTaskIds.remove(activity.getTaskId());
    }

    // If all tabbed mode tasks listed in Android recents are alive, check to see if
    // any have incognito tabs exist.  If all are alive and no tabs exist, we should ensure that
    // we delete the incognito profile if one is around still.
    if (tabbedModeTaskIds.size() == 0) {
        return TabWindowManager.getInstance().canDestroyIncognitoProfile()
                && Profile.getLastUsedProfile().hasOffTheRecordProfile();
    }

    // In this case, we have tabbed mode activities listed in recents that do not have an
    // active running activity associated with them.  We can not accurately get an incognito
    // tab count as we do not know if any incognito tabs are associated with the yet unrestored
    // tabbed mode.  Thus we do not proactivitely destroy the incognito profile.
    return false;
}