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

Commit 0549d7d8 authored by Zixuan Qu's avatar Zixuan Qu Committed by Android (Google) Code Review
Browse files

Merge changes I97186034,Ifdfe17a1

* changes:
  Improve test setup for VirtualDeviceManagerServiceTest.
  Override the locale hints when the app is running on a virtual device.
parents aecdff38 b7dccf9b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -124,6 +124,10 @@ public final class VirtualKeyboardConfig extends VirtualInputDeviceConfig implem
         * Note that the preferred layout is not guaranteed. If the specified language is
         * well-formed but not supported, the keyboard will be using English US QWERTY layout.
         *
         * In case where the owning Virtual Device has created multiple virtual keyboards, only the
         * {@code languageTag} of the most recent virtual keyboard will be kept to hint the locale
         * of the Virtual Device.
         *
         *  @throws IllegalArgumentException if either of the language or country is not present in
         *  the language tag.
         */
+13 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import android.hardware.input.VirtualTouchEvent;
import android.hardware.input.VirtualTouchscreenConfig;
import android.os.Binder;
import android.os.IBinder;
import android.os.LocaleList;
import android.os.Looper;
import android.os.PowerManager;
import android.os.RemoteException;
@@ -123,6 +124,9 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
    // The default setting for showing the pointer on new displays.
    @GuardedBy("mVirtualDeviceLock")
    private boolean mDefaultShowPointerIcon = true;
    @GuardedBy("mVirtualDeviceLock")
    @Nullable
    private LocaleList mLocaleList = null;

    private ActivityListener createListenerAdapter() {
        return new ActivityListener() {
@@ -247,6 +251,13 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        return mParams.getName();
    }

    /** Returns the locale of the device. */
    LocaleList getDeviceLocaleList() {
        synchronized (mVirtualDeviceLock) {
            return mLocaleList;
        }
    }

    /** Returns the policy specified for this policy type */
    public @VirtualDeviceParams.DevicePolicy int getDevicePolicy(
            @VirtualDeviceParams.PolicyType int policyType) {
@@ -344,6 +355,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
                mVirtualAudioController.stopListening();
                mVirtualAudioController = null;
            }
            mLocaleList = null;
        }
        mOnDeviceCloseListener.onClose(mDeviceId);
        mAppToken.unlinkToDeath(this, 0);
@@ -445,6 +457,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
                        "Cannot create a virtual keyboard for a display not associated with "
                                + "this virtual device");
            }
            mLocaleList = LocaleList.forLanguageTags(config.getLanguageTag());
        }
        final long ident = Binder.clearCallingIdentity();
        try {
+16 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.hardware.display.VirtualDisplayConfig;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.LocaleList;
import android.os.Looper;
import android.os.Parcel;
import android.os.Process;
@@ -591,6 +592,21 @@ public class VirtualDeviceManagerService extends SystemService {
            return ((VirtualDeviceImpl) virtualDevice).getBaseVirtualDisplayFlags();
        }

        @Override
        @Nullable
        public LocaleList getPreferredLocaleListForUid(int uid) {
            // TODO: b/263188984 support the case where an app is running on multiple VDs
            synchronized (mVirtualDeviceManagerLock) {
                for (int i = 0; i < mAppsOnVirtualDevices.size(); i++) {
                    if (mAppsOnVirtualDevices.valueAt(i).contains(uid)) {
                        int deviceId = mAppsOnVirtualDevices.keyAt(i);
                        return mVirtualDevices.get(deviceId).getDeviceLocaleList();
                    }
                }
            }
            return null;
        }

        @Override
        public boolean isAppRunningOnAnyVirtualDevice(int uid) {
            synchronized (mVirtualDeviceManagerLock) {
+16 −0
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
package com.android.server.companion.virtual;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.companion.virtual.IVirtualDevice;
import android.os.LocaleList;

import java.util.Set;

@@ -110,6 +112,20 @@ public abstract class VirtualDeviceManagerInternal {
     */
    public abstract int getBaseVirtualDisplayFlags(IVirtualDevice virtualDevice);

    /**
     * Returns the preferred locale hints of the Virtual Device on which the given app is running,
     * or {@code null} if the hosting virtual device doesn't have a virtual keyboard or the app is
     * not on any virtual device.
     *
     * If an app is on multiple virtual devices, the locale of the virtual device created the
     * earliest will be returned.
     *
     * See {@link android.hardware.input.VirtualKeyboardConfig#setLanguageTag() for how the locale
     * is specified for virtual keyboard.
     */
    @Nullable
    public abstract LocaleList getPreferredLocaleListForUid(int uid);

    /**
     * Returns true if the given {@code uid} is currently running on any virtual devices. This is
     * determined by whether the app has any activities in the task stack on a virtual-device-owned
+13 −0
Original line number Diff line number Diff line
@@ -183,6 +183,7 @@ import com.android.server.LocalServices;
import com.android.server.ServiceThread;
import com.android.server.SystemServerInitThreadPool;
import com.android.server.SystemService;
import com.android.server.companion.virtual.VirtualDeviceManagerInternal;
import com.android.server.input.InputManagerInternal;
import com.android.server.inputmethod.InputMethodManagerInternal.InputMethodListListener;
import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
@@ -304,6 +305,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
     */
    @Nullable
    private AudioManagerInternal mAudioManagerInternal = null;
    @Nullable
    private VirtualDeviceManagerInternal mVdmInternal = null;

    // All known input methods.
    final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>();
@@ -2533,6 +2536,16 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        mCurVirtualDisplayToScreenMatrix =
                getVirtualDisplayToScreenMatrixLocked(cs.mSelfReportedDisplayId,
                        mDisplayIdToShowIme);
        // Override the locale hints if the app is running on a virtual device.
        if (mVdmInternal == null) {
            mVdmInternal = LocalServices.getService(VirtualDeviceManagerInternal.class);
        }
        if (mVdmInternal != null && editorInfo.hintLocales == null) {
            LocaleList hintsFromVirtualDevice = mVdmInternal.getPreferredLocaleListForUid(cs.mUid);
            if (hintsFromVirtualDevice != null) {
                editorInfo.hintLocales = hintsFromVirtualDevice;
            }
        }
        mCurEditorInfo = editorInfo;

        // If configured, we want to avoid starting up the IME if it is not supposed to be showing
Loading