• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.launcher3;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.pm.ApplicationInfo;
23 import android.content.pm.LauncherActivityInfo;
24 import android.os.Build;
25 import android.os.Process;
26 import android.os.UserHandle;
27 
28 import com.android.launcher3.compat.UserManagerCompat;
29 import com.android.launcher3.util.ComponentKey;
30 import com.android.launcher3.util.PackageManagerHelper;
31 
32 /**
33  * Represents an app in AllAppsView.
34  */
35 public class AppInfo extends ItemInfoWithIcon {
36 
37     /**
38      * The intent used to start the application.
39      */
40     public Intent intent;
41 
42     public ComponentName componentName;
43 
AppInfo()44     public AppInfo() {
45         itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
46     }
47 
48     @Override
getIntent()49     public Intent getIntent() {
50         return intent;
51     }
52 
53     /**
54      * Must not hold the Context.
55      */
AppInfo(Context context, LauncherActivityInfo info, UserHandle user)56     public AppInfo(Context context, LauncherActivityInfo info, UserHandle user) {
57         this(info, user, UserManagerCompat.getInstance(context).isQuietModeEnabled(user));
58     }
59 
AppInfo(LauncherActivityInfo info, UserHandle user, boolean quietModeEnabled)60     public AppInfo(LauncherActivityInfo info, UserHandle user, boolean quietModeEnabled) {
61         this.componentName = info.getComponentName();
62         this.container = ItemInfo.NO_ID;
63         this.user = user;
64         intent = makeLaunchIntent(info);
65 
66         if (quietModeEnabled) {
67             runtimeStatusFlags |= FLAG_DISABLED_QUIET_USER;
68         }
69         updateRuntimeFlagsForActivityTarget(this, info);
70     }
71 
AppInfo(AppInfo info)72     public AppInfo(AppInfo info) {
73         super(info);
74         componentName = info.componentName;
75         title = Utilities.trim(info.title);
76         intent = new Intent(info.intent);
77     }
78 
79     @Override
dumpProperties()80     protected String dumpProperties() {
81         return super.dumpProperties() + " componentName=" + componentName;
82     }
83 
makeWorkspaceItem()84     public WorkspaceItemInfo makeWorkspaceItem() {
85         return new WorkspaceItemInfo(this);
86     }
87 
toComponentKey()88     public ComponentKey toComponentKey() {
89         return new ComponentKey(componentName, user);
90     }
91 
makeLaunchIntent(LauncherActivityInfo info)92     public static Intent makeLaunchIntent(LauncherActivityInfo info) {
93         return makeLaunchIntent(info.getComponentName());
94     }
95 
makeLaunchIntent(ComponentName cn)96     public static Intent makeLaunchIntent(ComponentName cn) {
97         return new Intent(Intent.ACTION_MAIN)
98                 .addCategory(Intent.CATEGORY_LAUNCHER)
99                 .setComponent(cn)
100                 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
101     }
102 
updateRuntimeFlagsForActivityTarget( ItemInfoWithIcon info, LauncherActivityInfo lai)103     public static void updateRuntimeFlagsForActivityTarget(
104             ItemInfoWithIcon info, LauncherActivityInfo lai) {
105         ApplicationInfo appInfo = lai.getApplicationInfo();
106         if (PackageManagerHelper.isAppSuspended(appInfo)) {
107             info.runtimeStatusFlags |= FLAG_DISABLED_SUSPENDED;
108         }
109         info.runtimeStatusFlags |= (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0
110                 ? FLAG_SYSTEM_NO : FLAG_SYSTEM_YES;
111 
112         if (Utilities.ATLEAST_OREO
113                 && appInfo.targetSdkVersion >= Build.VERSION_CODES.O
114                 && Process.myUserHandle().equals(lai.getUser())) {
115             // The icon for a non-primary user is badged, hence it's not exactly an adaptive icon.
116             info.runtimeStatusFlags |= FLAG_ADAPTIVE_ICON;
117         }
118     }
119 }
120