OSDN Git Service

Require InputContentInfo.requestPermission()
authorYohei Yukawa <yukawa@google.com>
Tue, 10 Jan 2017 22:32:46 +0000 (14:32 -0800)
committerYohei Yukawa <yukawa@google.com>
Tue, 10 Jan 2017 22:32:46 +0000 (14:32 -0800)
This CL logically reverts my previous CL [1], which allowed the system
automatically grant a temporary URI permission to the target
application when the IME calls InputConnection#commitContent() with
InputConnection#INPUT_CONTENT_GRANT_READ_URI_PERMISSION.

Based on conversations with application developers who have supported
Commit Content APIs, I concluded that my assumption that automatically
granting the permission without an explicit call of
InputContentInfo.requestPermission() would help application developers
was wrong.  They anyway need to take care of the situation where the
app fails to read the data from the given content URI.  Thus just
receiving SecurityException() because of not calling it is still one
of such cases that application developers cannot forget about.

Therefore with this CL InputContentInfo.requestPermission() becomes
mandatory when InputConnection#INPUT_CONTENT_GRANT_READ_URI_PERMISSION
is specified.

 [1]: Id955435dd2e72549ee7134f46b3c6951581694ad
      f3806f57a59ede663f3fa2ad1f5080bdbf20e372

Bug: 32315394
Test: By github.com/googlesamples/android-CommitContentSampleApp
Change-Id: I8a3cb79ae6d6c4113914734799b21bfc96e3ca3e

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

index 4f7b106..0185e30 100644 (file)
@@ -562,8 +562,6 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
             }
             case DO_COMMIT_CONTENT: {
                 final int flags = msg.arg1;
-                final boolean grantUriPermission =
-                        (flags & InputConnection.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0;
                 SomeArgs args = (SomeArgs) msg.obj;
                 try {
                     InputConnection ic = getInputConnection();
@@ -579,22 +577,8 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
                         args.callback.setCommitContentResult(false, args.seq);
                         return;
                     }
-                    if (grantUriPermission) {
-                        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);
-                    // If this request is not handled, then there is no reason to keep the URI
-                    // permission.
-                    if (grantUriPermission && !result) {
-                        inputContentInfo.releasePermission();
-                    }
                     args.callback.setCommitContentResult(result, args.seq);
                 } catch (RemoteException e) {
                     Log.w(TAG, "Got RemoteException calling commitContent", e);