org.chromium.chrome.browser.document.DocumentUtils Java Examples

The following examples show how to use org.chromium.chrome.browser.document.DocumentUtils. 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: DocumentTabModelImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a DocumentTabModel.
 * @param activityDelegate Delegate to use for accessing the ActivityManager.
 * @param storageDelegate Delegate to use for accessing persistent storage.
 * @param tabCreatorManager Used to create Tabs.
 * @param isIncognito Whether or not the TabList is managing incognito tabs.
 * @param prioritizedTabId ID of the tab to prioritize when loading.
 * @param context Context to use for accessing SharedPreferences.
 */
public DocumentTabModelImpl(ActivityDelegate activityDelegate, StorageDelegate storageDelegate,
        TabCreatorManager tabCreatorManager, boolean isIncognito, int prioritizedTabId,
        Context context) {
    super(isIncognito);
    mActivityDelegate = activityDelegate;
    mStorageDelegate = storageDelegate;
    mContext = context;

    mCurrentState = STATE_UNINITIALIZED;
    mTabIdList = new ArrayList<Integer>();
    mEntryMap = new SparseArray<Entry>();
    mHistoricalTabs = new ArrayList<Integer>();

    mLastShownTabId = DocumentUtils.getLastShownTabIdFromPrefs(mContext, isIncognito());

    // Restore the tab list.
    setCurrentState(STATE_READ_RECENT_TASKS_START);
    mStorageDelegate.restoreTabEntries(
            isIncognito, activityDelegate, mEntryMap, mTabIdList, mHistoricalTabs);
    setCurrentState(STATE_READ_RECENT_TASKS_END);
}
 
Example #2
Source File: ActivityDelegateImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public List<Entry> getTasksFromRecents(boolean isIncognito) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<Entry> entries = new ArrayList<Entry>();
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (!isValidActivity(isIncognito, intent)) continue;

        int tabId = getTabIdFromIntent(intent);
        if (tabId == Tab.INVALID_TAB_ID) continue;

        String initialUrl = getInitialUrlForDocument(intent);
        entries.add(new Entry(tabId, initialUrl));
    }
    return entries;
}
 
Example #3
Source File: DocumentModeAssassin.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Kicks off tasks for the new state of the pipeline.
 *
 * We don't wait for the DocumentTabModel to finish parsing its metadata file before proceeding
 * with migration because it doesn't have actionable information:
 *
 * 1) WE DON'T NEED TO RE-POPULATE THE "RECENTLY CLOSED" LIST:
 *    The metadata file contains a list of tabs Chrome knew about before it died, which
 *    could differ from the list of tabs in Android Overview.  The canonical list of
 *    live tabs, however, has always been the ones displayed by the Android Overview.
 *
 * 2) RETARGETING MIGRATED TABS FROM THE HOME SCREEN IS A CORNER CASE:
 *    The only downside here is that Chrome ends up creating a new tab for a home screen
 *    shortcut the first time they start Chrome after migration.  This was already
 *    broken for document mode during cold starts, anyway.
 */
private final void startStage(int newStage) {
    ThreadUtils.assertOnUiThread();
    if (!mIsPipelineActive) return;

    if (newStage == STAGE_INITIALIZED) {
        Log.d(TAG, "Migrating user into tabbed mode.");
        int selectedTabId = DocumentUtils.getLastShownTabIdFromPrefs(getContext(), false);
        copyTabStateFiles(selectedTabId);
    } else if (newStage == STAGE_COPY_TAB_STATES_DONE) {
        Log.d(TAG, "Writing tabbed mode metadata file.");
        writeTabModelMetadata(mMigratedTabIds);
    } else if (newStage == STAGE_WRITE_TABMODEL_METADATA_DONE) {
        Log.d(TAG, "Changing user preference.");
        switchToTabbedMode();
    } else if (newStage == STAGE_CHANGE_SETTINGS_DONE) {
        Log.d(TAG, "Cleaning up document mode data.");
        deleteDocumentModeData();
    }
}
 
