1 /*
2  * Copyright (C) 2019 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 package com.android.server.locksettings;
17 
18 import androidx.test.InstrumentationRegistry;
19 
20 import java.io.File;
21 import java.nio.file.Files;
22 import java.nio.file.Paths;
23 
24 public class PasswordSlotManagerTestable extends PasswordSlotManager {
25 
26     private int mGsiImageNumber;
27     private String mSlotMapDir;
28 
PasswordSlotManagerTestable()29     public PasswordSlotManagerTestable() {
30         mGsiImageNumber = 0;
31     }
32 
33     @Override
getGsiImageNumber()34     protected int getGsiImageNumber() {
35         return mGsiImageNumber;
36     }
37 
38     @Override
getSlotMapDir()39     protected String getSlotMapDir() {
40         if (mSlotMapDir == null) {
41             final File testDir = InstrumentationRegistry.getContext().getFilesDir();
42             if (!testDir.exists()) {
43                 testDir.mkdirs();
44             }
45 
46             mSlotMapDir = testDir.getPath();
47         }
48         return mSlotMapDir;
49     }
50 
setGsiImageNumber(int gsiImageNumber)51     void setGsiImageNumber(int gsiImageNumber) {
52         mGsiImageNumber = gsiImageNumber;
53     }
54 
cleanup()55     void cleanup() {
56         try {
57             Files.delete(Paths.get(getSlotMapDir(), "slot_map"));
58         } catch (Exception e) {
59         }
60     }
61 }
62