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

Commit a75fd790 authored by Vadim Tryshev's avatar Vadim Tryshev Committed by Android (Google) Code Review
Browse files

Merge "Avoiding unconditional 5 sec wait in the beginning of inproc tests" into main

parents 54acb41e 3f7e82e8
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -229,6 +229,7 @@ public final class LauncherInstrumentation {

    /**
     * Constructs the root of TAPL hierarchy. You get all other objects from it.
     *
     * @deprecated use the constructor without Instrumentation parameter instead.
     */
    @Deprecated
@@ -238,6 +239,7 @@ public final class LauncherInstrumentation {

    /**
     * Constructs the root of TAPL hierarchy. You get all other objects from it.
     *
     * @deprecated use the constructor without Instrumentation parameter instead.
     */
    @Deprecated
@@ -280,33 +282,31 @@ public final class LauncherInstrumentation {
        if (pm.getComponentEnabledSetting(cn) != COMPONENT_ENABLED_STATE_ENABLED) {
            if (TestHelpers.isInLauncherProcess()) {
                pm.setComponentEnabledSetting(cn, COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP);
                // b/195031154
                SystemClock.sleep(5000);
            } else {
                try {
                    final int userId = getContext().getUserId();
                    final String launcherPidCommand = "pidof " + pi.packageName;
                    final String initialPid = mDevice.executeShellCommand(launcherPidCommand)
                            .replaceAll("\\s", "");
                    mDevice.executeShellCommand(
                            "pm enable --user " + userId + " " + cn.flattenToString());
                } catch (IOException e) {
                    fail(e.toString());
                }
            }

                    // Wait for Launcher restart after enabling test provider.
            final int iterations = isLauncherTest ? 300 : 100;

            // Wait for Launcher content provider to become enabled.
            for (int i = 0; i < iterations; ++i) {
                        final String currentPid = mDevice.executeShellCommand(launcherPidCommand)
                                .replaceAll("\\s", "");
                        if (!currentPid.isEmpty() && !currentPid.equals(initialPid)) break;
                final ContentProviderClient testProvider = getContext().getContentResolver()
                        .acquireContentProviderClient(mTestProviderUri);
                if (testProvider != null) {
                    testProvider.close();
                    break;
                }
                if (i == iterations - 1) {
                            fail("Launcher didn't restart after enabling test provider");
                    fail("Launcher content provider is still not enabled");
                }
                SystemClock.sleep(100);
            }
                } catch (IOException e) {
                    fail(e.toString());
                }
            }
        }
    }