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