blob: 1e855a9819ac4ccd9c61bce9e988b6f31601bb4e [file] [log] [blame]
David Anderson28dea682019-02-20 13:37:51 -08001/*
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 */
16package com.android.server.locksettings;
17
18import androidx.test.InstrumentationRegistry;
19
20import java.io.File;
21import java.nio.file.Files;
22import java.nio.file.Paths;
23
24public class PasswordSlotManagerTestable extends PasswordSlotManager {
25
26 private int mGsiImageNumber;
27 private String mSlotMapDir;
28
29 public PasswordSlotManagerTestable() {
30 mGsiImageNumber = 0;
31 }
32
33 @Override
34 protected int getGsiImageNumber() {
35 return mGsiImageNumber;
36 }
37
38 @Override
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
51 void setGsiImageNumber(int gsiImageNumber) {
52 mGsiImageNumber = gsiImageNumber;
53 }
54
55 void cleanup() {
56 try {
57 Files.delete(Paths.get(getSlotMapDir(), "slot_map"));
58 } catch (Exception e) {
59 }
60 }
61};