Use a flag to grant a temporary URI permission.

It turns out that we can let the system to call
InputMethodService#exposeContent(InputContentInfo, EditorInfo), which
added in my previous CL [1], during the IME is calling
InputConnection#commitContent() as follows.

  [IME]
  InputContentInfo contentInfo = new InputContentInfo(
          contentUri,
          new ClipDescription(description, new String[]{mimeType}),
          linkUrl);
  getCurrentInputConnection().commitContent(
          inputContentInfo,
          InputConnection.INPUT_CONTENT_GRANT_READ_URI_PERMISSION,
          null);

  [App]
  try {
      contentInfo.requestPermission();
      // Load inputContentInfo.getContentUri() here.
  } finally {
      contentInfo.releasePermission();
  }

This gives us flexibility to let InputConnection#commitContent() do all
the magic for IME developers like other APIs such as
Context#startActivity(), rather than asking them to call one more API to
grant a temporary URI permission like a scenario where
Context#grantUriPermission() is used.

 [1]: I2772889ca01f2ecb2cdeed4e04a9319bdf7bc5a6
      25e0813e6eb6315b1016db805fa9b791b4ae5cc2

Bug: 29450031
Change-Id: I99536cd58c9984af30b0bafb4a1dd25a26634a2d
diff --git a/core/java/com/android/internal/view/IInputConnectionWrapper.java b/core/java/com/android/internal/view/IInputConnectionWrapper.java
index dce9d2c..62e34a6 100644
--- a/core/java/com/android/internal/view/IInputConnectionWrapper.java
+++ b/core/java/com/android/internal/view/IInputConnectionWrapper.java
@@ -243,9 +243,10 @@
         dispatchMessage(obtainMessage(DO_CLOSE_CONNECTION));
     }
 
-    public void commitContent(InputContentInfo inputContentInfo, Bundle opts,
+    public void commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts,
             int seq, IInputContextCallback callback) {
-        dispatchMessage(obtainMessageOOSC(DO_COMMIT_CONTENT, inputContentInfo, opts, seq, callback));
+        dispatchMessage(obtainMessageIOOSC(DO_COMMIT_CONTENT, flags, inputContentInfo, opts, seq,
+                callback));
     }
 
     void dispatchMessage(Message msg) {
@@ -560,6 +561,7 @@
                 return;
             }
             case DO_COMMIT_CONTENT: {
+                final int flags = msg.arg1;
                 SomeArgs args = (SomeArgs) msg.obj;
                 try {
                     InputConnection ic = getInputConnection();
@@ -576,7 +578,8 @@
                         return;
                     }
                     args.callback.setCommitContentResult(
-                            ic.commitContent(inputContentInfo, (Bundle) args.arg2), args.seq);
+                            ic.commitContent(inputContentInfo, flags, (Bundle) args.arg2),
+                            args.seq);
                 } catch (RemoteException e) {
                     Log.w(TAG, "Got RemoteException calling commitContent", e);
                 }
@@ -612,14 +615,14 @@
         return mH.obtainMessage(what, arg1, arg2, args);
     }
 
-    Message obtainMessageOOSC(int what, Object arg1, Object arg2, int seq,
+    Message obtainMessageIOOSC(int what, int arg1, Object objArg1, Object objArg2, int seq,
             IInputContextCallback callback) {
         SomeArgs args = new SomeArgs();
-        args.arg1 = arg1;
-        args.arg2 = arg2;
+        args.arg1 = objArg1;
+        args.arg2 = objArg2;
         args.callback = callback;
         args.seq = seq;
-        return mH.obtainMessage(what, 0, 0, args);
+        return mH.obtainMessage(what, arg1, 0, args);
     }
 
     Message obtainMessageIOSC(int what, int arg1, Object arg2, int seq,