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

Commit 56313636 authored by Xin Li's avatar Xin Li Committed by Gerrit Code Review
Browse files

Merge "Merge android14-tests-dev" into main

parents f578d795 49acc798
Loading
Loading
Loading
Loading
+22 −3
Original line number Original line Diff line number Diff line
@@ -21,11 +21,13 @@ import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.IBinder;
import android.os.IBinder;
import android.os.InputConfig;
import android.os.InputConfig;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;
import android.util.SparseArray;
import android.view.InputWindowHandle;
import android.view.InputWindowHandle;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -119,13 +121,13 @@ public class WindowInfosListenerForTest {
                            "Exception thrown while waiting for listener to be called with "
                            "Exception thrown while waiting for listener to be called with "
                                    + "initial state");
                                    + "initial state");
                }
                }
                consumer.accept(buildWindowInfos(windowHandles));
                consumer.accept(buildWindowInfos(windowHandles, displayInfos));
            }
            }
        };
        };
        mListeners.put(consumer, listener);
        mListeners.put(consumer, listener);
        Pair<InputWindowHandle[], WindowInfosListener.DisplayInfo[]> initialState =
        Pair<InputWindowHandle[], WindowInfosListener.DisplayInfo[]> initialState =
                listener.register();
                listener.register();
        consumer.accept(buildWindowInfos(initialState.first));
        consumer.accept(buildWindowInfos(initialState.first, initialState.second));
        calledWithInitialState.countDown();
        calledWithInitialState.countDown();
    }
    }


