Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Add support for Android 9 #227

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

shobhitagarwal1612
Copy link
Contributor

@shobhitagarwal1612 shobhitagarwal1612 commented Mar 25, 2019

Closes #191

What has been done to verify that this works as intended?

Tested by sending forms multiple times on MotoG5 Plus (Android 9)

Why is this the best possible solution? Were any other approaches considered?

Not the best solution but this is the best I could come up with. Please suggest if you have any other approaches. So the current approach goes like this:

  • The first problem was that the IP of the host resolved by the receiver was incorrect (default isn't 192.168.43.1 in Android 9). So, now we send IP along with the QR Code and get IP from network interface instead of from dhcp server
  • Removed startLocalOnlyHotspot as server socket wasn't reachable with that way. It works perfectly to start/stop hotspot but the ultimate goal wasn't being served. I searched a lot but wasn't able to find anything solid as to why the sockets were unreachable. Although, the host was pingable (tested by ping <host_ip> from the shell of the receiver device)
  • Only system apps have permission to read/write wifi hotspot configurations. So, we have to rely on manual entry of ssid and password which happens on the first launch of the app for Android 9 devices.
  • Since users might not change their default hotspot's name, I had to remove the filter which only shows devices running the same app. We can explore NSD for that purpose in the future.
  • Also fixes a bug when play services are not available

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Need feedback for this approach. Might still contain bugs but at least it works now.

If you are testing this PR, then uninstall the currently installed app. Need shared preferences to be cleared.

Before submitting this PR, please make sure you have:

  • run ./gradlew checkCode and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.

@shobhitagarwal1612
Copy link
Contributor Author

shobhitagarwal1612 commented Mar 28, 2019

I've requested a review from people I remember might have mentioned that they have an Android 9 device to try this PR out. If I forgot someone's name, then apologies for that.

@udhay24
Copy link
Contributor

udhay24 commented Mar 28, 2019

@shobhitagarwal1612 i don't have a android 9 device now but i can get my hands on one by monday

@lakshyagupta21
Copy link
Contributor

@shobhitagarwal1612 Please fix the conflicts.

Copy link
Contributor

@ajay-prabhakar ajay-prabhakar left a comment

Choose a reason for hiding this comment

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

@shobhitagarwal1612 It is working fine for me now and close the support for Android 8.0.0 when this is merging, I just now checked it is working fine as expected

@shobhitagarwal1612
Copy link
Contributor Author

Thanks for testing it out @Chromicle and I'm glad that it worked for you. Could you please mention which all devices you used for testing this PR? It would be nice to keep a track of devices and android versions

@ajay-prabhakar
Copy link
Contributor

Samsung J8 of Android 8.0.0 and samsung note 3 of Android 9 these all devices I tested it is working fine

@shobhitagarwal1612
Copy link
Contributor Author

@shobhitagarwal1612 Please fix the conflicts.

@lakshyagupta21 Done

@udhay24
Copy link
Contributor

udhay24 commented Apr 6, 2019

ezgif com-video-to-gif

@shobhitagarwal1612 i just tested it in samsung j7(2016) - android 8.1. I noticed that AlertDialog keeps popping one after the another until the app becomes un-responsive

@shobhitagarwal1612
Copy link
Contributor Author

I found another bug, not the one you have mentioned @udhay24. Also, I tested on Android 9 as I don't have an Android 8 device

@ajay-prabhakar
Copy link
Contributor

ajay-prabhakar commented Apr 6, 2019

@udhay24 I just now checked I did not find that type of behavior in android 8.0.0
@shobhitagarwal1612 I also found the bug is when the hotspot is turned on initially now also it is asking to on the hotspot

@shobhitagarwal1612
Copy link
Contributor Author

shobhitagarwal1612 commented Apr 6, 2019

I didn't find a way to get the status of the hotspot in Android 9. Hence the alert dialog.

My intention behind this PR was to give a push to this GSoC project and get the base ready i.e. sending/receiving so that you guys can focus on new features and overall stability. All these issues can be opened separately and fixed during the summer

@udhay24
Copy link
Contributor

udhay24 commented Apr 6, 2019

ezgif com-video-to-gif

@shobhitagarwal1612 i just tested it in samsung j7(2016) - android 8.1. I noticed that AlertDialog keeps popping one after the another until the app becomes un-responsive

@shobhitagarwal1612 i forgot to mention that the location was already enabled but the app was still asking to enable the location.

@shobhitagarwal1612
Copy link
Contributor Author

@udhay24 I was able to reproduce the issue. Please review again

Copy link
Contributor

@huangyz0918 huangyz0918 left a comment

Choose a reason for hiding this comment

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

Great fix for android 9.0, I have tested it using Nexus 6P and Pixel XL and they both worked!
Several improvements for your reference.

return ssid.contains(getString(R.string.hotspot_name_suffix)) ||
ssid.contains(getString(R.string.hotspot_name_prefix_oreo));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If the code is useless, please remove them or making comments to clarify the reason for keeping them.

port = (Integer) obj.get(PORT);
isProtected = (boolean) obj.get(PROTECTED);
if (isProtected) {
passwordScanned = (String) obj.get(PASSWORD);
}

Timber.d("Scanned results " + ssidScanned + " " + port + " " + isProtected + " " + passwordScanned);
Timber.d("Scanned results " + wifiNetworkSSID + " " + port + " " + isProtected + " " + passwordScanned);
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest removing all the test log if they are only used for debugging, or just comment them.

@@ -397,19 +399,25 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
// request was canceled...
Timber.i("QR code scanning cancelled");
} else {
Timber.d("RESULT " + result);
Copy link
Contributor

Choose a reason for hiding this comment

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

The same as above.

} else {
Toast.makeText(this, "already connected to " + ssidScanned, Toast.LENGTH_SHORT).show();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we extract the toasts into something like ToastUtils.java? You can refer to Collect's. Something for showing dialogs can be refactor as well.

@@ -106,11 +102,10 @@ protected void onCreate(Bundle savedInstanceState) {
formIds = getIntent().getLongArrayExtra(FORM_IDS);
}


port = SocketUtils.getPort();

if (port == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

-1 can be replaced by a static variable with meaningful name, like NO_AVAILABLE_PORT_CODE?

isHotspotInitiated = true;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// do nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

//TODO: will be helpful.

alertDialog.setCancelable(false);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok), quitListener);
alertDialog.show();
new AlertDialog.Builder(this)
Copy link
Contributor

