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

Negotiating data exchange, Tracking last sent data on the receiver & generate hash key if not presenter device start #32

Merged
merged 18 commits into from
Apr 17, 2019

Conversation

ekigamba
Copy link
Contributor

@ekigamba ekigamba commented Mar 27, 2019

Fixes #8
Fixes #5
Covers some tasks on #6

  • Negotiating data exchange
  • Tracking last sent data on the receiver
  • Generate hash key if not presenter device start

@ekigamba ekigamba force-pushed the issue/8-negotiating-data-exchange branch from db0c31f to 19c2831 Compare March 28, 2019 08:12
@ekigamba ekigamba changed the title Negotiating data exchange & Tracking last sent data on the receiver Negotiating data exchange, Tracking last sent data on the receiver & generate hash key if not presenter device start Apr 1, 2019
ekigamba added 14 commits April 1, 2019 11:37
Capitalize Constant sub-classes/interfaces instead of using UPPER_CASE
- Add room and encrypted sql cipher
- Use Wifi mac address as the device unique identifier since it persists across installs and device formats
- Add SendingDevice records as sending_devices table to keep track of sending devices
- Add p2p_received_history table to keep track of received history
- Sending devices sends the hash_key(app-lifetime-key) to the receiving device together with the unique identifier
- Register new sending device on recieving device
- Clear previous receiving history if the sending device has it's app-lifetime-key(hash_key) changed
…enderPresenter

- Move log strings and other UI strings to strings.xml
- This seems to work better than ConnectionsClient.stopAllEndpoints() and reduces the possibilty of memory leaks
- This also fixes the NPE when a connection callback is called after the app exits and the interactor is null
- Change the current connection level of the app after authorization
and after negotiating the start of the data exchange

Fixes #8
@ekigamba ekigamba force-pushed the issue/8-negotiating-data-exchange branch from 19c2831 to d8835e3 Compare April 1, 2019 08:39
@ekigamba ekigamba requested a review from githengi April 4, 2019 13:49
view.showToast(view.getString(R.string.an_error_occurred_before_acceptance_or_rejection), Toast.LENGTH_LONG);
resetState();
startAdvertisingMode();
if (getCurrentPeerDevice() != null && endpointId.equals(getCurrentPeerDevice().getEndpointId())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there be an else

Copy link
Contributor Author

@ekigamba ekigamba Apr 17, 2019

Choose a reason for hiding this comment

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

The else is not supposed to be possible, if it is, then due to the memory leak whose issue is here #39.

The app was crashing without the if since the code was being run even after exiting the activity and the ConnectionsClient is holding on to the callbacks passed

If the google issue has no reply by the time I am done with the remaining issues and no other solution in site, then we'll have to use WeakReferences for the view (Or clean it up) but the API might still hold onto the listener until it makes the last call

The else happening, means that the callback was called although we are not connected to the endpoint or have already disconnected

resetState();
view.showToast(String.format(view.getString(R.string.connection_to_endpoint_broken), endpointId), Toast.LENGTH_LONG);
startAdvertisingMode();
if (getCurrentPeerDevice() != null && endpointId.equals(getCurrentPeerDevice().getEndpointId())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there be an else

Copy link
Contributor Author

@ekigamba ekigamba Apr 17, 2019

Choose a reason for hiding this comment

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

The else is not supposed to be possible, if it is, then due to the memory leak whose issue is here #39.

The app was crashing without the if since the code was being run even after exiting the activity and the ConnectionsClient is holding on to the callbacks passed

If the google issue has no reply by the time I am done with the remaining issues and no other solution in site, then we'll have to use WeakReferences for the view (Or clean it up) but the API might still hold onto the listener until it makes the last call

The else happening, means that the callback was called although we are not connected to the endpoint or have already disconnected

sendingDevice.setAppLifetimeKey(appLifetimeKey);
db.sendingDeviceDao().update(sendingDevice);

return db.p2pReceivedHistoryDao()
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't clear be done before update or maybe consider using Transaction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either can work, there is device_id which will never change and is used to reference the device in the received_history table. I will add a transaction to this

Timber.e(view.getString(R.string.log_endpoint_lost), endpointId);
resetState();
startAdvertisingMode();
if (getCurrentPeerDevice() != null && endpointId.equals(getCurrentPeerDevice().getEndpointId())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding else to do cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The else is not supposed to be possible, if it is, then due to the memory leak whose issue is here #39.

The app was crashing without the if since the code was being run even after exiting the activity and the ConnectionsClient is holding on to the callbacks passed

If the google issue has no reply by the time I am done with the remaining issues and no other solution in site, then we'll have to use WeakReferences for the view (Or clean it up) but the API might still hold onto the listener until it makes the last call

The else happening, means that the callback was called although we are not connected to the endpoint or have already disconnected

view.showToast(view.getString(R.string.an_error_occurred_before_acceptance_or_rejection), Toast.LENGTH_LONG);
resetState();
startDiscoveringMode();
if (getCurrentPeerDevice() != null && endpointId.equals(getCurrentPeerDevice().getEndpointId())) {
Copy link
Contributor

@githengi githengi Apr 17, 2019

Choose a reason for hiding this comment

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

Consider doing cleanup for an else clause

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same case

The else is not supposed to be possible, if it is, then due to the memory leak whose issue is here #39.

The app was crashing without the if since the code was being run even after exiting the activity and the ConnectionsClient is holding on to the callbacks passed

If the google issue has no reply by the time I am done with the remaining issues and no other solution in site, then we'll have to use WeakReferences for the view (Or clean it up) but the API might still hold onto the listener until it makes the last call

The else happening, means that the callback was called although we are not connected to the endpoint or have already disconnected

view.showToast(String.format(view.getString(R.string.connection_to_endpoint_broken)
, endpointId), Toast.LENGTH_LONG);
startDiscoveringMode();
if (getCurrentPeerDevice() != null && endpointId.equals(getCurrentPeerDevice().getEndpointId())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider an else and doing cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The else is not supposed to be possible, if it is, then due to the memory leak whose issue is here #39.

The app was crashing without the if since the code was being run even after exiting the activity and the ConnectionsClient is holding on to the callbacks passed

If the google issue has no reply by the time I am done with the remaining issues and no other solution in site, then we'll have to use WeakReferences for the view (Or clean it up) but the API might still hold onto the listener until it makes the last call

The else happening, means that the callback was called although we are not connected to the endpoint or have already disconnected

@ekigamba ekigamba merged commit 6aa80be into master Apr 17, 2019
@ekigamba ekigamba deleted the issue/8-negotiating-data-exchange branch April 17, 2019 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negotiating start of data exchange Generate a Hash key when the library is started
2 participants