Repository: kivy/python-for-android

Issue:
PR 2285 breaks requestPermissions 
<!--
The issue tracker is a tool to address bugs NOT a support platform.
Please use the Discord community or Stack Overflow for support questions,
more information at https://github.com/kivy/python-for-android#support
-->

### Checklist

- [x] the issue is indeed a bug and not a support request
- [x] issue doesn't already exist: https://github.com/kivy/python-for-android/issues
- [x] I have a short, runnable example that reproduces the issue
- [x] I reproduced the problem with the latest development version (`p4a.branch = develop`)
- [x] I used the grave accent (aka backticks) to format code or logs when appropriated

### Versions

- Python: Python 3.8.2 (default, Jul 16 2020, 14:00:26) 
- OS: Ubuntu 20.04.1 LTS
- Kivy: master
- Cython: 0.29.17
- OpenJDK: 1.8.0_265

### Description

After PR #2285 , the app crashes when calling the following instruction.
```
request_permissions([Permission.ACCESS_COARSE_LOCATION])
```

### buildozer.spec

Command:
```sh
buildozer android debug deploy run
```

### Logs

```
08-27 18:05:07.895 18125 18146 I python  :    File "jnius/jnius_export_class.pxi", line 1134, in jnius.jnius.JavaMultipleMethod.__call__
08-27 18:05:07.896 18125 18146 I python  :  jnius.jnius.JavaException: No methods matching your arguments, requested: (['android.permission.ACCESS_COARSE_LOCATION'],), available: []
08-27 18:05:07.896 18125 18146 I python  : Python for android ended.
```



Discussion:
Relevant pyjnius issue: kivy/pyjnius#538.
This seems to be a bug in p4a's `android` library.

It looks like `python_activity.requestPermissions` is a non-static method. But it's being called as if it were static. Which for some reason used to work with older versions of pyjnius. Using `python_activity.mActivity.requestPermissions` instead seems to work with 1.3.0.

I'm not sure whether the best way to fix this is to make the method static (if that doesn't break anything) or to call it on the instance. And I suspect there are more cases where this happens.

Resolving patch:
diff --git a/pythonforandroid/recipes/android/src/android/loadingscreen.py b/pythonforandroid/recipes/android/src/android/loadingscreen.py
--- a/pythonforandroid/recipes/android/src/android/loadingscreen.py
+++ b/pythonforandroid/recipes/android/src/android/loadingscreen.py
@@ -5,5 +5,5 @@
 
 
 def hide_loading_screen():
-    python_activity = autoclass(ACTIVITY_CLASS_NAME)
-    python_activity.removeLoadingScreen()
+    mActivity = autoclass(ACTIVITY_CLASS_NAME).mActivity
+    mActivity.removeLoadingScreen()
diff --git a/pythonforandroid/recipes/android/src/android/permissions.py b/pythonforandroid/recipes/android/src/android/permissions.py
--- a/pythonforandroid/recipes/android/src/android/permissions.py
+++ b/pythonforandroid/recipes/android/src/android/permissions.py
@@ -487,8 +487,8 @@ class _RequestPermissionsManager:
     def register_callback(cls):
         """Register Java callback for requestPermissions."""
         cls._java_callback = _onRequestPermissionsCallback(cls.python_callback)
-        python_activity = autoclass(ACTIVITY_CLASS_NAME)
-        python_activity.addPermissionsCallback(cls._java_callback)
+        mActivity = autoclass(ACTIVITY_CLASS_NAME).mActivity
+        mActivity.addPermissionsCallback(cls._java_callback)
 
     @classmethod
     def request_permissions(cls, permissions, callback=None):
@@ -511,12 +511,12 @@ def request_permissions(cls, permissions, callback=None):
         with cls._lock:
             if not cls._java_callback:
                 cls.register_callback()
-            python_activity = autoclass(ACTIVITY_CLASS_NAME)
+            mActivity = autoclass(ACTIVITY_CLASS_NAME).mActivity
             if not callback:
-                python_activity.requestPermissions(permissions)
+                mActivity.requestPermissions(permissions)
             else:
                 cls._callback_id += 1
-                python_activity.requestPermissionsWithRequestCode(
+                mActivity.requestPermissionsWithRequestCode(
                     permissions, cls._callback_id)
                 cls._callbacks[cls._callback_id] = callback
 
@@ -586,8 +586,8 @@ def check_permission(permission):
     Returns:
         bool: True if the app holds the permission given, False otherwise.
     """
-    python_activity = autoclass(ACTIVITY_CLASS_NAME)
-    result = bool(python_activity.checkCurrentPermission(
+    mActivity = autoclass(ACTIVITY_CLASS_NAME).mActivity
+    result = bool(mActivity.checkCurrentPermission(
         permission + ""
     ))
     return result


Test patch: