1 /*
2  * Copyright (C) 2020 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.role.persistence;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.annotation.SystemApi.Client;
23 import android.os.UserHandle;
24 
25 /**
26  * Persistence for roles.
27  *
28  * TODO(b/147914847): Remove @hide when it becomes the default.
29  * @hide
30  */
31 @SystemApi(client = Client.SYSTEM_SERVER)
32 public interface RolesPersistence {
33 
34     /**
35      * Read the roles from persistence.
36      *
37      * This will perform I/O operations synchronously.
38      *
39      * @param user the user to read for
40      * @return the roles read
41      */
42     @Nullable
readForUser(@onNull UserHandle user)43     RolesState readForUser(@NonNull UserHandle user);
44 
45     /**
46      * Write the roles to persistence.
47      *
48      * This will perform I/O operations synchronously.
49      *
50      * @param roles the roles to write
51      * @param user the user to write for
52      */
writeForUser(@onNull RolesState roles, @NonNull UserHandle user)53     void writeForUser(@NonNull RolesState roles, @NonNull UserHandle user);
54 
55     /**
56      * Delete the roles from persistence.
57      *
58      * This will perform I/O operations synchronously.
59      *
60      * @param user the user to delete for
61      */
deleteForUser(@onNull UserHandle user)62     void deleteForUser(@NonNull UserHandle user);
63 
64     /**
65      * Create a new instance of {@link RolesPersistence} implementation.
66      *
67      * @return the new instance.
68      */
69     @NonNull
createInstance()70     static RolesPersistence createInstance() {
71         return new RolesPersistenceImpl();
72     }
73 }
74