• 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 static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
20 
21 import android.content.ComponentName;
22 import android.content.Context;
23 import android.content.pm.ApplicationInfo;
24 import android.content.pm.PackageManager;
25 import android.os.UserHandle;
26 import android.util.Log;
27 
28 import com.android.launcher3.pm.UserCache;
29 import com.android.launcher3.util.ComponentKey;
30 import com.android.launcher3.util.PackageManagerHelper;
31 import com.android.systemui.shared.recents.model.Task;
32 import com.android.systemui.shared.system.ActivityManagerWrapper;
33 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
34 
35 import java.util.List;
36 
37 /**
38  * Contains helpful methods for retrieving data from {@link Task}s.
39  */
40 public final class TaskUtils {
41 
42     private static final String TAG = "TaskUtils";
43 
TaskUtils()44     private TaskUtils() {}
45 
46     /**
47      * TODO: remove this once we switch to getting the icon and label from IconCache.
48      */
getTitle(Context context, Task task)49     public static CharSequence getTitle(Context context, Task task) {
50         UserHandle user = UserHandle.of(task.key.userId);
51         ApplicationInfo applicationInfo = new PackageManagerHelper(context)
52                 .getApplicationInfo(task.getTopComponent().getPackageName(), user, 0);
53         if (applicationInfo == null) {
54             Log.e(TAG, "Failed to get title for task " + task);
55             return "";
56         }
57         PackageManager packageManager = context.getPackageManager();
58         return packageManager.getUserBadgedLabel(
59             applicationInfo.loadLabel(packageManager), user);
60     }
61 
getLaunchComponentKeyForTask(Task.TaskKey taskKey)62     public static ComponentKey getLaunchComponentKeyForTask(Task.TaskKey taskKey) {
63         final ComponentName cn = taskKey.sourceComponent != null
64                 ? taskKey.sourceComponent
65                 : taskKey.getComponent();
66         return new ComponentKey(cn, UserHandle.of(taskKey.userId));
67     }
68 
69 
taskIsATargetWithMode(RemoteAnimationTargetCompat[] targets, int taskId, int mode)70     public static boolean taskIsATargetWithMode(RemoteAnimationTargetCompat[] targets,
71             int taskId, int mode) {
72         for (RemoteAnimationTargetCompat target : targets) {
73             if (target.mode == mode && target.taskId == taskId) {
74                 return true;
75             }
76         }
77         return false;
78     }
79 
checkCurrentOrManagedUserId(int currentUserId, Context context)80     public static boolean checkCurrentOrManagedUserId(int currentUserId, Context context) {
81         if (currentUserId == UserHandle.myUserId()) {
82             return true;
83         }
84         List<UserHandle> allUsers = UserCache.INSTANCE.get(context).getUserProfiles();
85         for (int i = allUsers.size() - 1; i >= 0; i--) {
86             if (currentUserId == allUsers.get(i).getIdentifier()) {
87                 return true;
88             }
89         }
90         return false;
91     }
92 
93     /**
94      * Requests that the system close any open system windows (including other SystemUI).
95      */
closeSystemWindowsAsync(String reason)96     public static void closeSystemWindowsAsync(String reason) {
97         UI_HELPER_EXECUTOR.execute(
98                 () -> ActivityManagerWrapper.getInstance().closeSystemWindows(reason));
99     }
100 }
101