1 /* 2 * Copyright (C) 2017 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 package com.android.car.settings.applications; 17 18 import android.content.Intent; 19 import android.content.pm.PackageManager; 20 import android.content.pm.ResolveInfo; 21 import android.os.Bundle; 22 23 import androidx.car.widget.ListItem; 24 import androidx.car.widget.ListItemProvider; 25 26 import com.android.car.settings.R; 27 import com.android.car.settings.common.ListItemSettingsFragment; 28 29 import java.util.ArrayList; 30 import java.util.List; 31 32 /** 33 * Lists all installed applications and their summary. 34 */ 35 public class ApplicationSettingsFragment extends ListItemSettingsFragment { 36 37 /** 38 * Gets an instance of this object. 39 */ newInstance()40 public static ApplicationSettingsFragment newInstance() { 41 ApplicationSettingsFragment applicationSettingsFragment = new ApplicationSettingsFragment(); 42 Bundle bundle = ListItemSettingsFragment.getBundle(); 43 bundle.putInt(EXTRA_TITLE_ID, R.string.applications_settings); 44 applicationSettingsFragment.setArguments(bundle); 45 return applicationSettingsFragment; 46 } 47 48 @Override getItemProvider()49 public ListItemProvider getItemProvider() { 50 return new ListItemProvider.ListProvider(getListItems()); 51 } 52 getListItems()53 private List<ListItem> getListItems() { 54 PackageManager pm = getContext().getPackageManager(); 55 Intent intent= new Intent(Intent.ACTION_MAIN); 56 intent.addCategory(Intent.CATEGORY_LAUNCHER); 57 List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 58 PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS 59 | PackageManager.MATCH_DISABLED_COMPONENTS); 60 ArrayList<ListItem> items = new ArrayList<>(); 61 for (ResolveInfo resolveInfo : resolveInfos) { 62 items.add(new ApplicationLineItem( 63 getContext(), pm, resolveInfo, getFragmentController())); 64 } 65 return items; 66 } 67 } 68