@@ -140,11 +142,28 @@ public class WindowInfosListenerForTest {
        listener.unregister();
        listener.unregister();
    }
    }


    private static List<WindowInfo> buildWindowInfos(InputWindowHandle[] windowHandles) {
    private static List<WindowInfo> buildWindowInfos(
            InputWindowHandle[] windowHandles, WindowInfosListener.DisplayInfo[] displayInfos) {
        var windowInfos = new ArrayList<WindowInfo>(windowHandles.length);
        var windowInfos = new ArrayList<WindowInfo>(windowHandles.length);

        var displayInfoById = new SparseArray<WindowInfosListener.DisplayInfo>(displayInfos.length);
        for (var displayInfo : displayInfos) {
            displayInfoById.put(displayInfo.mDisplayId, displayInfo);
        }

        var tmp = new RectF();
        for (var handle : windowHandles) {
        for (var handle : windowHandles) {
            var bounds = new Rect(handle.frameLeft, handle.frameTop, handle.frameRight,
            var bounds = new Rect(handle.frameLeft, handle.frameTop, handle.frameRight,
                    handle.frameBottom);
                    handle.frameBottom);

            // Transform bounds from physical display coordinates to logical display coordinates.
            var display = displayInfoById.get(handle.displayId);
            if (display != null) {
                tmp.set(bounds);
                display.mTransform.mapRect(tmp);
                tmp.round(bounds);
            }

            windowInfos.add(new WindowInfo(handle.getWindowToken(), handle.name, handle.displayId,
            windowInfos.add(new WindowInfo(handle.getWindowToken(), handle.name, handle.displayId,
                    bounds, handle.inputConfig));
                    bounds, handle.inputConfig));
        }
        }
+0 −10
Original line number Original line Diff line number Diff line
@@ -86,16 +86,6 @@ public final class GameManagerTests {
        GameModeInfo gameModeInfo = mGameManager.getGameModeInfo(mPackageName);
        GameModeInfo gameModeInfo = mGameManager.getGameModeInfo(mPackageName);
        assertNotNull(gameModeInfo);
        assertNotNull(gameModeInfo);
        assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_CUSTOM));
        assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_CUSTOM));
        GameModeConfiguration unsupportedFpsConfig =
                new GameModeConfiguration.Builder().setFpsOverride(
                        70).setScalingFactor(0.5f).build();
        mGameManager.updateCustomGameModeConfiguration(mPackageName, unsupportedFpsConfig);
        gameModeInfo = mGameManager.getGameModeInfo(mPackageName);
        assertNotNull(gameModeInfo);
        // TODO(b/243448953): update to non-zero FPS when matching is implemented
        assertEquals(new GameModeConfiguration.Builder().setFpsOverride(
                        GameModeConfiguration.FPS_OVERRIDE_NONE).setScalingFactor(0.5f).build(),
                gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_CUSTOM));


        GameModeConfiguration supportedFpsConfig =
        GameModeConfiguration supportedFpsConfig =
                new GameModeConfiguration.Builder().setFpsOverride(
                new GameModeConfiguration.Builder().setFpsOverride(
+1 −0
Original line number Original line Diff line number Diff line
@@ -442,6 +442,7 @@ public final class MediaSession {
     * but it must be released if your activity or service is being destroyed.
     * but it must be released if your activity or service is being destroyed.
     */
     */
    public void release() {
    public void release() {
        setCallback(null);
        try {
        try {
            mBinder.destroySession();
            mBinder.destroySession();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
+12 −55
Original line number Original line Diff line number Diff line
@@ -399,59 +399,6 @@ public final class GameManagerService extends IGameManagerService.Stub {
        }
        }
    }
    }


    public enum FrameRate {
        FPS_DEFAULT(0),
        FPS_30(30),
        FPS_36(36),
        FPS_40(40),
        FPS_45(45),
        FPS_48(48),
        FPS_60(60),
        FPS_72(72),
        FPS_90(90),
        FPS_120(120),
        FPS_144(144),
        FPS_INVALID(-1);

        public final int fps;

        FrameRate(int fps) {
            this.fps = fps;
        }
    }

    // Turn the raw string to the corresponding fps int.
    // Return 0 when disabling, -1 for invalid fps.
    static int getFpsInt(String raw) {
        // TODO(b/243448953): make sure this translates to proper values based on current display
        switch (raw) {
            case "30":
                return FrameRate.FPS_30.fps;
            case "36":
                return FrameRate.FPS_36.fps;
            case "40":
                return FrameRate.FPS_40.fps;
            case "45":
                return FrameRate.FPS_45.fps;
            case "48":
                return FrameRate.FPS_48.fps;
            case "60":
                return FrameRate.FPS_60.fps;
            case "72":
                return FrameRate.FPS_72.fps;
            case "90":
                return FrameRate.FPS_90.fps;
            case "120":
                return FrameRate.FPS_120.fps;
            case "144":
                return FrameRate.FPS_144.fps;
            case "disable":
            case "":
                return FrameRate.FPS_DEFAULT.fps;
        }
        return FrameRate.FPS_INVALID.fps;
    }

    /**
    /**
     * Called by games to communicate the current state to the platform.
     * Called by games to communicate the current state to the platform.
     *
     *
@@ -699,7 +646,12 @@ public final class GameManagerService extends IGameManagerService.Stub {
            }
            }


            public synchronized int getFps() {
            public synchronized int getFps() {
                return GameManagerService.getFpsInt(mFps);
                try {
                    final int fpsInt = Integer.parseInt(mFps);
                    return fpsInt;
                } catch (NumberFormatException e) {
                    return 0;
                }
            }
            }


            synchronized String getFpsStr() {
            synchronized String getFpsStr() {
@@ -739,7 +691,12 @@ public final class GameManagerService extends IGameManagerService.Stub {
            }
            }


            android.app.GameModeConfiguration toPublicGameModeConfig() {
            android.app.GameModeConfiguration toPublicGameModeConfig() {
                int fpsOverride = getFpsInt(mFps);
                int fpsOverride;
                try {
                    fpsOverride = Integer.parseInt(mFps);
                } catch (NumberFormatException e) {
                    fpsOverride = 0;
                }
                // TODO(b/243448953): match to proper value in case of display change?
                // TODO(b/243448953): match to proper value in case of display change?
                fpsOverride = fpsOverride > 0 ? fpsOverride
                fpsOverride = fpsOverride > 0 ? fpsOverride
                        : android.app.GameModeConfiguration.FPS_OVERRIDE_NONE;
                        : android.app.GameModeConfiguration.FPS_OVERRIDE_NONE;
+6 −4
Original line number Original line Diff line number Diff line
@@ -241,8 +241,10 @@ public class GameManagerShellCommand extends ShellCommand {
                case "--fps":
                case "--fps":
                    if (fpsStr == null) {
                    if (fpsStr == null) {
                        fpsStr = getNextArgRequired();
                        fpsStr = getNextArgRequired();
                        if (fpsStr != null && GameManagerService.getFpsInt(fpsStr) == -1) {
                        try {
                            pw.println("Invalid frame rate '" + fpsStr + "'");
                            Integer.parseInt(fpsStr);
                        } catch (NumberFormatException e) {
                            pw.println("Invalid frame rate: '" + fpsStr + "'");
                            return -1;
                            return -1;
                        }
                        }
                    } else {
                    } else {
@@ -375,8 +377,8 @@ public class GameManagerShellCommand extends ShellCommand {
        pw.println("      --downscale [0.3|0.35|0.4|0.45|0.5|0.55|0.6|0.65");
        pw.println("      --downscale [0.3|0.35|0.4|0.45|0.5|0.55|0.6|0.65");
        pw.println("                  |0.7|0.75|0.8|0.85|0.9|disable]: Set app to run at the");
        pw.println("                  |0.7|0.75|0.8|0.85|0.9|disable]: Set app to run at the");
        pw.println("                                                   specified scaling ratio.");
        pw.println("                                                   specified scaling ratio.");
        pw.println("      --fps [30|45|60|90|120|disable]: Set app to run at the specified fps,");
        pw.println("      --fps: Integer value to set app to run at the specified fps,");
        pw.println("                                       if supported.");
        pw.println("             if supported. 0 to disable.");
        pw.println("  reset [--mode [2|3|performance|battery] --user <USER_ID>] <PACKAGE_NAME>");
        pw.println("  reset [--mode [2|3|performance|battery] --user <USER_ID>] <PACKAGE_NAME>");
        pw.println("      Resets the game mode of the app to device configuration.");
        pw.println("      Resets the game mode of the app to device configuration.");
        pw.println("      This should only be used to reset any override to non custom game mode");
        pw.println("      This should only be used to reset any override to non custom game mode");