1 package com.android.quickstep;
2 
3 import android.app.Activity;
4 import android.content.Context;
5 import android.os.Bundle;
6 
7 import com.android.launcher3.LauncherState;
8 import com.android.launcher3.config.FeatureFlags;
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)24     public Bundle call(String method) {
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_OVERVIEW_ACTIONS_ENABLED: {
57                 response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD,
58                         FeatureFlags.ENABLE_OVERVIEW_ACTIONS.get());
59                 return response;
60             }
61         }
62 
63         return super.call(method);
64     }
65 
66     @Override
getCurrentActivity()67     protected Activity getCurrentActivity() {
68         RecentsAnimationDeviceState rads = new RecentsAnimationDeviceState(mContext);
69         OverviewComponentObserver observer = new OverviewComponentObserver(mContext, rads);
70         try {
71             return observer.getActivityInterface().getCreatedActivity();
72         } finally {
73             observer.onDestroy();
74             rads.destroy();
75         }
76     }
77 
78     @Override
isLauncherInitialized()79     protected boolean isLauncherInitialized() {
80         return super.isLauncherInitialized() && TouchInteractionService.isInitialized();
81     }
82 }
83