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

Commit 24676604 authored by Chun-Ku Lin's avatar Chun-Ku Lin Committed by Android (Google) Code Review
Browse files

Merge "Allow internal service to add or remove a TileService" into main

parents a2d78978 6b314d9a
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -151,8 +151,17 @@ oneway interface IStatusBar
     * @param hidesStatusBar whether it is being hidden
     */
    void setTopAppHidesStatusBar(boolean hidesStatusBar);

    /**
     * Add a tile to the Quick Settings Panel to the first item in the QS Panel
     * @param tile the ComponentName of the {@link android.service.quicksettings.TileService}
     */
    void addQsTile(in ComponentName tile);
    /**
     * Add a tile to the Quick Settings Panel
     * @param tile the ComponentName of the {@link android.service.quicksettings.TileService}
     * @param end if true, the tile will be added at the end. If false, at the beginning.
     */
    void addQsTileToFrontOrEnd(in ComponentName tile, boolean end);
    void remQsTile(in ComponentName tile);
    void setQsTiles(in String[] tiles);
    void clickQsTile(in ComponentName tile);
+44 −5
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.view.KeyEvent;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsController.Appearance;
import android.view.WindowInsetsController.Behavior;
import android.view.accessibility.Flags;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
@@ -305,6 +306,13 @@ public class CommandQueue extends IStatusBar.Stub implements
        default void setTopAppHidesStatusBar(boolean topAppHidesStatusBar) { }

        default void addQsTile(ComponentName tile) { }

        /**
         * Add a tile to the Quick Settings Panel
         * @param tile the ComponentName of the {@link android.service.quicksettings.TileService}
         * @param end if true, the tile will be added at the end. If false, at the beginning.
         */
        default void addQsTileToFrontOrEnd(ComponentName tile, boolean end) { }
        default void remQsTile(ComponentName tile) { }

        default void setQsTiles(String[] tiles) {}
