From 449e6f2ffc25540620120130a2be298559f12394 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Thu, 15 Sep 2022 14:02:45 +0530 Subject: [PATCH] privacymodulee: Add support for sdk 32 --- privacymodulese/build.gradle | 6 +++--- .../permissions/PermissionsPrivacyModule.kt | 21 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/privacymodulese/build.gradle b/privacymodulese/build.gradle index f30b2ab..5813979 100644 --- a/privacymodulese/build.gradle +++ b/privacymodulese/build.gradle @@ -4,11 +4,11 @@ apply plugin: 'maven-publish' android { - compileSdkVersion 30 + compileSdkVersion 32 defaultConfig { minSdkVersion 30 - targetSdkVersion 30 + targetSdkVersion 32 versionName advanced_privacy_version consumerProguardFiles "consumer-rules.pro" @@ -38,7 +38,7 @@ publishing { maven(MavenPublication) { groupId 'foundation.e' //You can either define these here or get them from project conf elsewhere - artifactId 'privacymodule-e-30' + artifactId 'privacymodule-e-32' version android.defaultConfig.versionName artifact "$buildDir/outputs/aar/privacymodulese-release.aar" //aar artifact you want to publish // artifact "$buildDir/outputs/aar/privacymodulese-debug.aar" //aar artifact you want to publish diff --git a/privacymodulese/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt b/privacymodulese/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt index 524400f..5adae85 100644 --- a/privacymodulese/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt +++ b/privacymodulese/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt @@ -4,9 +4,8 @@ import android.app.AppOpsManager import android.app.AppOpsManager.OP_NONE import android.app.AppOpsManager.strOpToOp import android.content.Context -import android.net.IConnectivityManager +import android.net.VpnManager import android.net.VpnManager.TYPE_VPN_SERVICE -import android.os.ServiceManager import android.os.UserHandle import android.util.Log import foundation.e.privacymodules.permissions.data.AppOpModes @@ -20,6 +19,9 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont private val appOpsManager: AppOpsManager get() = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager + private val vpnManager: VpnManager get() + = context.getSystemService(Context.VPN_MANAGEMENT_SERVICE) as VpnManager + /** * @see IPermissionsPrivacyModule.toggleDangerousPermission * Always return true, permission is set using privileged capacities. @@ -53,25 +55,22 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont override fun setAppOpMode( appDesc: ApplicationDescription, - permissionName: String, - mode: AppOpModes + appOpPermissionName: String, + status: AppOpModes ): Boolean { - val op = strOpToOp(permissionName) + val op = strOpToOp(appOpPermissionName) if (op != OP_NONE) { - appOpsManager.setMode(op, appDesc.uid, appDesc.packageName, mode.modeValue) + appOpsManager.setMode(op, appDesc.uid, appDesc.packageName, status.modeValue) } return true } override fun setVpnPackageAuthorization(packageName: String): Boolean { - val service: IConnectivityManager = IConnectivityManager.Stub.asInterface( - ServiceManager.getService(Context.CONNECTIVITY_SERVICE)) - try { - if (service.prepareVpn(null, packageName, UserHandle.myUserId())) { + if (vpnManager.prepareVpn(null, packageName, UserHandle.myUserId())) { // Authorize this app to initiate VPN connections in the future without user // intervention. - service.setVpnPackageAuthorization(packageName, UserHandle.myUserId(), TYPE_VPN_SERVICE) + vpnManager.setVpnPackageAuthorization(packageName, UserHandle.myUserId(), TYPE_VPN_SERVICE) return true } } catch (e: java.lang.Exception) { -- GitLab