summaryrefslogtreecommitdiff
path: root/core/src/main/java/foundation/e/advancedprivacy/externalinterfaces/permissions/IPermissionsPrivacyModule.kt
blob: da11769ee3c419c35ed1c5ead48b88a9c93f88f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright (C) 2022 - 2023 MURENA SAS
 * Copyright (C) 2021 E FOUNDATION
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package foundation.e.advancedprivacy.externalinterfaces.permissions

import android.app.NotificationChannel
import android.content.pm.ApplicationInfo
import android.content.pm.PackageInfo
import android.graphics.drawable.Drawable
import foundation.e.advancedprivacy.domain.entities.AppOpModes
import foundation.e.advancedprivacy.domain.entities.ApplicationDescription
import foundation.e.advancedprivacy.domain.entities.PermissionDescription
import foundation.e.advancedprivacy.domain.entities.ProfileType

/**
 * List applications and manage theirs permissions.
 */
interface IPermissionsPrivacyModule {

    fun buildApplicationDescription(
        appInfo: ApplicationInfo,
        profileId: Int = -1,
        profileType: ProfileType = ProfileType.MAIN
    ): ApplicationDescription

    fun getApplications(
        filter: ((PackageInfo) -> Boolean)?,
    ): List<ApplicationDescription>

    /**
     * List of permissions names used by an app, specified by its [packageName].
     * @param packageName the appId of the app
     * @return the list off permission, in the "android.permission.PERMISSION" format.
     */
    fun getPermissions(packageName: String): List<String>

    fun getPermissionDescription(permissionName: String): PermissionDescription

    /**
     * Get the filled up [ApplicationDescription] for the app specified by its [packageName]
     * @param packageName the appId of the app
     * @return the informations about the app.
     */
    fun getApplicationDescription(packageName: String, withIcon: Boolean = true): ApplicationDescription

    /**
     * Check if the current runtime permission is granted for the specified app.
     *
     * @param packageName the packageName of the app
     * @param permissionName the name of the permission in "android.permission.PERMISSION" format.
     * @return the current status for this permission.
     */
    fun isDangerousPermissionGranted(packageName: String, permissionName: String): Boolean

    /**
     * Get the appOps mode for the specified [appOpPermissionName] of the specified application.
     *
     * @param appDesc the application
     * @param appOpPermissionName the AppOps permission name.
     * @return mode, as a [AppOpModes]
     */
    fun getAppOpMode(appDesc: ApplicationDescription, appOpPermissionName: String): AppOpModes

    /**
     * Grant or revoke the specified permission for the specigfied app.
     * If their is not enough privileges to get the permission, return the false
     *
     * @param appDesc the application
     * @param permissionName the name of the permission in "android.permission.PERMISSION" format.
     * @param grant true grant the permission, false revoke it.
     * @return true if the permission is or has just been granted, false if
     * user has to do it himself.
     */
    fun toggleDangerousPermission(
        appDesc: ApplicationDescription,
        permissionName: String,
        grant: Boolean
    ): Boolean

    /**
     * Change the appOp Mode for the specified appOpPermission and application.
     * @param appDesc the application
     * @param appOpPermissionName the AppOps permission name.
     * @return true if the mode has been changed, false if
     * user has to do it himself.
     */
    fun setAppOpMode(
        appDesc: ApplicationDescription,
        appOpPermissionName: String,
        status: AppOpModes
    ): Boolean

    /**
     * Return true if the application is flagged Dangerous.
     */
    fun isPermissionsDangerous(permissionName: String): Boolean

    /**
     * Get the application icon.
     */
    fun getApplicationIcon(packageName: String): Drawable?

    /**
     * Get the application icon.
     */
    fun getApplicationIcon(app: ApplicationDescription): Drawable?

    /**
     *  Authorize the specified package to be used as Vpn.
     *  @return true if authorization has been set, false if an error has occurred.
     */
    fun setVpnPackageAuthorization(packageName: String): Boolean

    /**
     * Returns the package name of the currently set always-on VPN application, or null.
     */
    fun getAlwaysOnVpnPackage(): String?

    /**
     * Allows users to block notifications sent through this channel, if this channel belongs to
     * a package that is signed with the system signature.
     *
     * If the channel does not belong to a package that is signed with the system signature, this
     * method does nothing, since such channels are blockable by default and cannot be set to be
     * unblockable.
     */
    fun setBlockable(notificationChannel: NotificationChannel)
}