Merge "Switching swipe-up to overview to using test info provider" into ub-launcher3-master

This commit is contained in:
TreeHugger Robot 2019-03-15 18:52:25 +00:00 committed by Android (Google) Code Review
commit d082129ef8
9 changed files with 91 additions and 35 deletions

View File

@ -152,14 +152,6 @@
android:writePermission="${packageName}.permission.WRITE_SETTINGS" android:writePermission="${packageName}.permission.WRITE_SETTINGS"
android:readPermission="${packageName}.permission.READ_SETTINGS" /> android:readPermission="${packageName}.permission.READ_SETTINGS" />
<provider
android:name="com.android.launcher3.TestInformationProvider"
android:authorities="${packageName}.TestInfo"
android:readPermission="android.permission.WRITE_SECURE_SETTINGS"
android:writePermission="android.permission.WRITE_SECURE_SETTINGS"
android:exported="true">
</provider>
<!-- <!--
The content provider for exposing various launcher grid options. The content provider for exposing various launcher grid options.
TODO: Enable when all apps columns are correct TODO: Enable when all apps columns are correct

View File

@ -84,9 +84,11 @@ public class OverviewState extends LauncherState {
super.onBackPressed(launcher); super.onBackPressed(launcher);
} }
public static float getDefaultSwipeHeight(Launcher launcher) { public static float getDefaultSwipeHeight(Launcher launcher) {
DeviceProfile dp = launcher.getDeviceProfile(); return getDefaultSwipeHeight(launcher.getDeviceProfile());
}
public static float getDefaultSwipeHeight(DeviceProfile dp) {
return dp.allAppsCellHeightPx - dp.allAppsIconTextSizePx; return dp.allAppsCellHeightPx - dp.allAppsIconTextSizePx;
} }
} }

View File

@ -73,6 +73,14 @@
</intent-filter> </intent-filter>
</provider> </provider>
<provider
android:name="com.android.quickstep.TestInformationProvider"
android:authorities="${packageName}.TestInfo"
android:readPermission="android.permission.WRITE_SECURE_SETTINGS"
android:writePermission="android.permission.WRITE_SECURE_SETTINGS"
android:exported="true">
</provider>
<service <service
android:name="com.android.launcher3.uioverrides.dynamicui.WallpaperManagerCompatVL$ColorExtractionService" android:name="com.android.launcher3.uioverrides.dynamicui.WallpaperManagerCompatVL$ColorExtractionService"
tools:node="remove" /> tools:node="remove" />

View File

@ -26,6 +26,7 @@ import android.view.View;
import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherState;
import com.android.launcher3.R; import com.android.launcher3.R;
@ -132,7 +133,10 @@ public class OverviewState extends LauncherState {
} }
public static float getDefaultSwipeHeight(Launcher launcher) { public static float getDefaultSwipeHeight(Launcher launcher) {
DeviceProfile dp = launcher.getDeviceProfile(); return getDefaultSwipeHeight(launcher.getDeviceProfile());
}
public static float getDefaultSwipeHeight(DeviceProfile dp) {
return dp.allAppsCellHeightPx - dp.allAppsIconTextSizePx; return dp.allAppsCellHeightPx - dp.allAppsIconTextSizePx;
} }

View File

