summaryrefslogtreecommitdiff
path: root/permissionse
diff options
context:
space:
mode:
Diffstat (limited to 'permissionse')
-rw-r--r--permissionse/libs/hidden-apis-stub/src/main/java/android/net/IConnectivityManager.java6
-rw-r--r--permissionse/libs/hidden-apis-stub/src/main/java/android/net/VpnManager.java11
-rw-r--r--permissionse/src/main/AndroidManifest.xml2
-rw-r--r--permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt67
4 files changed, 77 insertions, 9 deletions
diff --git a/permissionse/libs/hidden-apis-stub/src/main/java/android/net/IConnectivityManager.java b/permissionse/libs/hidden-apis-stub/src/main/java/android/net/IConnectivityManager.java
index d7f6ccf..53440e0 100644
--- a/permissionse/libs/hidden-apis-stub/src/main/java/android/net/IConnectivityManager.java
+++ b/permissionse/libs/hidden-apis-stub/src/main/java/android/net/IConnectivityManager.java
@@ -32,7 +32,7 @@ public interface IConnectivityManager {
@TargetApi(29)
@DeprecatedSinceApi(
api = 31,
- message = "TODO"
+ message = "Moved to android.net.VpnManager"
)
boolean prepareVpn(String oldPackage, String newPackage, int userId) throws RemoteException;
@@ -53,9 +53,9 @@ public interface IConnectivityManager {
@TargetApi(29)
@DeprecatedSinceApi(
api = 31,
- message = "TODO"
+ message = "Moved to android.net.VpnManager"
)
- String getAlwaysOnVpnPackage(int userId) throws RemoteException;
+ public String getAlwaysOnVpnPackage(int userId) throws RemoteException;
public abstract static class Stub extends Binder implements IConnectivityManager {
public static IConnectivityManager asInterface(IBinder obj) {
diff --git a/permissionse/libs/hidden-apis-stub/src/main/java/android/net/VpnManager.java b/permissionse/libs/hidden-apis-stub/src/main/java/android/net/VpnManager.java
index 7cc9b6a..bdb9e95 100644
--- a/permissionse/libs/hidden-apis-stub/src/main/java/android/net/VpnManager.java
+++ b/permissionse/libs/hidden-apis-stub/src/main/java/android/net/VpnManager.java
@@ -21,6 +21,7 @@ import android.annotation.TargetApi;
import androidx.annotation.DeprecatedSinceApi;
import androidx.annotation.Nullable;
+import androidx.annotation.RequiresPermission;
// Stub based on:
// https://gitlab.e.foundation/e/os/android_frameworks_base/-/blob/[SDK_VERSION]/core/java/android/net/VpnManager.java
@@ -50,4 +51,14 @@ public class VpnManager {
int userId,
int vpnType
) {}
+
+ @TargetApi(31)
+ @DeprecatedSinceApi(
+ api = 33,
+ message = "Check disponibility in SDK33"
+ )
+ @RequiresPermission("android.permission.CONTROL_ALWAYS_ON_VPN")
+ public String getAlwaysOnVpnPackageForUser(int userId) {
+ return null;
+ }
}
diff --git a/permissionse/src/main/AndroidManifest.xml b/permissionse/src/main/AndroidManifest.xml
index 6a7e416..428a612 100644
--- a/permissionse/src/main/AndroidManifest.xml
+++ b/permissionse/src/main/AndroidManifest.xml
@@ -33,4 +33,6 @@
/>
<uses-permission android:name="android.permission.CONTROL_VPN"
tools:ignore="ProtectedPermissions" />
+ <uses-permission android:name="android.permission.CONTROL_ALWAYS_ON_VPN"
+ tools:ignore="ProtectedPermissions" />
</manifest>
diff --git a/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt b/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt
index fe5b7ac..83711dd 100644
--- a/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt
+++ b/permissionse/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2022 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.privacymodules.permissions
import android.annotation.TargetApi
@@ -18,10 +35,10 @@ import foundation.e.privacymodules.permissions.data.ApplicationDescription
/**
* Implements [IPermissionsPrivacyModule] with all privileges of a system app.
*/
-class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(context) {
+class PermissionsPrivacyModule(context: Context) : APermissionsPrivacyModule(context) {
- private val appOpsManager: AppOpsManager get()
- = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
+ private val appOpsManager: AppOpsManager
+ get() = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
/**
* @see IPermissionsPrivacyModule.toggleDangerousPermission
@@ -67,7 +84,7 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont
}
override fun setVpnPackageAuthorization(packageName: String): Boolean {
- return when(Build.VERSION.SDK_INT) {
+ return when (Build.VERSION.SDK_INT) {
29 -> setVpnPackageAuthorizationSDK29(packageName)
30 -> setVpnPackageAuthorizationSDK30(packageName)
31, 32 -> setVpnPackageAuthorizationSDK32(packageName)
@@ -81,7 +98,8 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont
@TargetApi(29)
private fun setVpnPackageAuthorizationSDK29(packageName: String): Boolean {
val service: IConnectivityManager = IConnectivityManager.Stub.asInterface(
- ServiceManager.getService(Context.CONNECTIVITY_SERVICE))
+ ServiceManager.getService(Context.CONNECTIVITY_SERVICE)
+ )
try {
if (service.prepareVpn(null, packageName, UserHandle.myUserId())) {
@@ -101,7 +119,8 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont
@TargetApi(30)
private fun setVpnPackageAuthorizationSDK30(packageName: String): Boolean {
val service: IConnectivityManager = IConnectivityManager.Stub.asInterface(
- ServiceManager.getService(Context.CONNECTIVITY_SERVICE))
+ ServiceManager.getService(Context.CONNECTIVITY_SERVICE)
+ )
try {
if (service.prepareVpn(null, packageName, UserHandle.myUserId())) {
@@ -136,4 +155,40 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont
}
return false
}
+
+ override fun getAlwaysOnVpnPackage(): String? {
+ return when (Build.VERSION.SDK_INT) {
+ 29, 30 -> getAlwaysOnVpnPackageSDK29()
+ 31, 32 -> getAlwaysOnVpnPackageSDK32()
+ else -> {
+ Log.e("Permissions-e", "Bad android sdk version")
+ null
+ }
+ }
+ }
+
+ @TargetApi(29)
+ private fun getAlwaysOnVpnPackageSDK29(): String? {
+ val service: IConnectivityManager = IConnectivityManager.Stub.asInterface(
+ ServiceManager.getService(Context.CONNECTIVITY_SERVICE)
+ )
+
+ return try {
+ service.getAlwaysOnVpnPackage(UserHandle.myUserId())
+ } catch (e: java.lang.Exception) {
+ Log.e("Permissions-e", "Bad android sdk version ", e)
+ return null
+ }
+ }
+
+ @TargetApi(31)
+ private fun getAlwaysOnVpnPackageSDK32(): String? {
+ val vpnManager = context.getSystemService(Context.VPN_MANAGEMENT_SERVICE) as VpnManager
+ return try {
+ vpnManager.getAlwaysOnVpnPackageForUser(UserHandle.myUserId())
+ } catch (e: java.lang.Exception) {
+ Log.e("Permissions-e", "Bad android sdk version ", e)
+ return null
+ }
+ }
}