Android Open Source - AndroidPlugin Plugin Delegate Content Provider Impl






From Project

Back to project page AndroidPlugin.

License

The source code is released under:

MIT License

If you think the Android project AndroidPlugin listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.limemobile.app.plugin.internal;
//from ww w  .j  ava2s.  c o m
import java.lang.reflect.Constructor;

import android.annotation.TargetApi;
import android.content.ContentProvider;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.ProviderInfo;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.os.Build;
import android.text.TextUtils;

import com.limemobile.app.plugin.IPluginContentProvider;

public class PluginDelegateContentProviderImpl {
  protected String mPluginClientContentProviderClass;
  protected String mPluginClientPackageName;

  protected PluginClientInfo mPluginClient;
  protected PluginClientManager mPluginManager;

  protected AssetManager mAssetManager;
  protected Resources mResources;
  protected Theme mTheme;

  protected ProviderInfo mProviderInfo;
  protected ContentProvider mPluginHostContentProvider;
  protected IPluginContentProvider mDelegatedContentProvider;

  public PluginDelegateContentProviderImpl(ContentProvider provider) {
    mPluginHostContentProvider = provider;
  }

  public void onCreate(Intent intent) {
    mPluginClientPackageName = intent
        .getStringExtra(PluginClientManager.INTENT_EXTRA_PLUGIN_CLIENT_PACKAGE_NAME);
    mPluginClientContentProviderClass = intent
        .getStringExtra(PluginClientManager.INTENT_EXTRA_PLUGIN_CLIENT_CONTENT_PROVIDER_CLASS);

    mPluginManager = PluginClientManager
        .sharedInstance(mPluginHostContentProvider.getContext());
    mPluginClient = mPluginManager
        .getPluginClient(mPluginClientPackageName);
    mAssetManager = mPluginClient.mAssetManager;
    mResources = mPluginClient.mResources;

    initializeContentProviderInfo();

    launchTargetContentProvider();
  }

  private void initializeContentProviderInfo() {
    PackageInfo packageInfo = mPluginClient.mClientPackageInfo;
    if ((packageInfo.providers != null)
        && (packageInfo.providers.length > 0)) {
      if (TextUtils.isEmpty(mPluginClientContentProviderClass)) {
        mPluginClientContentProviderClass = packageInfo.providers[0].name;
      }
      for (ProviderInfo a : packageInfo.providers) {
        if (a.name.equals(mPluginClientContentProviderClass)) {
          mProviderInfo = a;
        }
      }
    }
  }

  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  protected void launchTargetContentProvider() {
    try {
      Class<?> localClass = getClassLoader().loadClass(
          mPluginClientContentProviderClass);
      Constructor<?> localConstructor = localClass
          .getConstructor(new Class[] {});
      Object instance = localConstructor.newInstance(new Object[] {});
      if (!(instance instanceof IPluginContentProvider)) {
        throw new IllegalArgumentException();
      }
      mDelegatedContentProvider = (IPluginContentProvider) instance;
      ((IPluginContentProviderDelegate) mPluginHostContentProvider)
          .attach(mDelegatedContentProvider);

      mDelegatedContentProvider.setDelegate(mPluginHostContentProvider,
          mPluginClient);

      mDelegatedContentProvider.onCreate();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public ClassLoader getClassLoader() {
    return mPluginClient.mClassLoader;
  }

  public AssetManager getAssets() {
    return mAssetManager;
  }

  public Resources getResources() {
    return mResources;
  }

  public Theme getTheme() {
    return mTheme;
  }

  public IPluginContentProvider getRemoteContentProvider() {
    return mDelegatedContentProvider;
  }

}




Java Source Code List

android.widget.ViewStub.java
androidx.plmgrdemo.MainActivity.java
androidx.plmgrdemo.PlugListViewAdapter.java
androidx.pluginmgr.ActivityClassGenerator.java
androidx.pluginmgr.ActivityOverider.java
androidx.pluginmgr.FileUtil.java
androidx.pluginmgr.FrameworkClassLoader.java
androidx.pluginmgr.LayoutInflaterWrapper.java
androidx.pluginmgr.PlugInfo.java
androidx.pluginmgr.PluginActivityLifeCycleCallback.java
androidx.pluginmgr.PluginClassLoader.java
androidx.pluginmgr.PluginContextWrapper.java
androidx.pluginmgr.PluginManager.java
androidx.pluginmgr.PluginManifestUtil.java
androidx.pluginmgr.ReflectionUtils.java
androidx.pluginmgr.XmlManifestReader.java
com.limemobile.app.demo.pluginclienta.ClientABindService.java
com.limemobile.app.demo.pluginclienta.ClientAStartedService.java
com.limemobile.app.demo.pluginclienta.MainActivity.java
com.limemobile.app.demo.pluginclienta.TestButton.java
com.limemobile.app.demo.pluginclienta.TestFragmentActivity.java
com.limemobile.app.demo.pluginclienta.TestFragment.java
com.limemobile.app.demo.pluginclientb.ClientBStartedService.java
com.limemobile.app.demo.pluginclientb.MainActivity.java
com.limemobile.app.demo.pluginhost.HostBindService.java
com.limemobile.app.demo.pluginhost.HostStartedService.java
com.limemobile.app.demo.pluginhost.MainActivity.java
com.limemobile.app.demo.pluginhost.MyApplication.java
com.limemobile.app.demo.pluginhost.TestHostClass.java
com.limemobile.app.plugin.IPluginActivity.java
com.limemobile.app.plugin.IPluginContentProvider.java
com.limemobile.app.plugin.IPluginService.java
com.limemobile.app.plugin.PluginClientActivity.java
com.limemobile.app.plugin.PluginClientFragmentActivity.java
com.limemobile.app.plugin.PluginClientService.java
com.limemobile.app.plugin.PluginHostApplication.java
com.limemobile.app.plugin.PluginHostContentProvider.java
com.limemobile.app.plugin.PluginHostDelegateActivity.java
com.limemobile.app.plugin.PluginHostDelegateContentProvider.java
com.limemobile.app.plugin.PluginHostDelegateFragmentActivity.java
com.limemobile.app.plugin.PluginHostDelegateService.java
com.limemobile.app.plugin.internal.IPluginActivityDelegate.java
com.limemobile.app.plugin.internal.IPluginContentProviderDelegate.java
com.limemobile.app.plugin.internal.IPluginServiceDelegate.java
com.limemobile.app.plugin.internal.PluginClientDexClassLoader.java
com.limemobile.app.plugin.internal.PluginClientInfo.java
com.limemobile.app.plugin.internal.PluginClientManager.java
com.limemobile.app.plugin.internal.PluginDelegateActivityImpl.java
com.limemobile.app.plugin.internal.PluginDelegateContentProviderImpl.java
com.limemobile.app.plugin.internal.PluginDelegateServiceImpl.java
com.limemobile.app.plugin.internal.ReflectFieldAccessor.java