LockSettingsStorageTestable.java revision 3bf722a8d54ca7192dfe07ee7b73eac7d25ccac5
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.Context;
20
21import java.io.File;
22
23public class LockSettingsStorageTestable extends LockSettingsStorage {
24
25    public File mStorageDir;
26
27    public LockSettingsStorageTestable(Context context, File storageDir) {
28        super(context);
29        mStorageDir = storageDir;
30    }
31
32    @Override
33    String getLockPatternFilename(int userId) {
34        return makeDirs(mStorageDir,
35                super.getLockPatternFilename(userId)).getAbsolutePath();
36    }
37
38    @Override
39    String getLockPasswordFilename(int userId) {
40        return makeDirs(mStorageDir,
41                super.getLockPasswordFilename(userId)).getAbsolutePath();
42    }
43
44    @Override
45    String getChildProfileLockFile(int userId) {
46        return makeDirs(mStorageDir,
47                super.getChildProfileLockFile(userId)).getAbsolutePath();
48    }
49
50    @Override
51    protected File getSyntheticPasswordDirectoryForUser(int userId) {
52        return makeDirs(mStorageDir, super.getSyntheticPasswordDirectoryForUser(
53                userId).getAbsolutePath());
54    }
55
56    private File makeDirs(File baseDir, String filePath) {
57        File path = new File(filePath);
58        if (path.getParent() == null) {
59            return new File(baseDir, filePath);
60        } else {
61            File mappedDir = new File(baseDir, path.getParent());
62            mappedDir.mkdirs();
63            return new File(mappedDir, path.getName());
64        }
65    }
66}
67