Add getApplicationConfigForPackage

getApplicationConfigForPackage will be used by system components that
need to make connections for apps, e.g. DownloadManager, so that their
secure connections have the same configuration as those from the app
itself.

Bug: 29505888
Change-Id: Idf1cac6307431911eda34529d3fd50f9ca0da314
This commit is contained in:
Chad Brubaker
2016-06-20 12:40:20 -07:00
parent 7c6692646c
commit 9f779ab4af

View File

@@ -17,7 +17,10 @@
package android.security;
import android.annotation.TestApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.security.net.config.ApplicationConfig;
import android.security.net.config.ManifestConfigSource;
/**
* Network security policy.
@@ -98,4 +101,16 @@ public class NetworkSecurityPolicy {
public void handleTrustStorageUpdate() {
ApplicationConfig.getDefaultInstance().handleTrustStorageUpdate();
}
/**
* 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);
}
}