diff options
| author | Yohei Yukawa <yukawa@google.com> | 2016-06-23 17:12:59 -0700 |
|---|---|---|
| committer | Yohei Yukawa <yukawa@google.com> | 2016-06-23 17:12:59 -0700 |
| commit | 45700fa135e83ed44e4b69ca60cf12960a5898d7 (patch) | |
| tree | e734d40c9a3c23b3d83a8a7fb195986ba7c221ff /core/java/android/inputmethodservice/AbstractInputMethodService.java | |
| parent | 9ee8f8066c15f7d4977a26d624baca1210666026 (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/AbstractInputMethodService.java')
| -rw-r--r-- | core/java/android/inputmethodservice/AbstractInputMethodService.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/core/java/android/inputmethodservice/AbstractInputMethodService.java b/core/java/android/inputmethodservice/AbstractInputMethodService.java index 3531926d347c..29177b6b47cf 100644 --- a/core/java/android/inputmethodservice/AbstractInputMethodService.java +++ b/core/java/android/inputmethodservice/AbstractInputMethodService.java @@ -16,11 +16,14 @@ package android.inputmethodservice; +import android.annotation.NonNull; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.view.KeyEvent; import android.view.MotionEvent; +import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputContentInfo; import android.view.inputmethod.InputMethod; import android.view.inputmethod.InputMethodSession; @@ -208,7 +211,7 @@ public abstract class AbstractInputMethodService extends Service * * @param event The motion event being received. * @return True if the event was handled in this function, false otherwise. - * @see View#onTrackballEvent + * @see android.view.View#onTrackballEvent(MotionEvent) */ public boolean onTrackballEvent(MotionEvent event) { return false; @@ -219,9 +222,30 @@ public abstract class AbstractInputMethodService extends Service * * @param event The motion event being received. * @return True if the event was handled in this function, false otherwise. - * @see View#onGenericMotionEvent + * @see android.view.View#onGenericMotionEvent(MotionEvent) */ public boolean onGenericMotionEvent(MotionEvent event) { return false; } + + /** + * Allow the receiver of {@link InputContentInfo} to obtain a temporary read-only access + * permission to the content. + * + * <p>Default implementation does nothing.</p> + * + * @param inputContentInfo Content to be temporarily exposed from the input method to the + * application. + * This cannot be {@code null}. + * @param inputConnection {@link InputConnection} with which + * {@link InputConnection#commitContent(InputContentInfo, int, android.os.Bundle)} will be + * called. + * @return {@code false} if we cannot allow a temporary access permission. + * @hide + */ + public void exposeContent(@NonNull InputContentInfo inputContentInfo, + @NonNull InputConnection inputConnection) { + return; + } + } |
