Search in sources :

Example 6 with LoadedApk

use of android.app.LoadedApk in project platform_frameworks_base by android.

the class CaptivePortalLoginActivity method setWebViewProxy.

// Find WebView's proxy BroadcastReceiver and prompt it to read proxy system properties.
private void setWebViewProxy() {
    LoadedApk loadedApk = getApplication().mLoadedApk;
    try {
        Field receiversField = LoadedApk.class.getDeclaredField("mReceivers");
        receiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object rec : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = rec.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(rec, getApplicationContext(), intent);
                    Log.v(TAG, "Prompting WebView proxy reload.");
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception while setting WebView proxy: " + e);
    }
}
Also used : Field(java.lang.reflect.Field) LoadedApk(android.app.LoadedApk) ArrayMap(android.util.ArrayMap) Intent(android.content.Intent) Method(java.lang.reflect.Method) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InterruptedException(java.lang.InterruptedException)

Example 7 with LoadedApk

use of android.app.LoadedApk in project platform_frameworks_base by android.

the class CaptivePortalLoginActivity method setWebViewProxy.

// Find WebView's proxy BroadcastReceiver and prompt it to read proxy system properties.
private void setWebViewProxy() {
    LoadedApk loadedApk = getApplication().mLoadedApk;
    try {
        Field receiversField = LoadedApk.class.getDeclaredField("mReceivers");
        receiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object rec : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = rec.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(rec, getApplicationContext(), intent);
                    Log.v(TAG, "Prompting WebView proxy reload.");
                }
            }
        }
    } catch (Exception e) {
        loge("Exception while setting WebView proxy: " + e);
    }
}
Also used : Field(java.lang.reflect.Field) LoadedApk(android.app.LoadedApk) ArrayMap(android.util.ArrayMap) Intent(android.content.Intent) Method(java.lang.reflect.Method) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

LoadedApk (android.app.LoadedApk)7 Intent (android.content.Intent)6 ArrayMap (android.util.ArrayMap)6 IOException (java.io.IOException)6 Field (java.lang.reflect.Field)6 Method (java.lang.reflect.Method)6 MalformedURLException (java.net.MalformedURLException)6 InterruptedException (java.lang.InterruptedException)5 Application (android.app.Application)1 Context (android.content.Context)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 Configuration (android.content.res.Configuration)1 Resources (android.content.res.Resources)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 RoboInstrumentation (org.robolectric.android.fakes.RoboInstrumentation)1 DefaultPackageManager (org.robolectric.res.builder.DefaultPackageManager)1 Scheduler (org.robolectric.util.Scheduler)1