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.UserHandle; 25 26 import com.android.launcher3.compat.UserManagerCompat; 27 import com.android.launcher3.util.ComponentKey; 28 import com.android.launcher3.util.PackageManagerHelper; 29 30 /** 31 * Represents an app in AllAppsView. 32 */ 33 public class AppInfo extends ItemInfoWithIcon { 34 35 public static final int FLAG_SYSTEM_UNKNOWN = 0; 36 public static final int FLAG_SYSTEM_YES = 1 << 0; 37 public static final int FLAG_SYSTEM_NO = 1 << 1; 38 39 /** 40 * The intent used to start the application. 41 */ 42 public Intent intent; 43 44 public ComponentName componentName; 45 46 /** 47 * {@see ShortcutInfo#isDisabled} 48 */ 49 public int isDisabled = ShortcutInfo.DEFAULT; 50 51 /** 52 * Stores if the app is a system app or not. 53 */ 54 public int isSystemApp; 55 56 public AppInfo() { 57 itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; 58 } 59 60 @Override 61 public Intent getIntent() { 62 return intent; 63 } 64 65 /** 66 * Must not hold the Context. 67 */ 68 public AppInfo(Context context, LauncherActivityInfo info, UserHandle user) { 69 this(info, user, UserManagerCompat.getInstance(context).isQuietModeEnabled(user)); 70 } 71 72 public AppInfo(LauncherActivityInfo info, UserHandle user, boolean quietModeEnabled) { 73 this.componentName = info.getComponentName(); 74 this.container = ItemInfo.NO_ID; 75 this.user = user; 76 if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) { 77 isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED; 78 } 79 if (quietModeEnabled) { 80 isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER; 81 } 82 83 intent = makeLaunchIntent(info); 84 85 isSystemApp = (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0 86 ? FLAG_SYSTEM_NO : FLAG_SYSTEM_YES; 87 88 } 89 90 public AppInfo(AppInfo info) { 91 super(info); 92 componentName = info.componentName; 93 title = Utilities.trim(info.title); 94 intent = new Intent(info.intent); 95 isDisabled = info.isDisabled; 96 isSystemApp = info.isSystemApp; 97 } 98 99 @Override 100 protected String dumpProperties() { 101 return super.dumpProperties() + " componentName=" + componentName; 102 } 103 104 public ShortcutInfo makeShortcut() { 105 return new ShortcutInfo(this); 106 } 107 108 public ComponentKey toComponentKey() { 109 return new ComponentKey(componentName, user); 110 } 111 112 public static Intent makeLaunchIntent(LauncherActivityInfo info) { 113 return makeLaunchIntent(info.getComponentName()); 114 } 115 116 public static Intent makeLaunchIntent(ComponentName cn) { 117 return new Intent(Intent.ACTION_MAIN) 118 .addCategory(Intent.CATEGORY_LAUNCHER) 119 .setComponent(cn) 120 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 121 } 122 123 @Override 124 public boolean isDisabled() { 125 return isDisabled != 0; 126 } 127 } 128