diff options
author | Seweryn Fornalik <s3w3ryn@e.email> | 2021-05-06 22:57:11 +0200 |
---|---|---|
committer | Seweryn Fornalik <s3w3ryn@e.email> | 2021-05-10 15:05:06 +0200 |
commit | 31e75dda8668dbb825b71ce81d57d1b5f48fb55a (patch) | |
tree | d6ef58279258cff5d647cfdd5cc2740b87671d76 | |
parent | 204c625ea307d30026b43cfe2fe4076aacb7e099 (diff) |
Add API integration
-rw-r--r-- | .idea/.name | 1 | ||||
-rw-r--r-- | app/build.gradle | 6 | ||||
-rw-r--r-- | app/src/e/res/values/strings.xml | 3 | ||||
-rw-r--r-- | app/src/google/res/values/strings.xml | 3 | ||||
-rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt | 54 | ||||
-rw-r--r-- | privacymodulesapi/build.gradle | 2 | ||||
-rw-r--r-- | privacymodulese/build.gradle | 3 | ||||
-rw-r--r-- | privacymodulesgoogle/build.gradle | 2 | ||||
-rw-r--r-- | settings.gradle | 3 |
9 files changed, 77 insertions, 0 deletions
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 @@ +<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) ) 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 |