1 package com.android.quickstep; 2 3 import android.app.Activity; 4 import android.content.Context; 5 import android.graphics.Rect; 6 import android.os.Bundle; 7 8 import com.android.launcher3.LauncherState; 9 import com.android.launcher3.testing.TestInformationHandler; 10 import com.android.launcher3.testing.TestProtocol; 11 import com.android.launcher3.touch.PagedOrientationHandler; 12 import com.android.launcher3.uioverrides.touchcontrollers.PortraitStatesTouchController; 13 import com.android.quickstep.util.LayoutUtils; 14 15 public class QuickstepTestInformationHandler extends TestInformationHandler { 16 17 protected final Context mContext; 18 QuickstepTestInformationHandler(Context context)19 public QuickstepTestInformationHandler(Context context) { 20 mContext = context; 21 } 22 23 @Override call(String method, String arg)24 public Bundle call(String method, String arg) { 25 final Bundle response = new Bundle(); 26 switch (method) { 27 case TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT: { 28 return getLauncherUIProperty(Bundle::putInt, l -> { 29 final float progress = LauncherState.OVERVIEW.getVerticalProgress(l) 30 - LauncherState.ALL_APPS.getVerticalProgress(l); 31 final float distance = l.getAllAppsController().getShiftRange() * progress; 32 return (int) distance; 33 }); 34 } 35 36 case TestProtocol.REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT: { 37 final float swipeHeight = 38 LayoutUtils.getDefaultSwipeHeight(mContext, mDeviceProfile); 39 response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight); 40 return response; 41 } 42 43 case TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT: { 44 final float swipeHeight = 45 LayoutUtils.getShelfTrackingDistance(mContext, mDeviceProfile, 46 PagedOrientationHandler.PORTRAIT); 47 response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight); 48 return response; 49 } 50 51 case TestProtocol.REQUEST_HOTSEAT_TOP: { 52 return getLauncherUIProperty( 53 Bundle::putInt, PortraitStatesTouchController::getHotseatTop); 54 } 55 56 case TestProtocol.REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET: { 57 if (!mDeviceProfile.isTablet) { 58 return null; 59 } 60 Rect focusedTaskRect = new Rect(); 61 LauncherActivityInterface.INSTANCE.calculateTaskSize(mContext, mDeviceProfile, 62 focusedTaskRect); 63 response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, focusedTaskRect.height()); 64 return response; 65 } 66 67 case TestProtocol.REQUEST_GET_GRID_TASK_SIZE_RECT_FOR_TABLET: { 68 if (!mDeviceProfile.isTablet) { 69 return null; 70 } 71 Rect gridTaskRect = new Rect(); 72 LauncherActivityInterface.INSTANCE.calculateGridTaskSize(mContext, mDeviceProfile, 73 gridTaskRect, PagedOrientationHandler.PORTRAIT); 74 response.putParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD, gridTaskRect); 75 return response; 76 } 77 } 78 79 return super.call(method, arg); 80 } 81 82 @Override getCurrentActivity()83 protected Activity getCurrentActivity() { 84 RecentsAnimationDeviceState rads = new RecentsAnimationDeviceState(mContext); 85 OverviewComponentObserver observer = new OverviewComponentObserver(mContext, rads); 86 try { 87 return observer.getActivityInterface().getCreatedActivity(); 88 } finally { 89 observer.onDestroy(); 90 rads.destroy(); 91 } 92 } 93 94 @Override isLauncherInitialized()95 protected boolean isLauncherInitialized() { 96 return super.isLauncherInitialized() && TouchInteractionService.isInitialized(); 97 } 98 } 99