Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df3741cb authored by Sebastián Franco's avatar Sebastián Franco Committed by Automerger Merge Worker
Browse files

Merge "Binding tests to TouchInteractionService to preventing it from getting...

Merge "Binding tests to TouchInteractionService to preventing it from getting destroyed" into tm-qpr-dev am: 2e1524ec

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/21186951



Change-Id: I00ec06d94c55eacbb4aee745f1e7882cc4e77d84
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d3f23005 2e1524ec
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ filegroup {
    srcs: [
      "src/com/android/launcher3/ui/AbstractLauncherUiTest.java",
      "src/com/android/launcher3/ui/PortraitLandscapeRunner.java",
      "src/com/android/launcher3/ui/TaplTestsLauncher3.java",
      "src/com/android/launcher3/util/TestUtil.java",
      "src/com/android/launcher3/util/Wait.java",
      "src/com/android/launcher3/util/WidgetUtils.java",
@@ -54,7 +55,7 @@ filegroup {
      "src/com/android/launcher3/util/rule/ShellCommandRule.java",
      "src/com/android/launcher3/util/rule/SimpleActivityRule.java",
      "src/com/android/launcher3/util/rule/TestStabilityRule.java",
      "src/com/android/launcher3/ui/TaplTestsLauncher3.java",
      "src/com/android/launcher3/util/rule/TISBindRule.java",
      "src/com/android/launcher3/testcomponent/BaseTestingActivity.java",
      "src/com/android/launcher3/testcomponent/OtherBaseTestingActivity.java",
      "src/com/android/launcher3/testcomponent/CustomShortcutConfigActivity.java",
+14 −9
Original line number Diff line number Diff line
@@ -51,11 +51,13 @@ import com.android.launcher3.tapl.Widgets;
import com.android.launcher3.tapl.Workspace;
import com.android.launcher3.util.TestUtil;
import com.android.launcher3.util.rule.ScreenRecordRule.ScreenRecord;
import com.android.launcher3.util.rule.TISBindRule;
import com.android.launcher3.widget.picker.WidgetsFullSheet;
import com.android.launcher3.widget.picker.WidgetsRecyclerView;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -71,6 +73,9 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
    private static final String STORE_APP_NAME = "Play Store";
    private static final String GMAIL_APP_NAME = "Gmail";

    @Rule
    public TISBindRule mTISBindRule = new TISBindRule();

    @Before
    public void setUp() throws Exception {
        super.setUp();
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.util.rule;

import android.app.UiAutomation;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

public class TISBindRule implements TestRule {
    public static String TAG = "TISBindRule";
    public static String INTENT_FILTER = "android.intent.action.QUICKSTEP_SERVICE";
    public static String TIS_PERMISSIONS = "android.permission.STATUS_BAR_SERVICE";

    private String getLauncherPackageName(Context context) {
        return ComponentName.unflattenFromString(context.getString(
                com.android.internal.R.string.config_recentsComponentName)).getPackageName();
    }

    private ServiceConnection createConnection() {
        return new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                Log.d(TAG, "Connected to TouchInteractionService");
            }

            @Override
            public void onServiceDisconnected(ComponentName componentName) {
                Log.d(TAG, "Disconnected from TouchInteractionService");
            }
        };
    }

    @NonNull
    @Override
    public Statement apply(@NonNull Statement base, @NonNull Description description) {
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
                final ServiceConnection connection = createConnection();
                UiAutomation uiAutomation =
                        InstrumentationRegistry.getInstrumentation().getUiAutomation();
                uiAutomation.adoptShellPermissionIdentity(TIS_PERMISSIONS);
                Intent launchIntent = new Intent(INTENT_FILTER);
                launchIntent.setPackage(getLauncherPackageName(context));
                context.bindService(launchIntent, connection, Context.BIND_AUTO_CREATE);
                uiAutomation.dropShellPermissionIdentity();
                try {
                    base.evaluate();
                } finally {
                    context.unbindService(connection);
                }
            }
        };
    }
}