diff options
author | Jon Noack <noackjr@google.com> | 2017-01-13 17:44:30 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-01-13 17:44:30 +0000 |
commit | b703c32e27a3995732387e06fab24ffda7d64ff8 (patch) | |
tree | acd2f574542c6c3bea6847afdf86663af9a9ebce | |
parent | 8e58f1bef28a4de72f5f788df2b2317ede0b78d7 (diff) | |
parent | 87738871b50552a98a083f8e840089e8889b3e2a (diff) | |
download | multidex-b703c32e27a3995732387e06fab24ffda7d64ff8.tar.gz |
Use context.getApplicationInfo()
am: 87738871b5
Change-Id: Ia0fe8f8b038b38cb58906727a4f79b8a32ec5298
-rw-r--r-- | library/src/android/support/multidex/MultiDex.java | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/library/src/android/support/multidex/MultiDex.java b/library/src/android/support/multidex/MultiDex.java index 9864656..142f125 100644 --- a/library/src/android/support/multidex/MultiDex.java +++ b/library/src/android/support/multidex/MultiDex.java @@ -19,8 +19,6 @@ package android.support.multidex; import android.app.Application; import android.content.Context; import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; import android.os.Build; import android.util.Log; @@ -181,13 +179,17 @@ public final class MultiDex { Log.i(TAG, "install done"); } - private static ApplicationInfo getApplicationInfo(Context context) - throws NameNotFoundException { - PackageManager pm; - String packageName; + private static ApplicationInfo getApplicationInfo(Context context) { try { - pm = context.getPackageManager(); - packageName = context.getPackageName(); + /* Due to package install races it is possible for a process to be started from an old + * apk even though that apk has been replaced. Querying for ApplicationInfo by package + * name may return information for the new apk, leading to a runtime with the old main + * dex file and new secondary dex files. This leads to various problems like + * ClassNotFoundExceptions. Using context.getApplicationInfo() should result in the + * process having a consistent view of the world (even if it is of the old world). The + * package install races are eventually resolved and old processes are killed. + */ + return context.getApplicationInfo(); } catch (RuntimeException e) { /* Ignore those exceptions so that we don't break tests relying on Context like * a android.test.mock.MockContext or a android.content.ContextWrapper with a null @@ -197,13 +199,6 @@ public final class MultiDex { "Must be running in test mode. Skip patching.", e); return null; } - if (pm == null || packageName == null) { - // This is most likely a mock context, so just return without patching. - return null; - } - ApplicationInfo applicationInfo = - pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); - return applicationInfo; } /** |