Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 056e8b5a authored by Chad Brubaker's avatar Chad Brubaker
Browse files

Add getApplicationConfigForPackage

This allows services which make network connections on behalf of
applications to honor the application's network security policy.

Change-Id: I562b7bd0eb20f2f8c9f8342c211166d4e3397780
parent b7fbe110
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package android.security;

import android.content.Context;
import android.content.pm.PackageManager;
import android.security.net.config.ApplicationConfig;
import android.security.net.config.ManifestConfigSource;

/**
 * Network security policy.
 *
@@ -87,4 +92,17 @@ public class NetworkSecurityPolicy {
        FrameworkNetworkSecurityPolicy policy = new FrameworkNetworkSecurityPolicy(permitted);
        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);
    }
}