• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.quickstep;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.pm.ApplicationInfo;
22 import android.content.pm.PackageManager;
23 import android.os.UserHandle;
24 import android.util.Log;
25 
26 import com.android.launcher3.compat.LauncherAppsCompat;
27 import com.android.launcher3.compat.UserManagerCompat;
28 import com.android.launcher3.util.ComponentKey;
29 import com.android.systemui.shared.recents.model.Task;
30 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
31 
32 import java.util.List;
33 
34 /**
35  * Contains helpful methods for retrieving data from {@link Task}s.
36  */
37 public final class TaskUtils {
38 
39     private static final String TAG = "TaskUtils";
40 
TaskUtils()41     private TaskUtils() {}
42 
43     /**
44      * TODO: remove this once we switch to getting the icon and label from IconCache.
45      */
getTitle(Context context, Task task)46     public static CharSequence getTitle(Context context, Task task) {
47         LauncherAppsCompat launcherAppsCompat = LauncherAppsCompat.getInstance(context);
48         PackageManager packageManager = context.getPackageManager();
49         UserHandle user = UserHandle.of(task.key.userId);
50         ApplicationInfo applicationInfo = launcherAppsCompat.getApplicationInfo(
51             task.getTopComponent().getPackageName(), 0, user);
52         if (applicationInfo == null) {
53             Log.e(TAG, "Failed to get title for task " + task);
54             return "";
55         }
56         return packageManager.getUserBadgedLabel(
57             applicationInfo.loadLabel(packageManager), user);
58     }
59 
getLaunchComponentKeyForTask(Task.TaskKey taskKey)60     public static ComponentKey getLaunchComponentKeyForTask(Task.TaskKey taskKey) {
61         final ComponentName cn = taskKey.sourceComponent != null
62                 ? taskKey.sourceComponent
63                 : taskKey.getComponent();
64         return new ComponentKey(cn, UserHandle.of(taskKey.userId));
65     }
66 
67 
taskIsATargetWithMode(RemoteAnimationTargetCompat[] targets, int taskId, int mode)68     public static boolean taskIsATargetWithMode(RemoteAnimationTargetCompat[] targets,
69             int taskId, int mode) {
70         for (RemoteAnimationTargetCompat target : targets) {
71             if (target.mode == mode && target.taskId == taskId) {
72                 return true;
73             }
74         }
75         return false;
76     }
77 
checkCurrentOrManagedUserId(int currentUserId, Context context)78     public static boolean checkCurrentOrManagedUserId(int currentUserId, Context context) {
79         if (currentUserId == UserHandle.myUserId()) {
80             return true;
81         }
82         List<UserHandle> allUsers = UserManagerCompat.getInstance(context).getUserProfiles();
83         for (int i = allUsers.size() - 1; i >= 0; i--) {
84             if (currentUserId == allUsers.get(i).getIdentifier()) {
85                 return true;
86             }
87         }
88         return false;
89     }
90 }
91