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.UserManager; 24 import android.os.storage.StorageManager; 25 import android.os.storage.VolumeInfo; 26 27 import com.android.car.settings.R; 28 import com.android.car.settings.applications.AppListFragment; 29 import com.android.car.settings.applications.ApplicationListItemManager; 30 import com.android.settingslib.applications.ApplicationsState; 31 32 /** 33 * Lists all installed applications with no category defined and their summary. 34 */ 35 public class StorageOtherCategoryDetailFragment extends AppListFragment { 36 37 private ApplicationListItemManager mAppListItemManager; 38 39 @Override getPreferenceScreenResId()40 protected int getPreferenceScreenResId() { 41 return R.xml.storage_other_category_detail_fragment; 42 } 43 44 @Override onAttach(Context context)45 public void onAttach(Context context) { 46 super.onAttach(context); 47 Application application = requireActivity().getApplication(); 48 StorageManager sm = context.getSystemService(StorageManager.class); 49 UserManager um = context.getSystemService(UserManager.class); 50 VolumeInfo volume = maybeInitializeVolume(sm, getArguments()); 51 mAppListItemManager = new ApplicationListItemManager(volume, getLifecycle(), 52 ApplicationsState.getInstance(application), 53 getContext().getResources().getInteger( 54 R.integer.millisecond_app_data_update_interval), 55 getContext().getResources().getInteger( 56 R.integer.millisecond_max_app_load_wait_interval), 57 getContext().getPackageManager(), um); 58 mAppListItemManager.registerListener( 59 use(StorageApplicationListPreferenceController.class, 60 R.string.pk_storage_other_apps_details)); 61 } 62 63 @Override onCreate(Bundle savedInstanceState)64 public void onCreate(Bundle savedInstanceState) { 65 super.onCreate(savedInstanceState); 66 mAppListItemManager.startLoading(getAppFilter(), ApplicationsState.SIZE_COMPARATOR); 67 } 68 69 @Override onStart()70 public void onStart() { 71 super.onStart(); 72 mAppListItemManager.onFragmentStart(); 73 } 74 75 @Override onStop()76 public void onStop() { 77 super.onStop(); 78 mAppListItemManager.onFragmentStop(); 79 } 80 81 @Override onToggleShowSystemApps(boolean showSystem)82 protected void onToggleShowSystemApps(boolean showSystem) { 83 mAppListItemManager.rebuildWithFilter(getAppFilter()); 84 } 85 getAppFilter()86 private ApplicationsState.AppFilter getAppFilter() { 87 ApplicationsState.AppFilter filter = ApplicationsState.FILTER_OTHER_APPS; 88 if (!shouldShowSystemApps()) { 89 filter = new ApplicationsState.CompoundFilter(filter, 90 ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT); 91 } 92 return filter; 93 } 94 } 95