summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Noack <noackjr@google.com>2017-01-12 12:16:58 -0600
committerJon Noack <noackjr@google.com>2017-01-13 09:26:45 -0600
commit87738871b50552a98a083f8e840089e8889b3e2a (patch)
treeacd2f574542c6c3bea6847afdf86663af9a9ebce
parent07bca8fb7f8d97223a1c27dd5f18008f56e406af (diff)
downloadmultidex-87738871b50552a98a083f8e840089e8889b3e2a.tar.gz
Use context.getApplicationInfo()
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. Test: Passes Google Play services tests Change-Id: I95257d851eb678c55a19e731183f7add2b540615
-rw-r--r--library/src/android/support/multidex/MultiDex.java25
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;
}
/**