Closed hikaritenchi closed 4 years ago
@hikaritenchi thank you very much for reporting this bug and including the extensive analysis. I will try to fix this a.s.a.p. and run an update this week.
@mvanbeusekom Has this been fixed? Because the changelog of version 2.0.2 says
Fixed bug where method shouldShowRequestPermissionRationale always returns false.
but the PR #11 has not been merged. I've also checked the commit history and except for 71c5017d56f9da08a7489e1ac8d6a4ad522f3a4c, which only changed the version number, there seems to have been no code change between 2.0.1 and 2.0.2.
Also, when I check the code of version 2.0.2 in my local pub-cache folder, the changes of PR #11 are not there.
🔙 Regression
shouldShowRequestPermissionRationale()
receives aContext
, but updates toonMethodCall()
guarantees that it is not anActivity
, and will always log an error and returnfalse
.Old (and correct) behavior
onMethodCall()
saved a final reference to aContext
via a deleted methodgetActiveContext()
, which used eithermRegistrar.activeContext()
ormRegistrar.activity()
.That
Context
was passed toshouldShowRequestPermissionRationale()
, which checked if it wasinstanceof
anActivity
, which would succeed ifmRegistrar.activity()
was called ingetActiveContext()
.Current behavior
onMethodCall()
saves a final reference to aContext
viamRegistrar.context()
. From the documentation, that method returns theApplication
'sContext
, which by definition will not be anActivity
, thereby guaranteeing the error inshouldShowRequestPermissionRationale()
and returningfalse
.Reproduction steps
Call
LocationPermissions().shouldShowRequestPermissionRationale()
in Flutter.Suggested Steps
In
onMethodCall()
, I suggest replacingfinal Context context = mRegistrar.context();
withfinal Context context = mRegistrar.activeContext();
The documentation states that it returns the currentActivity
, or theApplication
if that's null, which is exactly what thegetActiveContext()
method was trying to do. As I'm not familiar with the rest of the logic, a cursory review of the other methods that accept aContext
fromonMethodCall()
seem to be unaffected by this change.Relevant Commit
8bd14831582fda4b74855e9dabc43fe4c5f99307
Version: 2.0.1
Platform: