1 /*
2  * Copyright (C) 2021 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 import android.annotation.NonNull;
18 import android.annotation.Nullable;
19 import android.content.Context;
20 import android.os.storage.StorageManager;
21 
22 import java.util.List;
23 
24 public class StorageManagerCompat {
StorageManagerCompat(StorageManager manager)25     public StorageManagerCompat(StorageManager manager) {
26         mManager = manager;
27     }
28 
StorageManagerCompat(Context context)29     public StorageManagerCompat(Context context) {
30         mManager = context.getSystemService(StorageManager.class);
31     }
32 
33     private final StorageManager mManager;
34 
registerListener(StorageEventListenerCompat listener)35     public void registerListener(StorageEventListenerCompat listener) {
36         mManager.registerListener(listener.listener);
37     }
38 
unregisterListener(StorageEventListenerCompat listener)39     public void unregisterListener(StorageEventListenerCompat listener) {
40         mManager.unregisterListener(listener.listener);
41     }
42 
43     public @Nullable
findRecordByUuid(String fsUuid)44     VolumeRecordCompat findRecordByUuid(String fsUuid) {
45         return new VolumeRecordCompat(mManager.findRecordByUuid(fsUuid));
46     }
47 
48     public @NonNull
getVolumes()49     List<VolumeInfoCompat> getVolumes() {
50         return VolumeInfoCompat.convert(mManager.getVolumes());
51     }
52 
53     public @NonNull
getDisks()54     List<DiskInfoCompat> getDisks() {
55         return DiskInfoCompat.convert(mManager.getDisks());
56     }
57 
58     public @NonNull
getVolumeRecords()59     List<VolumeRecordCompat> getVolumeRecords() {
60         return VolumeRecordCompat.convert(mManager.getVolumeRecords());
61     }
62 
63     public @Nullable
findDiskById(String id)64     DiskInfoCompat findDiskById(String id) {
65         return new DiskInfoCompat(mManager.findDiskById(id));
66     }
67 
68     public @Nullable
findVolumeByUuid(String fsUuid)69     VolumeInfoCompat findVolumeByUuid(String fsUuid) {
70         return new VolumeInfoCompat(mManager.findVolumeByUuid(fsUuid));
71     }
72 
forgetVolume(String fsUuid)73     public void forgetVolume(String fsUuid) {
74         mManager.forgetVolume(fsUuid);
75     }
76 
77     public @Nullable
getBestVolumeDescription(VolumeInfoCompat vol)78     String getBestVolumeDescription(VolumeInfoCompat vol) {
79         return mManager.getBestVolumeDescription(vol.mVolumeInfo);
80     }
81 
82     public @Nullable
findEmulatedForPrivate(VolumeInfoCompat privateVol)83     VolumeInfoCompat findEmulatedForPrivate(VolumeInfoCompat privateVol) {
84         return new VolumeInfoCompat(mManager.findEmulatedForPrivate(privateVol.mVolumeInfo));
85     }
86 
87     public @Nullable
findVolumeById(String id)88     VolumeInfoCompat findVolumeById(String id) {
89         return new VolumeInfoCompat(mManager.findVolumeById(id));
90     }
91 
partitionPublic(String diskId)92     public void partitionPublic(String diskId) {
93         mManager.partitionPublic(diskId);
94     }
95 
partitionPrivate(String diskId)96     public void partitionPrivate(String diskId) {
97         mManager.partitionPrivate(diskId);
98     }
99 
benchmark(String volId)100     public long benchmark(String volId) {
101         return mManager.benchmark(volId);
102     }
103 
unmount(String volId)104     public void unmount(String volId) {
105         mManager.unmount(volId);
106     }
107 }
108