@ -14,14 +14,22 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.launcher3; package com.android.quickstep;
import android.content.ContentProvider; import android.content.ContentProvider;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.TestProtocol;
import com.android.launcher3.Utilities;
import com.android.launcher3.uioverrides.OverviewState;
import com.android.quickstep.util.LayoutUtils;
public class TestInformationProvider extends ContentProvider { public class TestInformationProvider extends ContentProvider {
@Override @Override
public boolean onCreate() { public boolean onCreate() {
@ -55,10 +63,26 @@ public class TestInformationProvider extends ContentProvider {
@Override @Override
public Bundle call(String method, String arg, Bundle extras) { public Bundle call(String method, String arg, Bundle extras) {
if (TestProtocol.IS_TEST_INFO_ENABLED.equals(method)) { if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
final Bundle response = new Bundle(); final Bundle response = new Bundle();
response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, final Context context = getContext();
Utilities.IS_RUNNING_IN_TEST_HARNESS); final DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.
get(context).getDeviceProfile(context);
switch (method) {
case TestProtocol.REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT: {
final float swipeHeight =
OverviewState.getDefaultSwipeHeight(deviceProfile);
response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight);
break;
}
case TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT: {
final float swipeHeight =
LayoutUtils.getShelfTrackingDistance(context, deviceProfile);
response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight);
break;
}
}
return response; return response;
} }
return null; return null;

View File

@ -31,6 +31,9 @@ public final class TestProtocol {
public static final int ALL_APPS_STATE_ORDINAL = 3; public static final int ALL_APPS_STATE_ORDINAL = 3;
public static final int BACKGROUND_APP_STATE_ORDINAL = 4; public static final int BACKGROUND_APP_STATE_ORDINAL = 4;
public static final String IS_TEST_INFO_ENABLED = "is-test-info-enabled";
public static final String TEST_INFO_RESPONSE_FIELD = "response"; public static final String TEST_INFO_RESPONSE_FIELD = "response";
public static final String REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT =
"home-to-overview-swipe-height";
public static final String REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT =
"background-to-overview-swipe-height";
} }

View File

@ -22,11 +22,14 @@ import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import android.view.ViewConfiguration;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.test.uiautomator.By; import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until; import androidx.test.uiautomator.Until;
import com.android.launcher3.TestProtocol;
/** /**
* Indicates the base state with a UI other than Overview running as foreground. It can also * Indicates the base state with a UI other than Overview running as foreground. It can also
* indicate Launcher as long as Launcher is not in Overview state. * indicate Launcher as long as Launcher is not in Overview state.
@ -59,20 +62,24 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
protected void goToOverviewUnchecked(int expectedState) { protected void goToOverviewUnchecked(int expectedState) {
if (mLauncher.isSwipeUpEnabled()) { if (mLauncher.isSwipeUpEnabled()) {
final int height = mLauncher.getDevice().getDisplayHeight(); final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
final UiObject2 navBar = mLauncher.getSystemUiObject("navigation_bar_frame"); final int startY = getSwipeStartY();
final int swipeHeight = mLauncher.getTestInfo(
getSwipeHeightRequestName()).
getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
final int slop = ViewConfiguration.get(mLauncher.getContext()).getScaledTouchSlop();
int swipeLength = Math.round(getSwipeLength() * mLauncher.getDisplayDensity()); mLauncher.swipe(centerX, startY, centerX, startY - swipeHeight - slop, expectedState);
mLauncher.swipe(
navBar.getVisibleBounds().centerX(), navBar.getVisibleBounds().centerY(),
navBar.getVisibleBounds().centerX(), height - swipeLength,
expectedState);
} else { } else {
mLauncher.getSystemUiObject("recent_apps").click(); mLauncher.getSystemUiObject("recent_apps").click();
} }
} }
protected int getSwipeLength() { protected String getSwipeHeightRequestName() {
return 200; return TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT;
}
protected int getSwipeStartY() {
return mLauncher.getSystemUiObject("home").getVisibleBounds().centerY();
} }
} }

View File

@ -18,9 +18,11 @@ package com.android.launcher3.tapl;
import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME; import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
import android.app.ActivityManager;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.app.UiAutomation; import android.app.UiAutomation;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Point; import android.graphics.Point;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -106,7 +108,13 @@ public final class LauncherInstrumentation {
mInstrumentation = instrumentation; mInstrumentation = instrumentation;
mDevice = UiDevice.getInstance(instrumentation); mDevice = UiDevice.getInstance(instrumentation);
final String testPackage = mInstrumentation.getContext().getPackageName(); // Launcher should run in test harness so that custom accessibility protocol between
// Launcher and TAPL is enabled. In-process tests enable this protocol with a direct call
// into Launcher.
assertTrue("Device must run in a test harness",
TestHelpers.isInLauncherProcess() || ActivityManager.isRunningInTestHarness());
final String testPackage = getContext().getPackageName();
final String targetPackage = mInstrumentation.getTargetContext().getPackageName(); final String targetPackage = mInstrumentation.getTargetContext().getPackageName();
// Launcher package. As during inproc tests the tested launcher may not be selected as the // Launcher package. As during inproc tests the tested launcher may not be selected as the
@ -127,13 +135,14 @@ public final class LauncherInstrumentation {
} catch (IOException e) { } catch (IOException e) {
fail(e.toString()); fail(e.toString());
} }
}
// Launcher should run in test harness so that custom test protocols between Launcher and Context getContext() {
// TAPL are enabled. In-process tests enable this protocol with a direct call into Launcher. return mInstrumentation.getContext();
final Bundle response = mInstrumentation.getContext().getContentResolver().call( }
mTestProviderUri, TestProtocol.IS_TEST_INFO_ENABLED, null, null);
assertTrue("Launcher is not running in test harness", Bundle getTestInfo(String request) {
response.getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, false)); return getContext().getContentResolver().call(mTestProviderUri, request, null, null);
} }
void setActiveContainer(VisibleContainer container) { void setActiveContainer(VisibleContainer container) {

View File

@ -28,6 +28,8 @@ import androidx.annotation.Nullable;
import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.Direction;
import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.UiObject2;
import com.android.launcher3.TestProtocol;
/** /**
* Operations on the workspace screen. * Operations on the workspace screen.
*/ */
@ -162,7 +164,12 @@ public final class Workspace extends Home {
} }
@Override @Override
protected int getSwipeLength() { protected String getSwipeHeightRequestName() {
return 100; return TestProtocol.REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT;
}
@Override
protected int getSwipeStartY() {
return mLauncher.waitForLauncherObject("hotseat").getVisibleBounds().top;
} }
} }