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

Commit 16afc6ff authored by Vladimir Komsiyski's avatar Vladimir Komsiyski Committed by Android (Google) Code Review
Browse files

Merge changes from topic "uimode-1" into main

* changes:
  Display-aware UiModeManager get* APIs
  VDM API for per-display UI Mode
parents 2dd6acdf d27293ab
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3638,6 +3638,7 @@ package android.companion.virtual {
    method public void setDevicePolicy(int, int);
    method @FlaggedApi("android.companion.virtualdevice.flags.activity_control_api") public void setDevicePolicy(int, int, int);
    method public void setDisplayImePolicy(int, int);
    method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_ui_mode") public void setDisplayUiMode(int, int);
    method public void setShowPointerIcon(boolean);
    method public void unregisterIntentInterceptor(@NonNull android.companion.virtual.VirtualDeviceManager.IntentInterceptorCallback);
    method @FlaggedApi("android.companion.virtualdevice.flags.device_aware_display_power") public void wakeUp();
+4 −4
Original line number Diff line number Diff line
@@ -54,9 +54,9 @@ interface IUiModeManager {
    void disableCarModeByCallingPackage(int flags, String callingPackage);

    /**
     * Return the current running mode.
     * Returns the current running mode on the given display.
     */
    int getCurrentModeType();
    int getCurrentModeType(int displayId);

    /**
     * Sets the night mode.
@@ -69,14 +69,14 @@ interface IUiModeManager {
    void setNightMode(int mode);

    /**
     * Gets the currently configured night mode.
     * Returns the currently configured night mode on the given display.
     * <p>
     * Returns
     * <ol>notnight mode</ol>
     * <ol>night mode</ol>
     * <ol>custom schedule mode switching</ol>
     */
    int getNightMode();
    int getNightMode(int displayId);

    /**
     * Sets the current night mode to {@link #MODE_NIGHT_CUSTOM} with the custom night mode type
+24 −16
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.util.ArraySet;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.view.Display;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.function.pooled.PooledLambda;
@@ -956,10 +957,10 @@ public class UiModeManager {
        }
    }

    private Integer getCurrentModeTypeFromServer() {
    private Integer getCurrentModeTypeFromServer(int displayId) {
        try {
            if (sGlobals != null) {
                return sGlobals.mService.getCurrentModeType();
                return sGlobals.mService.getCurrentModeType(displayId);
            }
            return Configuration.UI_MODE_TYPE_NORMAL;
        } catch (RemoteException e) {
@@ -971,13 +972,13 @@ public class UiModeManager {
    /**
     * Retrieve the current running mode type for the user.
     */
    private final IpcDataCache.QueryHandler<Void, Integer> mCurrentModeTypeQuery =
    private final IpcDataCache.QueryHandler<Integer, Integer> mCurrentModeTypeQuery =
            new IpcDataCache.QueryHandler<>() {

                @Override
                @NonNull
                public Integer apply(Void query) {
                    return getCurrentModeTypeFromServer();
                public Integer apply(Integer displayId) {
                    return getCurrentModeTypeFromServer(displayId);
                }
            };

@@ -986,7 +987,7 @@ public class UiModeManager {
    /**
     * Cache the current running mode type for a user.
     */
    private final IpcDataCache<Void, Integer> mCurrentModeTypeCache =
    private final IpcDataCache<Integer, Integer> mCurrentModeTypeCache =
            new IpcDataCache<>(1, IpcDataCache.MODULE_SYSTEM,
                    CURRENT_MODE_TYPE_API, /* cacheName= */ "CurrentModeTypeCache",
                    mCurrentModeTypeQuery);
@@ -1015,9 +1016,9 @@ public class UiModeManager {
     */
    public int getCurrentModeType() {
        if (enableCurrentModeTypeBinderCache()) {
            return mCurrentModeTypeCache.query(null);
            return mCurrentModeTypeCache.query(getDisplayId());
        } else {
            return getCurrentModeTypeFromServer();
            return getCurrentModeTypeFromServer(getDisplayId());
        }
    }

@@ -1193,10 +1194,10 @@ public class UiModeManager {
        }
    }

    private Integer getNightModeFromServer() {
    private Integer getNightModeFromServer(int displayId) {
        try {
            if (sGlobals != null) {
                return sGlobals.mService.getNightMode();
                return sGlobals.mService.getNightMode(displayId);
            }
            return -1;
        } catch (RemoteException e) {
@@ -1208,13 +1209,13 @@ public class UiModeManager {
    /**
     * Retrieve the night mode for the user.
     */
    private final IpcDataCache.QueryHandler<Void, Integer> mNightModeQuery =
    private final IpcDataCache.QueryHandler<Integer, Integer> mNightModeQuery =
            new IpcDataCache.QueryHandler<>() {

                @Override
                @NonNull
                public Integer apply(Void query) {
                    return getNightModeFromServer();
                public Integer apply(Integer displayId) {
                    return getNightModeFromServer(displayId);
                }
            };

@@ -1223,7 +1224,7 @@ public class UiModeManager {
    /**
     * Cache the night mode for a user.
     */
    private final IpcDataCache<Void, Integer> mNightModeCache =
    private final IpcDataCache<Integer, Integer> mNightModeCache =
            new IpcDataCache<>(1, IpcDataCache.MODULE_SYSTEM,
                    NIGHT_MODE_API, /* cacheName= */ "NightModeCache", mNightModeQuery);

@@ -1255,9 +1256,9 @@ public class UiModeManager {
     */
    public @NightMode int getNightMode() {
        if (enableNightModeBinderCache()) {
            return mNightModeCache.query(null);
            return mNightModeCache.query(getDisplayId());
        } else {
            return getNightModeFromServer();
            return getNightModeFromServer(getDisplayId());
        }
    }

@@ -1812,4 +1813,11 @@ public class UiModeManager {
    private int getUserId() {
        return mContext != null ? mContext.getUserId() : UserHandle.myUserId();
    }

    private int getDisplayId() {
        if (!android.companion.virtualdevice.flags.Flags.deviceAwareUiMode()) {
            return Display.DEFAULT_DISPLAY;
        }
        return mContext == null ? Display.DEFAULT_DISPLAY : mContext.getDisplayId();
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -206,6 +206,9 @@ interface IVirtualDevice {
    /** Sets an IME policy for the given display. */
    void setDisplayImePolicy(int displayId, int policy);

    /** Sets the UI mode for the given display. */
    void setDisplayUiMode(int displayId, int uiMode);

    /**
     * Registers an intent interceptor that will intercept an intent attempting to launch
     * when matching the provided IntentFilter and calls the callback with the intercepted
+7 −0
Original line number Diff line number Diff line
@@ -519,6 +519,13 @@ public class VirtualDeviceInternal {
        }
    }

    void setDisplayUiMode(int displayId, int uiMode) {
        try {
            mVirtualDevice.setDisplayUiMode(displayId, uiMode);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    void addActivityListener(
            @CallbackExecutor @NonNull Executor executor,
            @NonNull VirtualDeviceManager.ActivityListener listener) {
Loading