Skip to content

Commit

Permalink
Merge pull request #75 from onaio/74-upgrade-location-services
Browse files Browse the repository at this point in the history
Update Google Location Services to 21+
  • Loading branch information
Rkareko authored Aug 22, 2024
2 parents b0f6980 + e2a6efa commit 0e9b5d7
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
api-level: [ 30 ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Spotless check p2p-lib module
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "com.android.tools.build:gradle:7.1.3"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
classpath "com.android.tools.build:gradle:8.3.1"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22'
classpath "org.jetbrains.kotlin:kotlin-serialization:1.7.10"
classpath deps.kotlin_coveralls_plugin
classpath deps.spotless
Expand Down
4 changes: 2 additions & 2 deletions deps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ versions.core = '1.3.0'
versions.junit5_api = '5.7.1'
versions.junit5_plugin = '1.7.1.1'
versions.ktlint = '0.41.0'
versions.mockk = '1.11.0'
versions.robolectric = '4.8'
versions.mockk = '1.13.8'
versions.robolectric = '4.10.3'
versions.timber = '4.7.1'
versions.room = '2.3.0'
versions.spotless = '5.11.0'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Nov 02 07:33:43 EAT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
16 changes: 9 additions & 7 deletions p2p-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ jacoco {
android {
compileSdk 34

namespace = "org.smartregister.p2p"

defaultConfig {
minSdk 21
targetSdk 30
targetSdk 34
versionCode 1
versionName "1.0"

Expand All @@ -42,18 +44,18 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = JavaVersion.VERSION_17.toString()
}
buildFeatures {
compose true
viewBinding true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.0'
kotlinCompilerExtensionVersion '1.5.8'
}
testOptions {
animationsDisabled true
Expand Down Expand Up @@ -143,7 +145,7 @@ def roomDependencies(configuration) {
}

def locationDependencies(configuration) {
configuration.implementation 'com.google.android.gms:play-services-location:16.0.0'
configuration.implementation 'com.google.android.gms:play-services-location:21.2.0'
}

task jacocoTestReport(type: JacocoReport, dependsOn: [
Expand Down Expand Up @@ -227,7 +229,7 @@ afterEvaluate {
from(components["release"])
artifactId = "p2p-lib"
groupId = "org.smartregister"
version = "0.6.9-SNAPSHOT"
version = "0.6.10-SNAPSHOT"
pom {
name.set("Peer to Peer Library")
}
Expand Down
1 change: 1 addition & 0 deletions p2p-lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />

<application>
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class WifiDirectDataSharingStrategy : DataSharingStrategy, P2PManagerListener {
context.application.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager
}
private val accessFineLocationPermissionRequestInt: Int = 12345
private val nearbyWifiDevicesPermissionRequestInt: Int = 67890
private var wifiP2pChannel: WifiP2pManager.Channel? = null
private var wifiP2pReceiver: BroadcastReceiver? = null

Expand Down Expand Up @@ -160,6 +161,9 @@ class WifiDirectDataSharingStrategy : DataSharingStrategy, P2PManagerListener {
requestAccessFineLocationIfNotGranted()
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requestNearbyWifiDevicesNotGranted()
}
// Check if already connected and disconnect
requestDeviceInfo(onDeviceFound = onDeviceFound, onConnected = onConnected)
}
Expand All @@ -184,13 +188,25 @@ class WifiDirectDataSharingStrategy : DataSharingStrategy, P2PManagerListener {
}

private fun initiatePeerDiscoveryOnceAccessFineLocationGranted() {
if (ActivityCompat.checkSelfPermission(
if ((ActivityCompat.checkSelfPermission(
context,
android.Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
)) != PackageManager.PERMISSION_GRANTED ||
(ActivityCompat.checkSelfPermission(
context,
android.Manifest.permission.NEARBY_WIFI_DEVICES
)) != PackageManager.PERMISSION_GRANTED
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
logDebug(
"initiatePeerDiscoveryOnceAccessFineLocationGranted(): requesting ACCESS_FINE_LOCATION"
)
requestAccessFineLocationIfNotGranted()
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
logDebug(
"initiatePeerDiscoveryOnceAccessFineLocationGranted(): requesting NEARBY_WIFI_DEVICES"
)
requestNearbyWifiDevicesNotGranted()
} else {
handleMinimumSDKVersionNotMet(Build.VERSION_CODES.M)
}
Expand All @@ -217,6 +233,24 @@ class WifiDirectDataSharingStrategy : DataSharingStrategy, P2PManagerListener {
}
}

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private fun requestNearbyWifiDevicesNotGranted() {
when (ActivityCompat.checkSelfPermission(
context,
android.Manifest.permission.NEARBY_WIFI_DEVICES
)
) {
PackageManager.PERMISSION_GRANTED -> logDebug("Wifi P2P: Nearby wifi devices granted")
else -> {
logDebug("Wifi P2P: Requesting Nearby wifi devices granted permission")
return context.requestPermissions(
arrayOf(android.Manifest.permission.NEARBY_WIFI_DEVICES),
nearbyWifiDevicesPermissionRequestInt
)
}
}
}

private fun initiatePeerDiscovery(onDeviceFound: OnDeviceFound?) {
if (ActivityCompat.checkSelfPermission(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ class WifiDirectDataSharingStrategyTest : RobolectricTest() {
every {
context.checkPermission(android.Manifest.permission.ACCESS_FINE_LOCATION, any(), any())
} returns PackageManager.PERMISSION_GRANTED
every {
context.checkPermission(android.Manifest.permission.NEARBY_WIFI_DEVICES, any(), any())
} returns PackageManager.PERMISSION_GRANTED
every { wifiP2pManager.discoverPeers(any(), any()) } just runs
ReflectionHelpers.callInstanceMethod<WifiDirectDataSharingStrategy>(
wifiDirectDataSharingStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ import org.smartregister.p2p.R
class TestApplication : Application() {
override fun onCreate() {
super.onCreate()
setTheme(R.style.Theme_MaterialComponents_DayNight_DarkActionBar)
setTheme(com.google.android.material.R.style.Theme_MaterialComponents_DayNight_DarkActionBar)
}
}
9 changes: 5 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ plugins {

android {
compileSdk 34
namespace = "org.smartregister.p2p.sample"

defaultConfig {
applicationId "org.smartregister.p2p.sample"
minSdk 21
targetSdk 31
targetSdk 34
versionCode 1
versionName "1.0"

Expand All @@ -23,11 +24,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = JavaVersion.VERSION_17
}
buildFeatures {
viewBinding = true
Expand Down

0 comments on commit 0e9b5d7

Please sign in to comment.