• 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 
17 package com.android.car.settings.storage;
18 
19 import static com.android.car.settings.storage.StorageUtils.maybeInitializeVolume;
20 
21 import android.annotation.XmlRes;
22 import android.content.Context;
23 import android.os.Bundle;
24 import android.os.storage.StorageManager;
25 import android.os.storage.VolumeInfo;
26 import android.provider.Settings;
27 
28 import androidx.loader.app.LoaderManager;
29 
30 import com.android.car.settings.R;
31 import com.android.car.settings.common.SettingsFragment;
32 import com.android.car.settings.search.CarBaseSearchIndexProvider;
33 import com.android.settingslib.search.SearchIndexable;
34 
35 import java.util.Arrays;
36 import java.util.List;
37 
38 /** Fragment which shows the settings for storage. */
39 @SearchIndexable
40 public class StorageSettingsFragment extends SettingsFragment {
41 
42     private StorageSettingsManager mStorageSettingsManager;
43 
44     @Override
45     @XmlRes
getPreferenceScreenResId()46     protected int getPreferenceScreenResId() {
47         return R.xml.storage_settings_fragment;
48     }
49 
50     @Override
onAttach(Context context)51     public void onAttach(Context context) {
52         super.onAttach(context);
53         StorageManager sm = context.getSystemService(StorageManager.class);
54         VolumeInfo volume = maybeInitializeVolume(sm, getArguments());
55         mStorageSettingsManager = new StorageSettingsManager(getContext(), volume);
56         List<StorageUsageBasePreferenceController> usagePreferenceControllers =
57                 Arrays.asList(
58                         use(StorageMediaCategoryPreferenceController.class,
59                                 R.string.pk_storage_music_audio),
60                         use(StorageOtherCategoryPreferenceController.class,
61                                 R.string.pk_storage_other_apps),
62                         use(StorageFileCategoryPreferenceController.class,
63                                 R.string.pk_storage_files),
64                         use(StorageSystemCategoryPreferenceController.class,
65                                 R.string.pk_storage_system));
66 
67         for (StorageUsageBasePreferenceController pc : usagePreferenceControllers) {
68             mStorageSettingsManager.registerListener(pc);
69             pc.setVolumeInfo(volume);
70         }
71     }
72 
73     @Override
onCreate(Bundle savedInstanceState)74     public void onCreate(Bundle savedInstanceState) {
75         super.onCreate(savedInstanceState);
76         LoaderManager loaderManager = LoaderManager.getInstance(this);
77         mStorageSettingsManager.startLoading(loaderManager);
78     }
79 
80     public static final CarBaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
81             new CarBaseSearchIndexProvider(R.xml.storage_settings_fragment,
82                     Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
83 }
84