• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.server.healthconnect.utils;
18 
19 
20 import java.io.File;
21 
22 /**
23  * Class to help with the filesystem related methods.
24  *
25  * @hide
26  */
27 public final class FilesUtil {
28 
29     /**
30      * Get the health connect dir for the user to store sensitive data in a credential encrypted
31      * dir.
32      *
33      * @param environmentDataDirectory The environment data directory to use, allowing this to be
34      *     overridden for tests. Should normally be {@link android.os.Environment#getDataDirectory}.
35      */
getDataSystemCeHCDirectoryForUser( File environmentDataDirectory, int userId)36     public static File getDataSystemCeHCDirectoryForUser(
37             File environmentDataDirectory, int userId) {
38         // Duplicates the implementation of Environment#getDataSystemCeDirectory
39         // TODO(b/191059409): Unhide Environment#getDataSystemCeDirectory and switch to it.
40         File systemCeDir = new File(environmentDataDirectory, "system_ce");
41         File systemCeUserDir = new File(systemCeDir, String.valueOf(userId));
42         return new File(systemCeUserDir, "healthconnect");
43     }
44 
45     /** Delete the dir recursively. */
deleteDir(File dir)46     public static void deleteDir(File dir) {
47         File[] files = dir.listFiles();
48         if (files != null) {
49             for (var file : files) {
50                 if (file.isDirectory()) {
51                     deleteDir(file);
52                 } else {
53                     file.delete();
54                 }
55             }
56         }
57         dir.delete();
58     }
59 
FilesUtil()60     private FilesUtil() {}
61 }
62