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