Choose a reason for hiding this comment

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

So many similar dialogs, can we building something like DailogFactory.java which has different static methods can return dialogs?

}

if (openSettings) {
} else if (openSettings) {
Copy link
Contributor

Choose a reason for hiding this comment

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

openSettings is a bad name for a boolean value.

}

public void stopHotspot() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For those version checks, we can build a boolean variable like isApiHigherThanO = ..., can call isApiHigherThanO or !isApiHigherThanO if necessary, which can simplify the code and make them better to read.

@shobhitagarwal1612
Copy link
Contributor Author

shobhitagarwal1612 commented Jul 5, 2019

@lakshyagupta21 What are your thoughts about this PR? Do you think this would be a good solution to some of the mentioned wifi hotspot issues?
If yes, then would it be a feasible and good task for @huangyz0918 to finish off the remaining work in this PR by adjusting some of the non-crucial tasks in his timeline after he is done with #260?

@lakshyagupta21
Copy link
Contributor

@lakshyagupta21 What are your thoughts about this PR? Do you think this would be a good solution to some of the mention wifi hotspot issues?

Even I think that should resolve some of the issues. yeah it would be a good idea to let @huangyz0918 pick this up, if he needs some help with the Android 9 testing in case he doesn't have one then we can hop in.

@huangyz0918
Copy link
Contributor

huangyz0918 commented Jul 9, 2019

yeah it would be a good idea to let @huangyz0918 pick this up, if he needs some help with the Android 9 testing in case he doesn't have one then we can hop in.

Yeah I'd like to, but I don't have two android 9 devices currently, so I may have some trouble testing the changes. Can you help me to test the PR #260 using android 9 first? @lakshyagupta21 I want to know what kinds of issue in android 9 with bluetooth feature (I tested the PR in android 8.0.0, 8.0.1 and 6.0.1 with success), for you guys have android 9 devices @Chromicle @udhay24 @iadeelzafar , I think it will be very nice to have a quick test with that too, thanks so much!!

@shobhitagarwal1612
Copy link
Contributor Author

You don't need to have both android 9 devices at the same time. The same device can be used for validating sending/receiving one at a time.

@huangyz0918
Copy link
Contributor

huangyz0918 commented Jul 10, 2019

You don't need to have both android 9 devices at the same time. The same device can be used for validating sending/receiving one at a time.

I think I can flash my Nexus 6P to android 9 after #260 was merged. If there are issues with android 9, we can open another issue for that.

@@ -88,9 +87,6 @@
private long[] formIds;
private int mode;

private WifiManager.LocalOnlyHotspotReservation hotspotReservation;
Copy link
Contributor

Choose a reason for hiding this comment

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

@shobhitagarwal1612 Is there any specific reason for removing this class and its API usage? I think Google has introduced this Class and some APIs so that hotspot connection can be made and two nearby devices can share the data locally without sharing the user's mobile data.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to send forms on Android 9
5 participants