Commit d870e4a7 authored by Nicolas Fella's avatar Nicolas Fella Committed by Nicolas Fella

Support runtime permissions

Summary:
To be able to release Itinerary in Google Play we need to target SDK version 28. This requires us to support the permission system introduced in Marshmallow. Before we access the calendar we need to check and potentially request
the calendar permission.

It seems like we don't actually need the storage permission, we get access rights to files received via intents automatically.

Reviewers: vkrause

Reviewed By: vkrause

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D18409
parent 4880e682
......@@ -79,10 +79,9 @@
</activity>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<!-- %%INSERT_PERMISSIONS -->
......
......@@ -53,6 +53,9 @@
using namespace KItinerary;
#ifdef Q_OS_ANDROID
#define PERMISSION_CALENDAR QStringLiteral("android.permission.READ_CALENDAR")
static void importReservation(JNIEnv *env, jobject that, jstring data)
{
Q_UNUSED(that);
......@@ -452,9 +455,18 @@ void ApplicationController::importIataBcbp(const QByteArray &data)
void ApplicationController::checkCalendar()
{
#ifdef Q_OS_ANDROID
const auto activity = QtAndroid::androidActivity();
if (activity.isValid()) {
activity.callMethod<void>("checkCalendar");
if (QtAndroid::checkPermission(PERMISSION_CALENDAR) == QtAndroid::PermissionResult::Granted) {
const auto activity = QtAndroid::androidActivity();
if (activity.isValid()) {
activity.callMethod<void>("checkCalendar");
}
} else {
QtAndroid::requestPermissions({PERMISSION_CALENDAR}, [this] (const QtAndroid::PermissionResultMap &result){
if (result[PERMISSION_CALENDAR] == QtAndroid::PermissionResult::Granted) {
checkCalendar();
}
});
}
#endif
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment