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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user