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

Add support for Android 12 and for requesting SMS permission #262

Merged
merged 20 commits into from
May 9, 2022

Conversation

latin-panda
Copy link
Contributor

@latin-panda latin-panda commented Apr 13, 2022

Description

This PR:

  • Upgrades to Android 12

  • Upgrades dependencies that support Android 12

  • Fixes url validation for the Connexion Error page and adds a test case to cover this validation.

    • This is a bug that we didn't catch while removing the /medic/_design/medic/_rewrite/ from AppURL in this PR. I discovered the problem when testing the Connection Error Page and using Gamma Dev. Because Gamma Dev's url has a slash, https://gamma.dev.medicmobile.org/ then it wasn't passing the validation and the Connection Error Page didn't display.
    • Steps: 1. install the app. 2. select gamma.dev (my connection with this server is slow) 3. immediately turn on airplane mode. 4. the app should show the connection error page
  • Fixes deprecated attributes (backup strategy) in the manifest.

  • Adds SEND_SMS permission in the manifest, because when sending reports as SMS I was getting this error: java.lang.SecurityException: Sending SMS message: uid 10655 does not have android.permission.SEND_SMS

    • This isn't from Message tab but it is from Reports tab (Enketo form) When submitting a form, and if gateway is configured, then cht-core will send the form as SMS
    • The app will request SEND_SMS when sending the form as sms and if the permission isn't granted, at the moment you should be able to see the prominent disclosure.
  • Adds prominent disclosure when requesting SEND_SMS permission and adds unit tests that cover this scenario.

  • Fixed deprecation from SmsSender, where it gets the SmsManager from the activity context.

  • Fixed deprecation in Alert's vibrator (form)

  • Removed unused spinner code in the Utils class, this spinner was used in the PhotoGrabber the old library for image picker.

  • Fixed deprecation of AsynTask by creating a TaskRunner that is used when validating the app url in the Settings Dialog page.

Closes #205

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@latin-panda latin-panda changed the title 205 - upgrade to Android 12 205 - Upgrade to Android 12 Apr 13, 2022
@latin-panda latin-panda linked an issue Apr 13, 2022 that may be closed by this pull request
@latin-panda latin-panda marked this pull request as ready for review April 14, 2022 16:16
@latin-panda latin-panda requested a review from jkuester April 14, 2022 16:39
@latin-panda
Copy link
Contributor Author

Hi @jkuester can you please review? And thanks a lot for all the reviews and suggestions, I've learned tons! 🤩

…205-Android_12

� Conflicts:
�	src/main/java/org/medicmobile/webapp/mobile/SettingsDialogActivity.java
Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

I have not finished here yet, but I have looked through all the SMS logic (not tests) and wanted to submit what I have so far.

Couple of questions I have after this initial look:

  • Do I need to do anything special to get the app to ask for the SMS permission? I thought all I would need to do was send a message from the Messages tab, but that did not trigger it. (Maybe I need some special config on my CHT instance?)
  • What is the actual problem we are trying to solve with the new URL code? (What was not working before?)

README.md Outdated Show resolved Hide resolved
build.gradle Outdated Show resolved Hide resolved
src/main/AndroidManifest.xml Show resolved Hide resolved
src/main/AndroidManifest.xml Outdated Show resolved Hide resolved
src/main/res/xml/backup_rules.xml Show resolved Hide resolved
src/main/java/org/medicmobile/webapp/mobile/SmsSender.java Outdated Show resolved Hide resolved
src/main/java/org/medicmobile/webapp/mobile/SmsSender.java Outdated Show resolved Hide resolved
src/main/java/org/medicmobile/webapp/mobile/SmsSender.java Outdated Show resolved Hide resolved
@latin-panda
Copy link
Contributor Author

latin-panda commented Apr 20, 2022

Do I need to do anything special to get the app to ask for the SMS permission? I thought all I would need to do was send a message from the Messages tab, but that did not trigger it. (Maybe I need some special config on my CHT instance?)

This isn't from Message tab but from Reports tab(Enketo form), it took me awhile to partially figure it out.
When submitting a form, and if gateway is configured, then cht-core will send the form as SMS.
I was in a rush to finish this before I leave, so I just made Enketo to always submit the form as sms in my local environment, instead of configuring the gateway and others things (that I still need to discover 😬)...

Edit: You should be able to see the disclosure page after saving the form and sending it as sms, and if the permission isn't granted yet.

What is the actual problem we are trying to solve with the new URL code? (What was not working before?)

Remove backslash at the end of the AppURL, this is a bug that we didn't catch while removing the /medic/_design/medic/_rewrite/ from AppURL in this PR. I discover the problem when testing the Connection Error Page and using Gamma Dev.

  1. install the app
  2. select gamma.dev (my connection with this server is slow)
  3. immediately turn on airplane mode.
  4. the app should show the connection error page

Because Gamma Dev's url has a blackslash, https://gamma.dev.medicmobile.org/ then it wasn't passing the validation and the Connection Error Page didn't display.

I'll put this details in the PR description for QA.

@jkuester
Copy link
Contributor

This isn't from Message tab but from Reports tab(Enketo form), it took me awhile to partially figure it out. . . . (that I still need to discover 😬)...

Thanks for the pointers here! This makes so much more sense now. For the record, I got really curious about this and dug in long enough to figure out how to get the SMS to send!

  • In settings.js doc, Set a phone number in the settings object for the name gateway_number
    • "settings":{"gateway_number":"*the_phone_num*" ... }
  • In your form document (e.g. form:enketo_widgets), set "xml2sms": true

This will trigger SMS messages to be sent to the gateway number when submitting a form using the Android app. (Note that the gateway number cannot be the number of the phone that the app is running on (seems that you cannot sent SMS to yourself..)).

For more info: https://docs.communityhealthtoolkit.org/apps/guides/forms/app-form-sms/

Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

Okay, made it though the rest of the implementation code. Still need to look at the tests....

src/main/java/org/medicmobile/webapp/mobile/Alert.java Outdated Show resolved Hide resolved
executor.execute(() -> {
try {
final R result = callable.call();
handler.post(() -> callback.onComplete(result));
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, just want to be sure I am understanding what is going on here! After we execute the callable (asynchronously in a new Thread), this handler will trigger the callback to be run back on the main thread. Is that right?

return false;
}

return getAppUrl().equals(url.trim().replaceAll("/$", ""));
Copy link
Contributor

@jkuester jkuester Apr 21, 2022

Choose a reason for hiding this comment

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

Is this what is actually causing the bug around the "Connection Error Page"? Is it just a race condition between hitting the UrlHandler.onReceivedError before the AppUrlVerifier task could save the cleaned URL?

@@ -11,7 +11,7 @@
<exclude name="AvoidDuplicateLiterals"/>
<exclude name="AvoidDuplicateLiterals"/>
<exclude name="AvoidFieldNameMatchingMethodName"/>
<exclude name="MissingBreakInSwitch"/>
<exclude name="ImplicitSwitchFallThrough"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Name changed in the new version of PMD

Copy link
Contributor

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

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

Awesome work @jkuester and @latin-panda !

@jkuester jkuester changed the title 205 - Upgrade to Android 12 Add support for Android 12 and for requesting SMS permission May 9, 2022
@jkuester jkuester merged commit e642664 into master May 9, 2022
@jkuester jkuester deleted the 205-Android_12 branch May 9, 2022 16:31
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.

Upgrade to Android 12 and check for breaking changes
3 participants