MockStorageManager.java revision ee67b61bb08ab09be413f181f948f6359f4c256d
1/*
2 * Copyright (C) 2017 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
17package com.android.server;
18
19import android.content.pm.IPackageMoveObserver;
20import android.os.IBinder;
21import android.os.IProgressListener;
22import android.os.ParcelFileDescriptor;
23import android.os.RemoteException;
24import android.os.storage.DiskInfo;
25import android.os.storage.IObbActionListener;
26import android.os.storage.IStorageEventListener;
27import android.os.storage.IStorageManager;
28import android.os.storage.IStorageShutdownObserver;
29import android.os.storage.StorageVolume;
30import android.os.storage.VolumeInfo;
31import android.os.storage.VolumeRecord;
32import android.util.ArrayMap;
33import android.util.Pair;
34
35import com.android.internal.os.AppFuseMount;
36
37import junit.framework.AssertionFailedError;
38
39import java.util.ArrayList;
40import java.util.Arrays;
41
42public class MockStorageManager implements IStorageManager {
43
44    private ArrayMap<Integer, ArrayList<Pair<byte[], byte[]>>> mAuth = new ArrayMap<>();
45    private boolean mIgnoreBadUnlock;
46
47    @Override
48    public void addUserKeyAuth(int userId, int serialNumber, byte[] token, byte[] secret)
49            throws RemoteException {
50        getUserAuth(userId).add(new Pair<>(token, secret));
51    }
52
53    @Override
54    public void fixateNewestUserKeyAuth(int userId) throws RemoteException {
55        ArrayList<Pair<byte[], byte[]>> auths = mAuth.get(userId);
56        Pair<byte[], byte[]> latest = auths.get(auths.size() - 1);
57        auths.clear();
58        auths.add(latest);
59    }
60
61    private ArrayList<Pair<byte[], byte[]>> getUserAuth(int userId) {
62        if (!mAuth.containsKey(userId)) {
63            ArrayList<Pair<byte[], byte[]>> auths = new ArrayList<Pair<byte[], byte[]>>();
64            auths.add(new Pair(null, null));
65            mAuth.put(userId,  auths);
66        }
67        return mAuth.get(userId);
68    }
69
70    public byte[] getUserUnlockToken(int userId) {
71        ArrayList<Pair<byte[], byte[]>> auths = getUserAuth(userId);
72        if (auths.size() != 1) {
73            throw new AssertionFailedError("More than one secret exists");
74        }
75        return auths.get(0).second;
76    }
77
78    public void unlockUser(int userId, byte[] secret, IProgressListener listener)
79            throws RemoteException {
80        listener.onStarted(userId, null);
81        listener.onFinished(userId, null);
82        ArrayList<Pair<byte[], byte[]>> auths = getUserAuth(userId);
83        if (secret != null) {
84            if (auths.size() > 1) {
85                throw new AssertionFailedError("More than one secret exists");
86            }
87            Pair<byte[], byte[]> auth = auths.get(0);
88            if ((!mIgnoreBadUnlock) && auth.second != null && !Arrays.equals(secret, auth.second)) {
89                throw new AssertionFailedError("Invalid secret to unlock user");
90            }
91        } else {
92            if (auths != null && auths.size() > 0) {
93                throw new AssertionFailedError("Cannot unlock encrypted user with empty token");
94            }
95        }
96    }
97
98    public void setIgnoreBadUnlock(boolean ignore) {
99        mIgnoreBadUnlock = ignore;
100    }
101
102    @Override
103    public IBinder asBinder() {
104        throw new UnsupportedOperationException();
105    }
106
107    @Override
108    public void registerListener(IStorageEventListener listener) throws RemoteException {
109        throw new UnsupportedOperationException();
110    }
111
112    @Override
113    public void unregisterListener(IStorageEventListener listener) throws RemoteException {
114        throw new UnsupportedOperationException();
115    }
116
117    @Override
118    public boolean isUsbMassStorageConnected() throws RemoteException {
119        throw new UnsupportedOperationException();
120    }
121
122    @Override
123    public void setUsbMassStorageEnabled(boolean enable) throws RemoteException {
124        throw new UnsupportedOperationException();
125    }
126
127    @Override
128    public boolean isUsbMassStorageEnabled() throws RemoteException {
129        throw new UnsupportedOperationException();
130    }
131
132    @Override
133    public int mountVolume(String mountPoint) throws RemoteException {
134        throw new UnsupportedOperationException();
135    }
136
137    @Override
138    public void unmountVolume(String mountPoint, boolean force, boolean removeEncryption)
139            throws RemoteException {
140        throw new UnsupportedOperationException();
141
142    }
143
144    @Override
145    public int formatVolume(String mountPoint) throws RemoteException {
146        throw new UnsupportedOperationException();
147    }
148
149    @Override
150    public int[] getStorageUsers(String path) throws RemoteException {
151        throw new UnsupportedOperationException();
152    }
153
154    @Override
155    public String getVolumeState(String mountPoint) throws RemoteException {
156        throw new UnsupportedOperationException();
157    }
158
159    @Override
160    public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid,
161            boolean external) throws RemoteException {
162        throw new UnsupportedOperationException();
163    }
164
165    @Override
166    public int finalizeSecureContainer(String id) throws RemoteException {
167        throw new UnsupportedOperationException();
168    }
169
170    @Override
171    public int destroySecureContainer(String id, boolean force) throws RemoteException {
172        throw new UnsupportedOperationException();
173    }
174
175    @Override
176    public int mountSecureContainer(String id, String key, int ownerUid, boolean readOnly)
177            throws RemoteException {
178        throw new UnsupportedOperationException();
179    }
180
181    @Override
182    public int unmountSecureContainer(String id, boolean force) throws RemoteException {
183        throw new UnsupportedOperationException();
184    }
185
186    @Override
187    public boolean isSecureContainerMounted(String id) throws RemoteException {
188        throw new UnsupportedOperationException();
189    }
190
191    @Override
192    public int renameSecureContainer(String oldId, String newId) throws RemoteException {
193        throw new UnsupportedOperationException();
194    }
195
196    @Override
197    public String getSecureContainerPath(String id) throws RemoteException {
198        throw new UnsupportedOperationException();
199    }
200
201    @Override
202    public String[] getSecureContainerList() throws RemoteException {
203        throw new UnsupportedOperationException();
204    }
205
206    @Override
207    public void shutdown(IStorageShutdownObserver observer) throws RemoteException {
208        throw new UnsupportedOperationException();
209    }
210
211    @Override
212    public void finishMediaUpdate() throws RemoteException {
213        throw new UnsupportedOperationException();
214    }
215
216    @Override
217    public void mountObb(String rawPath, String canonicalPath, String key, IObbActionListener token,
218            int nonce) throws RemoteException {
219        throw new UnsupportedOperationException();
220    }
221
222    @Override
223    public void unmountObb(String rawPath, boolean force, IObbActionListener token, int nonce)
224            throws RemoteException {
225        throw new UnsupportedOperationException();
226    }
227
228    @Override
229    public boolean isObbMounted(String rawPath) throws RemoteException {
230        throw new UnsupportedOperationException();
231    }
232
233    @Override
234    public String getMountedObbPath(String rawPath) throws RemoteException {
235        throw new UnsupportedOperationException();
236    }
237
238    @Override
239    public boolean isExternalStorageEmulated() throws RemoteException {
240        throw new UnsupportedOperationException();
241    }
242
243    @Override
244    public int decryptStorage(String password) throws RemoteException {
245        throw new UnsupportedOperationException();
246    }
247
248    @Override
249    public int encryptStorage(int type, String password) throws RemoteException {
250        throw new UnsupportedOperationException();
251    }
252
253    @Override
254    public int changeEncryptionPassword(int type, String password) throws RemoteException {
255        throw new UnsupportedOperationException();
256    }
257
258    @Override
259    public StorageVolume[] getVolumeList(int uid, String packageName, int flags)
260            throws RemoteException {
261        throw new UnsupportedOperationException();
262    }
263
264    @Override
265    public String getSecureContainerFilesystemPath(String cid) throws RemoteException {
266        throw new UnsupportedOperationException();
267    }
268
269    @Override
270    public int getEncryptionState() throws RemoteException {
271        throw new UnsupportedOperationException();
272    }
273
274    @Override
275    public int verifyEncryptionPassword(String password) throws RemoteException {
276        throw new UnsupportedOperationException();
277    }
278
279    @Override
280    public int fixPermissionsSecureContainer(String id, int gid, String filename)
281            throws RemoteException {
282        throw new UnsupportedOperationException();
283    }
284
285    @Override
286    public int mkdirs(String callingPkg, String path) throws RemoteException {
287        throw new UnsupportedOperationException();
288    }
289
290    @Override
291    public int getPasswordType() throws RemoteException {
292        throw new UnsupportedOperationException();
293    }
294
295    @Override
296    public String getPassword() throws RemoteException {
297        throw new UnsupportedOperationException();
298    }
299
300    @Override
301    public void clearPassword() throws RemoteException {
302        throw new UnsupportedOperationException();
303
304    }
305
306    @Override
307    public void setField(String field, String contents) throws RemoteException {
308        throw new UnsupportedOperationException();
309
310    }
311
312    @Override
313    public String getField(String field) throws RemoteException {
314        throw new UnsupportedOperationException();
315    }
316
317    @Override
318    public int resizeSecureContainer(String id, int sizeMb, String key) throws RemoteException {
319        throw new UnsupportedOperationException();
320    }
321
322    @Override
323    public long lastMaintenance() throws RemoteException {
324        throw new UnsupportedOperationException();
325    }
326
327    @Override
328    public void runMaintenance() throws RemoteException {
329        throw new UnsupportedOperationException();
330    }
331
332    @Override
333    public void waitForAsecScan() throws RemoteException {
334        throw new UnsupportedOperationException();
335    }
336
337    @Override
338    public DiskInfo[] getDisks() throws RemoteException {
339        throw new UnsupportedOperationException();
340    }
341
342    @Override
343    public VolumeInfo[] getVolumes(int flags) throws RemoteException {
344        throw new UnsupportedOperationException();
345    }
346
347    @Override
348    public VolumeRecord[] getVolumeRecords(int flags) throws RemoteException {
349        throw new UnsupportedOperationException();
350    }
351
352    @Override
353    public void mount(String volId) throws RemoteException {
354        throw new UnsupportedOperationException();
355    }
356
357    @Override
358    public void unmount(String volId) throws RemoteException {
359        throw new UnsupportedOperationException();
360    }
361
362    @Override
363    public void format(String volId) throws RemoteException {
364        throw new UnsupportedOperationException();
365    }
366
367    @Override
368    public void partitionPublic(String diskId) throws RemoteException {
369        throw new UnsupportedOperationException();
370    }
371
372    @Override
373    public void partitionPrivate(String diskId) throws RemoteException {
374        throw new UnsupportedOperationException();
375    }
376
377    @Override
378    public void partitionMixed(String diskId, int ratio) throws RemoteException {
379        throw new UnsupportedOperationException();
380    }
381
382    @Override
383    public void setVolumeNickname(String fsUuid, String nickname) throws RemoteException {
384        throw new UnsupportedOperationException();
385    }
386
387    @Override
388    public void setVolumeUserFlags(String fsUuid, int flags, int mask) throws RemoteException {
389        throw new UnsupportedOperationException();
390    }
391
392    @Override
393    public void forgetVolume(String fsUuid) throws RemoteException {
394        throw new UnsupportedOperationException();
395    }
396
397    @Override
398    public void forgetAllVolumes() throws RemoteException {
399        throw new UnsupportedOperationException();
400    }
401
402    @Override
403    public String getPrimaryStorageUuid() throws RemoteException {
404        throw new UnsupportedOperationException();
405    }
406
407    @Override
408    public void setPrimaryStorageUuid(String volumeUuid, IPackageMoveObserver callback)
409            throws RemoteException {
410        throw new UnsupportedOperationException();
411    }
412
413    @Override
414    public long benchmark(String volId) throws RemoteException {
415        throw new UnsupportedOperationException();
416    }
417
418    @Override
419    public void setDebugFlags(int flags, int mask) throws RemoteException {
420        throw new UnsupportedOperationException();
421    }
422
423    @Override
424    public void createUserKey(int userId, int serialNumber, boolean ephemeral)
425            throws RemoteException {
426        throw new UnsupportedOperationException();
427    }
428
429    @Override
430    public void destroyUserKey(int userId) throws RemoteException {
431        throw new UnsupportedOperationException();
432    }
433
434    @Override
435    public void unlockUserKey(int userId, int serialNumber, byte[] token, byte[] secret)
436            throws RemoteException {
437        throw new UnsupportedOperationException();
438    }
439
440    @Override
441    public void lockUserKey(int userId) throws RemoteException {
442        throw new UnsupportedOperationException();
443    }
444
445    @Override
446    public boolean isUserKeyUnlocked(int userId) throws RemoteException {
447        throw new UnsupportedOperationException();
448    }
449
450    @Override
451    public void prepareUserStorage(String volumeUuid, int userId, int serialNumber, int flags)
452            throws RemoteException {
453        throw new UnsupportedOperationException();
454    }
455
456    @Override
457    public void destroyUserStorage(String volumeUuid, int userId, int flags)
458            throws RemoteException {
459        throw new UnsupportedOperationException();
460    }
461
462    @Override
463    public boolean isConvertibleToFBE() throws RemoteException {
464        throw new UnsupportedOperationException();
465    }
466
467    @Override
468    public void fstrim(int flags) throws RemoteException {
469        throw new UnsupportedOperationException();
470    }
471
472    @Override
473    public AppFuseMount mountProxyFileDescriptorBridge() throws RemoteException {
474        throw new UnsupportedOperationException();
475    }
476
477    @Override
478    public ParcelFileDescriptor openProxyFileDescriptor(int mountPointId, int fileId, int mode)
479            throws RemoteException {
480        throw new UnsupportedOperationException();
481    }
482
483    @Override
484    public long getCacheQuotaBytes(String volumeUuid, int uid) throws RemoteException {
485        throw new UnsupportedOperationException();
486    }
487
488    @Override
489    public long getCacheSizeBytes(String volumeUuid, int uid) throws RemoteException {
490        throw new UnsupportedOperationException();
491    }
492
493    @Override
494    public long getAllocatableBytes(String path, int flags) {
495        throw new UnsupportedOperationException();
496    }
497
498    @Override
499    public void allocateBytes(String path, long bytes, int flags) {
500        throw new UnsupportedOperationException();
501    }
502
503    @Override
504    public void secdiscard(String path) throws RemoteException {
505        throw new UnsupportedOperationException();
506    }
507
508}
509