diff options
29 files changed, 290 insertions, 197 deletions
diff --git a/Android.bp b/Android.bp index b80282eb5..4c3820597 100644 --- a/Android.bp +++ b/Android.bp @@ -25,7 +25,7 @@ android_library { "tests/tapl/**/*.java", "src/com/android/launcher3/util/SecureSettingsObserver.java", "src/com/android/launcher3/ResourceUtils.java", - "src/com/android/launcher3/TestProtocol.java", + "src/com/android/launcher3/testing/TestProtocol.java", ], manifest: "tests/tapl/AndroidManifest.xml", platform_apis: true, diff --git a/AndroidManifest-common.xml b/AndroidManifest-common.xml index ef5bb2672..5318a12ed 100644 --- a/AndroidManifest-common.xml +++ b/AndroidManifest-common.xml @@ -176,5 +176,12 @@ </intent-filter> </activity> + <provider + android:name="com.android.launcher3.testing.TestInformationProvider" + android:authorities="${packageName}.TestInfo" + android:readPermission="android.permission.WRITE_SECURE_SETTINGS" + android:writePermission="android.permission.WRITE_SECURE_SETTINGS" + android:exported="true" + android:enabled="false" /> </application> </manifest> diff --git a/quickstep/AndroidManifest.xml b/quickstep/AndroidManifest.xml index be275e0e8..a38979d41 100644 --- a/quickstep/AndroidManifest.xml +++ b/quickstep/AndroidManifest.xml @@ -73,14 +73,6 @@ </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" /> diff --git a/quickstep/res/values/config.xml b/quickstep/res/values/config.xml index e84543b37..5c4d6d869 100644 --- a/quickstep/res/values/config.xml +++ b/quickstep/res/values/config.xml @@ -25,6 +25,8 @@ <string name="stats_log_manager_class" translatable="false">com.android.quickstep.logging.StatsLogCompatManager</string> + <string name="test_information_handler_class" translatable="false">com.android.quickstep.QuickstepTestInformationHandler</string> + <!-- The number of thumbnails and icons to keep in the cache. The thumbnail cache size also determines how many thumbnails will be fetched in the background. --> <integer name="recentsThumbnailCacheSize">3</integer> diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java new file mode 100644 index 000000000..89513634f --- /dev/null +++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java @@ -0,0 +1,36 @@ +package com.android.quickstep; + +import android.content.Context; +import android.os.Bundle; + +import com.android.launcher3.testing.TestInformationHandler; +import com.android.launcher3.testing.TestProtocol; +import com.android.launcher3.uioverrides.states.OverviewState; +import com.android.quickstep.util.LayoutUtils; + +public class QuickstepTestInformationHandler extends TestInformationHandler { + + public QuickstepTestInformationHandler(Context context) { } + + @Override + public Bundle call(String method) { + final Bundle response = new Bundle(); + switch (method) { + case TestProtocol.REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT: { + final float swipeHeight = + OverviewState.getDefaultSwipeHeight(mDeviceProfile); + response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight); + return response; + } + + case TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT: { + final float swipeHeight = + LayoutUtils.getShelfTrackingDistance(mContext, mDeviceProfile); + response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight); + return response; + } + } + + return super.call(method); + } +} diff --git a/quickstep/src/com/android/quickstep/TestInformationProvider.java b/quickstep/src/com/android/quickstep/TestInformationProvider.java deleted file mode 100644 index d96f9af6f..000000000 --- a/quickstep/src/com/android/quickstep/TestInformationProvider.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -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.Launcher; -import com.android.launcher3.LauncherAppState; -import com.android.launcher3.LauncherState; -import com.android.launcher3.TestProtocol; -import com.android.launcher3.Utilities; -import com.android.launcher3.uioverrides.states.OverviewState; -import com.android.quickstep.util.LayoutUtils; - -public class TestInformationProvider extends ContentProvider { - @Override - public boolean onCreate() { - return true; - } - - @Override - public int update(Uri uri, ContentValues contentValues, String s, String[] strings) { - return 0; - } - - @Override - public int delete(Uri uri, String s, String[] strings) { - return 0; - } - - @Override - public Uri insert(Uri uri, ContentValues contentValues) { - return null; - } - - @Override - public String getType(Uri uri) { - return null; - } - - @Override - public Cursor query(Uri uri, String[] strings, String s, String[] strings1, String s1) { - return null; - } - - @Override - public Bundle call(String method, String arg, Bundle extras) { - if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { - final Bundle response = new Bundle(); - final Context context = getContext(); - final DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE. - get(context).getDeviceProfile(context); - final LauncherAppState launcherAppState = LauncherAppState.getInstanceNoCreate(); - final Launcher launcher = launcherAppState != null ? - (Launcher) launcherAppState.getModel().getCallback() : null; - - 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; - } - - case TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT: { - if (launcher == null) return null; - - final float progress = LauncherState.OVERVIEW.getVerticalProgress(launcher) - - LauncherState.ALL_APPS.getVerticalProgress(launcher); - final float distance = - launcher.getAllAppsController().getShiftRange() * progress; - response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) distance); - break; - } - - case TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT: { - if (launcher == null) return null; - - final float progress = LauncherState.NORMAL.getVerticalProgress(launcher) - - LauncherState.ALL_APPS.getVerticalProgress(launcher); - final float distance = - launcher.getAllAppsController().getShiftRange() * progress; - response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) distance); - break; - } - - case TestProtocol.REQUEST_ENABLE_DEBUG_TRACING: - TestProtocol.sDebugTracing = true; - break; - - case TestProtocol.REQUEST_DISABLE_DEBUG_TRACING: - TestProtocol.sDebugTracing = false; - break; - } - return response; - } - return null; - } -} diff --git a/res/values/config.xml b/res/values/config.xml index 984729b20..638a411be 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -71,6 +71,7 @@ <string name="main_process_initializer_class" translatable="false"></string> <string name="system_shortcut_factory_class" translatable="false"></string> <string name="app_launch_tracker_class" translatable="false"></string> + <string name="test_information_handler_class" translatable="false"></string> <!-- Package name of the default wallpaper picker. --> <string name="wallpaper_picker_package" translatable="false"></string> diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index bd6ac90f3..f69b17248 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -34,6 +34,7 @@ import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.model.AppLaunchTracker; import com.android.launcher3.shortcuts.DeepShortcutManager; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.uioverrides.DisplayRotationListener; import com.android.launcher3.uioverrides.WallpaperColorInfo; import com.android.launcher3.util.Themes; @@ -134,8 +135,8 @@ public abstract class BaseDraggingActivity extends BaseActivity public boolean startActivitySafely(View v, Intent intent, @Nullable ItemInfo item, @Nullable String sourceContainer) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_START_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_START_TAG, "startActivitySafely 1"); } if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { @@ -161,8 +162,8 @@ public abstract class BaseDraggingActivity extends BaseActivity startShortcutIntentSafely(intent, optsBundle, item, sourceContainer); } else if (user == null || user.equals(Process.myUserHandle())) { // Could be launching some bookkeeping activity - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_START_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_START_TAG, "startActivitySafely 2"); } startActivity(intent, optsBundle); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 35113d213..7790475f6 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -110,6 +110,7 @@ import com.android.launcher3.popup.PopupDataProvider; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.states.InternalStateHandler; import com.android.launcher3.states.RotationHelper; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.touch.ItemClickHandler; import com.android.launcher3.uioverrides.UiFactory; import com.android.launcher3.userevent.nano.LauncherLogProto; @@ -1782,8 +1783,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, public boolean startActivitySafely(View v, Intent intent, ItemInfo item, @Nullable String sourceContainer) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_START_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_START_TAG, "startActivitySafely outer"); } boolean success = super.startActivitySafely(v, intent, item, sourceContainer); diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java index eff58a701..3a92dfb96 100644 --- a/src/com/android/launcher3/LauncherState.java +++ b/src/com/android/launcher3/LauncherState.java @@ -18,13 +18,13 @@ package com.android.launcher3; import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO; import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS; import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; -import static com.android.launcher3.TestProtocol.ALL_APPS_STATE_ORDINAL; -import static com.android.launcher3.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; -import static com.android.launcher3.TestProtocol.NORMAL_STATE_ORDINAL; -import static com.android.launcher3.TestProtocol.OVERVIEW_PEEK_STATE_ORDINAL; -import static com.android.launcher3.TestProtocol.OVERVIEW_STATE_ORDINAL; -import static com.android.launcher3.TestProtocol.QUICK_SWITCH_STATE_ORDINAL; -import static com.android.launcher3.TestProtocol.SPRING_LOADED_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.ALL_APPS_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.NORMAL_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.OVERVIEW_PEEK_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.QUICK_SWITCH_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.SPRING_LOADED_STATE_ORDINAL; import static com.android.launcher3.anim.Interpolators.ACCEL_2; import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java index 49ae33894..3edd8385a 100644 --- a/src/com/android/launcher3/LauncherStateManager.java +++ b/src/com/android/launcher3/LauncherStateManager.java @@ -48,6 +48,7 @@ import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.anim.AnimatorSetBuilder; import com.android.launcher3.anim.PropertySetter; import com.android.launcher3.anim.PropertySetter.AnimatedPropertySetter; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.uioverrides.UiFactory; import java.io.PrintWriter; @@ -447,8 +448,8 @@ public class LauncherStateManager { } private void onStateTransitionStart(LauncherState state) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "onStateTransitionStart"); } if (mState != state) { @@ -576,8 +577,8 @@ public class LauncherStateManager { private final AnimatorSet mAnim; public StartAnimRunnable(AnimatorSet anim) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "StartAnimRunnable"); } mAnim = anim; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index d19f9cd73..f784226a5 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -20,8 +20,6 @@ import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY; import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; -import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; -import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; import static com.android.launcher3.LauncherState.ALL_APPS; import static com.android.launcher3.LauncherState.NORMAL; import static com.android.launcher3.LauncherState.SPRING_LOADED; @@ -86,6 +84,7 @@ import com.android.launcher3.graphics.RotationMode; import com.android.launcher3.pageindicators.WorkspacePageIndicator; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.touch.WorkspaceTouchListener; import com.android.launcher3.userevent.nano.LauncherLogProto.Action; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; @@ -371,8 +370,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator> @Override public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "onDragStart 1"); } if (ENFORCE_DRAG_EVENT_ORDER) { @@ -425,8 +424,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator> } // Always enter the spring loaded mode - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "onDragStart 2"); } mLauncher.getStateManager().goToState(SPRING_LOADED); diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 63682c73a..d8094ea62 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -43,7 +43,7 @@ import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.R; -import com.android.launcher3.TestProtocol; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.Utilities; import com.android.launcher3.compat.AccessibilityManagerCompat; import com.android.launcher3.config.FeatureFlags; diff --git a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java index 86f773fa3..8e59d32bd 100644 --- a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java +++ b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java @@ -23,7 +23,7 @@ import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; -import com.android.launcher3.TestProtocol; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.Utilities; import java.util.function.Consumer; diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index bf692fe47..9d3c8f75d 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -41,6 +41,7 @@ import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.accessibility.DragViewStateAnnouncer; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.Thunk; import com.android.launcher3.util.TouchController; @@ -472,8 +473,8 @@ public class DragController implements DragDriver.EventListener, TouchController } private void handleMoveEvent(int x, int y) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "handleMoveEvent 1"); } mDragObject.dragView.move(x, y); @@ -492,8 +493,8 @@ public class DragController implements DragDriver.EventListener, TouchController if (mIsInPreDrag && mOptions.preDragCondition != null && mOptions.preDragCondition.shouldStartDrag(mDistanceSinceScroll)) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "handleMoveEvent 2"); } callOnDragStart(); @@ -533,8 +534,8 @@ public class DragController implements DragDriver.EventListener, TouchController * Call this from a drag source view. */ public boolean onControllerTouchEvent(MotionEvent ev) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "onControllerTouchEvent"); } if (mDragDriver == null || mOptions == null || mOptions.isAccessibleDrag) { diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java new file mode 100644 index 000000000..b8476aa1d --- /dev/null +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.testing; + +import android.content.Context; +import android.os.Bundle; + +import com.android.launcher3.DeviceProfile; +import com.android.launcher3.InvariantDeviceProfile; +import com.android.launcher3.Launcher; +import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherState; +import com.android.launcher3.R; +import com.android.launcher3.util.ResourceBasedOverride; + +public class TestInformationHandler implements ResourceBasedOverride { + + public static TestInformationHandler newInstance(Context context) { + return Overrides.getObject(TestInformationHandler.class, + context, R.string.test_information_handler_class); + } + + protected Context mContext; + protected DeviceProfile mDeviceProfile; + protected LauncherAppState mLauncherAppState; + protected Launcher mLauncher; + + public void init(Context context) { + mContext = context; + mDeviceProfile = InvariantDeviceProfile.INSTANCE. + get(context).getDeviceProfile(context); + mLauncherAppState = LauncherAppState.getInstanceNoCreate(); + mLauncher = mLauncherAppState != null ? + (Launcher) mLauncherAppState.getModel().getCallback() : null; + } + + public Bundle call(String method) { + final Bundle response = new Bundle(); + switch (method) { + case TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT: { + if (mLauncher == null) return null; + + final float progress = LauncherState.OVERVIEW.getVerticalProgress(mLauncher) + - LauncherState.ALL_APPS.getVerticalProgress(mLauncher); + final float distance = mLauncher.getAllAppsController().getShiftRange() * progress; + response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) distance); + break; + } + + case TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT: { + if (mLauncher == null) return null; + + final float progress = LauncherState.NORMAL.getVerticalProgress(mLauncher) + - LauncherState.ALL_APPS.getVerticalProgress(mLauncher); + final float distance = mLauncher.getAllAppsController().getShiftRange() * progress; + response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) distance); + break; + } + + case TestProtocol.REQUEST_ENABLE_DEBUG_TRACING: + TestProtocol.sDebugTracing = true; + break; + + case TestProtocol.REQUEST_DISABLE_DEBUG_TRACING: + TestProtocol.sDebugTracing = false; + break; + } + return response; + } +} diff --git a/src/com/android/launcher3/testing/TestInformationProvider.java b/src/com/android/launcher3/testing/TestInformationProvider.java new file mode 100644 index 000000000..bd177c003 --- /dev/null +++ b/src/com/android/launcher3/testing/TestInformationProvider.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.testing; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; + +import com.android.launcher3.Utilities; + +public class TestInformationProvider extends ContentProvider { + @Override + public boolean onCreate() { + return true; + } + + @Override + public int update(Uri uri, ContentValues contentValues, String s, String[] strings) { + return 0; + } + + @Override + public int delete(Uri uri, String s, String[] strings) { + return 0; + } + + @Override + public Uri insert(Uri uri, ContentValues contentValues) { + return null; + } + + @Override + public String getType(Uri uri) { + return null; + } + + @Override + public Cursor query(Uri uri, String[] strings, String s, String[] strings1, String s1) { + return null; + } + + @Override + public Bundle call(String method, String arg, Bundle extras) { + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + TestInformationHandler handler = TestInformationHandler.newInstance(getContext()); + handler.init(getContext()); + return handler.call(method); + } + return null; + } +} diff --git a/src/com/android/launcher3/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index a0440e877..9fd44a1c4 100644 --- a/src/com/android/launcher3/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.launcher3; +package com.android.launcher3.testing; /** * Protocol for custom accessibility events for communication with UI Automation tests. diff --git a/src/com/android/launcher3/touch/ItemClickHandler.java b/src/com/android/launcher3/touch/ItemClickHandler.java index 99b9f25b1..f858dc4c6 100644 --- a/src/com/android/launcher3/touch/ItemClickHandler.java +++ b/src/com/android/launcher3/touch/ItemClickHandler.java @@ -47,6 +47,7 @@ import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.compat.AppWidgetManagerCompat; import com.android.launcher3.folder.Folder; import com.android.launcher3.folder.FolderIcon; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.widget.PendingAppWidgetHostView; import com.android.launcher3.widget.WidgetAddFlowHandler; @@ -66,15 +67,15 @@ public class ItemClickHandler { } private static void onClick(View v, String sourceContainer) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_START_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_START_TAG, "onClick 1"); } // Make sure that rogue clicks don't get through while allapps is launching, or after the // view has detached (it's possible for this to happen if the view is removed mid touch). if (v.getWindowToken() == null) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_START_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_START_TAG, "onClick 2"); } return; @@ -82,8 +83,8 @@ public class ItemClickHandler { Launcher launcher = Launcher.getLauncher(v.getContext()); if (!launcher.getWorkspace().isFinishedSwitchingState()) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_START_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_START_TAG, "onClick 3"); } return; @@ -97,8 +98,8 @@ public class ItemClickHandler { onClickFolderIcon(v); } } else if (tag instanceof AppInfo) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_START_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_START_TAG, "onClick 4"); } startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher, @@ -232,8 +233,8 @@ public class ItemClickHandler { private static void startAppShortcutOrInfoActivity(View v, ItemInfo item, Launcher launcher, @Nullable String sourceContainer) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_START_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_START_TAG, "startAppShortcutOrInfoActivity"); } Intent intent; diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java index 496418240..001951ac1 100644 --- a/src/com/android/launcher3/views/BaseDragLayer.java +++ b/src/com/android/launcher3/views/BaseDragLayer.java @@ -41,6 +41,7 @@ import android.widget.FrameLayout; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.InsettableFrameLayout; import com.android.launcher3.Utilities; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.util.MultiValueAlpha; import com.android.launcher3.util.MultiValueAlpha.AlphaProperty; import com.android.launcher3.util.TouchController; @@ -213,8 +214,8 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext> @Override public boolean onTouchEvent(MotionEvent ev) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "onTouchEvent " + ev); } int action = ev.getAction(); @@ -226,8 +227,8 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext> } if (mActiveController != null) { - if (com.android.launcher3.TestProtocol.sDebugTracing) { - android.util.Log.d(com.android.launcher3.TestProtocol.NO_DRAG_TAG, + if (TestProtocol.sDebugTracing) { + android.util.Log.d(TestProtocol.NO_DRAG_TAG, "onTouchEvent 1"); } return mActiveController.onControllerTouchEvent(ev); diff --git a/tests/Android.mk b/tests/Android.mk index 0991a0439..978209feb 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -32,7 +32,7 @@ else LOCAL_SRC_FILES := $(call all-java-files-under, tapl) \ ../src/com/android/launcher3/ResourceUtils.java \ ../src/com/android/launcher3/util/SecureSettingsObserver.java \ - ../src/com/android/launcher3/TestProtocol.java + ../src/com/android/launcher3/testing/TestProtocol.java endif LOCAL_MODULE := ub-launcher-aosp-tapl diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index b2043cb5a..18a8f2755 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -27,7 +27,7 @@ import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.UiObject2; import com.android.launcher3.ResourceUtils; -import com.android.launcher3.TestProtocol; +import com.android.launcher3.testing.TestProtocol; /** * Operations on AllApps opened from Home. Also a parent for All Apps opened from Overview. diff --git a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java index a472d3134..f48d4dd4c 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java @@ -16,14 +16,14 @@ package com.android.launcher3.tapl; -import static com.android.launcher3.TestProtocol.OVERVIEW_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; import android.graphics.Point; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; -import com.android.launcher3.TestProtocol; +import com.android.launcher3.testing.TestProtocol; /** * Operations on AllApps opened from Overview. diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index 55e14cc80..8627f485b 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -16,7 +16,7 @@ package com.android.launcher3.tapl; -import static com.android.launcher3.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; import android.graphics.Point; import android.os.SystemClock; @@ -24,7 +24,7 @@ import android.view.MotionEvent; import androidx.annotation.NonNull; -import com.android.launcher3.TestProtocol; +import com.android.launcher3.testing.TestProtocol; /** * Indicates the base state with a UI other than Overview running as foreground. It can also diff --git a/tests/tapl/com/android/launcher3/tapl/Home.java b/tests/tapl/com/android/launcher3/tapl/Home.java index 20c116ce2..cfc43749d 100644 --- a/tests/tapl/com/android/launcher3/tapl/Home.java +++ b/tests/tapl/com/android/launcher3/tapl/Home.java @@ -16,7 +16,7 @@ package com.android.launcher3.tapl; -import static com.android.launcher3.TestProtocol.OVERVIEW_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; import androidx.annotation.NonNull; diff --git a/tests/tapl/com/android/launcher3/tapl/Launchable.java b/tests/tapl/com/android/launcher3/tapl/Launchable.java index 3295ddbef..ee90d37b6 100644 --- a/tests/tapl/com/android/launcher3/tapl/Launchable.java +++ b/tests/tapl/com/android/launcher3/tapl/Launchable.java @@ -24,7 +24,7 @@ import androidx.test.uiautomator.UiDevice; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; -import com.android.launcher3.TestProtocol; +import com.android.launcher3.testing.TestProtocol; /** * Ancestor for AppIcon and AppMenuItem. diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 7978c7928..8d69b3783 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -16,16 +16,23 @@ package com.android.launcher3.tapl; -import static com.android.launcher3.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; -import static com.android.launcher3.TestProtocol.NORMAL_STATE_ORDINAL; +import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; +import static android.content.pm.PackageManager.DONT_KILL_APP; +import static android.content.pm.PackageManager.MATCH_ALL; +import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS; + +import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.NORMAL_STATE_ORDINAL; import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName; import android.app.ActivityManager; import android.app.Instrumentation; import android.app.UiAutomation; +import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; +import android.content.pm.ProviderInfo; import android.content.res.Resources; import android.graphics.Point; import android.graphics.Rect; @@ -53,7 +60,7 @@ import androidx.test.uiautomator.UiDevice; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; -import com.android.launcher3.TestProtocol; +import com.android.launcher3.testing.TestProtocol; import com.android.systemui.shared.system.QuickStepContract; import org.junit.Assert; @@ -149,9 +156,10 @@ public final class LauncherInstrumentation { getLauncherPackageName() : targetPackage; + String testProviderAuthority = authorityPackage + ".TestInfo"; mTestProviderUri = new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) - .authority(authorityPackage + ".TestInfo") + .authority(testProviderAuthority) .build(); try { @@ -160,6 +168,25 @@ public final class LauncherInstrumentation { } catch (IOException e) { fail(e.toString()); } + + + PackageManager pm = getContext().getPackageManager(); + ProviderInfo pi = pm.resolveContentProvider( + testProviderAuthority, MATCH_ALL | MATCH_DISABLED_COMPONENTS); + ComponentName cn = new ComponentName(pi.packageName, pi.name); + + if (pm.getComponentEnabledSetting(cn) != COMPONENT_ENABLED_STATE_ENABLED) { + if (TestHelpers.isInLauncherProcess()) { + getContext().getPackageManager().setComponentEnabledSetting( + cn, COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP); + } else { + try { + mDevice.executeShellCommand("pm enable " + cn.flattenToString()); + } catch (IOException e) { + fail(e.toString()); + } + } + } } Context getContext() { diff --git a/tests/tapl/com/android/launcher3/tapl/Overview.java b/tests/tapl/com/android/launcher3/tapl/Overview.java index ec99d26c1..1aa957a17 100644 --- a/tests/tapl/com/android/launcher3/tapl/Overview.java +++ b/tests/tapl/com/android/launcher3/tapl/Overview.java @@ -16,7 +16,7 @@ package com.android.launcher3.tapl; -import static com.android.launcher3.TestProtocol.ALL_APPS_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.ALL_APPS_STATE_ORDINAL; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 10b253d44..7dcc426b9 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -16,7 +16,7 @@ package com.android.launcher3.tapl; -import static com.android.launcher3.TestProtocol.ALL_APPS_STATE_ORDINAL; +import static com.android.launcher3.testing.TestProtocol.ALL_APPS_STATE_ORDINAL; import static junit.framework.TestCase.assertTrue; @@ -30,7 +30,7 @@ import androidx.annotation.Nullable; import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.UiObject2; -import com.android.launcher3.TestProtocol; +import com.android.launcher3.testing.TestProtocol; /** * Operations on the workspace screen. |