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.os.IVold; 20 import android.os.storage.VolumeInfo; 21 22 import java.io.File; 23 import java.util.ArrayList; 24 import java.util.Comparator; 25 import java.util.List; 26 27 public class VolumeInfoCompat { 28 VolumeInfo mVolumeInfo; 29 public String fsUuid; 30 31 public static final String ACTION_VOLUME_STATE_CHANGED = VolumeInfo.ACTION_VOLUME_STATE_CHANGED; 32 public static final String EXTRA_VOLUME_ID = VolumeInfo.EXTRA_VOLUME_ID; 33 public static final String EXTRA_VOLUME_STATE = VolumeInfo.EXTRA_VOLUME_STATE; 34 35 /** Stub volume representing internal private storage */ 36 public static final String ID_PRIVATE_INTERNAL = VolumeInfo.ID_PRIVATE_INTERNAL; 37 /** Real volume representing internal emulated storage */ 38 39 public static final int TYPE_PUBLIC = IVold.VOLUME_TYPE_PUBLIC; 40 public static final int TYPE_PRIVATE = IVold.VOLUME_TYPE_PRIVATE; 41 public static final int TYPE_EMULATED = IVold.VOLUME_TYPE_EMULATED; 42 public static final int TYPE_ASEC = IVold.VOLUME_TYPE_ASEC; 43 public static final int TYPE_OBB = IVold.VOLUME_TYPE_OBB; 44 public static final int TYPE_STUB = IVold.VOLUME_TYPE_STUB; 45 46 public static final int STATE_UNMOUNTED = IVold.VOLUME_STATE_UNMOUNTED; 47 public static final int STATE_CHECKING = IVold.VOLUME_STATE_CHECKING; 48 public static final int STATE_MOUNTED = IVold.VOLUME_STATE_MOUNTED; 49 public static final int STATE_MOUNTED_READ_ONLY = IVold.VOLUME_STATE_MOUNTED_READ_ONLY; 50 public static final int STATE_FORMATTING = IVold.VOLUME_STATE_FORMATTING; 51 public static final int STATE_EJECTING = IVold.VOLUME_STATE_EJECTING; 52 public static final int STATE_UNMOUNTABLE = IVold.VOLUME_STATE_UNMOUNTABLE; 53 public static final int STATE_REMOVED = IVold.VOLUME_STATE_REMOVED; 54 public static final int STATE_BAD_REMOVAL = IVold.VOLUME_STATE_BAD_REMOVAL; 55 VolumeInfoCompat(VolumeInfo volumeInfo)56 VolumeInfoCompat(VolumeInfo volumeInfo) { 57 mVolumeInfo = volumeInfo; 58 fsUuid = volumeInfo.fsUuid; 59 } 60 convert(List<VolumeInfo> infos)61 static List<VolumeInfoCompat> convert(List<VolumeInfo> infos) { 62 List<VolumeInfoCompat> list = new ArrayList<>(); 63 for (VolumeInfo info : infos) { 64 list.add(new VolumeInfoCompat(info)); 65 } 66 return list; 67 } 68 69 public @Nullable getFsUuid()70 String getFsUuid() { 71 return mVolumeInfo.getFsUuid(); 72 } 73 74 public @NonNull getId()75 String getId() { 76 return mVolumeInfo.getId(); 77 } 78 getType()79 public int getType() { 80 return mVolumeInfo.getType(); 81 } 82 getDisk()83 public DiskInfoCompat getDisk() { 84 return new DiskInfoCompat(mVolumeInfo.getDisk()); 85 } 86 87 public @Nullable getDiskId()88 String getDiskId() { 89 return mVolumeInfo.getDiskId(); 90 } 91 getPath()92 public File getPath() { 93 return mVolumeInfo.getPath(); 94 } 95 isMountedWritable()96 public boolean isMountedWritable() { 97 return mVolumeInfo.isMountedWritable(); 98 } 99 isMountedReadable()100 public boolean isMountedReadable() { 101 return mVolumeInfo.isMountedReadable(); 102 } 103 104 public static @NonNull getDescriptionComparator()105 Comparator<VolumeInfoCompat> getDescriptionComparator() { 106 return new Comparator<VolumeInfoCompat>() { 107 @Override 108 public int compare(VolumeInfoCompat o1, VolumeInfoCompat o2) { 109 return VolumeInfo.getDescriptionComparator().compare( 110 o1.mVolumeInfo, o2.mVolumeInfo); 111 } 112 }; 113 } 114 } 115