Merge "Add ConfigNetworkSecurityPolicy"
am: 2786002bd5
* commit '2786002bd51b229d9a4672e3c43f835796de06ea':
Add ConfigNetworkSecurityPolicy
This commit is contained in:
@@ -120,6 +120,32 @@ public final class ApplicationConfig {
|
|||||||
return mTrustManager;
|
return mTrustManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if cleartext traffic is permitted for this application, which is the
|
||||||
|
* case only if all configurations permit cleartext traffic. For finer-grained policy use
|
||||||
|
* {@link #isCleartextTrafficPermitted(String)}.
|
||||||
|
*/
|
||||||
|
public boolean isCleartextTrafficPermitted() {
|
||||||
|
ensureInitialized();
|
||||||
|
if (mConfigs != null) {
|
||||||
|
for (Pair<Domain, NetworkSecurityConfig> entry : mConfigs) {
|
||||||
|
if (!entry.second.isCleartextTrafficPermitted()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mDefaultConfig.isCleartextTrafficPermitted();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if cleartext traffic is permitted for this application when connecting
|
||||||
|
* to {@code hostname}.
|
||||||
|
*/
|
||||||
|
public boolean isCleartextTrafficPermitted(String hostname) {
|
||||||
|
return getConfigForHostname(hostname).isCleartextTrafficPermitted();
|
||||||
|
}
|
||||||
|
|
||||||
private void ensureInitialized() {
|
private void ensureInitialized() {
|
||||||
synchronized(mLock) {
|
synchronized(mLock) {
|
||||||
if (mInitialized) {
|
if (mInitialized) {
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015, The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package android.security.net.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link libcore.net.NetworkSecurityPolicy} based on an {@link ApplicationConfig}.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public class ConfigNetworkSecurityPolicy extends libcore.net.NetworkSecurityPolicy {
|
||||||
|
private final ApplicationConfig mConfig;
|
||||||
|
|
||||||
|
public ConfigNetworkSecurityPolicy(ApplicationConfig config) {
|
||||||
|
mConfig = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCleartextTrafficPermitted() {
|
||||||
|
return mConfig.isCleartextTrafficPermitted();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCleartextTrafficPermitted(String hostname) {
|
||||||
|
return mConfig.isCleartextTrafficPermitted(hostname);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,5 +40,6 @@ public final class NetworkSecurityConfigProvider extends Provider {
|
|||||||
throw new RuntimeException("Failed to install provider as highest priority provider."
|
throw new RuntimeException("Failed to install provider as highest priority provider."
|
||||||
+ " Provider was installed at position " + pos);
|
+ " Provider was installed at position " + pos);
|
||||||
}
|
}
|
||||||
|
libcore.net.NetworkSecurityPolicy.setInstance(new ConfigNetworkSecurityPolicy(config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user