Download File
Download Project
Settings
Line Wrap
Themes
default
ambiance
bespin
dracula
eclipse
material
mbo
mdn-like
neat
solarized dark
ttcn
zenburn
ManageAppFragment.java
/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.afwsamples.testdpc.common; import android.content.pm.ApplicationInfo; import android.widget.SpinnerAdapter; import com.afwsamples.testdpc.R; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; public abstract class ManageAppFragment extends BaseManageComponentFragment
{ /** * List of packages always shown in the app list. */ private static final Set
WHITELISTED_APPS = new HashSet<>(); static { // GmsCore WHITELISTED_APPS.add("com.google.android.gms"); } @Override protected SpinnerAdapter createSpinnerAdapter() { List
managedAppList = getInstalledOrLaunchableApps(); Collections.sort(managedAppList, new ApplicationInfo.DisplayNameComparator(mPackageManager)); return new AppInfoSpinnerAdapter(getActivity(), R.layout.app_row, R.id.pkg_name, managedAppList); } private List
getInstalledOrLaunchableApps() { List
installedApps = mPackageManager.getInstalledApplications( 0 /* Default flags */); List
filteredAppList = new ArrayList<>(); for (ApplicationInfo applicationInfo : installedApps) { if (mPackageManager.getLaunchIntentForPackage(applicationInfo.packageName) != null || (applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 || WHITELISTED_APPS.contains(applicationInfo.packageName)) { filteredAppList.add(applicationInfo); } } return filteredAppList; } }