Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91e88122 authored by satok's avatar satok
Browse files

Enable IMEs to set additional subtypes in background

Bug: 4591792

Change-Id: I7e61a576c56d1a3a56001bdf2fd51ad3801add01
parent bd029f64
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23887,7 +23887,7 @@ package android.view.inputmethod {
    method public boolean isWatchingCursor(android.view.View);
    method public void restartInput(android.view.View);
    method public void sendAppPrivateCommand(android.view.View, java.lang.String, android.os.Bundle);
    method public boolean setAdditionalInputMethodSubtypes(android.os.IBinder, android.view.inputmethod.InputMethodSubtype[]);
    method public boolean setAdditionalInputMethodSubtypes(java.lang.String, android.view.inputmethod.InputMethodSubtype[]);
    method public boolean setCurrentInputMethodSubtype(android.view.inputmethod.InputMethodSubtype);
    method public void setInputMethod(android.os.IBinder, java.lang.String);
    method public void setInputMethodAndSubtype(android.os.IBinder, java.lang.String, android.view.inputmethod.InputMethodSubtype);
+6 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.internal.view.IInputMethodSession;
import com.android.internal.view.InputBindResult;

import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
@@ -1580,16 +1581,16 @@ public final class InputMethodManager {
    }

    /**
     * Set additional input method subtypes.
     * @param imeToken Supplies the identifying token given to an input method.
     * Set additional input method subtypes. Only a process which shares the same uid with the IME
     * can add additional input method subtypes to the IME.
     * @param imiId Id of InputMethodInfo which additional input method subtypes will be added to.
     * @param subtypes subtypes will be added as additional subtypes of the current input method.
     * @return true if the additional input method subtypes are successfully added.
     */
    public boolean setAdditionalInputMethodSubtypes(
            IBinder imeToken, InputMethodSubtype[] subtypes) {
    public boolean setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
        synchronized (mH) {
            try {
                return mService.setAdditionalInputMethodSubtypes(imeToken, subtypes);
                return mService.setAdditionalInputMethodSubtypes(imiId, subtypes);
            } catch (RemoteException e) {
                Log.w(TAG, "IME died: " + mCurId, e);
                return false;
+1 −1
Original line number Diff line number Diff line
@@ -68,5 +68,5 @@ interface IInputMethodManager {
    boolean setCurrentInputMethodSubtype(in InputMethodSubtype subtype);
    boolean switchToLastInputMethod(in IBinder token);
    boolean setInputMethodEnabled(String id, boolean enabled);
    boolean setAdditionalInputMethodSubtypes(in IBinder token, in InputMethodSubtype[] subtypes);
    boolean setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
}
+19 −10
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
@@ -1632,20 +1633,28 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }

    @Override
    public boolean setAdditionalInputMethodSubtypes(IBinder token, InputMethodSubtype[] subtypes) {
        if (token == null || mCurToken != token) {
            return false;
        }
        if (subtypes == null || subtypes.length == 0) return false;
    public boolean setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
        // By this IPC call, only a process which shares the same uid with the IME can add
        // additional input method subtypes to the IME.
        if (TextUtils.isEmpty(imiId) || subtypes == null || subtypes.length == 0) return false;
        synchronized (mMethodMap) {
            final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
            final InputMethodInfo imi = mMethodMap.get(imiId);
            if (imi == null) return false;
            final int N = subtypes.length;
            final PackageManager pm = mContext.getPackageManager();
            final String[] packageInfos = pm.getPackagesForUid(Binder.getCallingUid());
            if (packageInfos != null) {
                final int packageNum = packageInfos.length;
                for (int i = 0; i < packageNum; ++i) {
                    if (packageInfos[i].equals(imi.getPackageName())) {
                        mFileManager.addInputMethodSubtypes(imi, subtypes);
                        buildInputMethodListLocked(mMethodList, mMethodMap);
                        return true;
                    }
                }
            }
        }
        return false;
    }

    private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) {
        synchronized (mMethodMap) {
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public class BridgeIInputMethodManager implements IInputMethodManager {

    }

    public boolean setAdditionalInputMethodSubtypes(IBinder arg0, InputMethodSubtype[] arg1)
    public boolean setAdditionalInputMethodSubtypes(String arg0, InputMethodSubtype[] arg1)
            throws RemoteException {
        // TODO Auto-generated method stub
        return false;