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 import android.os.Environment; 20 21 import java.io.File; 22 23 /** 24 * Class to help with the filesystem related methods. 25 * 26 * @hide 27 */ 28 public final class FilesUtil { 29 /** 30 * Get the health connect dir for the user to store sensitive data in a credential encrypted 31 * dir. 32 */ getDataSystemCeHCDirectoryForUser(int userId)33 public static File getDataSystemCeHCDirectoryForUser(int userId) { 34 // Duplicates the implementation of Environment#getDataSystemCeDirectory 35 // TODO(b/191059409): Unhide Environment#getDataSystemCeDirectory and switch to it. 36 File systemCeDir = new File(Environment.getDataDirectory(), "system_ce"); 37 File systemCeUserDir = new File(systemCeDir, String.valueOf(userId)); 38 return new File(systemCeUserDir, "healthconnect"); 39 } 40 41 /** Delete the dir recursively. */ deleteDir(File dir)42 public static void deleteDir(File dir) { 43 File[] files = dir.listFiles(); 44 if (files != null) { 45 for (var file : files) { 46 if (file.isDirectory()) { 47 deleteDir(file); 48 } else { 49 file.delete(); 50 } 51 } 52 } 53 dir.delete(); 54 } 55 FilesUtil()56 private FilesUtil() {} 57 } 58