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

[MRG] Add the location permission for android 9. #286

Merged

Conversation

huangyz0918
Copy link
Contributor

@huangyz0918 huangyz0918 commented Jul 28, 2019

Closes #284

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

Tested in my Nexus 6P (android 9.0) with success.

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

This fix the android 9 permission issue with bluetooth, and after this issue was resolved, the bluetooth feature can work well in android 9 devices I think.

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?

N/A

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.

@@ -73,6 +75,11 @@ protected void onCreate(Bundle savedInstanceState) {
setTitle(getString(R.string.send_instance_title));
setSupportActionBar(toolbar);

//checking the location permission for bluetooth for android 9.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to ask for this permission before opening the activity(When bluetooth option is choosen). Because both the permission asking dialog and scanning dialog appears at the same time .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we grant this permission when we are entering the main page? If we choose bluetooth then popup the permission dialog, that page still has the method choosing dialog appears at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we ask for location permission on start, then what if the user never chooses Bluetooth as the transfer mode then it would not be of no use.
I'm suggesting to open a dialog asking for user permission when user taps on Bluetooth as the transfer mode(Close the dialog asking for the mode of transfer then only show the dialog for the permission) and if user allows then send to BluetoothReceiver/Sender Screen otherwise again show the dialog saying that Location permission is needed for Bluetooth transfer with two button options Cancel(negative) and Access permission(positive). Access permission will ask user again for the permission and if he has selected the checkbox Never ask again when permission was asked then you won't be able to request for permission again, in that case, you have to navigate user to our apps' settings so that he can manually go and give permission to us.
I know its pretty long process and but I think this is the way to tackle this issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is how generally other apps tackle this, in case you've some other option in mind please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, I'll follow your suggestion. But can I use some run-time android permission library? So that I can remove the PermissionUtil.java and make the code more flexible, something like https://github.com/Karumi/Dexter, it can also help me to build a dialog.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, It totally depends on you what you want to use, and but don't forget to add it in our Open Source Licenses section, its always to good to give the credits. And yes if you're doing it for Location permission then do it for every dangerous permission like read and write storage. Or you can open a different PR for that.

@huangyz0918
Copy link
Contributor Author

@lakshyagupta21 I got a better idea, you can have a review of the code now.

ezgif.com-video-to-gif.gif

@lakshyagupta21
Copy link
Contributor

This also looks good to me.

@huangyz0918
Copy link
Contributor Author

@lakshyagupta21 thanks for your detailed review! I think the code is ready now.

updated the open source license.
@huangyz0918
Copy link
Contributor Author

I think it's ready for a review @lakshyagupta21 .

@ajay-prabhakar
Copy link
Contributor

ajay-prabhakar commented Aug 3, 2019

@huangyz0918 I just checked in android 6(Tablet) I am unable to send the forms it is exiting app automatically
In logs, I can't see any crash message or error message I can't understand why it happens

@huangyz0918
Copy link
Contributor Author

@Chromicle This PR is not related to android 6, can you work normally in master?

skunkworks_crow/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
skunkworks_crow/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts(SCHEME, packageName, null);
intent.setData(uri);
targetActivity.startActivity(intent);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an issue over here when the user moves to app settings, and no matter what he does there and after doing all the activity on app settings when he presses back he goes back to the Send data screen with empty view.
You should check whenever an activity is resumed, whether user actually left application to actually play with the app settings, if the answer is yes then check if we've enough permission to do the transmission, if not then again display the same dialog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, I tested in android 9 and non-android 9 devices, no issues, but I think it still needs more tests.

skunkworks_crow/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
@OnPermissionDenied({Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION})
void showDeniedForLocation() {
Toast.makeText(this, R.string.permission_location_denied, 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.

Change the toast length to LONG, everywhere

@lakshyagupta21
Copy link
Contributor

I think we've to enable location permission for all device because in Android 7.1 I've to go and enable the location permission from the settings then only it starts showing the bluetooth devices when I start scanning it.

@huangyz0918
Copy link
Contributor Author

I think we've to enable location permission for all device because in Android 7.1 I've to go and enable the location permission from the settings then only it starts showing the bluetooth devices when I start scanning it.

So you mean I should remove the android 9 checks?

@lakshyagupta21
Copy link
Contributor

Can you check this once in any of your Android 6 and Android 7 device, don't forget to check for location permission (verify when enabled/disabled)

@huangyz0918
Copy link
Contributor Author

Ok, will do that and update this PR.

@huangyz0918
Copy link
Contributor Author

Can you check this once in any of your Android 6 and Android 7 device, don't forget to check for location permission (verify when enabled/disabled)

You can checkout this, from Android 6, the ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION need to be obtained from run time. So I think we should remove the API checks and apply that to all devices. @lakshyagupta21 I updated this PR and please review.

@lakshyagupta21
Copy link
Contributor

ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION need to be obtained from run time

I know that these permissions are required to be asked at runtime, but my doubt was why do we need to ask it I mean who requires this permission.
We found this problem for Android 9, then how was it working previously for other versions if location permission was not given to any of them.

@huangyz0918
Copy link
Contributor Author

I know that these permissions are required to be asked at runtime, but my doubt was why do we need to ask it I mean who requires this permission.

I have done some tests on different devices using both real devices and virtual devices.

Device Name Android Version Needs Location Permission for Bluetooth
Nexus 6P 9.0.0 Yes
Huawei P10 7.1.0 Yes
Nexus 5X 6.0.1 Yes
Samsung Galaxy Note3 5.0.0 No

The conclusion is, in versions of Android prior to Marshmallow, the user could use Bluetooth without location services enabled, we need the location permission in all the devices with an API level > 6.0. @lakshyagupta21

@lakshyagupta21 lakshyagupta21 merged commit ae84efc into getodk:master Aug 10, 2019
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.

Location permission required in android 9
3 participants