• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import static com.android.car.settings.storage.StorageMediaCategoryPreferenceController.EXTRA_AUDIO_BYTES;
20 import static com.android.car.settings.storage.StorageUtils.maybeInitializeVolume;
21 
22 import android.app.Application;
23 import android.content.Context;
24 import android.os.Bundle;
25 import android.os.storage.StorageManager;
26 import android.os.storage.VolumeInfo;
27 
28 import com.android.car.settings.R;
29 import com.android.car.settings.applications.AppListFragment;
30 import com.android.car.settings.applications.ApplicationListItemManager;
31 import com.android.settingslib.applications.ApplicationsState;
32 
33 /**
34  * Lists all installed applications with category audio and their summary.
35  */
36 public class StorageMediaCategoryDetailFragment extends AppListFragment {
37 
38     private ApplicationListItemManager mAppListItemManager;
39 
40     /**
41      * Gets the instance of this class.
42      */
getInstance()43     public static StorageMediaCategoryDetailFragment getInstance() {
44         StorageMediaCategoryDetailFragment storageMedia = new StorageMediaCategoryDetailFragment();
45         return storageMedia;
46     }
47 
48     @Override
getPreferenceScreenResId()49     protected int getPreferenceScreenResId() {
50         return R.xml.storage_media_category_detail_fragment;
51     }
52 
53     @Override
onAttach(Context context)54     public void onAttach(Context context) {
55         super.onAttach(context);
56         Bundle bundle = getArguments();
57         long externalAudioBytes = bundle.getLong(EXTRA_AUDIO_BYTES);
58         StorageManager sm = context.getSystemService(StorageManager.class);
59         VolumeInfo volume = maybeInitializeVolume(sm, getArguments());
60         Application application = requireActivity().getApplication();
61         mAppListItemManager = new ApplicationListItemManager(volume, getLifecycle(),
62                 ApplicationsState.getInstance(application),
63                 getContext().getResources().getInteger(
64                         R.integer.millisecond_app_data_update_interval),
65                 getContext().getResources().getInteger(
66                         R.integer.millisecond_max_app_load_wait_interval));
67         StorageMediaCategoryDetailPreferenceController pc = use(
68                 StorageMediaCategoryDetailPreferenceController.class,
69                 R.string.pk_storage_music_audio_details);
70         mAppListItemManager.registerListener(pc);
71         pc.setExternalAudioBytes(externalAudioBytes);
72     }
73 
74     @Override
onCreate(Bundle savedInstanceState)75     public void onCreate(Bundle savedInstanceState) {
76         super.onCreate(savedInstanceState);
77         mAppListItemManager.startLoading(getAppFilter(), ApplicationsState.SIZE_COMPARATOR);
78     }
79 
80     @Override
onStart()81     public void onStart() {
82         super.onStart();
83         mAppListItemManager.onFragmentStart();
84     }
85 
86     @Override
onStop()87     public void onStop() {
88         super.onStop();
89         mAppListItemManager.onFragmentStop();
90     }
91 
92     @Override
onToggleShowSystemApps(boolean showSystem)93     protected void onToggleShowSystemApps(boolean showSystem) {
94         mAppListItemManager.rebuildWithFilter(getAppFilter());
95     }
96 
getAppFilter()97     private ApplicationsState.AppFilter getAppFilter() {
98         ApplicationsState.AppFilter filter = ApplicationsState.FILTER_AUDIO;
99         if (!shouldShowSystemApps()) {
100             filter = new ApplicationsState.CompoundFilter(filter,
101                     ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT);
102         }
103         return filter;
104     }
105 }
106