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