Search in sources :

Example 1 with RecentTaskInfo

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;
}
Also used : Context(android.content.Context) RecentTaskInfo(android.app.ActivityManager.RecentTaskInfo) ActivityManager(android.app.ActivityManager)

Example 2 with RecentTaskInfo

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();
        }
    }
}
Also used : Context(android.content.Context) AppTask(android.app.ActivityManager.AppTask) RecentTaskInfo(android.app.ActivityManager.RecentTaskInfo) PackageManager(android.content.pm.PackageManager) ActivityManager(android.app.ActivityManager) TargetApi(android.annotation.TargetApi)

Example 3 with RecentTaskInfo

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;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) RecentTaskInfo(android.app.ActivityManager.RecentTaskInfo) Intent(android.content.Intent)

Example 4 with RecentTaskInfo

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);
}
Also used : AppTask(android.app.ActivityManager.AppTask) RecentTaskInfo(android.app.ActivityManager.RecentTaskInfo) Test(org.junit.Test)

Example 5 with 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);
}
Also used : Context(android.content.Context) AppTask(android.app.ActivityManager.AppTask) RecentTaskInfo(android.app.ActivityManager.RecentTaskInfo) AppTask(android.app.ActivityManager.AppTask) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager)

Aggregations

RecentTaskInfo (android.app.ActivityManager.RecentTaskInfo)5 ActivityManager (android.app.ActivityManager)3 AppTask (android.app.ActivityManager.AppTask)3 Context (android.content.Context)3 Intent (android.content.Intent)2 TargetApi (android.annotation.TargetApi)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1