Java Code Examples for org.chromium.base.ApplicationStatus#getRunningActivities()
The following examples show how to use
org.chromium.base.ApplicationStatus#getRunningActivities() .
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: Tab.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the * foreground, or null if this isn't possible. */ @Nullable public static Intent createBringTabToFrontIntent(int tabId) { // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded. List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities(); for (WeakReference<Activity> ref : list) { Activity activity = ref.get(); if (activity instanceof CustomTabActivity && ((CustomTabActivity) activity).getActivityTab() != null && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) { return null; } } String packageName = ContextUtils.getApplicationContext().getPackageName(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName); intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId); intent.setPackage(packageName); return intent; }
Example 2
Source File: IncognitoNotificationService.java From delion with Apache License 2.0 | 6 votes |
private void focusChromeIfNecessary() { Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities(); int tabbedTaskId = -1; List<WeakReference<Activity>> runningActivities = ApplicationStatus.getRunningActivities(); for (int i = 0; i < runningActivities.size(); i++) { Activity activity = runningActivities.get(i).get(); if (activity == null) continue; if (activity instanceof ChromeTabbedActivity) { tabbedTaskId = activity.getTaskId(); break; } } // If the task containing the tabbed activity is visible, then do nothing as there is no // snapshot that would need to be regenerated. if (visibleTaskIds.contains(tabbedTaskId)) return; Context context = ContextUtils.getApplicationContext(); Intent startIntent = new Intent(Intent.ACTION_MAIN); startIntent.setPackage(context.getPackageName()); startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(startIntent); }
Example 3
Source File: ChromeLifetimeController.java From 365browser with Apache License 2.0 | 6 votes |
@Override public void onTerminate(boolean restart) { mRestartChromeOnDestroy = restart; // Tell all Chrome Activities to finish themselves. for (WeakReference<Activity> weakActivity : ApplicationStatus.getRunningActivities()) { Activity activity = weakActivity.get(); if (activity != null) { ApplicationStatus.registerStateListenerForActivity(this, activity); mRemainingActivitiesCount++; activity.finish(); } } // Kick off a timer to kill the process after a delay, which fires only if the Activities // take too long to be finished. mHandler.postDelayed(mRestartRunnable, WATCHDOG_DELAY_MS); }
Example 4
Source File: IncognitoNotificationService.java From 365browser with Apache License 2.0 | 6 votes |
private Set<Integer> getTaskIdsForVisibleActivities() { List<WeakReference<Activity>> runningActivities = ApplicationStatus.getRunningActivities(); Set<Integer> visibleTaskIds = new HashSet<>(); for (int i = 0; i < runningActivities.size(); i++) { Activity activity = runningActivities.get(i).get(); if (activity == null) continue; int activityState = ApplicationStatus.getStateForActivity(activity); if (activityState != ActivityState.STOPPED && activityState != ActivityState.DESTROYED) { visibleTaskIds.add(activity.getTaskId()); } } return visibleTaskIds; }
Example 5
Source File: Tab.java From delion with Apache License 2.0 | 6 votes |
/** * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the * foreground, or null if this isn't possible. */ public static Intent createBringTabToFrontIntent(int tabId) { // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded. List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities(); for (WeakReference<Activity> ref : list) { Activity activity = ref.get(); if (activity instanceof CustomTabActivity && ((CustomTabActivity) activity).getActivityTab() != null && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) { return null; } } String packageName = ContextUtils.getApplicationContext().getPackageName(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName); intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId); intent.setPackage(packageName); return intent; }
Example 6
Source File: IncognitoNotificationService.java From AndroidChromium with Apache License 2.0 | 6 votes |
private Set<Integer> getTaskIdsForVisibleActivities() { List<WeakReference<Activity>> runningActivities = ApplicationStatus.getRunningActivities(); Set<Integer> visibleTaskIds = new HashSet<>(); for (int i = 0; i < runningActivities.size(); i++) { Activity activity = runningActivities.get(i).get(); if (activity == null) continue; int activityState = ApplicationStatus.getStateForActivity(activity); if (activityState != ActivityState.STOPPED && activityState != ActivityState.DESTROYED) { visibleTaskIds.add(activity.getTaskId()); } } return visibleTaskIds; }
Example 7
Source File: IncognitoNotificationService.java From AndroidChromium with Apache License 2.0 | 6 votes |
private void focusChromeIfNecessary() { Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities(); int tabbedTaskId = -1; List<WeakReference<Activity>> runningActivities = ApplicationStatus.getRunningActivities(); for (int i = 0; i < runningActivities.size(); i++) { Activity activity = runningActivities.get(i).get(); if (activity == null) continue; if (activity instanceof ChromeTabbedActivity) { tabbedTaskId = activity.getTaskId(); break; } } // If the task containing the tabbed activity is visible, then do nothing as there is no // snapshot that would need to be regenerated. if (visibleTaskIds.contains(tabbedTaskId)) return; Context context = ContextUtils.getApplicationContext(); Intent startIntent = new Intent(Intent.ACTION_MAIN); startIntent.setPackage(context.getPackageName()); startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(startIntent); }
Example 8
Source File: IncognitoNotificationService.java From 365browser with Apache License 2.0 | 6 votes |
private void focusChromeIfNecessary() { Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities(); int tabbedTaskId = -1; List<WeakReference<Activity>> runningActivities = ApplicationStatus.getRunningActivities(); for (int i = 0; i < runningActivities.size(); i++) { Activity activity = runningActivities.get(i).get(); if (activity == null) continue; if (activity instanceof ChromeTabbedActivity) { tabbedTaskId = activity.getTaskId(); break; } } // If the task containing the tabbed activity is visible, then do nothing as there is no // snapshot that would need to be regenerated. if (visibleTaskIds.contains(tabbedTaskId)) return; Context context = ContextUtils.getApplicationContext(); Intent startIntent = new Intent(Intent.ACTION_MAIN); startIntent.setPackage(context.getPackageName()); startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(startIntent); }
Example 9
Source File: ActivityDelegate.java From delion with Apache License 2.0 | 5 votes |
/** * @return Running Activity that owns the given Tab, null if the Activity couldn't be found. */ public static Activity getActivityForTabId(int id) { if (id == Tab.INVALID_TAB_ID) return null; for (WeakReference<Activity> ref : ApplicationStatus.getRunningActivities()) { if (!(ref.get() instanceof ChromeActivity)) continue; ChromeActivity activity = (ChromeActivity) ref.get(); if (activity == null) continue; if (activity.getTabModelSelector().getTabById(id) != null) return activity; } return null; }
Example 10
Source File: CustomTabTabPersistencePolicy.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Gathers all of the tab IDs and task IDs for all currently live Custom Tabs. * * @param liveTabIds Where tab IDs will be added. * @param liveTaskIds Where task IDs will be added. */ protected static void getAllLiveTabAndTaskIds( Set<Integer> liveTabIds, Set<Integer> liveTaskIds) { ThreadUtils.assertOnUiThread(); List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); for (int i = 0; i < activities.size(); i++) { Activity activity = activities.get(i).get(); if (activity == null) continue; if (!(activity instanceof CustomTabActivity)) continue; getAllTabIdsForActivity((CustomTabActivity) activity, liveTabIds); liveTaskIds.add(activity.getTaskId()); } }
Example 11
Source File: FirstRunActivity.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Finish all the instances of the given Activity. * @param targetActivity The class name of the target Activity. * @param result The result code to propagate back to the originating activity. * @param data The data to propagate back to the originating activity. */ protected static void finishAllTheActivities(String targetActivity, int result, Intent data) { List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); for (WeakReference<Activity> weakActivity : activities) { Activity activity = weakActivity.get(); if (activity != null && activity.getLocalClassName().equals(targetActivity)) { activity.setResult(result, data); activity.finish(); } } }
Example 12
Source File: ActivityDelegate.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Check if the Tab is associated with an Activity that hasn't been destroyed. * This catches situations where a DocumentActivity is no longer listed in Android's Recents * list, but is not dead yet. * @param tabId ID of the Tab to find. * @return Whether the tab is still alive. */ public boolean isTabAssociatedWithNonDestroyedActivity(boolean isIncognito, int tabId) { List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); for (WeakReference<Activity> ref : activities) { Activity activity = ref.get(); if (activity != null && isValidActivity(isIncognito, activity.getIntent()) && getTabIdFromIntent(activity.getIntent()) == tabId && !isActivityDestroyed(activity)) { return true; } } return false; }
Example 13
Source File: ActivityDelegate.java From 365browser with Apache License 2.0 | 5 votes |
/** * @return Running Activity that owns the given Tab, null if the Activity couldn't be found. */ public static Activity getActivityForTabId(int id) { if (id == Tab.INVALID_TAB_ID) return null; for (WeakReference<Activity> ref : ApplicationStatus.getRunningActivities()) { if (!(ref.get() instanceof ChromeActivity)) continue; ChromeActivity activity = (ChromeActivity) ref.get(); if (activity == null) continue; if (activity.getTabModelSelector().getTabById(id) != null) return activity; } return null; }
Example 14
Source File: ChromeLauncherActivity.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * @return Whether there is already an browser instance of Chrome already running. */ public boolean isChromeBrowserActivityRunning() { for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) { Activity activity = reference.get(); if (activity == null) continue; String className = activity.getClass().getName(); if (TextUtils.equals(className, ChromeTabbedActivity.class.getName())) { return true; } } return false; }
Example 15
Source File: ActivityDelegate.java From 365browser with Apache License 2.0 | 5 votes |
/** * Check if the Tab is associated with an Activity that hasn't been destroyed. * This catches situations where a DocumentActivity is no longer listed in Android's Recents * list, but is not dead yet. * @param tabId ID of the Tab to find. * @return Whether the tab is still alive. */ public boolean isTabAssociatedWithNonDestroyedActivity(boolean isIncognito, int tabId) { List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); for (WeakReference<Activity> ref : activities) { Activity activity = ref.get(); if (activity != null && isValidActivity(isIncognito, activity.getIntent()) && getTabIdFromIntent(activity.getIntent()) == tabId && !isActivityDestroyed(activity)) { return true; } } return false; }
Example 16
Source File: CustomTabTabPersistencePolicy.java From 365browser with Apache License 2.0 | 5 votes |
/** * Gathers all of the tab IDs and task IDs for all currently live Custom Tabs. * * @param liveTabIds Where tab IDs will be added. * @param liveTaskIds Where task IDs will be added. */ protected static void getAllLiveTabAndTaskIds( Set<Integer> liveTabIds, Set<Integer> liveTaskIds) { ThreadUtils.assertOnUiThread(); List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); for (int i = 0; i < activities.size(); i++) { Activity activity = activities.get(i).get(); if (activity == null) continue; if (!(activity instanceof CustomTabActivity)) continue; getAllTabIdsForActivity((CustomTabActivity) activity, liveTabIds); liveTaskIds.add(activity.getTaskId()); } }
Example 17
Source File: ActivityDelegate.java From delion with Apache License 2.0 | 5 votes |
/** * Check if the Tab is associated with an Activity that hasn't been destroyed. * This catches situations where a DocumentActivity is no longer listed in Android's Recents * list, but is not dead yet. * @param tabId ID of the Tab to find. * @return Whether the tab is still alive. */ public boolean isTabAssociatedWithNonDestroyedActivity(boolean isIncognito, int tabId) { List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); for (WeakReference<Activity> ref : activities) { Activity activity = ref.get(); if (activity != null && isValidActivity(isIncognito, activity.getIntent()) && getTabIdFromIntent(activity.getIntent()) == tabId && !isActivityDestroyed(activity)) { return true; } } return false; }
Example 18
Source File: MultiWindowUtils.java From 365browser with Apache License 2.0 | 4 votes |
/** * Determines the correct ChromeTabbedActivity class to use for an incoming intent. * @param intent The incoming intent that is starting ChromeTabbedActivity. * @param context The current Context, used to retrieve the ActivityManager system service. * @return The ChromeTabbedActivity to use for the incoming intent. */ public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent( @Nullable Intent intent, Context context) { // 1. Exit early if the build version doesn't support Android N+ multi-window mode or // ChromeTabbedActivity2 isn't running. if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2TaskRunning)) { return ChromeTabbedActivity.class; } // 2. If the intent has a window id set, use that. if (intent != null && IntentUtils.safeHasExtra(intent, IntentHandler.EXTRA_WINDOW_ID)) { int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_WINDOW_ID, 0); if (windowId == 1) return ChromeTabbedActivity.class; if (windowId == 2) return ChromeTabbedActivity2.class; } // 3. If only one ChromeTabbedActivity is currently in Android recents, use it. boolean tabbed2TaskRunning = isActivityTaskInRecents( ChromeTabbedActivity2.class.getName(), context); // Exit early if ChromeTabbedActivity2 isn't running. if (!tabbed2TaskRunning) { mTabbedActivity2TaskRunning = false; return ChromeTabbedActivity.class; } boolean tabbedTaskRunning = isActivityTaskInRecents( ChromeTabbedActivity.class.getName(), context); if (!tabbedTaskRunning) { return ChromeTabbedActivity2.class; } // 4. If only one of the ChromeTabbedActivity's is currently visible use it. // e.g. ChromeTabbedActivity is docked to the top of the screen and another app is docked // to the bottom. // Find the activities. Activity tabbedActivity = null; Activity tabbedActivity2 = null; for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) { Activity activity = reference.get(); if (activity == null) continue; if (activity.getClass().equals(ChromeTabbedActivity.class)) { tabbedActivity = activity; } else if (activity.getClass().equals(ChromeTabbedActivity2.class)) { tabbedActivity2 = activity; } } // Determine if only one is visible. boolean tabbedActivityVisible = isActivityVisible(tabbedActivity); boolean tabbedActivity2Visible = isActivityVisible(tabbedActivity2); if (tabbedActivityVisible ^ tabbedActivity2Visible) { if (tabbedActivityVisible) return ChromeTabbedActivity.class; return ChromeTabbedActivity2.class; } // 5. Use the ChromeTabbedActivity that was resumed most recently if it's still running. if (mLastResumedTabbedActivity != null) { ChromeTabbedActivity lastResumedActivity = mLastResumedTabbedActivity.get(); if (lastResumedActivity != null) { Class<?> lastResumedClassName = lastResumedActivity.getClass(); if (tabbedTaskRunning && lastResumedClassName.equals(ChromeTabbedActivity.class)) { return ChromeTabbedActivity.class; } if (tabbed2TaskRunning && lastResumedClassName.equals(ChromeTabbedActivity2.class)) { return ChromeTabbedActivity2.class; } } } // 6. Default to regular ChromeTabbedActivity. return ChromeTabbedActivity.class; }
Example 19
Source File: ChromeTabbedActivity.java From 365browser with Apache License 2.0 | 4 votes |
/** * 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; }
Example 20
Source File: MultiWindowUtils.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Determines the correct ChromeTabbedActivity class to use for an incoming intent. * @param intent The incoming intent that is starting ChromeTabbedActivity. * @param context The current Context, used to retrieve the ActivityManager system service. * @return The ChromeTabbedActivity to use for the incoming intent. */ public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent(Intent intent, Context context) { // 1. Exit early if the build version doesn't support Android N+ multi-window mode or // ChromeTabbedActivity2 isn't running. if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2TaskRunning)) { return ChromeTabbedActivity.class; } // 2. If the intent has a window id set, use that. if (intent.hasExtra(IntentHandler.EXTRA_WINDOW_ID)) { int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_WINDOW_ID, 0); if (windowId == 1) return ChromeTabbedActivity.class; if (windowId == 2) return ChromeTabbedActivity2.class; } // 3. If only one ChromeTabbedActivity is currently in Android recents, use it. boolean tabbed2TaskRunning = isActivityTaskInRecents( ChromeTabbedActivity2.class.getName(), context); // Exit early if ChromeTabbedActivity2 isn't running. if (!tabbed2TaskRunning) { mTabbedActivity2TaskRunning = false; return ChromeTabbedActivity.class; } boolean tabbedTaskRunning = isActivityTaskInRecents( ChromeTabbedActivity.class.getName(), context); if (!tabbedTaskRunning) { return ChromeTabbedActivity2.class; } // 4. If only one of the ChromeTabbedActivity's is currently visible use it. // e.g. ChromeTabbedActivity is docked to the top of the screen and another app is docked // to the bottom. // Find the activities. Activity tabbedActivity = null; Activity tabbedActivity2 = null; for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) { Activity activity = reference.get(); if (activity == null) continue; if (activity.getClass().equals(ChromeTabbedActivity.class)) { tabbedActivity = activity; } else if (activity.getClass().equals(ChromeTabbedActivity2.class)) { tabbedActivity2 = activity; } } // Determine if only one is visible. boolean tabbedActivityVisible = isActivityVisible(tabbedActivity); boolean tabbedActivity2Visible = isActivityVisible(tabbedActivity2); if (tabbedActivityVisible ^ tabbedActivity2Visible) { if (tabbedActivityVisible) return ChromeTabbedActivity.class; return ChromeTabbedActivity2.class; } // 5. Use the ChromeTabbedActivity that was resumed most recently if it's still running. if (mLastResumedTabbedActivity != null) { ChromeTabbedActivity lastResumedActivity = mLastResumedTabbedActivity.get(); if (lastResumedActivity != null) { Class<?> lastResumedClassName = lastResumedActivity.getClass(); if (tabbedTaskRunning && lastResumedClassName.equals(ChromeTabbedActivity.class)) { return ChromeTabbedActivity.class; } if (tabbed2TaskRunning && lastResumedClassName.equals(ChromeTabbedActivity2.class)) { return ChromeTabbedActivity2.class; } } } // 6. Default to regular ChromeTabbedActivity. return ChromeTabbedActivity.class; }