Merge \"Use a flag to grant a temporary URI permission.\" into nyc-mr1-dev
am: cb56978912
Change-Id: I20e1481c6f68a5af4f33e699f5bc505b3a4c1457
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
|
||||
int missingMethods = msg.arg1;
|
||||
IInputContext inputContext = (IInputContext)args.arg1;
|
||||
InputConnection ic = inputContext != null
|
||||
? new InputConnectionWrapper(inputContext, missingMethods) : null;
|
||||
? new InputConnectionWrapper(mTarget, inputContext, missingMethods) : null;
|
||||
EditorInfo info = (EditorInfo)args.arg2;
|
||||
info.makeCompatible(mTargetSdkVersion);
|
||||
inputMethod.startInput(ic, info);
|
||||
@@ -180,7 +180,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
|
||||
int missingMethods = msg.arg1;
|
||||
IInputContext inputContext = (IInputContext)args.arg1;
|
||||
InputConnection ic = inputContext != null
|
||||
? new InputConnectionWrapper(inputContext, missingMethods) : null;
|
||||
? new InputConnectionWrapper(mTarget, inputContext, missingMethods) : null;
|
||||
EditorInfo info = (EditorInfo)args.arg2;
|
||||
info.makeCompatible(mTargetSdkVersion);
|
||||
inputMethod.restartInput(ic, info);
|
||||
@@ -251,7 +251,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
|
||||
public void bindInput(InputBinding binding) {
|
||||
// This IInputContext is guaranteed to implement all the methods.
|
||||
final int missingMethodFlags = 0;
|
||||
InputConnection ic = new InputConnectionWrapper(
|
||||
InputConnection ic = new InputConnectionWrapper(mTarget,
|
||||
IInputContext.Stub.asInterface(binding.getConnectionToken()), missingMethodFlags);
|
||||
InputBinding nu = new InputBinding(ic, binding);
|
||||
mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_INPUT_CONTEXT, nu));
|
||||
|
||||
@@ -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
|
||||
* <grant-uri-permissions>} 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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -855,5 +855,7 @@ public class BaseInputConnection implements InputConnection {
|
||||
/**
|
||||
* The default implementation does nothing.
|
||||
*/
|
||||
public boolean commitContent(InputContentInfo inputContentInfo, Bundle opts) { return false; }
|
||||
public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,10 +368,10 @@ public class EditorInfo implements InputType, Parcelable {
|
||||
|
||||
/**
|
||||
* List of acceptable MIME types for
|
||||
* {@link InputConnection#commitContent(InputContentInfo, Bundle)}.
|
||||
* {@link InputConnection#commitContent(InputContentInfo, int, Bundle)}.
|
||||
*
|
||||
* <p>{@code null} or an empty array means that
|
||||
* {@link InputConnection#commitContent(InputContentInfo, Bundle)} is not supported in this
|
||||
* {@link InputConnection#commitContent(InputContentInfo, int, Bundle)} is not supported in this
|
||||
* editor.</p>
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
@@ -839,6 +839,24 @@ public interface InputConnection {
|
||||
*/
|
||||
public void closeConnection();
|
||||
|
||||
/**
|
||||
* When this flag is used, the editor will be able to request read access to the content URI
|
||||
* contained in the {@link InputContentInfo} object.
|
||||
*
|
||||
* <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
|
||||
* <grant-uri-permissions>} 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>
|
||||
**/
|
||||
public static int INPUT_CONTENT_GRANT_READ_URI_PERMISSION =
|
||||
android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; // 0x00000001
|
||||
|
||||
/**
|
||||
* Called by the input method to commit a content such as PNG image to the editor.
|
||||
*
|
||||
@@ -862,9 +880,11 @@ public interface InputConnection {
|
||||
* </ul>
|
||||
*
|
||||
* @param inputContentInfo Content to be inserted.
|
||||
* @param flags {@code 0} or {@link #INPUT_CONTENT_GRANT_READ_URI_PERMISSION}.
|
||||
* @param opts optional bundle data. This can be {@code null}.
|
||||
* @return {@code true} if this request is accepted by the application, no matter if the request
|
||||
* is already handled or still being handled in background.
|
||||
*/
|
||||
public boolean commitContent(@NonNull InputContentInfo inputContentInfo, @Nullable Bundle opts);
|
||||
public boolean commitContent(@NonNull InputContentInfo inputContentInfo, int flags,
|
||||
@Nullable Bundle opts);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public final class InputConnectionInspector {
|
||||
*/
|
||||
int CLOSE_CONNECTION = 1 << 6;
|
||||
/**
|
||||
* {@link InputConnection#commitContent(InputContentInfo, Bundle)} is available in
|
||||
* {@link InputConnection#commitContent(InputContentInfo, int, Bundle)} is available in
|
||||
* {@link android.os.Build.VERSION_CODES#N} MR-1 and later.
|
||||
*/
|
||||
int COMMIT_CONTENT = 1 << 7;
|
||||
@@ -209,7 +209,7 @@ public final class InputConnectionInspector {
|
||||
private static boolean hasCommitContent(@NonNull final Class clazz) {
|
||||
try {
|
||||
final Method method = clazz.getMethod("commitContent", InputContentInfo.class,
|
||||
Bundle.class);
|
||||
int.class, Bundle.class);
|
||||
return !Modifier.isAbstract(method.getModifiers());
|
||||
} catch (NoSuchMethodException e) {
|
||||
return false;
|
||||
|
||||
@@ -274,7 +274,7 @@ public class InputConnectionWrapper implements InputConnection {
|
||||
* {@inheritDoc}
|
||||
* @throws NullPointerException if the target is {@code null}.
|
||||
*/
|
||||
public boolean commitContent(InputContentInfo inputContentInfo, Bundle opts) {
|
||||
return mTarget.commitContent(inputContentInfo, opts);
|
||||
public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts) {
|
||||
return mTarget.commitContent(inputContentInfo, flags, opts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2304,10 +2304,9 @@ public final class InputMethodManager {
|
||||
* 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.
|
||||
* @hide
|
||||
*/
|
||||
public boolean exposeContent(@NonNull IBinder token, @NonNull InputContentInfo inputContentInfo,
|
||||
public void exposeContent(@NonNull IBinder token, @NonNull InputContentInfo inputContentInfo,
|
||||
@NonNull EditorInfo editorInfo) {
|
||||
final IInputContentUriToken uriToken;
|
||||
final Uri contentUri = inputContentInfo.getContentUri();
|
||||
@@ -2315,15 +2314,15 @@ public final class InputMethodManager {
|
||||
uriToken = mService.createInputContentUriToken(token, contentUri,
|
||||
editorInfo.packageName);
|
||||
if (uriToken == null) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "createInputContentAccessToken failed. contentUri=" + contentUri.toString()
|
||||
+ " packageName=" + editorInfo.packageName, e);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
inputContentInfo.setUriToken(uriToken);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
void doDump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
||||
|
||||
@@ -5985,8 +5985,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commitContent(InputContentInfo inputContentInfo, Bundle opts) {
|
||||
return getTarget().commitContent(inputContentInfo, opts);
|
||||
public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts) {
|
||||
return getTarget().commitContent(inputContentInfo, flags, opts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user