• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 android.car.builtin.os;
17 
18 import android.annotation.NonNull;
19 import android.annotation.SystemApi;
20 import android.annotation.UserIdInt;
21 import android.content.Context;
22 import android.os.storage.StorageManager;
23 
24 /**
25  * Helper for {@link StorageManager}.
26  *
27  * @hide
28  */
29 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
30 public class StorageManagerHelper {
31 
StorageManagerHelper()32     private StorageManagerHelper() {
33         throw new UnsupportedOperationException("contains only static members");
34     }
35 
36     /**
37      * Returns whether or not a user's storage is currently unlocked
38      */
isUserStorageUnlocked(@serIdInt int userId)39     public static boolean isUserStorageUnlocked(@UserIdInt int userId) {
40         return StorageManager.isCeStorageUnlocked(userId);
41     }
42 
43     /**
44      * Locks the user storage for the provided userId.
45      * @return true if the user storage was successfully locked
46      */
lockUserStorage(@onNull Context context, @UserIdInt int userId)47     public static boolean lockUserStorage(@NonNull Context context, @UserIdInt int userId) {
48         StorageManager sm = context.getSystemService(StorageManager.class);
49         if (sm != null) {
50             sm.lockCeStorage(userId);
51             return !isUserStorageUnlocked(userId);
52         }
53         return false;
54     }
55 }
56