From 31e75dda8668dbb825b71ce81d57d1b5f48fb55a Mon Sep 17 00:00:00 2001 From: Seweryn Fornalik Date: Thu, 6 May 2021 22:57:11 +0200 Subject: Add API integration --- .idea/.name | 1 + app/build.gradle | 6 +++ app/src/e/res/values/strings.xml | 3 ++ app/src/google/res/values/strings.xml | 3 ++ .../features/location/FakeLocationFragment.kt | 54 ++++++++++++++++++++++ privacymodulesapi/build.gradle | 2 + privacymodulese/build.gradle | 3 ++ privacymodulesgoogle/build.gradle | 2 + settings.gradle | 3 ++ 9 files changed, 77 insertions(+) create mode 100644 .idea/.name create mode 100644 app/src/e/res/values/strings.xml create mode 100644 app/src/google/res/values/strings.xml create mode 100644 privacymodulesapi/build.gradle create mode 100644 privacymodulese/build.gradle create mode 100644 privacymodulesgoogle/build.gradle diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..d32d4d9 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +PrivacyCentralApp \ No newline at end of file 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 @@ + + e - PrivacyModulesDemo + 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 @@ + + google - PrivacyModulesDemo + 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(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) ) diff --git a/privacymodulesapi/build.gradle b/privacymodulesapi/build.gradle new file mode 100644 index 0000000..2ebc707 --- /dev/null +++ b/privacymodulesapi/build.gradle @@ -0,0 +1,2 @@ +configurations.maybeCreate("default") +artifacts.add("default", file('privacymodulesapi-debug.aar')) \ No newline at end of file diff --git a/privacymodulese/build.gradle b/privacymodulese/build.gradle new file mode 100644 index 0000000..0cad7ab --- /dev/null +++ b/privacymodulese/build.gradle @@ -0,0 +1,3 @@ +configurations.maybeCreate("default") +//artifacts.add("default", file('privacymodulese-release.aar')) +artifacts.add("default", file('privacymodulese-debug.aar')) \ No newline at end of file diff --git a/privacymodulesgoogle/build.gradle b/privacymodulesgoogle/build.gradle new file mode 100644 index 0000000..a5ced21 --- /dev/null +++ b/privacymodulesgoogle/build.gradle @@ -0,0 +1,2 @@ +configurations.maybeCreate("default") +artifacts.add("default", file('privacymodulesgoogle-release.aar')) \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index dca731c..6532f7b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,6 @@ include ':flow-mvi' include ':app' +include ':privacymodulesgoogle' +include ':privacymodulese' +include ':privacymodulesapi' rootProject.name = "PrivacyCentralApp" \ No newline at end of file -- cgit v1.2.1