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

Commit 747b8a0f authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Add timeout to AMS.getContentProviderImpl()

Bug: 116876013
Test: atest CtsContentTestCases (except preexisting failures)
Test: manual test with debug code
Change-Id: Id5e7fff228d777eb0d1804654600d9ea156e36fd
parent d80c72ab
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -450,6 +450,12 @@ public class ActivityManagerService extends IActivityManager.Stub
    // before we decide it must be hung.
    static final int CONTENT_PROVIDER_PUBLISH_TIMEOUT = 10*1000;
    /**
     * How long we wait for an provider to be published. Should be longer than
     * {@link #CONTENT_PROVIDER_PUBLISH_TIMEOUT}.
     */
    static final int CONTENT_PROVIDER_WAIT_TIMEOUT = 20 * 1000;
    // How long we wait for a launched process to attach to the activity manager
    // before we decide it's never going to come up for real, when the process was
    // started with a wrapper for instrumentation (such as Valgrind) because it
@@ -7501,6 +7507,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        ContentProviderRecord cpr;
        ContentProviderConnection conn = null;
        ProviderInfo cpi = null;
        boolean providerRunning = false;
        synchronized(this) {
            long startTime = SystemClock.uptimeMillis();
@@ -7540,8 +7547,6 @@ public class ActivityManagerService extends IActivityManager.Stub
                }
            }
            boolean providerRunning = false;
            if (cpr != null && cpr.proc != null) {
                providerRunning = !cpr.proc.killed;
@@ -7866,6 +7871,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        // Wait for the provider to be published...
        final long timeout = SystemClock.uptimeMillis() + CONTENT_PROVIDER_WAIT_TIMEOUT;
        synchronized (cpr) {
            while (cpr.provider == null) {
                if (cpr.launchingApp == null) {
@@ -7880,13 +7886,22 @@ public class ActivityManagerService extends IActivityManager.Stub
                    return null;
                }
                try {
                    final long wait = Math.max(0L, timeout - SystemClock.uptimeMillis());
                    if (DEBUG_MU) Slog.v(TAG_MU,
                            "Waiting to start provider " + cpr
                            + " launchingApp=" + cpr.launchingApp);
                            + " launchingApp=" + cpr.launchingApp + " for " + wait + " ms");
                    if (conn != null) {
                        conn.waiting = true;
                    }
                    cpr.wait();
                    cpr.wait(wait);
                    if (cpr.provider == null) {
                        Slog.wtf(TAG, "Timeout waiting for provider "
                                + cpi.applicationInfo.packageName + "/"
                                + cpi.applicationInfo.uid + " for provider "
                                + name
                                + " providerRunning=" + providerRunning);
                        return null;
                    }
                } catch (InterruptedException ex) {
                } finally {
                    if (conn != null) {