summaryrefslogtreecommitdiff
path: root/core/java/android/inputmethodservice/InputMethodService.java
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2016-06-23 17:12:59 -0700
committerYohei Yukawa <yukawa@google.com>2016-06-23 17:12:59 -0700
commit45700fa135e83ed44e4b69ca60cf12960a5898d7 (patch)
treee734d40c9a3c23b3d83a8a7fb195986ba7c221ff /core/java/android/inputmethodservice/InputMethodService.java
parent9ee8f8066c15f7d4977a26d624baca1210666026 (diff)
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
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
-rw-r--r--core/java/android/inputmethodservice/InputMethodService.java32
1 files changed, 11 insertions, 21 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 8e0e0b0e4b9a..fede77d9bb1d 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -2603,33 +2603,23 @@ public class InputMethodService extends AbstractInputMethodService {
* Allow the receiver of {@link InputContentInfo} to obtain a temporary read-only access
* permission to the content.
*
- * <p>Make sure that the content provider owning the Uri sets the
- * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
- * grantUriPermissions} attribute in its manifest or included the
- * {@link android.R.styleable#AndroidManifestGrantUriPermission
- * &lt;grant-uri-permissions&gt;} tag. Otherwise {@link InputContentInfo#requestPermission()}
- * can fail.</p>
- *
- * <p>Although calling this API is allowed only for the IME that is currently selected, the
- * client is able to request a temporary read-only access even after the current IME is switched
- * to any other IME as long as the client keeps {@link InputContentInfo} object.</p>
- *
* @param inputContentInfo Content to be temporarily exposed from the input method to the
* application.
* This cannot be {@code null}.
- * @param editorInfo The editor that receives {@link InputContentInfo}.
- * @return {@code false} if we cannot allow a temporary access permission.
+ * @param inputConnection {@link InputConnection} with which
+ * {@link InputConnection#commitContent(InputContentInfo, Bundle)} will be called.
+ * @hide
*/
- public final boolean exposeContent(@NonNull InputContentInfo inputContentInfo,
- @NonNull EditorInfo editorInfo) {
- if (inputContentInfo == null) {
- throw new NullPointerException("inputContentInfo");
+ @Override
+ public final void exposeContent(@NonNull InputContentInfo inputContentInfo,
+ @NonNull InputConnection inputConnection) {
+ if (inputConnection == null) {
+ return;
}
- if (editorInfo == null) {
- throw new NullPointerException("editorInfo");
+ if (getCurrentInputConnection() != inputConnection) {
+ return;
}
-
- return mImm.exposeContent(mToken, inputContentInfo, editorInfo);
+ mImm.exposeContent(mToken, inputContentInfo, getCurrentInputEditorInfo());
}
/**