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

Fix a crash on newer android OS due to a depreacted API usage #492

Merged
merged 3 commits into from
Aug 12, 2020

Conversation

nagineni
Copy link
Contributor

TelephonyManager.getNetworkType() is deprecated in API level 30, so
using getDataNetworkType() to get the current data network type on
newer android OS.

Co-authored-by: Tobrun Van Nuland [email protected]

@alfwatt
Copy link

alfwatt commented Aug 10, 2020

Can we use hasCarrierPrivledges to avoid the potential exception in the try/catch block?

@alfwatt alfwatt requested review from harvsu and nkukday August 10, 2020 17:32
@alfwatt
Copy link

alfwatt commented Aug 10, 2020

@nkukday @harvsu we're trying to test out this change and appreciate any suggestions or advice, we'll need to get a test app build together and a release to test it out

@tobrun
Copy link
Member

tobrun commented Aug 10, 2020

Can we use hasCarrierPrivledges to avoid the potential exception in the try/catch block?

That doesn't avoid potential exceptions in the try catch block, see docs on getNetworkType

Requires Permission: READ_PHONE_STATE or that the calling app has carrier privileges (see hasCarrierPrivileges()).

The only way to avoid that exception is correctly integration of runtime permissions check. Given that this isn't possible with telemetry setup (no hook in the hosting activity), try-catch is the only thing we can do this.

Copy link
Member

@tobrun tobrun left a comment

Choose a reason for hiding this comment

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

code LGTM but will defer the actual review to someone else :)

Copy link
Contributor

@harvsu harvsu left a comment

Choose a reason for hiding this comment

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

LGTM! Instrumented unit test on this would be great!

@alfwatt
Copy link

alfwatt commented Aug 10, 2020

@harvsu, @tobrun thanks for the clarifications and suggestion.

@nagineni had questions about how to verify in the test app, @harvsu do we have a step-by-step guild for using the test app to verify a snapshot build of the SDKs?

@codecov
Copy link

codecov bot commented Aug 11, 2020

Codecov Report

Merging #492 into master will increase coverage by 0.14%.
The diff coverage is 62.50%.

@@             Coverage Diff              @@
##             master     #492      +/-   ##
============================================
+ Coverage     68.33%   68.48%   +0.14%     
- Complexity      406      408       +2     
============================================
  Files            70       70              
  Lines          2214     2221       +7     
  Branches        180      181       +1     
============================================
+ Hits           1513     1521       +8     
+ Misses          596      595       -1     
  Partials        105      105              

nagineni and others added 3 commits August 11, 2020 17:46
TelephonyManager.getNetworkType() is deprecated in API level 30, so
using getDataNetworkType() to get the current data network type on
newer android OS.

Co-authored-by: Tobrun Van Nuland <[email protected]>
config property of the location schema is not yet
added to the Android SDK, so ignoring it to make
the schema test pass.
@harvsu
Copy link
Contributor

harvsu commented Aug 11, 2020

@alfwatt Unfortunately, we do not have a step by step guild for the test app in this project. But fortunately, it is very straightforward in the main screen. We have leveraged the test app in the past to regression test the location, turnstile events and look for memory leaks. In addition, to test the differences in cross version API's, we used to create necessary build variants in the existing example app for android.

@nagineni nagineni merged commit 280720b into master Aug 12, 2020
@nagineni nagineni deleted the fix-482 branch August 12, 2020 11:26
@nagineni nagineni self-assigned this Aug 18, 2020
@prfarlow1
Copy link

So what are the consequences if Android apps using the Mapbox SDK do not have READ_PHONE_STATE permission? Will this library still function correctly?

@tobrun
Copy link
Member

tobrun commented Aug 24, 2020

@prfarlow1 yes, in that case the value of data network will be network type unknown

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.

6 participants