Merge "Use an attribute for the network security config resource" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6812bdf387
@@ -876,6 +876,7 @@ package android {
|
|||||||
field public static final int navigationMode = 16843471; // 0x10102cf
|
field public static final int navigationMode = 16843471; // 0x10102cf
|
||||||
field public static final int negativeButtonText = 16843254; // 0x10101f6
|
field public static final int negativeButtonText = 16843254; // 0x10101f6
|
||||||
field public static final int nestedScrollingEnabled = 16843830; // 0x1010436
|
field public static final int nestedScrollingEnabled = 16843830; // 0x1010436
|
||||||
|
field public static final int networkSecurityConfig = 16844074; // 0x101052a
|
||||||
field public static final int nextFocusDown = 16842980; // 0x10100e4
|
field public static final int nextFocusDown = 16842980; // 0x10100e4
|
||||||
field public static final int nextFocusForward = 16843580; // 0x101033c
|
field public static final int nextFocusForward = 16843580; // 0x101033c
|
||||||
field public static final int nextFocusLeft = 16842977; // 0x10100e1
|
field public static final int nextFocusLeft = 16842977; // 0x10100e1
|
||||||
|
|||||||
@@ -982,6 +982,7 @@ package android {
|
|||||||
field public static final int navigationMode = 16843471; // 0x10102cf
|
field public static final int navigationMode = 16843471; // 0x10102cf
|
||||||
field public static final int negativeButtonText = 16843254; // 0x10101f6
|
field public static final int negativeButtonText = 16843254; // 0x10101f6
|
||||||
field public static final int nestedScrollingEnabled = 16843830; // 0x1010436
|
field public static final int nestedScrollingEnabled = 16843830; // 0x1010436
|
||||||
|
field public static final int networkSecurityConfig = 16844074; // 0x101052a
|
||||||
field public static final int nextFocusDown = 16842980; // 0x10100e4
|
field public static final int nextFocusDown = 16842980; // 0x10100e4
|
||||||
field public static final int nextFocusForward = 16843580; // 0x101033c
|
field public static final int nextFocusForward = 16843580; // 0x101033c
|
||||||
field public static final int nextFocusLeft = 16842977; // 0x10100e1
|
field public static final int nextFocusLeft = 16842977; // 0x10100e1
|
||||||
|
|||||||
@@ -876,6 +876,7 @@ package android {
|
|||||||
field public static final int navigationMode = 16843471; // 0x10102cf
|
field public static final int navigationMode = 16843471; // 0x10102cf
|
||||||
field public static final int negativeButtonText = 16843254; // 0x10101f6
|
field public static final int negativeButtonText = 16843254; // 0x10101f6
|
||||||
field public static final int nestedScrollingEnabled = 16843830; // 0x1010436
|
field public static final int nestedScrollingEnabled = 16843830; // 0x1010436
|
||||||
|
field public static final int networkSecurityConfig = 16844074; // 0x101052a
|
||||||
field public static final int nextFocusDown = 16842980; // 0x10100e4
|
field public static final int nextFocusDown = 16842980; // 0x10100e4
|
||||||
field public static final int nextFocusForward = 16843580; // 0x101033c
|
field public static final int nextFocusForward = 16843580; // 0x101033c
|
||||||
field public static final int nextFocusLeft = 16842977; // 0x10100e1
|
field public static final int nextFocusLeft = 16842977; // 0x10100e1
|
||||||
|
|||||||
@@ -5221,7 +5221,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);
|
NetworkSecurityConfigProvider.install(appContext, data.appInfo);
|
||||||
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
|
|
||||||
// Continue loading instrumentation.
|
// Continue loading instrumentation.
|
||||||
|
|||||||
@@ -764,6 +764,12 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
|
public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource file providing the application's Network Security Config.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public int networkSecurityConfigRes;
|
||||||
|
|
||||||
public void dump(Printer pw, String prefix) {
|
public void dump(Printer pw, String prefix) {
|
||||||
dump(pw, prefix, DUMP_FLAG_ALL);
|
dump(pw, prefix, DUMP_FLAG_ALL);
|
||||||
}
|
}
|
||||||
@@ -835,6 +841,10 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
|
|||||||
pw.println(prefix + "fullBackupContent="
|
pw.println(prefix + "fullBackupContent="
|
||||||
+ (fullBackupContent < 0 ? "false" : "true"));
|
+ (fullBackupContent < 0 ? "false" : "true"));
|
||||||
}
|
}
|
||||||
|
if (networkSecurityConfigRes != 0) {
|
||||||
|
pw.println(prefix + "networkSecurityConfigRes=0x"
|
||||||
|
+ Integer.toHexString(networkSecurityConfigRes));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
super.dumpBack(pw, prefix);
|
super.dumpBack(pw, prefix);
|
||||||
}
|
}
|
||||||
@@ -921,6 +931,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
|
|||||||
uiOptions = orig.uiOptions;
|
uiOptions = orig.uiOptions;
|
||||||
backupAgentName = orig.backupAgentName;
|
backupAgentName = orig.backupAgentName;
|
||||||
fullBackupContent = orig.fullBackupContent;
|
fullBackupContent = orig.fullBackupContent;
|
||||||
|
networkSecurityConfigRes = orig.networkSecurityConfigRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
@@ -976,6 +987,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
|
|||||||
dest.writeInt(descriptionRes);
|
dest.writeInt(descriptionRes);
|
||||||
dest.writeInt(uiOptions);
|
dest.writeInt(uiOptions);
|
||||||
dest.writeInt(fullBackupContent);
|
dest.writeInt(fullBackupContent);
|
||||||
|
dest.writeInt(networkSecurityConfigRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<ApplicationInfo> CREATOR
|
public static final Parcelable.Creator<ApplicationInfo> CREATOR
|
||||||
@@ -1031,6 +1043,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
|
|||||||
descriptionRes = source.readInt();
|
descriptionRes = source.readInt();
|
||||||
uiOptions = source.readInt();
|
uiOptions = source.readInt();
|
||||||
fullBackupContent = source.readInt();
|
fullBackupContent = source.readInt();
|
||||||
|
networkSecurityConfigRes = source.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2945,6 +2945,10 @@ public class PackageParser {
|
|||||||
ai.privateFlags |= PRIVATE_FLAG_RESIZEABLE_ACTIVITIES;
|
ai.privateFlags |= PRIVATE_FLAG_RESIZEABLE_ACTIVITIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ai.networkSecurityConfigRes = sa.getResourceId(
|
||||||
|
com.android.internal.R.styleable.AndroidManifestApplication_networkSecurityConfig,
|
||||||
|
0);
|
||||||
|
|
||||||
String str;
|
String str;
|
||||||
str = sa.getNonConfigurationString(
|
str = sa.getNonConfigurationString(
|
||||||
com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
|
com.android.internal.R.styleable.AndroidManifestApplication_permission, 0);
|
||||||
|
|||||||
@@ -17,10 +17,7 @@
|
|||||||
package android.security;
|
package android.security;
|
||||||
|
|
||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.security.net.config.ApplicationConfig;
|
import android.security.net.config.ApplicationConfig;
|
||||||
import android.security.net.config.ManifestConfigSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Network security policy.
|
* Network security policy.
|
||||||
@@ -93,19 +90,6 @@ public class NetworkSecurityPolicy {
|
|||||||
libcore.net.NetworkSecurityPolicy.setInstance(policy);
|
libcore.net.NetworkSecurityPolicy.setInstance(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an {@link ApplicationConfig} based on the configuration for {@code packageName}.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static ApplicationConfig getApplicationConfigForPackage(Context context,
|
|
||||||
String packageName) throws PackageManager.NameNotFoundException {
|
|
||||||
Context appContext = context.createPackageContext(packageName, 0);
|
|
||||||
ManifestConfigSource source = new ManifestConfigSource(appContext);
|
|
||||||
return new ApplicationConfig(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle an update to the system or user certificate stores.
|
* Handle an update to the system or user certificate stores.
|
||||||
* @hide
|
* @hide
|
||||||
|
|||||||
@@ -18,25 +18,24 @@ package android.security.net.config;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public class ManifestConfigSource implements ConfigSource {
|
public class ManifestConfigSource implements ConfigSource {
|
||||||
public static final String META_DATA_NETWORK_SECURITY_CONFIG =
|
|
||||||
"android.security.net.config";
|
|
||||||
private static final boolean DBG = true;
|
private static final boolean DBG = true;
|
||||||
private static final String LOG_TAG = "NetworkSecurityConfig";
|
private static final String LOG_TAG = "NetworkSecurityConfig";
|
||||||
|
|
||||||
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 ConfigSource mConfigSource;
|
private ConfigSource mConfigSource;
|
||||||
|
|
||||||
public ManifestConfigSource(Context context) {
|
public ManifestConfigSource(Context context, ApplicationInfo info) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mInfo = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -54,22 +53,15 @@ public class ManifestConfigSource implements ConfigSource {
|
|||||||
if (mConfigSource != null) {
|
if (mConfigSource != null) {
|
||||||
return mConfigSource;
|
return mConfigSource;
|
||||||
}
|
}
|
||||||
ApplicationInfo info;
|
int targetSdkVersion = mInfo.targetSdkVersion;
|
||||||
try {
|
|
||||||
info = mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(),
|
|
||||||
PackageManager.GET_META_DATA);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
throw new RuntimeException("Failed to look up ApplicationInfo", e);
|
|
||||||
}
|
|
||||||
int targetSdkVersion = info.targetSdkVersion;
|
|
||||||
int configResourceId = 0;
|
int configResourceId = 0;
|
||||||
if (info != null && info.metaData != null) {
|
if (mInfo != null) {
|
||||||
configResourceId = info.metaData.getInt(META_DATA_NETWORK_SECURITY_CONFIG);
|
configResourceId = mInfo.networkSecurityConfigRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigSource source;
|
ConfigSource source;
|
||||||
if (configResourceId != 0) {
|
if (configResourceId != 0) {
|
||||||
boolean debugBuild = (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
boolean debugBuild = (mInfo.flags & 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(configResourceId)
|
||||||
@@ -82,7 +74,7 @@ public class ManifestConfigSource implements ConfigSource {
|
|||||||
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 =
|
||||||
(info.flags & ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0;
|
(mInfo.flags & ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0;
|
||||||
source = new DefaultConfigSource(usesCleartextTraffic, targetSdkVersion);
|
source = new DefaultConfigSource(usesCleartextTraffic, targetSdkVersion);
|
||||||
}
|
}
|
||||||
mConfigSource = source;
|
mConfigSource = source;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
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;
|
||||||
|
|
||||||
@@ -32,8 +33,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) {
|
public static void install(Context context, ApplicationInfo info) {
|
||||||
ApplicationConfig config = new ApplicationConfig(new ManifestConfigSource(context));
|
ApplicationConfig config = new ApplicationConfig(new ManifestConfigSource(context, info));
|
||||||
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) {
|
||||||
|
|||||||
@@ -1178,6 +1178,9 @@
|
|||||||
-->
|
-->
|
||||||
<attr name="autoVerify" format="boolean" />
|
<attr name="autoVerify" format="boolean" />
|
||||||
|
|
||||||
|
<!-- An XML resource with the application's Network Security Config. -->
|
||||||
|
<attr name="networkSecurityConfig" format="reference" />
|
||||||
|
|
||||||
<!-- The <code>manifest</code> tag is the root of an
|
<!-- The <code>manifest</code> tag is the root of an
|
||||||
<code>AndroidManifest.xml</code> file,
|
<code>AndroidManifest.xml</code> file,
|
||||||
describing the contents of an Android package (.apk) file. One
|
describing the contents of an Android package (.apk) file. One
|
||||||
@@ -1313,6 +1316,7 @@
|
|||||||
<attr name="defaultToDeviceProtectedStorage" format="boolean" />
|
<attr name="defaultToDeviceProtectedStorage" format="boolean" />
|
||||||
<attr name="directBootAware" />
|
<attr name="directBootAware" />
|
||||||
<attr name="resizeableActivity" />
|
<attr name="resizeableActivity" />
|
||||||
|
<attr name="networkSecurityConfig" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
<!-- The <code>permission</code> tag declares a security permission that can be
|
<!-- The <code>permission</code> tag declares a security permission that can be
|
||||||
used to control access from other packages to specific components or
|
used to control access from other packages to specific components or
|
||||||
|
|||||||
@@ -2718,6 +2718,7 @@
|
|||||||
<public type="attr" name="numberPickerStyle" />
|
<public type="attr" name="numberPickerStyle" />
|
||||||
<public type="attr" name="enableVrMode" />
|
<public type="attr" name="enableVrMode" />
|
||||||
<public type="attr" name="hash" />
|
<public type="attr" name="hash" />
|
||||||
|
<public type="attr" name="networkSecurityConfig" />
|
||||||
|
|
||||||
<public type="style" name="Theme.Material.Light.DialogWhenLarge.DarkActionBar" />
|
<public type="style" name="Theme.Material.Light.DialogWhenLarge.DarkActionBar" />
|
||||||
<public type="style" name="Widget.Material.SeekBar.Discrete" />
|
<public type="style" name="Widget.Material.SeekBar.Discrete" />
|
||||||
|
|||||||
Reference in New Issue
Block a user