Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2p merge #59

Merged
merged 100 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
52374b3
Handle device search error
Rkareko Dec 8, 2022
33c2a65
Handle device connecting error
Rkareko Dec 9, 2022
a8f4d47
Close wifi direct connection when exiting P2P screen
Rkareko Jan 5, 2023
b7cd326
Show error when receiving basic device details fails
Rkareko Jan 5, 2023
d53b27e
Fix pairing issue after location permission request
ekigamba Jan 6, 2023
347a0a4
Disconnect from wifi-direct appropriately
ekigamba Jul 19, 2022
c3d9f8d
Initiate sending of device details when pairing is successful
Rkareko Jan 7, 2023
ecb9640
Update unit tests
Rkareko Jan 8, 2023
cc352d6
Add bottom sheet screen tests
Rkareko Jan 9, 2023
0805dc2
Handle retrieval of current device details
Rkareko Jan 10, 2023
324311e
Fix P2P stuck after pairing
ekigamba Jan 10, 2023
98cbfda
Restart the P2P view after an exception during sending
ekigamba Jan 10, 2023
e5512f1
Code cleanup
ekigamba Jan 10, 2023
a0ada1d
Remove: Allow importing p2p into fhircore
ekigamba Jan 10, 2023
032ca6a
Merge remote-tracking branch 'origin/30-handle-WifiDirectDataSharingS…
ekigamba Jan 10, 2023
3a2783e
Refactor logic for retrieving current device info
Rkareko Jan 10, 2023
9c5f7e0
Handle socket connection errors when connection breaks
Rkareko Jan 11, 2023
d96b5ac
Fix failling test
Rkareko Jan 11, 2023
0152167
Merge remote-tracking branch 'origin/30-handle-WifiDirectDataSharingS…
ekigamba Jan 12, 2023
c715ceb
handle exception thrown when writing data
Rkareko Jan 12, 2023
ce506b9
Return to default P2P screen when bottom sheet dialog is closed
Rkareko Jan 13, 2023
769fefe
Fix merge issue
ekigamba Jan 13, 2023
3c65546
Merge remote-tracking branch 'origin/30-handle-WifiDirectDataSharingS…
ekigamba Jan 13, 2023
3025d23
Handle socket exceptions and restart the activity
ekigamba Jan 17, 2023
d199779
Code cleanup and add logging for records sent
ekigamba Jan 17, 2023
9d88338
Close server socket when closeconnections is called
Rkareko Jan 20, 2023
4e8f3e0
Improve dao to use offsets, limit and >= to avoid skipping records
ekigamba Jan 24, 2023
01ab5b0
Fix received record count message
ekigamba Jan 24, 2023
5b787cb
Ellipsize long device names
Rkareko Jan 25, 2023
0e02a87
Update sample app dao method signatures
ekigamba Jan 25, 2023
f77c432
Handle of socket exception correctly when p2p is cancelled
ekigamba Jan 26, 2023
1a07d93
Handle null group owner address
ekigamba Jan 26, 2023
c362afd
Handle socket connection exceptions where send or receive is called
Rkareko Jan 27, 2023
5f0841d
Update your to handle instances where data is upto date
Rkareko Jan 30, 2023
1c9ff45
Update bottom sheet header for receiver
Rkareko Jan 30, 2023
f044934
Disconect wifi-p2p when there are errors during transfer
Rkareko Jan 30, 2023
71451d9
Merge branch 'p2p-merge' of github.com:opensrp/p2p into 1960-sync-com…
Rkareko Jan 30, 2023
fefcd4b
Updat your to show error when connection is broken
Rkareko Jan 30, 2023
c38811c
Merge pull request #60 from opensrp/1960-sync-complete-ui-updates
Rkareko Feb 1, 2023
4e74296
Don't display device list when devices fail to pair
Rkareko Feb 1, 2023
fc0427c
Set p2p pairing timeout and callback when p2p pairing is successful
ekigamba Feb 1, 2023
ec8c704
Merge branch 'issue/fhircore/1960/p2p-bug-fixes/kigamba' into p2p-merge
ekigamba Feb 1, 2023
b6b4ca8
Updated pairing text depending on state
Rkareko Feb 2, 2023
7661a9a
Handle instances where received history is null
Rkareko Feb 2, 2023
40927a0
Close existing wifi p2p connections before scanning starts
Rkareko Feb 2, 2023
a467268
Fix socket address in use
ekigamba Feb 3, 2023
efc7209
Merge changes from p2p-merge
Rkareko Feb 3, 2023
1c1d6c6
Handle diconnection of wifi direct
Rkareko Feb 3, 2023
0c7f424
Fix sender device not sending
ekigamba Feb 3, 2023
f3e1fc2
Init channels and peer discovery after confirming successfull disconn…
Rkareko Feb 3, 2023
dcd39a8
Merge branch '1960-close-existing-wifi-p2p-connections' of github.com…
Rkareko Feb 3, 2023
63ec865
Bump up version
Rkareko Feb 3, 2023
fc0c38e
Merge branch 'p2p-merge' of github.com:opensrp/p2p into 1960-close-ex…
Rkareko Feb 6, 2023
451e035
Merge pull request #61 from opensrp/1960-close-existing-wifi-p2p-conn…
Rkareko Feb 6, 2023
355ae30
Allow cleaning of activity context P2PLibrary#clean
ekigamba Feb 7, 2023
6e1cc2d
Clean up P2PViewModel logging
Rkareko Feb 7, 2023
2c3d406
Close wifi direct connection and stop searching when bottom sheet is …
Rkareko Feb 7, 2023
55ee5cb
Close socket and streams when disconnect fails
Rkareko Feb 8, 2023
f51ed5e
Fix build errors in tests
Rkareko Feb 8, 2023
e77e266
Merge branch 'p2p-merge' into 1960-disconnect-wifi-on-closing-bottom-…
Rkareko Feb 8, 2023
265c8fa
Merge pull request #62 from opensrp/1960-disconnect-wifi-on-closing-b…
Rkareko Feb 8, 2023
eb6e4bc
Fix failing tests
Rkareko Feb 9, 2023
be06216
Run spotlessApply
Rkareko Feb 9, 2023
aa1adf6
Update WifiDirectDataSharingStrategy tests
Rkareko Feb 9, 2023
66fd871
Update unit tests
Rkareko Feb 9, 2023
b9c24a0
Merge changes from p2p-merge
Rkareko Feb 9, 2023
5e2901d
Run spotlessApply
Rkareko Feb 9, 2023
055291c
Bump up version
Rkareko Feb 10, 2023
5e1be48
Merge pull request #64 from opensrp/1960-spotless-apply
Rkareko Feb 13, 2023
b5a8096
Null check for current device before dsconnecting
Rkareko Feb 13, 2023
5a50129
Add comments
Rkareko Feb 13, 2023
e548e9d
Merge pull request #65 from opensrp/1960-location-permission-bug
Rkareko Feb 13, 2023
5189640
Bump up version
Rkareko Feb 13, 2023
d89bd08
Merge branch 'main' of github.com:opensrp/p2p into p2p-merge
Rkareko Feb 14, 2023
2aff836
Run spotlessApply
Rkareko Feb 14, 2023
0a4d8e8
Code cleanup
ekigamba Feb 16, 2023
5760e87
Fix crash when sending is disrupted
ekigamba Feb 17, 2023
bf25844
Run spotlessApply
Rkareko Feb 23, 2023
a4762d1
Update calculation of batch offset
Rkareko Mar 1, 2023
763d34c
Merge branch 'p2p-merge' of github.com:opensrp/p2p into p2p-merge
Rkareko Mar 1, 2023
6d088d5
Bump up version
Rkareko Mar 1, 2023
4159cad
Do not show list of devices when handling wifi_p2p_connection_action
Rkareko Mar 2, 2023
f4805ac
Bump up version
Rkareko Mar 3, 2023
0eeb9cc
Update unit tests
Rkareko Mar 6, 2023
77b569e
Update unit tests
Rkareko Mar 7, 2023
3b51acf
Remove call for jacocoTestReport task
Rkareko Mar 7, 2023
f3af38e
Update deprecated methords
Rkareko Mar 7, 2023
9b0a549
Add step to upload test artifacts
Rkareko Mar 7, 2023
303fe3b
Revert set up JDK checkout to v2
Rkareko Mar 7, 2023
f0298ee
Remove unneeded hyphen
Rkareko Mar 7, 2023
df80bb2
Run only compose tests
Rkareko Mar 7, 2023
b7d38bc
Explicitly call jacocoTestReport
Rkareko Mar 7, 2023
c17fa44
Explicitly call connectedDebugAndroidTest task
Rkareko Mar 8, 2023
192bb2e
Disable androidx test orchestrator
Rkareko Mar 8, 2023
793a996
Enable running of unit tests
Rkareko Mar 8, 2023
a0926ad
Remove build script used to run p2p-lib module directly inside FHIR Core
Rkareko Mar 8, 2023
021b3c0
Code clean up
Rkareko Mar 9, 2023
f93e1c0
Code clean up
Rkareko Mar 9, 2023
2e1c552
Update unit tests
Rkareko Mar 9, 2023
2c3b4af
Remove already handled TODOs
Rkareko Mar 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion p2p-lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@

