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: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.
TODO: Enable when all apps columns are correct

View File

@ -84,9 +84,11 @@ public class OverviewState extends LauncherState {
super.onBackPressed(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;
}
}

View File

@ -73,6 +73,14 @@
</intent-filter>
</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
android:name="com.android.launcher3.uioverrides.dynamicui.WallpaperManagerCompatVL$ColorExtractionService"
tools:node="remove" />

View File

@ -26,6 +26,7 @@ import android.view.View;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.R;
@ -132,7 +133,10 @@ public class OverviewState extends LauncherState {
}
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;
}

View File

@ -14,14 +14,22 @@
* limitations under the License.
*/
package com.android.launcher3;
package com.android.quickstep;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
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 {
@Override
public boolean onCreate() {
@ -55,10 +63,26 @@ public class TestInformationProvider extends ContentProvider {
@Override
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();
response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD,
Utilities.IS_RUNNING_IN_TEST_HARNESS);
final Context context = getContext();
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 null;

View File

@ -31,6 +31,9 @@ public final class TestProtocol {
public static final int ALL_APPS_STATE_ORDINAL = 3;
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 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 android.view.ViewConfiguration;
import androidx.annotation.NonNull;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiObject2;
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
* 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) {
if (mLauncher.isSwipeUpEnabled()) {
final int height = mLauncher.getDevice().getDisplayHeight();
final UiObject2 navBar = mLauncher.getSystemUiObject("navigation_bar_frame");
final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
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(
navBar.getVisibleBounds().centerX(), navBar.getVisibleBounds().centerY(),
navBar.getVisibleBounds().centerX(), height - swipeLength,
expectedState);
mLauncher.swipe(centerX, startY, centerX, startY - swipeHeight - slop, expectedState);
} else {
mLauncher.getSystemUiObject("recent_apps").click();
}
}
protected int getSwipeLength() {
return 200;
protected String getSwipeHeightRequestName() {
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 android.app.ActivityManager;
import android.app.Instrumentation;
import android.app.UiAutomation;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;
@ -106,7 +108,13 @@ public final class LauncherInstrumentation {
mInstrumentation = 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();
// 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) {
fail(e.toString());
}
}
// Launcher should run in test harness so that custom test protocols between Launcher and
// TAPL are enabled. In-process tests enable this protocol with a direct call into Launcher.
final Bundle response = mInstrumentation.getContext().getContentResolver().call(
mTestProviderUri, TestProtocol.IS_TEST_INFO_ENABLED, null, null);
assertTrue("Launcher is not running in test harness",
response.getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, false));
Context getContext() {
return mInstrumentation.getContext();
}
Bundle getTestInfo(String request) {
return getContext().getContentResolver().call(mTestProviderUri, request, null, null);
}
void setActiveContainer(VisibleContainer container) {

View File

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