Search in sources :

Example 1 with LoadedApk

use of android.app.LoadedApk in project android_frameworks_base by ResurrectionRemix.

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 2 with LoadedApk

use of android.app.LoadedApk in project android_frameworks_base by DirtyUnicorns.

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 3 with LoadedApk

use of android.app.LoadedApk in project android_frameworks_base by AOSPA.

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 4 with LoadedApk

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

the class ParallelUniverse method setUpApplicationState.

@Override
public void setUpApplicationState(Method method, TestLifecycle testLifecycle, AndroidManifest appManifest, Config config, ResourceTable compileTimeResourceTable, ResourceTable appResourceTable, ResourceTable systemResourceTable) {
    ReflectionHelpers.setStaticField(RuntimeEnvironment.class, "apiLevel", sdkConfig.getApiLevel());
    RuntimeEnvironment.application = null;
    RuntimeEnvironment.setMasterScheduler(new Scheduler());
    RuntimeEnvironment.setMainThread(Thread.currentThread());
    DefaultPackageManager packageManager = new DefaultPackageManager();
    RuntimeEnvironment.setRobolectricPackageManager(packageManager);
    RuntimeEnvironment.setCompileTimeResourceTable(compileTimeResourceTable);
    RuntimeEnvironment.setAppResourceTable(appResourceTable);
    RuntimeEnvironment.setSystemResourceTable(systemResourceTable);
    initializeAppManifest(appManifest, appResourceTable, packageManager);
    packageManager.setDependencies(appManifest, appResourceTable);
    if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
        Security.insertProviderAt(new BouncyCastleProvider(), 1);
    }
    String qualifiers = Qualifiers.addPlatformVersion(config.qualifiers(), sdkConfig.getApiLevel());
    qualifiers = Qualifiers.addSmallestScreenWidth(qualifiers, 320);
    qualifiers = Qualifiers.addScreenWidth(qualifiers, 320);
    Resources systemResources = Resources.getSystem();
    Configuration configuration = systemResources.getConfiguration();
    configuration.smallestScreenWidthDp = Qualifiers.getSmallestScreenWidth(qualifiers);
    configuration.screenWidthDp = Qualifiers.getScreenWidth(qualifiers);
    systemResources.updateConfiguration(configuration, systemResources.getDisplayMetrics());
    RuntimeEnvironment.setQualifiers(qualifiers);
    Class<?> contextImplClass = ReflectionHelpers.loadClass(getClass().getClassLoader(), shadowsAdapter.getShadowContextImplClassName());
    Class<?> activityThreadClass = ReflectionHelpers.loadClass(getClass().getClassLoader(), shadowsAdapter.getShadowActivityThreadClassName());
    // Looper needs to be prepared before the activity thread is created
    if (Looper.myLooper() == null) {
        Looper.prepareMainLooper();
    }
    ShadowLooper.getShadowMainLooper().resetScheduler();
    Object activityThread = ReflectionHelpers.newInstance(activityThreadClass);
    RuntimeEnvironment.setActivityThread(activityThread);
    ReflectionHelpers.setField(activityThread, "mInstrumentation", new RoboInstrumentation());
    ReflectionHelpers.setField(activityThread, "mCompatConfiguration", configuration);
    Context systemContextImpl = ReflectionHelpers.callStaticMethod(contextImplClass, "createSystemContext", ClassParameter.from(activityThreadClass, activityThread));
    final Application application = (Application) testLifecycle.createApplication(method, appManifest, config);
    RuntimeEnvironment.application = application;
    if (application != null) {
        shadowsAdapter.bind(application, appManifest);
        ApplicationInfo applicationInfo;
        try {
            applicationInfo = packageManager.getApplicationInfo(appManifest.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }
        Class<?> compatibilityInfoClass = ReflectionHelpers.loadClass(getClass().getClassLoader(), "android.content.res.CompatibilityInfo");
        LoadedApk loadedApk = ReflectionHelpers.callInstanceMethod(activityThread, "getPackageInfo", ClassParameter.from(ApplicationInfo.class, applicationInfo), ClassParameter.from(compatibilityInfoClass, null), ClassParameter.from(int.class, Context.CONTEXT_INCLUDE_CODE));
        try {
            Context contextImpl = systemContextImpl.createPackageContext(applicationInfo.packageName, Context.CONTEXT_INCLUDE_CODE);
            ReflectionHelpers.setField(activityThreadClass, activityThread, "mInitialApplication", application);
            ApplicationTestUtil.attach(application, contextImpl);
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }
        Resources appResources = application.getResources();
        ReflectionHelpers.setField(loadedApk, "mResources", appResources);
        ReflectionHelpers.setField(loadedApk, "mApplication", application);
        appResources.updateConfiguration(configuration, appResources.getDisplayMetrics());
        application.onCreate();
    }
}
Also used : Context(android.content.Context) Configuration(android.content.res.Configuration) LoadedApk(android.app.LoadedApk) Scheduler(org.robolectric.util.Scheduler) RoboInstrumentation(org.robolectric.android.fakes.RoboInstrumentation) DefaultPackageManager(org.robolectric.res.builder.DefaultPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) PackageManager(android.content.pm.PackageManager) DefaultPackageManager(org.robolectric.res.builder.DefaultPackageManager) Resources(android.content.res.Resources) Application(android.app.Application) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 5 with LoadedApk

use of android.app.LoadedApk in project android_frameworks_base by crdroidandroid.

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)

Aggregations

LoadedApk (android.app.LoadedApk)9 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)3 Context (android.content.Context)3 PackageManager (android.content.pm.PackageManager)3 ActivityThread (android.app.ActivityThread)2 ComponentName (android.content.ComponentName)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 Resources (android.content.res.Resources)2 ShadowContextImpl._ContextImpl_ (org.robolectric.shadows.ShadowContextImpl._ContextImpl_)2 ShadowLoadedApk._LoadedApk_ (org.robolectric.shadows.ShadowLoadedApk._LoadedApk_)2 Instrumentation (android.app.Instrumentation)1 ActivityInfo (android.content.pm.ActivityInfo)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1