1 /*
2  * Copyright (C) 2021 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.permission.access
18 
19 import android.os.UserHandle
20 
21 sealed class AccessUri(val scheme: String) {
equalsnull22     override fun equals(other: Any?): Boolean {
23         throw NotImplementedError()
24     }
25 
hashCodenull26     override fun hashCode(): Int {
27         throw NotImplementedError()
28     }
29 
toStringnull30     override fun toString(): String {
31         throw NotImplementedError()
32     }
33 }
34 
35 data class AppOpUri(val appOpName: String) : AccessUri(SCHEME) {
toStringnull36     override fun toString(): String = "$scheme:///$appOpName"
37 
38     companion object {
39         const val SCHEME = "app-op"
40     }
41 }
42 
43 data class PackageUri(val packageName: String, val userId: Int) : AccessUri(SCHEME) {
toStringnull44     override fun toString(): String = "$scheme:///$packageName/$userId"
45 
46     companion object {
47         const val SCHEME = "package"
48     }
49 }
50 
51 data class PermissionUri(val permissionName: String) : AccessUri(SCHEME) {
toStringnull52     override fun toString(): String = "$scheme:///$permissionName"
53 
54     companion object {
55         const val SCHEME = "permission"
56     }
57 }
58 
59 data class DevicePermissionUri(val permissionName: String, val deviceId: Int) : AccessUri(SCHEME) {
toStringnull60     override fun toString(): String = "$scheme:///$permissionName/$deviceId"
61 
62     companion object {
63         const val SCHEME = "device-permission"
64     }
65 }
66 
67 data class UidUri(val uid: Int) : AccessUri(SCHEME) {
68     val userId: Int
69         get() = UserHandle.getUserId(uid)
70 
71     val appId: Int
72         get() = UserHandle.getAppId(uid)
73 
toStringnull74     override fun toString(): String = "$scheme:///$uid"
75 
76     companion object {
77         const val SCHEME = "uid"
78     }
79 }
80