diff --git a/build.gradle b/build.gradle
index 953c0acff04accbbafbd5bcf99396e2558a2d5ea..c5bf448ca09ab9128763f439690333560752e8c7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
- ext.kotlin_version = "1.5.20"
+ ext.kotlin_version = "1.6.10"
+ ext.advanced_privacy_version = "1.2.0"
repositories {
google()
mavenCentral()
diff --git a/privacymodulese/build.gradle b/privacymodulese/build.gradle
index 0efd525b4a25c7882682fdcd1d7c2537eb2cbfba..1b308170eaffeef225f040de4ef58c7ed8df249e 100644
--- a/privacymodulese/build.gradle
+++ b/privacymodulese/build.gradle
@@ -9,8 +9,7 @@ android {
defaultConfig {
minSdkVersion 26
targetSdkVersion 29
- versionCode 3
- versionName "0.4.3"
+ versionName advanced_privacy_version
consumerProguardFiles "consumer-rules.pro"
}
@@ -27,7 +26,7 @@ android {
}
dependencies {
- implementation 'foundation.e:privacymodule.api:0.5.0'
+ implementation "foundation.e:privacymodule.api:$advanced_privacy_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
diff --git a/privacymodulese/src/main/AndroidManifest.xml b/privacymodulese/src/main/AndroidManifest.xml
index 02aad8f8534acb4b7cb471e6748b7628b7f96e4f..6a7e416c95903ade451c0c419a8896f390b64cf3 100644
--- a/privacymodulese/src/main/AndroidManifest.xml
+++ b/privacymodulese/src/main/AndroidManifest.xml
@@ -33,8 +33,4 @@
/>
-
-
-
diff --git a/privacymodulese/src/main/java/foundation/e/privacymodules/location/FakeLocationModule.kt b/privacymodulese/src/main/java/foundation/e/privacymodules/location/FakeLocationModule.kt
deleted file mode 100644
index 2de7873261de287d92b4aed7a6f7fd811eb25609..0000000000000000000000000000000000000000
--- a/privacymodulese/src/main/java/foundation/e/privacymodules/location/FakeLocationModule.kt
+++ /dev/null
@@ -1,100 +0,0 @@
-package foundation.e.privacymodules.location
-
-import android.content.Context
-import android.content.Context.LOCATION_SERVICE
-import android.location.Criteria
-import android.location.Location
-import android.location.LocationManager
-import android.os.Build
-import android.os.SystemClock
-import android.util.Log
-
-/**
- * Implementation of the functionality of fake location.
- * All of them are available for normal application, so just one version is enough.
- *
- * @param context an Android context, to retrieve system services for example.
- */
-class FakeLocationModule(protected val context: Context): IFakeLocationModule {
-
- /**
- * List of all the Location provider that will be mocked.
- */
- private val providers = listOf(LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER)
-
- /**
- * Handy accessor to the locationManager service.
- * We avoid getting it on module initialization to wait for the context to be ready.
- */
- private val locationManager: LocationManager get() =
- context.getSystemService(LOCATION_SERVICE) as LocationManager
-
- /**
- * @see IFakeLocationModule.startFakeLocation
- */
- @Synchronized
- override fun startFakeLocation() {
- providers.forEach { provider ->
- try {
- locationManager.removeTestProvider(provider)
- } catch(e: Exception) {
- Log.d("FakeLocationModule", "Test provider $provider already removed.")
- }
-
- locationManager.addTestProvider(
- provider,
- false,
- false,
- false,
- false,
- false,
- true,
- true,
- Criteria.POWER_LOW, Criteria.ACCURACY_FINE)
- locationManager.setTestProviderEnabled(provider, true)
- }
- }
-
- override fun setFakeLocation(latitude: Double, longitude: Double) {
- context.startService(FakeLocationService.buildFakeLocationIntent(context, latitude, longitude))
- }
-
- internal fun setTestProviderLocation(latitude: Double, longitude: Double) {
- providers.forEach { provider ->
- val location = Location(provider)
- location.latitude = latitude
- location.longitude = longitude
-
- // Set default value for all the other required fields.
- location.altitude = 3.0
- location.time = System.currentTimeMillis()
- location.speed = 0.01f
- location.bearing = 1f
- location.accuracy = 3f
- location.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- location.bearingAccuracyDegrees = 0.1f
- location.verticalAccuracyMeters = 0.1f
- location.speedAccuracyMetersPerSecond = 0.01f
- }
-
- locationManager.setTestProviderLocation(provider, location)
- }
- }
-
- /**
- * @see IFakeLocationModule.stopFakeLocation
- */
- override fun stopFakeLocation() {
- context.stopService(FakeLocationService.buildStopIntent(context))
- providers.forEach { provider ->
- try {
- locationManager.setTestProviderEnabled(provider, false)
- locationManager.removeTestProvider(provider)
- } catch (e: Exception) {
- Log.d("FakeLocationModule", "Test provider $provider already removed.")
- }
- }
- }
-}
diff --git a/privacymodulese/src/main/java/foundation/e/privacymodules/location/FakeLocationService.kt b/privacymodulese/src/main/java/foundation/e/privacymodules/location/FakeLocationService.kt
deleted file mode 100644
index e5c6f78486cff56a5081bba80f8f3dbfb31169bf..0000000000000000000000000000000000000000
--- a/privacymodulese/src/main/java/foundation/e/privacymodules/location/FakeLocationService.kt
+++ /dev/null
@@ -1,94 +0,0 @@
-package foundation.e.privacymodules.location
-
-
-import android.app.Service
-import android.content.Context
-import android.content.Intent
-import android.os.CountDownTimer
-import android.os.IBinder
-import android.util.Log
-
-class FakeLocationService: Service() {
-
- enum class Actions {
- START_FAKE_LOCATION
- }
-
- companion object {
- private const val PERIOD_LOCATION_UPDATE = 1000L
- private const val PERIOD_UPDATES_SERIE = 2 * 60 * 1000L
-
- private const val PARAM_LATITUDE = "PARAM_LATITUDE"
- private const val PARAM_LONGITUDE = "PARAM_LONGITUDE"
-
- fun buildFakeLocationIntent(context: Context, latitude: Double, longitude: Double): Intent {
- return Intent(context, FakeLocationService::class.java).apply {
- action = Actions.START_FAKE_LOCATION.name
- putExtra(PARAM_LATITUDE, latitude)
- putExtra(PARAM_LONGITUDE, longitude)
- }
- }
-
- fun buildStopIntent(context: Context) = Intent(context, FakeLocationService::class.java)
- }
-
- private lateinit var fakeLocationModule: FakeLocationModule
-
- private var countDownTimer: CountDownTimer? = null
-
- private var fakeLocation: Pair? = null
-
- override fun onCreate() {
- super.onCreate()
- fakeLocationModule = FakeLocationModule(applicationContext)
- }
-
- override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
- intent?.let {
- when (it.action?.let { str -> Actions.valueOf(str) }) {
- Actions.START_FAKE_LOCATION -> {
-
- fakeLocation = Pair(
- it.getDoubleExtra(PARAM_LATITUDE, 0.0),
- it.getDoubleExtra(PARAM_LONGITUDE, 0.0)
- )
- initTimer()
- }
- }
- }
-
- return START_STICKY
- }
-
- override fun onDestroy() {
- countDownTimer?.cancel()
- super.onDestroy()
- }
-
-
- private fun initTimer() {
- countDownTimer?.cancel()
- countDownTimer = object: CountDownTimer(PERIOD_UPDATES_SERIE, PERIOD_LOCATION_UPDATE) {
- override fun onTick(millisUntilFinished: Long) {
- fakeLocation?.let {
- try {
- fakeLocationModule.setTestProviderLocation(
- it.first,
- it.second
- )
- } catch (e: Exception) {
- Log.d("FakeLocationService", "setting fake location", e)
- }
- }
- }
-
- override fun onFinish() {
- initTimer()
- }
- }.start()
- }
-
- override fun onBind(intent: Intent?): IBinder? {
- return null
- }
-}
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 ed7c20eca0acb3ca89c5a62b0e48d6072b61ae46..d050352b274819391f779b550491d9d63e5e4ea1 100644
--- a/privacymodulese/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt
+++ b/privacymodulese/src/main/java/foundation/e/privacymodules/permissions/PermissionsPrivacyModule.kt
@@ -1,16 +1,15 @@
package foundation.e.privacymodules.permissions
import android.app.AppOpsManager
-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.os.ServiceManager
import android.os.UserHandle
import android.util.Log
-import foundation.e.privacymodules.commons.ManualAction
import foundation.e.privacymodules.permissions.data.AppOpModes
import foundation.e.privacymodules.permissions.data.ApplicationDescription
-import java.util.*
/**
* Implements [IPermissionsPrivacyModule] with all privileges of a system app.
@@ -22,11 +21,13 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont
/**
* @see IPermissionsPrivacyModule.toggleDangerousPermission
- * Always return null, permission is set using privileged capacities.
+ * Always return true, permission is set using privileged capacities.
*/
- override fun toggleDangerousPermission(appDesc: ApplicationDescription,
- permissionName: String,
- grant: Boolean): ManualAction? {
+ override fun toggleDangerousPermission(
+ appDesc: ApplicationDescription,
+ permissionName: String,
+ grant: Boolean
+ ): Boolean {
try {
if (grant) {
context.packageManager.grantRuntimePermission(
@@ -43,25 +44,24 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont
}
} catch (e: Exception) {
Log.e("Permissions-e", "Exception while setting permission", e)
+ return false
}
- return null
+ return true
}
override fun setAppOpMode(
appDesc: ApplicationDescription,
permissionName: String,
mode: AppOpModes
- ): ManualAction? {
+ ): Boolean {
val op = strOpToOp(permissionName)
if (op != OP_NONE) {
appOpsManager.setMode(op, appDesc.uid, appDesc.packageName, mode.modeValue)
}
- return null
+ return true
}
- override fun isAccessibilityEnabled(): Boolean? = null
-
override fun setVpnPackageAuthorization(packageName: String): Boolean {
val service: IConnectivityManager = IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE))
@@ -80,38 +80,4 @@ class PermissionsPrivacyModule(context: Context): APermissionsPrivacyModule(cont
}
return false
}
-
- // WIP, get history of permissions use.
- fun testPermissionHistory(appDesc: ApplicationDescription,
- permission: String) {
- // when we change with setAppOpsPermissiosn ...
-// appOpsManager.startWatchingMode(permissionToOp(permission), appDesc.packageName, OnOpChangedListener { op, packageName ->
-// Log.d("WatchMode", "op: $op for! $packageName")
-// })
-
-
- val ops = appOpsManager.getOpsForPackage(appDesc.uid, appDesc.packageName,
- OPSTR_CAMERA)
- val tag = "TestGetOps"
-
- Log.d(tag, "opsForPackage.size: ${ops.size}")
-
- ops.forEach {
- Log.d(tag, "pkg: ${it.packageName} - ops.size: ${it.ops.size}")
- it.ops.forEach { opEntry ->
- Log.d(tag, "time: ${Date(opEntry.time)} - duration: ${it.ops.firstOrNull()?.duration}ms, mode: ${opEntry.mode}, op: ${opEntry.opStr}")
- }
-
- }
- // Not available in API 24.
-// appOpsManager.startWatchingActive(
-// arrayOf(permissionToOpCode(permission)).toIntArray(),
-// //appDesc.packageName,
-// OnOpActiveChangedListener { code, uid, packageName, active ->
-// Log.d("WatchMode", "Op active: $active - op: ${opToName(code)} uid: $uid for $packageName")
-// })
-
- }
-
-
-}
\ No newline at end of file
+}