1 /* 2 * Copyright (C) 2018 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.car.settings.applications; 18 19 import static com.android.car.settings.storage.StorageUtils.maybeInitializeVolume; 20 21 import android.app.Application; 22 import android.content.Context; 23 import android.os.Bundle; 24 import android.os.storage.StorageManager; 25 import android.os.storage.VolumeInfo; 26 27 import com.android.car.settings.R; 28 import com.android.settingslib.applications.ApplicationsState; 29 30 /** 31 * Lists all installed applications and their summary. 32 */ 33 public class ApplicationsSettingsFragment extends AppListFragment { 34 35 private ApplicationListItemManager mAppListItemManager; 36 37 @Override getPreferenceScreenResId()38 protected int getPreferenceScreenResId() { 39 return R.xml.applications_settings_fragment; 40 } 41 42 @Override onAttach(Context context)43 public void onAttach(Context context) { 44 super.onAttach(context); 45 46 Application application = requireActivity().getApplication(); 47 StorageManager sm = context.getSystemService(StorageManager.class); 48 VolumeInfo volume = maybeInitializeVolume(sm, getArguments()); 49 mAppListItemManager = new ApplicationListItemManager(volume, getLifecycle(), 50 ApplicationsState.getInstance(application), 51 getContext().getResources().getInteger( 52 R.integer.millisecond_app_data_update_interval), 53 getContext().getResources().getInteger( 54 R.integer.millisecond_max_app_load_wait_interval)); 55 mAppListItemManager.registerListener( 56 use(ApplicationsSettingsPreferenceController.class, 57 R.string.pk_all_applications_settings_list)); 58 } 59 60 @Override onCreate(Bundle savedInstanceState)61 public void onCreate(Bundle savedInstanceState) { 62 super.onCreate(savedInstanceState); 63 mAppListItemManager.startLoading(getAppFilter(), ApplicationsState.ALPHA_COMPARATOR); 64 } 65 66 @Override onStart()67 public void onStart() { 68 super.onStart(); 69 mAppListItemManager.onFragmentStart(); 70 } 71 72 @Override onStop()73 public void onStop() { 74 super.onStop(); 75 mAppListItemManager.onFragmentStop(); 76 } 77 78 @Override onToggleShowSystemApps(boolean showSystem)79 protected void onToggleShowSystemApps(boolean showSystem) { 80 mAppListItemManager.rebuildWithFilter(getAppFilter()); 81 } 82 getAppFilter()83 private ApplicationsState.AppFilter getAppFilter() { 84 return shouldShowSystemApps() ? null 85 : ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT; 86 } 87 } 88