summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSeweryn Fornalik <s3w3ryn@e.email>2021-05-06 22:57:11 +0200
committerSeweryn Fornalik <s3w3ryn@e.email>2021-05-10 15:05:06 +0200
commit31e75dda8668dbb825b71ce81d57d1b5f48fb55a (patch)
treed6ef58279258cff5d647cfdd5cc2740b87671d76 /app
parent204c625ea307d30026b43cfe2fe4076aacb7e099 (diff)
Add API integration
Diffstat (limited to 'app')
-rw-r--r--app/build.gradle6
-rw-r--r--app/src/e/res/values/strings.xml3
-rw-r--r--app/src/google/res/values/strings.xml3
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt54
4 files changed, 66 insertions, 0 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 5352608..f0558fa 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -41,6 +41,12 @@ android {
}
dependencies {
+ implementation project(":privacymodulesapi")
+
+ // include the google specific version of the modules, just for the google flavor
+ googleImplementation project(":privacymodulesgoogle")
+ // include the e specific version of the modules, just for the e flavor
+ eImplementation project(":privacymodulese")
implementation project(":flow-mvi")
implementation Libs.Kotlin.stdlib
implementation Libs.AndroidX.coreKtx
diff --git a/app/src/e/res/values/strings.xml b/app/src/e/res/values/strings.xml
new file mode 100644
index 0000000..73affbc
--- /dev/null
+++ b/app/src/e/res/values/strings.xml
@@ -0,0 +1,3 @@
+<resources>
+ <string name="app_name">e - PrivacyModulesDemo</string>
+</resources>
diff --git a/app/src/google/res/values/strings.xml b/app/src/google/res/values/strings.xml
new file mode 100644
index 0000000..ebf51d0
--- /dev/null
+++ b/app/src/google/res/values/strings.xml
@@ -0,0 +1,3 @@
+<resources>
+ <string name="app_name">google - PrivacyModulesDemo</string>
+</resources>
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt
index 96bebb7..c5a952e 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt
@@ -19,8 +19,10 @@ package foundation.e.privacycentralapp.features.location
import android.annotation.SuppressLint
import android.content.Context
+import android.app.AppOpsManager
import android.os.Bundle
import android.os.Looper
+import android.os.Process
import android.text.Editable
import android.util.Log
import android.view.Gravity
@@ -60,9 +62,15 @@ import foundation.e.privacycentralapp.dummy.LocationMode
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
+import foundation.e.privacymodules.location.FakeLocation
+import foundation.e.privacymodules.location.IFakeLocation
+import foundation.e.privacymodules.permissions.PermissionsPrivacyModule
+import foundation.e.privacymodules.permissions.data.AppOpModes
+import foundation.e.privacymodules.permissions.data.ApplicationDescription
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
+import java.lang.Exception
class FakeLocationFragment :
Fragment(R.layout.fragment_fake_location),
@@ -129,6 +137,19 @@ class FakeLocationFragment :
private const val TAG = "FakeLocationFragment"
private const val DEFAULT_INTERVAL_IN_MILLISECONDS = 1000L
private const val DEFAULT_MAX_WAIT_TIME = DEFAULT_INTERVAL_IN_MILLISECONDS * 5
+ private const val DROPPED_MARKER_LAYER_ID = "DROPPED_MARKER_LAYER_ID"
+ }
+
+ private val fakeLocationModule: IFakeLocation by lazy { FakeLocation(this.requireContext()) }
+ private val permissionsModule by lazy { PermissionsPrivacyModule(this.requireContext()) }
+
+ private val appDesc by lazy {
+ ApplicationDescription(
+ packageName = this.requireContext().packageName,
+ uid = Process.myUid(),
+ label = getString(R.string.app_name),
+ icon = null
+ )
}
override fun onCreate(savedInstanceState: Bundle?) {
@@ -143,9 +164,11 @@ class FakeLocationFragment :
displayToast("Random location selected")
hoveringMarker?.visibility = View.GONE
isCameraMoved = false
+ setLondonLocation()
}
is FakeLocationFeature.SingleEvent.SpecificLocationSavedEvent -> {
// Hide camera hover marker when custom location is picked from map.
+ displayToast("Specific location selected")
hoveringMarker?.visibility = View.GONE
isCameraMoved = false
}
@@ -157,6 +180,7 @@ class FakeLocationFragment :
displayToast("Real location selected")
hoveringMarker?.visibility = View.GONE
isCameraMoved = false
+ setRealLocation()
}
}
}
@@ -173,6 +197,35 @@ class FakeLocationFragment :
.show()
}
+ private fun setFakeLocation(latitude: Double, longitude: Double) {
+ if (permissionsModule.getAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION) != AppOpModes.ALLOWED) {
+ permissionsModule.setAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION,
+ AppOpModes.ALLOWED)
+ }
+ try {
+ fakeLocationModule.startFakeLocation()
+ } catch(e: Exception) {
+ Log.e("FakeLoc", "Can't startFakeLocation", e)
+ }
+ fakeLocationModule.setFakeLocation(latitude, longitude)
+ }
+
+ private fun setRealLocation() {
+ try {
+ permissionsModule.setAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION,
+ AppOpModes.IGNORED)
+ fakeLocationModule.stopFakeLocation()
+ displayToast("Real location selected")
+ } catch(e: Exception) {
+ Log.e("FakeLoc", "Can't stop FakeLocation", e)
+ }
+ }
+
+ private fun setLondonLocation() {
+ displayToast("Random location selected")
+ setFakeLocation(51.5287718, -0.2416803)
+ }
+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val toolbar = view.findViewById<Toolbar>(R.id.toolbar)
@@ -257,6 +310,7 @@ class FakeLocationFragment :
}
private fun saveSpecificLocation(latitude: Double, longitude: Double) {
+ setFakeLocation(latitude, longitude)
viewModel.submitAction(
FakeLocationFeature.Action.SetFakeLocationAction(latitude, longitude)
)