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.pm.permission;
18 
19 import android.annotation.NonNull;
20 import android.content.pm.PermissionInfo;
21 
22 import java.util.Map;
23 
24 /**
25  * In-process api for permissions migration.
26  *
27  * @hide
28  */
29 public interface PermissionMigrationHelper {
30     /**
31      * Whether legacy permission definitions/trees exist or not.
32      */
hasLegacyPermission()33     boolean hasLegacyPermission();
34 
35     /**
36      * @return legacy permission definitions.
37      */
38     @NonNull
getLegacyPermissions()39     Map<String, LegacyPermission> getLegacyPermissions();
40 
41     /**
42      * @return legacy permission trees.
43      */
44     @NonNull
getLegacyPermissionTrees()45     Map<String, LegacyPermission> getLegacyPermissionTrees();
46 
47     /**
48      * @return legacy permissions state for a user.
49      */
50     @NonNull
getLegacyPermissionStates(int userId)51     Map<Integer, Map<String, LegacyPermissionState>> getLegacyPermissionStates(int userId);
52 
53     /**
54      * @return permissions file version for the given user.
55      */
getLegacyPermissionStateVersion(int userId)56     int getLegacyPermissionStateVersion(int userId);
57 
58     /**
59      * @return true if permissions state exists or not.
60      */
hasLegacyPermissionState(int userId)61     boolean hasLegacyPermissionState(int userId);
62 
63     /**
64      * Legacy permission definition.
65      */
66     final class LegacyPermission {
67         private final PermissionInfo mPermissionInfo;
68         private final int mType;
69 
LegacyPermission(PermissionInfo permissionInfo, int type)70         LegacyPermission(PermissionInfo permissionInfo, int type) {
71             mPermissionInfo = permissionInfo;
72             mType = type;
73         }
74 
75         @NonNull
getPermissionInfo()76         public PermissionInfo getPermissionInfo() {
77             return mPermissionInfo;
78         }
79 
getType()80         public int getType() {
81             return mType;
82         }
83     }
84 
85     /**
86      * State of a legacy permission.
87      */
88     final class LegacyPermissionState {
89         private final boolean mGranted;
90         private final int mFlags;
91 
LegacyPermissionState(boolean granted, int flags)92         LegacyPermissionState(boolean granted, int flags) {
93             mGranted = granted;
94             mFlags = flags;
95         }
96 
97         /**
98          * @return Whether the permission is granted or not.
99          */
isGranted()100         public boolean isGranted() {
101             return mGranted;
102         }
103 
104         /**
105          * @return Permission flags.
106          */
getFlags()107         public int getFlags() {
108             return mFlags;
109         }
110     }
111 }
112