Java Code Examples for android.app.Application#getBaseContext()

The following examples show how to use android.app.Application#getBaseContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GPTInstrumentation.java    From GPT with Apache License 2.0 5 votes vote down vote up
/**
 * onCallApplicationOnCreate
 *
 * @param app Application
 */
private void onCallApplicationOnCreate(Application app) {
    String packageName = app.getPackageName();
    boolean isPlugin = isPlugin(packageName);

    if (!isPlugin) {
        return;
    }

    // Begin:【FixBug】解决在中兴手机上找不到资源的问题,中兴部分手机的ROM上自己继承ContextImpl实现了一个AppContextImpl,
    // 里面做一些BaseContext的复用,导致插件获取Resources时可能会取到宿主的。
    try {
        Class<?> clsCtxImpl = Class.forName("android.app.ContextImpl");
        Object base = app.getBaseContext();
        if (base.getClass() != clsCtxImpl) {
            Constructor<?> cst = clsCtxImpl.getConstructor(clsCtxImpl);
            Object impl = cst.newInstance(base);
            JavaCalls.setField(app, "mBase", impl);
        }
    } catch (Exception e) {

        if (DEBUG) {
            e.printStackTrace();
        }
        if (ProxyEnvironment.hasInstance(app.getPackageName())) {
            ReportManger.getInstance().onException(
                    ProxyEnvironment.getInstance(app.getPackageName()).getApplicationProxy(), packageName,
                    Util.getCallStack(e), ExceptionConstants.TJ_78730010);
        }
    }

    replacePluginPackageName2Host(app);
    replaceSystemServices(app);
    replaceExternalDirs(app);

    ProxyUtil.replaceSystemServices(app);
}
 
Example 2
Source File: FreelineCore.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Object getPackageInfo(Application app) throws NoSuchFieldException,
        IllegalArgumentException, IllegalAccessException {
    Context contextImpl = app.getBaseContext();
    Field mPackageInfoField = contextImpl.getClass().getDeclaredField(
            "mPackageInfo");
    mPackageInfoField.setAccessible(true);
    Object mPackageInfo = mPackageInfoField.get(contextImpl);
    return mPackageInfo;
}
 
Example 3
Source File: PluginManager.java    From ZeusPlugin with MIT License 5 votes vote down vote up
/**
 * 得在插件相关的方法调用之前调用
 *
 * @param application application
 */
public static void init(Application application, HashMap<String, Integer> defaultList) {
    if(defaultList == null){
        mDefaultList = new HashMap<>();
    }else{
        mDefaultList = defaultList;
    }
    //初始化一些成员变量和加载已安装的插件
    mPackageInfo = PluginUtil.getField(application.getBaseContext(), "mPackageInfo");
    mBaseContext = application.getBaseContext();
    mNowClassLoader = mBaseContext.getClassLoader();
    mBaseClassLoader = mBaseContext.getClassLoader();
    mNowResources = mBaseContext.getResources();
    mBaseResources = mNowResources;
    //更改系统的Instrumentation对象,以便创建插件的activity
    Object mMainThread = PluginUtil.getField(mBaseContext, "mMainThread");
    PluginUtil.setField(mMainThread, "mInstrumentation", new ZeusInstrumentation());
    //创建插件的相关文件夹目录
    createPath();
    //加载已安装过的插件
    loadInstalledPlugins();
    //清除老版本的插件,最好放到软件退出时调用,防止让启动速度变慢
    clearOldPlugin();
    //安装内置插件
    Thread initPluginThread = new Thread(new Runnable() {
        @Override
        public void run() {
            installInitPlugins();
        }
    });
    initPluginThread.setName("initPluginThread");
    initPluginThread.start();
}
 
Example 4
Source File: SerieCsvExporterFactory.java    From CineLog with GNU General Public License v3.0 4 votes vote down vote up
public SerieCsvExporterFactory(Application application) {
    this(new SerieService(((KinoApplication) application).getDaoSession(), application.getBaseContext()));
}