1 /* 2 * Copyright (C) 2016 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.settingslib.deviceinfo; 18 19 import android.app.usage.StorageStatsManager; 20 import android.os.storage.StorageManager; 21 import android.os.storage.VolumeInfo; 22 23 import java.io.IOException; 24 import java.util.List; 25 26 /** 27 * StorageManagerVolumeProvider is a thin wrapper around the StorageManager to provide insight into 28 * the storage volumes on a device. 29 */ 30 public class StorageManagerVolumeProvider implements StorageVolumeProvider { 31 private StorageManager mStorageManager; 32 StorageManagerVolumeProvider(StorageManager sm)33 public StorageManagerVolumeProvider(StorageManager sm) { 34 mStorageManager = sm; 35 } 36 37 @Override getPrimaryStorageSize()38 public long getPrimaryStorageSize() { 39 return mStorageManager.getPrimaryStorageSize(); 40 } 41 42 @Override getVolumes()43 public List<VolumeInfo> getVolumes() { 44 return mStorageManager.getVolumes(); 45 } 46 47 @Override findEmulatedForPrivate(VolumeInfo privateVolume)48 public VolumeInfo findEmulatedForPrivate(VolumeInfo privateVolume) { 49 return mStorageManager.findEmulatedForPrivate(privateVolume); 50 } 51 52 @Override getTotalBytes(StorageStatsManager stats, VolumeInfo volume)53 public long getTotalBytes(StorageStatsManager stats, VolumeInfo volume) throws IOException { 54 return stats.getTotalBytes(volume.getFsUuid()); 55 } 56 57 @Override getFreeBytes(StorageStatsManager stats, VolumeInfo volume)58 public long getFreeBytes(StorageStatsManager stats, VolumeInfo volume) throws IOException { 59 return stats.getFreeBytes(volume.getFsUuid()); 60 } 61 } 62