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

Commit 0ef10a45 authored by Winson Chung's avatar Winson Chung
Browse files

Skip tests for overlays that don't exist on device

Bug: 138401738
Bug: 138227387
Change-Id: If661fd342e1382915485bccdf6ae2c9e77a92bc4
parent f88d0b5a
Loading
Loading
Loading
Loading
+33 −15
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_
import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_GESTURAL_OVERLAY;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;

import androidx.test.uiautomator.UiDevice;
@@ -106,35 +107,51 @@ public class NavigationModeSwitchRule implements TestRule {
                        Log.e(TAG, "Exception", e);
                        throw e;
                    } finally {
                        setActiveOverlay(prevOverlayPkg, originalMode);
                        Assert.assertTrue(setActiveOverlay(prevOverlayPkg, originalMode));
                    }
                    mLauncher.disableDebugTracing();
                }

                public void evaluateWithoutChangingSetting(Statement base) throws Throwable {
                private void evaluateWithThreeButtons() throws Throwable {
                    if (setActiveOverlay(NAV_BAR_MODE_3BUTTON_OVERLAY,
                            LauncherInstrumentation.NavigationModel.THREE_BUTTON)) {
                        base.evaluate();
                    }

                private void evaluateWithThreeButtons() throws Throwable {
                    setActiveOverlay(NAV_BAR_MODE_3BUTTON_OVERLAY,
                            LauncherInstrumentation.NavigationModel.THREE_BUTTON);
                    evaluateWithoutChangingSetting(base);
                }

                private void evaluateWithTwoButtons() throws Throwable {
                    setActiveOverlay(NAV_BAR_MODE_2BUTTON_OVERLAY,
                            LauncherInstrumentation.NavigationModel.TWO_BUTTON);
                    if (setActiveOverlay(NAV_BAR_MODE_2BUTTON_OVERLAY,
                            LauncherInstrumentation.NavigationModel.TWO_BUTTON)) {
                        base.evaluate();
                    }
                }

                private void evaluateWithZeroButtons() throws Throwable {
                    setActiveOverlay(NAV_BAR_MODE_GESTURAL_OVERLAY,
                            LauncherInstrumentation.NavigationModel.ZERO_BUTTON);
                    if (setActiveOverlay(NAV_BAR_MODE_GESTURAL_OVERLAY,
                            LauncherInstrumentation.NavigationModel.ZERO_BUTTON)) {
                        base.evaluate();
                    }
                }

                private boolean packageExists(String packageName) {
                    try {
                        PackageManager pm = getInstrumentation().getContext().getPackageManager();
                        if (pm.getApplicationInfo(packageName, 0 /* flags */) == null) {
                            return false;
                        }
                    } catch (PackageManager.NameNotFoundException e) {
                        return false;
                    }
                    return true;
                }

                private void setActiveOverlay(String overlayPackage,
                private boolean setActiveOverlay(String overlayPackage,
                        LauncherInstrumentation.NavigationModel expectedMode) throws Exception {
                    if (!packageExists(overlayPackage)) {
                        Log.d(TAG, "setActiveOverlay: " + overlayPackage + " pkg does not exist");
                        return false;
                    }

                    setOverlayPackageEnabled(NAV_BAR_MODE_3BUTTON_OVERLAY,
                            overlayPackage == NAV_BAR_MODE_3BUTTON_OVERLAY);
                    setOverlayPackageEnabled(NAV_BAR_MODE_2BUTTON_OVERLAY,
@@ -178,6 +195,7 @@ public class NavigationModeSwitchRule implements TestRule {
                    Assert.assertTrue("Switching nav mode: " + error, error == null);

                    Thread.sleep(5000);
                    return true;
                }

                private void setOverlayPackageEnabled(String overlayPackage, boolean enable)