InstalledAppCounter.java revision 13f569ebd676cf1616b039d0d8aa141fff34be49
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15package com.android.settings.applications; 16 17import android.content.Context; 18import android.content.Intent; 19import android.content.pm.ApplicationInfo; 20import android.content.pm.ResolveInfo; 21import android.content.pm.PackageManager; 22import android.os.UserHandle; 23 24import java.util.List; 25 26public abstract class InstalledAppCounter extends AppCounter { 27 28 private final int mInstallReason; 29 private final PackageManagerWrapper mPackageManager; 30 31 public InstalledAppCounter(Context context, int installReason, 32 PackageManagerWrapper packageManager) { 33 super(context, packageManager); 34 mInstallReason = installReason; 35 mPackageManager = packageManager; 36 } 37 38 @Override 39 protected boolean includeInCount(ApplicationInfo info) { 40 final int userId = UserHandle.getUserId(info.uid); 41 if (mInstallReason != ApplicationFeatureProvider.IGNORE_INSTALL_REASON 42 && mPackageManager.getInstallReason(info.packageName, 43 new UserHandle(userId)) != mInstallReason) { 44 return false; 45 } 46 if ((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { 47 return true; 48 } 49 if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { 50 return true; 51 } 52 Intent launchIntent = new Intent(Intent.ACTION_MAIN, null) 53 .addCategory(Intent.CATEGORY_LAUNCHER) 54 .setPackage(info.packageName); 55 List<ResolveInfo> intents = mPm.queryIntentActivitiesAsUser( 56 launchIntent, 57 PackageManager.GET_DISABLED_COMPONENTS 58 | PackageManager.MATCH_DIRECT_BOOT_AWARE 59 | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, 60 userId); 61 return intents != null && intents.size() != 0; 62 } 63} 64