@@ -904,10 +912,31 @@ public class CommandQueue extends IStatusBar.Stub implements

    @Override
    public void addQsTile(ComponentName tile) {
        if (Flags.a11yQsShortcut()) {
            addQsTileToFrontOrEnd(tile, false);
        } else {
            synchronized (mLock) {
                mHandler.obtainMessage(MSG_ADD_QS_TILE, tile).sendToTarget();
            }
        }
    }

    /**
     * Add a tile to the Quick Settings Panel
     * @param tile the ComponentName of the {@link android.service.quicksettings.TileService}
     * @param end if true, the tile will be added at the end. If false, at the beginning.
     */
    @Override
    public void addQsTileToFrontOrEnd(ComponentName tile, boolean end) {
        if (Flags.a11yQsShortcut()) {
            synchronized (mLock) {
                SomeArgs args = SomeArgs.obtain();
                args.arg1 = tile;
                args.arg2 = end;
                mHandler.obtainMessage(MSG_ADD_QS_TILE, args).sendToTarget();
            }
        }
    }

    @Override
    public void remQsTile(ComponentName tile) {
@@ -1546,11 +1575,21 @@ public class CommandQueue extends IStatusBar.Stub implements
                        mCallbacks.get(i).showPictureInPictureMenu();
                    }
                    break;
                case MSG_ADD_QS_TILE:
                case MSG_ADD_QS_TILE: {
                    if (Flags.a11yQsShortcut()) {
                        SomeArgs someArgs = (SomeArgs) msg.obj;
                        for (int i = 0; i < mCallbacks.size(); i++) {
                            mCallbacks.get(i).addQsTileToFrontOrEnd(
                                    (ComponentName) someArgs.arg1, (boolean) someArgs.arg2);
                        }
                        someArgs.recycle();
                    } else {
                        for (int i = 0; i < mCallbacks.size(); i++) {
                            mCallbacks.get(i).addQsTile((ComponentName) msg.obj);
                        }
                    }
                    break;
                }
                case MSG_REMOVE_QS_TILE:
                    for (int i = 0; i < mCallbacks.size(); i++) {
                        mCallbacks.get(i).remQsTile((ComponentName) msg.obj);
+5 −0
Original line number Diff line number Diff line
@@ -178,6 +178,11 @@ public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callba
        mQSHost.addTile(tile);
    }

    @Override
    public void addQsTileToFrontOrEnd(ComponentName tile, boolean end) {
        mQSHost.addTile(tile, end);
    }

    @Override
    public void remQsTile(ComponentName tile) {
        mQSHost.removeTileByUser(tile);
+41 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;

import android.content.ComponentName;
import android.graphics.Rect;
@@ -32,11 +33,14 @@ import android.hardware.biometrics.IBiometricSysuiReceiver;
import android.hardware.biometrics.PromptInfo;
import android.hardware.fingerprint.IUdfpsRefreshRateRequestCallback;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.view.KeyEvent;
import android.view.WindowInsets;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsController.Appearance;
import android.view.WindowInsetsController.Behavior;
import android.view.accessibility.Flags;

import androidx.test.filters.SmallTest;

@@ -365,13 +369,49 @@ public class CommandQueueTest extends SysuiTestCase {
    }

    @Test
    public void testAddQsTile() {
    @DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
    public void addQsTile_withA11yQsShortcutFlagOff() {
        ComponentName c = new ComponentName("testpkg", "testcls");

        mCommandQueue.addQsTile(c);
        waitForIdleSync();

        verify(mCallbacks).addQsTile(eq(c));
    }

    @Test
    @DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
    public void addQsTileToFrontOrEnd_withA11yQsShortcutFlagOff_doNothing() {
        ComponentName c = new ComponentName("testpkg", "testcls");

        mCommandQueue.addQsTileToFrontOrEnd(c, true);
        waitForIdleSync();

        verifyZeroInteractions(mCallbacks);
    }

    @Test
    @EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
    public void addQsTile_withA11yQsShortcutFlagOn() {
        ComponentName c = new ComponentName("testpkg", "testcls");

        mCommandQueue.addQsTile(c);
        waitForIdleSync();

        verify(mCallbacks).addQsTileToFrontOrEnd(eq(c), eq(false));
    }

    @Test
    @EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
    public void addQsTileAtTheEnd_withA11yQsShortcutFlagOn() {
        ComponentName c = new ComponentName("testpkg", "testcls");

        mCommandQueue.addQsTileToFrontOrEnd(c, true);
        waitForIdleSync();

        verify(mCallbacks).addQsTileToFrontOrEnd(eq(c), eq(true));
    }

    @Test
    public void testRemoveQsTile() {
        ComponentName c = new ComponentName("testpkg", "testcls");
+28 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.when;

import android.app.ActivityManager;
import android.app.StatusBarManager;
import android.content.ComponentName;
import android.os.PowerManager;
import android.os.UserHandle;
import android.os.Vibrator;
@@ -190,4 +191,31 @@ public class CentralSurfacesCommandQueueCallbacksTest extends SysuiTestCase {
                HapticFeedbackConstants.GESTURE_START
        );
    }

    @Test
    public void addQsTile_delegateCallToQsHost() {
        ComponentName c = new ComponentName("testpkg", "testcls");

        mSbcqCallbacks.addQsTile(c);

        verify(mQSHost).addTile(c);
    }

    @Test
    public void addQsTileToFrontOrEnd_toTheEnd_delegateCallToQsHost() {
        ComponentName c = new ComponentName("testpkg", "testcls");

        mSbcqCallbacks.addQsTileToFrontOrEnd(c, true);

        verify(mQSHost).addTile(c, true);
    }

    @Test
    public void addQsTileToFrontOrEnd_toTheFront_delegateCallToQsHost() {
        ComponentName c = new ComponentName("testpkg", "testcls");

        mSbcqCallbacks.addQsTileToFrontOrEnd(c, false);

        verify(mQSHost).addTile(c, false);
    }
}
Loading