OSDN Git Service

Handle exceptions from #requestPermission()
authorYohei Yukawa <yukawa@google.com>
Fri, 14 Oct 2016 07:07:59 +0000 (00:07 -0700)
committerYohei Yukawa <yukawa@google.com>
Fri, 14 Oct 2016 22:26:35 +0000 (22:26 +0000)
This is a follow up CL to my previous CL [1] that let
IInputConnectionWrapper to call InputContentInfo#requestPermission()
automatically so that temporary URI permissions can be granted
automatically on API 25+ devices whenever
INPUT_CONTENT_GRANT_READ_URI_PERMISSION is specified.

However, in that CL we forgot to handle exceptions thrown from
InputContentInfo#requestPermission().  This is problematic because it is
actually easy for IMEs to cause SecurityException by specifying a
content URI that does not allow grantUriPermission, e.g.:

  inputConnection.commitContent(
          new InputContentInfo(Uri.parse("content://call_log/test"),
          new ClipDescription("test", new String[]{"image/gif"}));

As a result, IMEs can let the application crash at any time because
InputContentInfo#requestPermission() is automatically called inside the
Framework.

This CL makes sure that exceptions thrown from
InputContentInfo#requestPermission() can be handled gracefully.

 [1]: Id955435dd2e72549ee7134f46b3c6951581694ad
      f3806f57a59ede663f3fa2ad1f5080bdbf20e372

Bug: 32162481
Change-Id: I08916a1f54518390d3b67ab1673dc901e3f9716a

core/java/com/android/internal/view/IInputConnectionWrapper.java

index 644c7e9..4f7b106 100644 (file)
@@ -580,7 +580,13 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
                         return;
                     }
                     if (grantUriPermission) {
-                        inputContentInfo.requestPermission();
+                        try {
+                            inputContentInfo.requestPermission();
+                        } catch (Exception e) {
+                            Log.e(TAG, "InputConnectionInfo.requestPermission() failed", e);
+                            args.callback.setCommitContentResult(false, args.seq);
+                            return;
+                        }
                     }
                     final boolean result =
                             ic.commitContent(inputContentInfo, flags, (Bundle) args.arg2);