From 93278ca144bef7d8af7a014e278f552da1fcb38c Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Fri, 14 Oct 2016 00:07:59 -0700 Subject: [PATCH] Handle exceptions from #requestPermission() 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/internal/view/IInputConnectionWrapper.java b/core/java/com/android/internal/view/IInputConnectionWrapper.java index 644c7e90f8b0..4f7b106a83fe 100644 --- a/core/java/com/android/internal/view/IInputConnectionWrapper.java +++ b/core/java/com/android/internal/view/IInputConnectionWrapper.java @@ -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); -- 2.11.0