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