use of android.app.ActivityManager.RecentTaskInfo in project AndroidChromium by JackyAndroid.
the class DocumentTabModelSelector method getLargestTaskIdFromRecents.
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;
}
use of android.app.ActivityManager.RecentTaskInfo in project AndroidChromium by JackyAndroid.
the class IncognitoNotificationService method removeNonVisibleChromeTabbedRecentEntries.
@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);
// 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();
}
}
}
use of android.app.ActivityManager.RecentTaskInfo in project AndroidChromium by JackyAndroid.
the class DocumentUtils method getTaskClassName.
/**
* 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;
}
}
use of android.app.ActivityManager.RecentTaskInfo in project robolectric by robolectric.
the class ShadowAppTaskTest method getTaskInfo_returnsCorrectValue.
@Test
public void getTaskInfo_returnsCorrectValue() {
final AppTask appTask = ShadowAppTask.newInstance();
final RecentTaskInfo recentTaskInfo = new RecentTaskInfo();
recentTaskInfo.description = "com.google.test";
shadowOf(appTask).setTaskInfo(recentTaskInfo);
assertThat(appTask.getTaskInfo()).isSameInstanceAs(recentTaskInfo);
}
use of android.app.ActivityManager.RecentTaskInfo in project AndroidChromium by JackyAndroid.
the class DocumentUtils method finishOtherTasksWithData.
/**
* 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);
}
Aggregations