Merge \"Don\'t depend directly on AppplicationInfo\" into nyc-dev

am: 55cf361d83

Change-Id: If30e7300c84a79871dc8a0288f8402ed49e4a662
This commit is contained in:
Chad Brubaker
2016-06-09 06:27:57 +00:00
committed by android-build-merger
3 changed files with 19 additions and 19 deletions

View File

@@ -5258,7 +5258,7 @@ public final class ActivityThread {
// code is loaded to prevent issues with instances of TLS objects being created before // code is loaded to prevent issues with instances of TLS objects being created before
// the provider is installed. // the provider is installed.
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install"); Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "NetworkSecurityConfigProvider.install");
NetworkSecurityConfigProvider.install(appContext, data.appInfo); NetworkSecurityConfigProvider.install(appContext);
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
// Continue loading instrumentation. // Continue loading instrumentation.

View File

@@ -29,13 +29,19 @@ public class ManifestConfigSource implements ConfigSource {
private final Object mLock = new Object(); private final Object mLock = new Object();
private final Context mContext; private final Context mContext;
private final ApplicationInfo mInfo; private final int mApplicationInfoFlags;
private final int mTargetSdkVersion;
private final int mConfigResourceId;
private ConfigSource mConfigSource; private ConfigSource mConfigSource;
public ManifestConfigSource(Context context, ApplicationInfo info) { public ManifestConfigSource(Context context) {
mContext = context; mContext = context;
mInfo = info; // Cache values because ApplicationInfo is mutable and apps do modify it :(
ApplicationInfo info = context.getApplicationInfo();
mApplicationInfoFlags = info.flags;
mTargetSdkVersion = info.targetSdkVersion;
mConfigResourceId = info.networkSecurityConfigRes;
} }
@Override @Override
@@ -53,29 +59,24 @@ public class ManifestConfigSource implements ConfigSource {
if (mConfigSource != null) { if (mConfigSource != null) {
return mConfigSource; return mConfigSource;
} }
int targetSdkVersion = mInfo.targetSdkVersion;
int configResourceId = 0;
if (mInfo != null) {
configResourceId = mInfo.networkSecurityConfigRes;
}
ConfigSource source; ConfigSource source;
if (configResourceId != 0) { if (mConfigResourceId != 0) {
boolean debugBuild = (mInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; boolean debugBuild = (mApplicationInfoFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
if (DBG) { if (DBG) {
Log.d(LOG_TAG, "Using Network Security Config from resource " Log.d(LOG_TAG, "Using Network Security Config from resource "
+ mContext.getResources().getResourceEntryName(configResourceId) + mContext.getResources().getResourceEntryName(mConfigResourceId)
+ " debugBuild: " + debugBuild); + " debugBuild: " + debugBuild);
} }
source = new XmlConfigSource(mContext, configResourceId, debugBuild, source = new XmlConfigSource(mContext, mConfigResourceId, debugBuild,
targetSdkVersion); mTargetSdkVersion);
} else { } else {
if (DBG) { if (DBG) {
Log.d(LOG_TAG, "No Network Security Config specified, using platform default"); Log.d(LOG_TAG, "No Network Security Config specified, using platform default");
} }
boolean usesCleartextTraffic = boolean usesCleartextTraffic =
(mInfo.flags & ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0; (mApplicationInfoFlags & ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0;
source = new DefaultConfigSource(usesCleartextTraffic, targetSdkVersion); source = new DefaultConfigSource(usesCleartextTraffic, mTargetSdkVersion);
} }
mConfigSource = source; mConfigSource = source;
return mConfigSource; return mConfigSource;

View File

@@ -17,7 +17,6 @@
package android.security.net.config; package android.security.net.config;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo;
import java.security.Security; import java.security.Security;
import java.security.Provider; import java.security.Provider;
@@ -33,8 +32,8 @@ public final class NetworkSecurityConfigProvider extends Provider {
put("Alg.Alias.TrustManagerFactory.X509", "PKIX"); put("Alg.Alias.TrustManagerFactory.X509", "PKIX");
} }
public static void install(Context context, ApplicationInfo info) { public static void install(Context context) {
ApplicationConfig config = new ApplicationConfig(new ManifestConfigSource(context, info)); ApplicationConfig config = new ApplicationConfig(new ManifestConfigSource(context));
ApplicationConfig.setDefaultInstance(config); ApplicationConfig.setDefaultInstance(config);
int pos = Security.insertProviderAt(new NetworkSecurityConfigProvider(), 1); int pos = Security.insertProviderAt(new NetworkSecurityConfigProvider(), 1);
if (pos != 1) { if (pos != 1) {