Android: further simplify permission request callback
Since we don't use the list of strings, don't pass it from Java to C++ at all. This saves us making a copy of the strings. And as we need to create a QList<PermissionResult> from the list of ints, don't receive the list of int's as a QList<int>, but as a QJniArray<int>, which means one less copy of the int-array we get from Java. Amends 46737c0bc0bb86df87f509628797b5cab184760a. Change-Id: Idae86174cafff90d56affba6e0862fb5c6668c13 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
parent
70738cf726
commit
3b85c77e89
@ -337,7 +337,7 @@ public class QtActivityBase extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
|
||||||
{
|
{
|
||||||
QtNative.sendRequestPermissionsResult(requestCode, permissions, grantResults);
|
QtNative.sendRequestPermissionsResult(requestCode, grantResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedFromNativeCode
|
@UsedFromNativeCode
|
||||||
|
@ -462,7 +462,7 @@ public class QtNative
|
|||||||
|
|
||||||
static native void runPendingCppRunnables();
|
static native void runPendingCppRunnables();
|
||||||
|
|
||||||
static native void sendRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults);
|
static native void sendRequestPermissionsResult(int requestCode, int[] grantResults);
|
||||||
// activity methods
|
// activity methods
|
||||||
|
|
||||||
// service methods
|
// service methods
|
||||||
|
@ -1051,15 +1051,14 @@ static int nextRequestCode()
|
|||||||
\internal
|
\internal
|
||||||
|
|
||||||
This function is called when the result of the permission request is available.
|
This function is called when the result of the permission request is available.
|
||||||
Once a permission is requested, the result is braodcast by the OS and listened
|
Once a permission is requested, the result is broadcast by the OS and listened
|
||||||
to by QtActivity which passes it to C++ through a native JNI method call.
|
to by QtActivity which passes it to C++ through a native JNI method call.
|
||||||
*/
|
*/
|
||||||
static void sendRequestPermissionsResult(JNIEnv *env, jobject obj, jint requestCode,
|
static void sendRequestPermissionsResult(JNIEnv *env, jclass obj, jint requestCode,
|
||||||
const QStringList &permissions, const QList<int> &grantResults)
|
const QJniArray<int> &grantResults)
|
||||||
{
|
{
|
||||||
Q_UNUSED(env);
|
Q_UNUSED(env);
|
||||||
Q_UNUSED(obj);
|
Q_UNUSED(obj);
|
||||||
Q_UNUSED(permissions);
|
|
||||||
|
|
||||||
QMutexLocker locker(&g_pendingPermissionRequestsMutex);
|
QMutexLocker locker(&g_pendingPermissionRequestsMutex);
|
||||||
auto it = g_pendingPermissionRequests->constFind(requestCode);
|
auto it = g_pendingPermissionRequests->constFind(requestCode);
|
||||||
@ -1072,8 +1071,13 @@ static void sendRequestPermissionsResult(JNIEnv *env, jobject obj, jint requestC
|
|||||||
g_pendingPermissionRequests->erase(it);
|
g_pendingPermissionRequests->erase(it);
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
for (qsizetype i = 0; i < grantResults.size(); ++i)
|
request->addResults([grantResults](){
|
||||||
request->addResult(resultFromAndroid(grantResults.at(i)), i);
|
QList<QtAndroidPrivate::PermissionResult> results(grantResults.size(),
|
||||||
|
Qt::Uninitialized);
|
||||||
|
for (qsizetype i = 0; i < grantResults.size(); ++i)
|
||||||
|
results[i] = resultFromAndroid(grantResults.at(i));
|
||||||
|
return results;
|
||||||
|
}());
|
||||||
|
|
||||||
QtAndroidPrivate::releaseAndroidDeadlockProtector();
|
QtAndroidPrivate::releaseAndroidDeadlockProtector();
|
||||||
request->finish();
|
request->finish();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user