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 android.app.AlertDialog;
20 import android.car.drivingstate.CarUxRestrictions;
21 import android.content.Context;
22 import android.net.TrafficStats;
23 import android.os.Build;
24 import android.util.SparseArray;
25 
26 import com.android.car.settings.R;
27 import com.android.car.settings.common.FragmentController;
28 import com.android.car.settings.common.ProgressBarPreference;
29 import com.android.car.ui.AlertDialogBuilder;
30 
31 /**
32  * Controller which determines the storage for system category in the storage preference screen.
33  */
34 public class StorageSystemCategoryPreferenceController extends
35         StorageUsageBasePreferenceController {
36 
StorageSystemCategoryPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)37     public StorageSystemCategoryPreferenceController(Context context,
38             String preferenceKey, FragmentController fragmentController,
39             CarUxRestrictions uxRestrictions) {
40         super(context, preferenceKey, fragmentController, uxRestrictions);
41     }
42 
43     @Override
calculateCategoryUsage( SparseArray<StorageAsyncLoader.AppsStorageResult> result, long usedSizeBytes)44     protected long calculateCategoryUsage(
45             SparseArray<StorageAsyncLoader.AppsStorageResult> result, long usedSizeBytes) {
46         long attributedSize = 0;
47         for (int i = 0; i < result.size(); i++) {
48             StorageAsyncLoader.AppsStorageResult otherData = result.valueAt(i);
49 
50             attributedSize += otherData.getGamesSize()
51                     + otherData.getMusicAppsSize()
52                     + otherData.getVideoAppsSize()
53                     + otherData.getPhotosAppsSize()
54                     + otherData.getOtherAppsSize();
55 
56             attributedSize += otherData.getExternalStats().totalBytes
57                     - otherData.getExternalStats().appBytes;
58         }
59         return Math.max(TrafficStats.GB_IN_BYTES, usedSizeBytes - attributedSize);
60     }
61 
62     @Override
handlePreferenceClicked(ProgressBarPreference preference)63     protected boolean handlePreferenceClicked(ProgressBarPreference preference) {
64         AlertDialog alertDialog = new AlertDialogBuilder(getContext())
65                 .setMessage(getContext().getString(R.string.storage_detail_dialog_system,
66                         Build.VERSION.RELEASE))
67                 .setPositiveButton(android.R.string.ok, null)
68                 .create();
69         alertDialog.show();
70         return true;
71     }
72 }
73