Warning, /graphics/krita/3rdparty/ext_qt/0033-Android-Add-a-way-to-check-permissions-for-external-.patch is written in an unsupported language. File is not indexed.

0001 From 066c35d54e98f2670411e16c79a0553f64871500 Mon Sep 17 00:00:00 2001
0002 From: Sharaf Zaman <sharafzaz121@gmail.com>
0003 Date: Tue, 6 Oct 2020 17:24:15 +0000
0004 Subject: [PATCH 33/46] Android: Add a way to check permissions for external
0005  URIs
0006 
0007 Prior to this we could only open those files which we had
0008 previously persisted permission to or the files that've
0009 been opened using SAF. With this in place we can add
0010 known URIs to which we received permission from other
0011 source like an Intent.
0012 ---
0013  .../org/qtproject/qt5/android/QtNative.java   | 27 +++++++++++++++++++
0014  1 file changed, 27 insertions(+)
0015 
0016 diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
0017 index c9a2179a27..38b595bfbc 100644
0018 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
0019 +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
0020 @@ -115,6 +115,8 @@ public class QtNative
0021      private static Method m_addItemMethod = null;
0022  
0023      private static HashMap<Integer, ParcelFileDescriptor> m_parcelFileDescriptors = new HashMap<Integer, ParcelFileDescriptor>();
0024 +    private static HashMap<Uri, Integer> m_uriPermissions = new HashMap<Uri, Integer>(); // for URIs which were not accessed through SAF e.g through an Intent
0025 +
0026  
0027      private static final Runnable runPendingCppRunnablesRunnable = new Runnable() {
0028          @Override
0029 @@ -168,6 +170,24 @@ public class QtNative
0030          return joinedString.split(",");
0031      }
0032  
0033 +    public static void addToKnownUri(Uri uri, int modeFlags) {
0034 +        m_uriPermissions.put(uri, modeFlags);
0035 +    }
0036 +
0037 +    public static boolean checkKnownUriPermission(Uri uri, String openMode) {
0038 +        if (!m_uriPermissions.containsKey(uri)) {
0039 +            return false;
0040 +        }
0041 +
0042 +        int modeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION;
0043 +
0044 +        if (!"r".equals(openMode)) {
0045 +            modeFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
0046 +        }
0047 +
0048 +        return (m_uriPermissions.get(uri) & modeFlags) != 0;
0049 +    }
0050 +
0051      private static Uri getUriWithValidPermission(Context context, String uri, String openMode)
0052      {
0053          try {
0054 @@ -186,6 +206,13 @@ public class QtNative
0055                  }
0056              }
0057  
0058 +            Uri uriParsed = Uri.parse(uri);
0059 +
0060 +            // give known URIs a try, perhaps we got it in a way we couldn't persist the permissions (say Intent)
0061 +            if (checkKnownUriPermission(uriParsed, openMode)) {
0062 +                return uriParsed;
0063 +            }
0064 +
0065              return null;
0066          } catch (SecurityException e) {
0067              e.printStackTrace();
0068 -- 
0069 2.33.0
0070