Example #4
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 #5
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 #6
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 #7
Source File: WebappActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onResume() {
    if (!isFinishing()) {
        if (getIntent() != null) {
            // Avoid situations where Android starts two Activities with the same data.
            DocumentUtils.finishOtherTasksWithData(getIntent().getData(), getTaskId());
        }
        updateTaskDescription();
    }
    super.onResume();

    // Kick off the old web app cleanup (if we haven't already) now that we have queued the
    // current web app's storage to be opened.
    if (!mOldWebappCleanupStarted) {
        WebappRegistry.unregisterOldWebapps(this, System.currentTimeMillis());
        mOldWebappCleanupStarted = true;
    }
}
 
Example #8
Source File: DocumentModeAssassin.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Kicks off tasks for the new state of the pipeline.
 *
 * We don't wait for the DocumentTabModel to finish parsing its metadata file before proceeding
 * with migration because it doesn't have actionable information:
 *
 * 1) WE DON'T NEED TO RE-POPULATE THE "RECENTLY CLOSED" LIST:
 *    The metadata file contains a list of tabs Chrome knew about before it died, which
 *    could differ from the list of tabs in Android Overview.  The canonical list of
 *    live tabs, however, has always been the ones displayed by the Android Overview.
 *
 * 2) RETARGETING MIGRATED TABS FROM THE HOME SCREEN IS A CORNER CASE:
 *    The only downside here is that Chrome ends up creating a new tab for a home screen
 *    shortcut the first time they start Chrome after migration.  This was already
 *    broken for document mode during cold starts, anyway.
 */
private final void startStage(int newStage) {
    ThreadUtils.assertOnUiThread();
    if (!mIsPipelineActive) return;

    if (newStage == STAGE_INITIALIZED) {
        Log.d(TAG, "Migrating user into tabbed mode.");
        int selectedTabId = DocumentUtils.getLastShownTabIdFromPrefs(getContext(), false);
        copyTabStateFiles(selectedTabId);
    } else if (newStage == STAGE_COPY_TAB_STATES_DONE) {
        Log.d(TAG, "Writing tabbed mode metadata file.");
        writeTabModelMetadata(mMigratedTabIds);
    } else if (newStage == STAGE_WRITE_TABMODEL_METADATA_DONE) {
        Log.d(TAG, "Changing user preference.");
        switchToTabbedMode();
    } else if (newStage == STAGE_CHANGE_SETTINGS_DONE) {
        Log.d(TAG, "Cleaning up document mode data.");
        deleteDocumentModeData();
    }
}
 
Example #9
Source File: DocumentTabModelImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a DocumentTabModel.
 * @param activityDelegate Delegate to use for accessing the ActivityManager.
 * @param storageDelegate Delegate to use for accessing persistent storage.
 * @param tabCreatorManager Used to create Tabs.
 * @param isIncognito Whether or not the TabList is managing incognito tabs.
 * @param prioritizedTabId ID of the tab to prioritize when loading.
 * @param context Context to use for accessing SharedPreferences.
 */
public DocumentTabModelImpl(ActivityDelegate activityDelegate, StorageDelegate storageDelegate,
        TabCreatorManager tabCreatorManager, boolean isIncognito, int prioritizedTabId,
        Context context) {
    super(isIncognito, false);
    mActivityDelegate = activityDelegate;
    mStorageDelegate = storageDelegate;
    mContext = context;

    mCurrentState = STATE_UNINITIALIZED;
    mTabIdList = new ArrayList<Integer>();
    mEntryMap = new SparseArray<Entry>();
    mHistoricalTabs = new ArrayList<Integer>();

    mLastShownTabId = DocumentUtils.getLastShownTabIdFromPrefs(mContext, isIncognito());

    // Restore the tab list.
    setCurrentState(STATE_READ_RECENT_TASKS_START);
    mStorageDelegate.restoreTabEntries(
            isIncognito, activityDelegate, mEntryMap, mTabIdList, mHistoricalTabs);
    setCurrentState(STATE_READ_RECENT_TASKS_END);
}
 
Example #10
Source File: DocumentModeAssassin.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Kicks off tasks for the new state of the pipeline.
 *
 * We don't wait for the DocumentTabModel to finish parsing its metadata file before proceeding
 * with migration because it doesn't have actionable information:
 *
 * 1) WE DON'T NEED TO RE-POPULATE THE "RECENTLY CLOSED" LIST:
 *    The metadata file contains a list of tabs Chrome knew about before it died, which
 *    could differ from the list of tabs in Android Overview.  The canonical list of
 *    live tabs, however, has always been the ones displayed by the Android Overview.
 *
 * 2) RETARGETING MIGRATED TABS FROM THE HOME SCREEN IS A CORNER CASE:
 *    The only downside here is that Chrome ends up creating a new tab for a home screen
 *    shortcut the first time they start Chrome after migration.  This was already
 *    broken for document mode during cold starts, anyway.
 */
private final void startStage(int newStage) {
    ThreadUtils.assertOnUiThread();
    if (!mIsPipelineActive) return;

    if (newStage == STAGE_INITIALIZED) {
        Log.d(TAG, "Migrating user into tabbed mode.");
        int selectedTabId = DocumentUtils.getLastShownTabIdFromPrefs(getContext(), false);
        copyTabStateFiles(selectedTabId);
    } else if (newStage == STAGE_COPY_TAB_STATES_DONE) {
        Log.d(TAG, "Writing tabbed mode metadata file.");
        writeTabModelMetadata(mMigratedTabIds);
    } else if (newStage == STAGE_WRITE_TABMODEL_METADATA_DONE) {
        Log.d(TAG, "Changing user preference.");
        switchToTabbedMode();
    } else if (newStage == STAGE_CHANGE_SETTINGS_DONE) {
        Log.d(TAG, "Cleaning up document mode data.");
        deleteDocumentModeData();
    }
}
 
Example #11
Source File: DocumentTabModelImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a DocumentTabModel.
 * @param activityDelegate Delegate to use for accessing the ActivityManager.
 * @param storageDelegate Delegate to use for accessing persistent storage.
 * @param tabCreatorManager Used to create Tabs.
 * @param isIncognito Whether or not the TabList is managing incognito tabs.
 * @param prioritizedTabId ID of the tab to prioritize when loading.
 * @param context Context to use for accessing SharedPreferences.
 */
public DocumentTabModelImpl(ActivityDelegate activityDelegate, StorageDelegate storageDelegate,
        TabCreatorManager tabCreatorManager, boolean isIncognito, int prioritizedTabId,
        Context context) {
    super(isIncognito, false);
    mActivityDelegate = activityDelegate;
    mStorageDelegate = storageDelegate;
    mContext = context;

    mCurrentState = STATE_UNINITIALIZED;
    mTabIdList = new ArrayList<Integer>();
    mEntryMap = new SparseArray<Entry>();
    mHistoricalTabs = new ArrayList<Integer>();

    mLastShownTabId = DocumentUtils.getLastShownTabIdFromPrefs(mContext, isIncognito());

    // Restore the tab list.
    setCurrentState(STATE_READ_RECENT_TASKS_START);
    mStorageDelegate.restoreTabEntries(
            isIncognito, activityDelegate, mEntryMap, mTabIdList, mHistoricalTabs);
    setCurrentState(STATE_READ_RECENT_TASKS_END);
}
 
Example #12
Source File: ActivityDelegateImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public List<Entry> getTasksFromRecents(boolean isIncognito) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<Entry> entries = new ArrayList<Entry>();
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (!isValidActivity(isIncognito, intent)) continue;

        int tabId = getTabIdFromIntent(intent);
        if (tabId == Tab.INVALID_TAB_ID) continue;

        String initialUrl = getInitialUrlForDocument(intent);
        entries.add(new Entry(tabId, initialUrl));
    }
    return entries;
}
 
Example #13
Source File: ActivityDelegateImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public List<Entry> getTasksFromRecents(boolean isIncognito) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<Entry> entries = new ArrayList<Entry>();
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (!isValidActivity(isIncognito, intent)) continue;

        int tabId = getTabIdFromIntent(intent);
        if (tabId == Tab.INVALID_TAB_ID) continue;

        String initialUrl = getInitialUrlForDocument(intent);
        entries.add(new Entry(tabId, initialUrl));
    }
    return entries;
}
 
