• 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.os.storage.DiskInfo;
20 import android.os.storage.StorageManager;
21 import android.os.storage.VolumeInfo;
22 import android.os.storage.VolumeRecord;
23 
24 import org.robolectric.annotation.Implementation;
25 import org.robolectric.annotation.Implements;
26 import org.robolectric.annotation.Resetter;
27 
28 @Implements(StorageManager.class)
29 public class ShadowStorageManager {
30 
31     private static boolean sIsUnmountCalled;
32     private static boolean sIsForgetCalled;
33     private static boolean sIsFileEncryptedNativeOrEmulated = true;
34 
isUnmountCalled()35     public static boolean isUnmountCalled() {
36         return sIsUnmountCalled;
37     }
38 
isForgetCalled()39     public static boolean isForgetCalled() {
40         return sIsForgetCalled;
41     }
42 
43     @Resetter
reset()44     public static void reset() {
45         sIsUnmountCalled = false;
46         sIsForgetCalled = false;
47         sIsFileEncryptedNativeOrEmulated = true;
48     }
49 
50     @Implementation
findVolumeById(String id)51     protected VolumeInfo findVolumeById(String id) {
52         return createVolumeInfo(id);
53     }
54 
55     @Implementation
findDiskById(String id)56     protected DiskInfo findDiskById(String id) {
57         return new DiskInfo(id, DiskInfo.FLAG_SD);
58     }
59 
60     @Implementation
findRecordByUuid(String fsUuid)61     protected VolumeRecord findRecordByUuid(String fsUuid) {
62         return createVolumeRecord(fsUuid);
63     }
64 
65     @Implementation
unmount(String volId)66     protected void unmount(String volId) {
67         sIsUnmountCalled = true;
68     }
69 
70     @Implementation
forgetVolume(String fsUuid)71     protected void forgetVolume(String fsUuid) {
72         sIsForgetCalled = true;
73     }
74 
75     @Implementation
isFileEncryptedNativeOrEmulated()76     protected static boolean isFileEncryptedNativeOrEmulated() {
77         return sIsFileEncryptedNativeOrEmulated;
78     }
79 
setIsFileEncryptedNativeOrEmulated(boolean encrypted)80     public static void setIsFileEncryptedNativeOrEmulated(boolean encrypted) {
81         sIsFileEncryptedNativeOrEmulated = encrypted;
82     }
83 
createVolumeInfo(String volumeId)84     private VolumeInfo createVolumeInfo(String volumeId) {
85         final DiskInfo disk = new DiskInfo("fakeid", 0);
86         return new VolumeInfo(volumeId, 0, disk, "guid");
87     }
88 
createVolumeRecord(String fsUuid)89     private VolumeRecord createVolumeRecord(String fsUuid) {
90         VolumeRecord record = new VolumeRecord(VolumeRecord.USER_FLAG_INITED, fsUuid);
91         record.nickname = "nickname";
92         return record;
93     }
94 }
95