buildscript {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. This is only required when using the p2p-lib module directly inside FHIR Core

apply from: '../deps.gradle'

versions.kotlin_coveralls = '2.12.0'
versions.jacoco_tool = '0.8.7'
ext.composeVersion = "1.2.1"

deps.kotlin_coveralls_plugin = "gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:$versions.kotlin_coveralls"


repositories {
google()
mavenCentral()
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 "org.jetbrains.kotlin:kotlin-serialization:1.7.10"
classpath deps.kotlin_coveralls_plugin
classpath deps.spotless

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

plugins {
id 'com.android.library'
id 'kotlin-android'
Expand Down Expand Up @@ -223,7 +251,7 @@ afterEvaluate {
from(components["release"])
artifactId = "p2p-lib"
groupId = "org.smartregister"
version = "0.6.0-SNAPSHOT"
version = "0.6.1-SNAPSHOT"
pom {
name.set("Peer to Peer Library")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.smartregister.p2p.search.ui.p2p

import android.net.wifi.p2p.WifiP2pDevice
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.ModalBottomSheetValue
Expand All @@ -26,6 +27,8 @@ import androidx.compose.ui.test.performClick
import org.junit.Rule
import org.junit.Test
import org.smartregister.p2p.authentication.model.DeviceRole
import org.smartregister.p2p.data_sharing.DeviceInfo
import org.smartregister.p2p.data_sharing.WifiDirectDataSharingStrategy
import org.smartregister.p2p.model.P2PState
import org.smartregister.p2p.search.ui.p2p.components.CIRCULAR_PROGRESS_INDICATOR_TEST_TAG

Expand All @@ -37,13 +40,13 @@ class BottomSheetScreenTest {
fun bottomSheetScreenRendersCorrectlyForSenderDevice() {
composeRule.setContent {
BottomSheet(
deviceList = emptyList(),
deviceList = listOf(populateDeviceInfo()),
onEvent = {},
modalBottomSheetState = ModalBottomSheetState(ModalBottomSheetValue.HalfExpanded),
p2PUiState = P2PUiState(),
deviceName = "John",
deviceRole = DeviceRole.SENDER,
p2PState = P2PState.RECEIVING_DATA
p2PState = P2PState.SEARCHING_FOR_RECIPIENT
)
}

Expand Down Expand Up @@ -100,7 +103,7 @@ class BottomSheetScreenTest {
}

composeRule.onNodeWithText("OKay").assertExists().assertIsDisplayed()
composeRule.onNodeWithText("Send Data").assertExists().assertIsDisplayed()
composeRule.onNodeWithText("Receive Data").assertExists().assertIsDisplayed()
composeRule.onNodeWithText("Device data successfully sent").assertExists().assertIsDisplayed()
composeRule
.onNodeWithTag(BOTTOM_SHEET_BUTTON_TEST_TAG)
Expand Down Expand Up @@ -134,4 +137,113 @@ class BottomSheetScreenTest {
.assertExists()
.assertIsDisplayed()
}

@Test
@OptIn(ExperimentalMaterialApi::class)
fun bottomSheetScreenRendersCorrectlyForReceiveBasicDeviceDetailsFailedStatus() {
composeRule.setContent {
BottomSheet(
deviceList = emptyList(),
onEvent = {},
modalBottomSheetState = ModalBottomSheetState(ModalBottomSheetValue.HalfExpanded),
p2PUiState = P2PUiState(),
deviceName = "John",
deviceRole = DeviceRole.RECEIVER,
p2PState = P2PState.RECEIVE_BASIC_DEVICE_DETAILS_FAILED
)
}

composeRule.onNodeWithText("OKay").assertExists().assertIsDisplayed()
composeRule.onNodeWithText("Receiving device details failed").assertExists().assertIsDisplayed()
composeRule
.onNodeWithText("Sorry could not receive device details")
.assertExists()
.assertIsDisplayed()
composeRule
.onNodeWithTag(BOTTOM_SHEET_BUTTON_TEST_TAG)
.assertExists()
.assertIsDisplayed()
.performClick()
composeRule
.onNodeWithTag(BOTTOM_SHEET_CANCEL_ICON_TEST_TAG)
.assertExists()
.assertIsDisplayed()
.performClick()
}

@Test
@OptIn(ExperimentalMaterialApi::class)
fun bottomSheetScreenRendersCorrectlyForPairDevicesSearchFailedStatus() {
composeRule.setContent {
BottomSheet(
deviceList = emptyList(),
onEvent = {},
modalBottomSheetState = ModalBottomSheetState(ModalBottomSheetValue.HalfExpanded),
p2PUiState = P2PUiState(),
deviceName = "John",
deviceRole = DeviceRole.SENDER,
p2PState = P2PState.PAIR_DEVICES_SEARCH_FAILED
)
}

composeRule.onNodeWithText("OKay").assertExists().assertIsDisplayed()
composeRule.onNodeWithText("Searching failed").assertExists().assertIsDisplayed()
composeRule
.onNodeWithText("Sorry could not find devices to pair with")
.assertExists()
.assertIsDisplayed()
composeRule
.onNodeWithTag(BOTTOM_SHEET_BUTTON_TEST_TAG)
.assertExists()
.assertIsDisplayed()
.performClick()
composeRule
.onNodeWithTag(BOTTOM_SHEET_CANCEL_ICON_TEST_TAG)
.assertExists()
.assertIsDisplayed()
.performClick()
}

@Test
@OptIn(ExperimentalMaterialApi::class)
fun bottomSheetScreenRendersCorrectlyForConnectToDeviceFailedStatus() {
composeRule.setContent {
BottomSheet(
deviceList = emptyList(),
onEvent = {},
modalBottomSheetState = ModalBottomSheetState(ModalBottomSheetValue.HalfExpanded),
p2PUiState = P2PUiState(),
deviceName = "John",
deviceRole = DeviceRole.SENDER,
p2PState = P2PState.CONNECT_TO_DEVICE_FAILED
)
}

composeRule.onNodeWithText("OKay").assertExists().assertIsDisplayed()
composeRule.onNodeWithText("Pairing failed").assertExists().assertIsDisplayed()
composeRule
.onNodeWithText("Sorry could not pair with device")
.assertExists()
.assertIsDisplayed()
composeRule
.onNodeWithTag(BOTTOM_SHEET_BUTTON_TEST_TAG)
.assertExists()
.assertIsDisplayed()
.performClick()
composeRule
.onNodeWithTag(BOTTOM_SHEET_CANCEL_ICON_TEST_TAG)
.assertExists()
.assertIsDisplayed()
.performClick()
}

private fun populateDeviceInfo(): DeviceInfo {
val wifiP2pDevice =
WifiP2pDevice().apply {
deviceName = "Google Pixel 7 android 12"
deviceAddress = "00:00:5e:00:53:af"
}
return WifiDirectDataSharingStrategy.WifiDirectDevice(wifiP2pDevice)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import org.junit.Rule
import org.junit.Test
import org.smartregister.p2p.model.P2PState
import org.smartregister.p2p.model.ProgressIndicator
import org.smartregister.p2p.model.ProgressIndicatorState
import org.smartregister.p2p.search.ui.p2p.P2PUiState
Expand All @@ -45,7 +46,7 @@ class DeviceListTest {

@Test
fun testPairDeviceRowIsRendered() {
composeTestRule.setContent { PairDeviceRow(device = null, onEvent = {}) }
composeTestRule.setContent { PairDeviceRow(device = null, onEvent = {}, p2PState = P2PState.PAIR_DEVICES_FOUND) }
composeTestRule.onNodeWithTag(PAIR_DEVICE_ROW_ICON_TAG).assertExists().assertIsDisplayed()
composeTestRule.onNodeWithTag(PAIR_DEVICE_ROW_NAME_TEXT_TAG).assertExists().assertIsDisplayed()
composeTestRule.onNodeWithTag(PAIR_DEVICE_ROW_BUTTON_TAG).assertExists().assertIsDisplayed()
Expand Down
9 changes: 8 additions & 1 deletion p2p-lib/src/main/java/org/smartregister/p2p/P2PLibrary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class P2PLibrary private constructor() {
private lateinit var options: Options
private var hashKey: String? = null
private var deviceUniqueIdentifier: String? = null
var dataSharingStrategy: DataSharingStrategy = WifiDirectDataSharingStrategy()
var dataSharingStrategy: DataSharingStrategy? = null

companion object {
private var instance: P2PLibrary? = null
Expand All @@ -45,6 +45,9 @@ class P2PLibrary private constructor() {
"in the onCreate method of " +
"your Application class ")
}
if (instance!!.dataSharingStrategy == null) {
instance!!.dataSharingStrategy = WifiDirectDataSharingStrategy()
}
return instance!!
}

Expand Down Expand Up @@ -72,6 +75,10 @@ class P2PLibrary private constructor() {
return AppDatabase.getInstance(getContext(), options.dbPassphrase)
}

fun clean() {
dataSharingStrategy = null
}

fun getHashKey(): String? {
if (hashKey == null) {
val settings = Settings(getContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.wifi.p2p.WifiP2pDevice
import android.net.wifi.p2p.WifiP2pGroup
import android.net.wifi.p2p.WifiP2pInfo
import android.net.wifi.p2p.WifiP2pManager
import android.os.Build
import androidx.core.app.ActivityCompat
import org.smartregister.p2p.search.contract.P2PManagerListener
import timber.log.Timber

class WifiP2pBroadcastReceiver(
private val manager: WifiP2pManager,
Expand All @@ -37,6 +38,7 @@ class WifiP2pBroadcastReceiver(
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION -> {
Timber.e("Wifi p2p Connection changed action")
val p2pGroupInfo =
intent.getParcelableExtra<WifiP2pGroup>(WifiP2pManager.EXTRA_WIFI_P2P_GROUP)
val wifiP2pInfo = intent.getParcelableExtra<WifiP2pInfo>(WifiP2pManager.EXTRA_WIFI_P2P_INFO)
Expand All @@ -47,7 +49,11 @@ class WifiP2pBroadcastReceiver(
WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION -> handlePeersChanged()
WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION ->
handleStateChanged(intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1))
WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION -> handleDeviceChanged()
WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION -> {
val device =
intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE) as WifiP2pDevice?
handleDeviceChanged(device = device)
}
}
}

Expand Down Expand Up @@ -101,32 +107,11 @@ class WifiP2pBroadcastReceiver(
/**
* https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager#WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
*/
private fun handleDeviceChanged() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED
) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
listener.handleAccessFineLocationNotGranted()
return
}
manager.requestDeviceInfo(channel) {
if (it == null) {
listener.handleWifiP2pDisabled()
} else {
listener.handleWifiP2pDevice(it)
}
}
private fun handleDeviceChanged(device: WifiP2pDevice?) {
if (device == null) {
listener.handleWifiP2pDisabled()
} else {
listener.handleMinimumSDKVersionNotMet(
Build.VERSION_CODES.Q,
)
listener.handleWifiP2pDevice(device)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ interface SenderTransferDao {

fun getTotalRecordCount(highestRecordIdMap: HashMap<String, Long>): Long

fun getJsonData(dataType: DataType, lastRecordId: Long, batchSize: Int): JsonData?
fun getJsonData(dataType: DataType, lastRecordId: Long, batchSize: Int, offset: Int = 0): JsonData?
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ interface DataSharingStrategy {

fun onPairingFailed(ex: Exception)

fun onPairingSucceeded()

fun onSendingFailed(ex: Exception)

fun onSearchingFailed(ex: Exception)
Expand Down Expand Up @@ -96,5 +98,15 @@ interface DataSharingStrategy {

fun onPause()

fun initChannel(onDeviceFound: OnDeviceFound, onConnected: DataSharingStrategy.PairingListener)
fun initChannel(onDeviceFound: OnDeviceFound, onConnected: PairingListener)

fun onStop()

fun cleanup() {}

fun connectionTimeout() : Int = 30

fun isPairingInitiated() : Boolean


}
Loading