Example #14
Source File: WebappDirectoryManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Returns a Set of Intents for all Chrome tasks currently known by the ActivityManager. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected Set<Intent> getBaseIntentsForAllTasks() {
    Set<Intent> baseIntents = new HashSet<Intent>();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (AppTask task : manager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (intent != null) baseIntents.add(intent);
    }

    return baseIntents;
}
 
Example #15
Source File: WebappDirectoryManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Returns a Set of Intents for all Chrome tasks currently known by the ActivityManager. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected Set<Intent> getBaseIntentsForAllTasks() {
    Set<Intent> baseIntents = new HashSet<Intent>();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (AppTask task : manager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (intent != null) baseIntents.add(intent);
    }

    return baseIntents;
}
 
Example #16
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 #17
Source File: ActivityDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private ActivityManager.AppTask getTask(boolean isIncognito, int tabId) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        int taskId = getTabIdFromIntent(intent);
        if (taskId == tabId && isValidActivity(isIncognito, intent)) return task;
    }
    return null;
}
 
Example #18
Source File: ActivityDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isIncognitoDocumentAccessibleToUser() {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (isValidActivity(true, intent)) return true;
    }
    return false;
}
 
Example #19
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 #20
Source File: ActivityDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Finishes all DocumentActivities that appear in Android's Recents.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void finishAllDocumentActivities() {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (isValidActivity(false, intent) || isValidActivity(true, intent)) {
            task.finishAndRemoveTask();
        }
    }
}
 
Example #21
Source File: TabWebContentsDelegateAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** If the API allows it, returns whether a Task still exists for the parent Activity. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean isParentInAndroidOverview() {
    ActivityManager activityManager = (ActivityManager) mTab.getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task);
        if (taskIntent != null && taskIntent.filterEquals(mTab.getParentIntent())) {
            return true;
        }
    }
    return false;
}
 
Example #22
Source File: WebappActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    if (!isFinishing()) {
        if (getIntent() != null) {
            // Avoid situations where Android starts two Activities with the same data.
            DocumentUtils.finishOtherTasksWithData(getIntent().getData(), getTaskId());
        }
        updateTaskDescription();
    }
    super.onResume();
}
 
Example #23
Source File: WebappActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    if (!isFinishing()) {
        if (getIntent() != null) {
            // Avoid situations where Android starts two Activities with the same data.
            DocumentUtils.finishOtherTasksWithData(getIntent().getData(), getTaskId());
        }
        updateTaskDescription();
    }
    super.onResume();
}
 
Example #24
Source File: TabWebContentsDelegateAndroid.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** If the API allows it, returns whether a Task still exists for the parent Activity. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean isParentInAndroidOverview() {
    ActivityManager activityManager = (ActivityManager) mTab.getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task);
        if (taskIntent != null && taskIntent.filterEquals(mTab.getParentIntent())) {
            return true;
        }
    }
    return false;
}
 
Example #25
Source File: ActivityDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Finishes all DocumentActivities that appear in Android's Recents.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void finishAllDocumentActivities() {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (isValidActivity(false, intent) || isValidActivity(true, intent)) {
            task.finishAndRemoveTask();
        }
    }
}
 
Example #26
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 #27
Source File: ActivityDelegateImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isIncognitoDocumentAccessibleToUser() {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (isValidActivity(true, intent)) return true;
    }
    return false;
}
 
Example #28
Source File: ActivityDelegateImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private ActivityManager.AppTask getTask(boolean isIncognito, int tabId) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        int taskId = getTabIdFromIntent(intent);
        if (taskId == tabId && isValidActivity(isIncognito, intent)) return task;
    }
    return null;
}
 
Example #29
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 #30
Source File: WebappDirectoryManager.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Returns a Set of Intents for all Chrome tasks currently known by the ActivityManager. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected Set<Intent> getBaseIntentsForAllTasks() {
    Set<Intent> baseIntents = new HashSet<Intent>();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (AppTask task : manager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (intent != null) baseIntents.add(intent);
    }

    return baseIntents;
}