1 /* 2 * Copyright (C) 2019 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.storage; 17 18 import static com.android.car.settings.storage.StorageUtils.maybeInitializeVolume; 19 20 import android.app.Application; 21 import android.content.Context; 22 import android.os.Bundle; 23 import android.os.storage.StorageManager; 24 import android.os.storage.VolumeInfo; 25 26 import com.android.car.settings.R; 27 import com.android.car.settings.applications.AppListFragment; 28 import com.android.car.settings.applications.ApplicationListItemManager; 29 import com.android.settingslib.applications.ApplicationsState; 30 31 /** 32 * Lists all installed applications with no category defined and their summary. 33 */ 34 public class StorageOtherCategoryDetailFragment extends AppListFragment { 35 36 private ApplicationListItemManager mAppListItemManager; 37 38 @Override getPreferenceScreenResId()39 protected int getPreferenceScreenResId() { 40 return R.xml.storage_other_category_detail_fragment; 41 } 42 43 @Override onAttach(Context context)44 public void onAttach(Context context) { 45 super.onAttach(context); 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(StorageApplicationListPreferenceController.class, 57 R.string.pk_storage_other_apps_details)); 58 } 59 60 @Override onCreate(Bundle savedInstanceState)61 public void onCreate(Bundle savedInstanceState) { 62 super.onCreate(savedInstanceState); 63 mAppListItemManager.startLoading(getAppFilter(), ApplicationsState.SIZE_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 ApplicationsState.AppFilter filter = ApplicationsState.FILTER_OTHER_APPS; 85 if (!shouldShowSystemApps()) { 86 filter = new ApplicationsState.CompoundFilter(filter, 87 ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT); 88 } 89 return filter; 90 } 91 } 92