• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.settings.testutils.shadow;
18 
19 import android.annotation.NonNull;
20 import android.os.storage.DiskInfo;
21 import android.os.storage.StorageManager;
22 import android.os.storage.VolumeInfo;
23 import android.os.storage.VolumeRecord;
24 
25 import org.robolectric.annotation.Implementation;
26 import org.robolectric.annotation.Implements;
27 import org.robolectric.annotation.Resetter;
28 
29 import java.util.ArrayList;
30 import java.util.List;
31 
32 @Implements(StorageManager.class)
33 public class ShadowStorageManager {
34 
35     private static boolean sIsUnmountCalled;
36     private static boolean sIsForgetCalled;
37     private static boolean sIsFileEncrypted = true;
38 
isUnmountCalled()39     public static boolean isUnmountCalled() {
40         return sIsUnmountCalled;
41     }
42 
isForgetCalled()43     public static boolean isForgetCalled() {
44         return sIsForgetCalled;
45     }
46 
getVolumes()47     public @NonNull List<VolumeInfo> getVolumes() {
48         return new ArrayList<VolumeInfo>();
49     }
50 
51     @Resetter
reset()52     public static void reset() {
53         sIsUnmountCalled = false;
54         sIsForgetCalled = false;
55         sIsFileEncrypted = true;
56     }
57 
58     @Implementation
findVolumeById(String id)59     protected VolumeInfo findVolumeById(String id) {
60         return createVolumeInfo(id);
61     }
62 
63     @Implementation
findDiskById(String id)64     protected DiskInfo findDiskById(String id) {
65         return new DiskInfo(id, DiskInfo.FLAG_SD);
66     }
67 
68     @Implementation
findRecordByUuid(String fsUuid)69     protected VolumeRecord findRecordByUuid(String fsUuid) {
70         return createVolumeRecord(fsUuid);
71     }
72 
73     @Implementation
unmount(String volId)74     protected void unmount(String volId) {
75         sIsUnmountCalled = true;
76     }
77 
78     @Implementation
forgetVolume(String fsUuid)79     protected void forgetVolume(String fsUuid) {
80         sIsForgetCalled = true;
81     }
82 
83     @Implementation
isFileEncrypted()84     protected static boolean isFileEncrypted() {
85         return sIsFileEncrypted;
86     }
87 
setIsFileEncrypted(boolean encrypted)88     public static void setIsFileEncrypted(boolean encrypted) {
89         sIsFileEncrypted = encrypted;
90     }
91 
createVolumeInfo(String volumeId)92     private VolumeInfo createVolumeInfo(String volumeId) {
93         final DiskInfo disk = new DiskInfo("fakeid", 0);
94         return new VolumeInfo(volumeId, 0, disk, "guid");
95     }
96 
createVolumeRecord(String fsUuid)97     private VolumeRecord createVolumeRecord(String fsUuid) {
98         VolumeRecord record = new VolumeRecord(VolumeRecord.USER_FLAG_INITED, fsUuid);
99         record.nickname = "nickname";
100         return record;
101     }
102 }
103