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

Commit 0a9bce97 authored by Wale Ogunwale's avatar Wale Ogunwale Committed by Android Git Automerger
Browse files

am 110919d9: am bd59764a: am 8f0e0c1f: Merge "Clean-up state if we have an...

am 110919d9: am bd59764a: am 8f0e0c1f: Merge "Clean-up state if we have an exception when acquiring provider"

* commit '110919d9':
  Clean-up state if we have an exception when acquiring provider
parents fe4d95c3 110919d9
Loading
Loading
Loading
Loading
+42 −24
Original line number Diff line number Diff line
@@ -259,6 +259,8 @@ public final class ActivityThread {
        IActivityManager.ContentProviderHolder holder;
        boolean acquiring = true;
        int requests = 1;
        // Set if there was a runtime exception when trying to acquire the provider.
        RuntimeException runtimeException = null;
    }

    // The lock of mProviderMap protects the following variables.
@@ -4728,6 +4730,7 @@ public final class ActivityThread {
        }

        IActivityManager.ContentProviderHolder holder = null;
        try {
            if (first) {
                // Multiple threads may try to acquire the same provider at the same time.
                // When this happens, we only let the first one really gets provider.
@@ -4735,16 +4738,8 @@ public final class ActivityThread {
                // Note that we cannot hold the lock while acquiring and installing the
                // provider since it might take a long time to run and it could also potentially
                // be re-entrant in the case where the provider is in the same process.
            try {
                holder = ActivityManagerNative.getDefault().getContentProvider(
                        getApplicationThread(), auth, userId, stable);
            } catch (RemoteException ex) {
            }
            synchronized (r) {
                r.holder = holder;
                r.acquiring = false;
                r.notifyAll();
            }
            } else {
                synchronized (r) {
                    while (r.acquiring) {
@@ -4756,11 +4751,34 @@ public final class ActivityThread {
                    holder = r.holder;
                }
            }
        } catch (RemoteException ex) {
        } catch (RuntimeException e) {
            synchronized (r) {
                r.runtimeException = e;
            }
        } finally {
            if (first) {
                synchronized (r) {
                    r.holder = holder;
                    r.acquiring = false;
                    r.notifyAll();
                }
            }

            synchronized (mAcquiringProviderMap) {
                if (--r.requests == 0) {
                    mAcquiringProviderMap.remove(key);
                }
            }

            if (r.runtimeException != null) {
                // Was set when the first thread tried to acquire the provider,
                // but we should make sure it is thrown for all threads trying to
                // acquire the provider.
                throw r.runtimeException;
            }
        }

        if (holder == null) {
            Slog.e(TAG, "Failed to find provider info for " + auth);
            return null;