android.app.ActivityManager.AppTask Java Examples
The following examples show how to use
android.app.ActivityManager.AppTask.
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: BackgroundModeExt.java From cordova-plugin-background-mode with Apache License 2.0 | 6 votes |
/** * Excludes the app from the recent tasks list. */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void excludeFromTaskList() { ActivityManager am = (ActivityManager) getService(ACTIVITY_SERVICE); if (am == null || SDK_INT < 21) return; List<AppTask> tasks = am.getAppTasks(); if (tasks == null || tasks.isEmpty()) return; tasks.get(0).setExcludeFromRecents(true); }
Example #2
Source File: DocumentUtils.java From delion with Apache License 2.0 | 6 votes |
/** * Finishes tasks other than the one with the given ID that were started with the given data * in the Intent, removing those tasks from Recents and leaving a unique task with the data. * @param data Passed in as part of the Intent's data when starting the Activity. * @param canonicalTaskId ID of the task will be the only one left with the ID. * @return Intent of one of the tasks that were finished. */ public static Intent finishOtherTasksWithData(Uri data, int canonicalTaskId) { if (data == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null; String dataString = data.toString(); Context context = ContextUtils.getApplicationContext(); ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.AppTask> tasksToFinish = new ArrayList<ActivityManager.AppTask>(); for (ActivityManager.AppTask task : manager.getAppTasks()) { RecentTaskInfo taskInfo = getTaskInfoFromTask(task); if (taskInfo == null) continue; int taskId = taskInfo.id; Intent baseIntent = taskInfo.baseIntent; String taskData = baseIntent == null ? null : taskInfo.baseIntent.getDataString(); if (TextUtils.equals(dataString, taskData) && (taskId == -1 || taskId != canonicalTaskId)) { tasksToFinish.add(task); } } return finishAndRemoveTasks(tasksToFinish); }
Example #3
Source File: DocumentUtils.java From 365browser with Apache License 2.0 | 6 votes |
/** * Given an AppTask retrieves the task class name. * @param task The app task to use. * @param pm The package manager to use for resolving intent. * @return Fully qualified class name or null if we were not able to * determine it. */ public static String getTaskClassName(AppTask task, PackageManager pm) { RecentTaskInfo info = getTaskInfoFromTask(task); if (info == null) return null; Intent baseIntent = info.baseIntent; if (baseIntent == null) { return null; } else if (baseIntent.getComponent() != null) { return baseIntent.getComponent().getClassName(); } else { ResolveInfo resolveInfo = pm.resolveActivity(baseIntent, 0); if (resolveInfo == null) return null; return resolveInfo.activityInfo.name; } }
Example #4
Source File: DocumentUtils.java From delion with Apache License 2.0 | 6 votes |
/** * Given an AppTask retrieves the task class name. * @param task The app task to use. * @param pm The package manager to use for resolving intent. * @return Fully qualified class name or null if we were not able to * determine it. */ public static String getTaskClassName(AppTask task, PackageManager pm) { RecentTaskInfo info = getTaskInfoFromTask(task); if (info == null) return null; Intent baseIntent = info.baseIntent; if (baseIntent == null) { return null; } else if (baseIntent.getComponent() != null) { return baseIntent.getComponent().getClassName(); } else { ResolveInfo resolveInfo = pm.resolveActivity(baseIntent, 0); if (resolveInfo == null) return null; return resolveInfo.activityInfo.name; } }
Example #5
Source File: DocumentUtils.java From 365browser with Apache License 2.0 | 6 votes |
/** * Finishes tasks other than the one with the given ID that were started with the given data * in the Intent, removing those tasks from Recents and leaving a unique task with the data. * @param data Passed in as part of the Intent's data when starting the Activity. * @param canonicalTaskId ID of the task will be the only one left with the ID. * @return Intent of one of the tasks that were finished. */ public static Intent finishOtherTasksWithData(Uri data, int canonicalTaskId) { if (data == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null; String dataString = data.toString(); Context context = ContextUtils.getApplicationContext(); ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.AppTask> tasksToFinish = new ArrayList<ActivityManager.AppTask>(); for (ActivityManager.AppTask task : manager.getAppTasks()) { RecentTaskInfo taskInfo = getTaskInfoFromTask(task); if (taskInfo == null) continue; int taskId = taskInfo.id; Intent baseIntent = taskInfo.baseIntent; String taskData = baseIntent == null ? null : taskInfo.baseIntent.getDataString(); if (TextUtils.equals(dataString, taskData) && (taskId == -1 || taskId != canonicalTaskId)) { tasksToFinish.add(task); } } return finishAndRemoveTasks(tasksToFinish); }
Example #6
Source File: IncognitoNotificationService.java From AndroidChromium with Apache License 2.0 | 6 votes |
@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: DocumentUtils.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Finishes tasks other than the one with the given ID that were started with the given data * in the Intent, removing those tasks from Recents and leaving a unique task with the data. * @param data Passed in as part of the Intent's data when starting the Activity. * @param canonicalTaskId ID of the task will be the only one left with the ID. * @return Intent of one of the tasks that were finished. */ public static Intent finishOtherTasksWithData(Uri data, int canonicalTaskId) { if (data == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null; String dataString = data.toString(); Context context = ContextUtils.getApplicationContext(); ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.AppTask> tasksToFinish = new ArrayList<ActivityManager.AppTask>(); for (ActivityManager.AppTask task : manager.getAppTasks()) { RecentTaskInfo taskInfo = getTaskInfoFromTask(task); if (taskInfo == null) continue; int taskId = taskInfo.id; Intent baseIntent = taskInfo.baseIntent; String taskData = baseIntent == null ? null : taskInfo.baseIntent.getDataString(); if (TextUtils.equals(dataString, taskData) && (taskId == -1 || taskId != canonicalTaskId)) { tasksToFinish.add(task); } } return finishAndRemoveTasks(tasksToFinish); }
Example #8
Source File: IncognitoNotificationService.java From 365browser with Apache License 2.0 | 6 votes |
@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 #9
Source File: IncognitoNotificationService.java From delion with Apache License 2.0 | 6 votes |
@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 #10
Source File: DocumentUtils.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Given an AppTask retrieves the task class name. * @param task The app task to use. * @param pm The package manager to use for resolving intent. * @return Fully qualified class name or null if we were not able to * determine it. */ public static String getTaskClassName(AppTask task, PackageManager pm) { RecentTaskInfo info = getTaskInfoFromTask(task); if (info == null) return null; Intent baseIntent = info.baseIntent; if (baseIntent == null) { return null; } else if (baseIntent.getComponent() != null) { return baseIntent.getComponent().getClassName(); } else { ResolveInfo resolveInfo = pm.resolveActivity(baseIntent, 0); if (resolveInfo == null) return null; return resolveInfo.activityInfo.name; } }
Example #11
Source File: DocumentUtils.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Returns the RecentTaskInfo for the task, if the ActivityManager succeeds in finding the task. * @param task AppTask containing information about a task. * @return The RecentTaskInfo associated with the task, or null if it couldn't be found. */ public static RecentTaskInfo getTaskInfoFromTask(AppTask task) { RecentTaskInfo info = null; try { info = task.getTaskInfo(); } catch (IllegalArgumentException e) { Log.e(TAG, "Failed to retrieve task info: ", e); } return info; }
Example #12
Source File: DocumentUtils.java From 365browser with Apache License 2.0 | 5 votes |
/** * Returns the RecentTaskInfo for the task, if the ActivityManager succeeds in finding the task. * @param task AppTask containing information about a task. * @return The RecentTaskInfo associated with the task, or null if it couldn't be found. */ public static RecentTaskInfo getTaskInfoFromTask(AppTask task) { RecentTaskInfo info = null; try { info = task.getTaskInfo(); } catch (IllegalArgumentException e) { Log.e(TAG, "Failed to retrieve task info: ", e); } return info; }
Example #13
Source File: DocumentUtils.java From 365browser with Apache License 2.0 | 5 votes |
private static Intent finishAndRemoveTasks(List<ActivityManager.AppTask> tasksToFinish) { Intent removedIntent = null; for (ActivityManager.AppTask task : tasksToFinish) { Log.d(TAG, "Removing task with duplicated data: " + task); removedIntent = getBaseIntentFromTask(task); task.finishAndRemoveTask(); } return removedIntent; }
Example #14
Source File: WebappDirectoryManager.java From 365browser with Apache License 2.0 | 5 votes |
/** 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: ChromeTabbedActivity.java From 365browser with Apache License 2.0 | 5 votes |
@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 #16
Source File: DocumentUtils.java From AndroidChromium with Apache License 2.0 | 5 votes |
private static Intent finishAndRemoveTasks(List<ActivityManager.AppTask> tasksToFinish) { Intent removedIntent = null; for (ActivityManager.AppTask task : tasksToFinish) { Log.d(TAG, "Removing task with duplicated data: " + task); removedIntent = getBaseIntentFromTask(task); task.finishAndRemoveTask(); } return removedIntent; }
Example #17
Source File: WebappDirectoryManager.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** 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 #18
Source File: ChromeTabbedActivity.java From AndroidChromium with Apache License 2.0 | 5 votes |
@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 #19
Source File: DocumentUtils.java From delion with Apache License 2.0 | 5 votes |
/** * Returns the RecentTaskInfo for the task, if the ActivityManager succeeds in finding the task. * @param task AppTask containing information about a task. * @return The RecentTaskInfo associated with the task, or null if it couldn't be found. */ public static RecentTaskInfo getTaskInfoFromTask(AppTask task) { RecentTaskInfo info = null; try { info = task.getTaskInfo(); } catch (IllegalArgumentException e) { Log.e(TAG, "Failed to retrieve task info: ", e); } return info; }
Example #20
Source File: DocumentUtils.java From delion with Apache License 2.0 | 5 votes |
private static Intent finishAndRemoveTasks(List<ActivityManager.AppTask> tasksToFinish) { Intent removedIntent = null; for (ActivityManager.AppTask task : tasksToFinish) { Log.d(TAG, "Removing task with duplicated data: " + task); removedIntent = getBaseIntentFromTask(task); task.finishAndRemoveTask(); } return removedIntent; }
Example #21
Source File: WebappDirectoryManager.java From delion with Apache License 2.0 | 5 votes |
/** 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 #22
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 #23
Source File: DocumentUtils.java From AndroidChromium with Apache License 2.0 | 2 votes |
/** * Returns the baseIntent of the RecentTaskInfo associated with the given task. * @param task Task to get the baseIntent for. * @return The baseIntent, or null if it couldn't be retrieved. */ public static Intent getBaseIntentFromTask(AppTask task) { RecentTaskInfo info = getTaskInfoFromTask(task); return info == null ? null : info.baseIntent; }
Example #24
Source File: DocumentUtils.java From delion with Apache License 2.0 | 2 votes |
/** * Returns the baseIntent of the RecentTaskInfo associated with the given task. * @param task Task to get the baseIntent for. * @return The baseIntent, or null if it couldn't be retrieved. */ public static Intent getBaseIntentFromTask(AppTask task) { RecentTaskInfo info = getTaskInfoFromTask(task); return info == null ? null : info.baseIntent; }
Example #25
Source File: DocumentUtils.java From 365browser with Apache License 2.0 | 2 votes |
/** * Returns the baseIntent of the RecentTaskInfo associated with the given task. * @param task Task to get the baseIntent for. * @return The baseIntent, or null if it couldn't be retrieved. */ public static Intent getBaseIntentFromTask(AppTask task) { RecentTaskInfo info = getTaskInfoFromTask(task); return info == null ? null : info.baseIntent; }