diff options
author | Wale Ogunwale <ogunwale@google.com> | 2015-04-13 04:56:21 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-04-13 04:56:21 +0000 |
commit | 110919d9952a60eb9a2ff1696f3e13818428ee6a (patch) | |
tree | 336b2b9b011e8bb8524c6d42e4c16e717be3ca5e /core | |
parent | dd804d908df04deba60e7f2021df1d7abbdd7d85 (diff) | |
parent | bd59764a2c20deeebe945c5008abf9a62df09a1e (diff) | |
download | frameworks_base-110919d9952a60eb9a2ff1696f3e13818428ee6a.zip frameworks_base-110919d9952a60eb9a2ff1696f3e13818428ee6a.tar.gz frameworks_base-110919d9952a60eb9a2ff1696f3e13818428ee6a.tar.bz2 |
am bd59764a: am 8f0e0c1f: Merge "Clean-up state if we have an exception when acquiring provider"
* commit 'bd59764a2c20deeebe945c5008abf9a62df09a1e':
Clean-up state if we have an exception when acquiring provider
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/app/ActivityThread.java | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index c05d0d4..6cbfee7 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -261,6 +261,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. @@ -4667,39 +4669,55 @@ public final class ActivityThread { } IActivityManager.ContentProviderHolder holder = null; - 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. - // Other threads just wait for its result. - // 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 { + 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. + // Other threads just wait for its result. + // 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. holder = ActivityManagerNative.getDefault().getContentProvider( getApplicationThread(), auth, userId, stable); - } catch (RemoteException ex) { + } else { + synchronized (r) { + while (r.acquiring) { + try { + r.wait(); + } catch (InterruptedException e) { + } + } + holder = r.holder; + } } + } catch (RemoteException ex) { + } catch (RuntimeException e) { synchronized (r) { - r.holder = holder; - r.acquiring = false; - r.notifyAll(); + r.runtimeException = e; } - } else { - synchronized (r) { - while (r.acquiring) { - try { - r.wait(); - } catch (InterruptedException e) { - } + } finally { + if (first) { + synchronized (r) { + r.holder = holder; + r.acquiring = false; + r.notifyAll(); } - holder = r.holder; } - } - synchronized (mAcquiringProviderMap) { - if (--r.requests == 0) { - mAcquiringProviderMap.remove(key); + + 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; |