android.content.Context.getClassLoader()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中android.content.Context.getClassLoader()方法的一些代码示例,展示了Context.getClassLoader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getClassLoader()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getClassLoader

Context.getClassLoader介绍

暂无

代码示例

代码示例来源:origin: xfumihiro/ViewInspector

private ViewProxyBuilder(Context context, Class<T> clazz) {
 mContext = context;
 mBaseClass = clazz;
 mParentClassLoader = context.getClassLoader();
}

代码示例来源:origin: oasisfeng/condom

@Override public ClassLoader getClassLoader() {
  return mBase.getClassLoader();
}

代码示例来源:origin: xfumihiro/ViewInspector

/**
 * Loads class for the given class name.
 */
static Class<?> loadViewClass(Context context, String name) throws ClassNotFoundException {
 return context.getClassLoader().loadClass(name).asSubclass(View.class);
}

代码示例来源:origin: Tencent/tinker

private void storeAndReplaceOriginalComponentName(Intent intent, String origPackageName, String origClassName, String stubClassName) {
  final ComponentName origComponentName = new ComponentName(origPackageName, origClassName);
  ShareIntentUtil.fixIntentClassLoader(intent, mContext.getClassLoader());
  intent.putExtra(EnvConsts.INTENT_EXTRA_OLD_COMPONENT, origComponentName);
  final ComponentName stubComponentName = new ComponentName(origPackageName, stubClassName);
  intent.setComponent(stubComponentName);
}

代码示例来源:origin: facebook/facebook-android-sdk

@Nullable
private static Class<?> getClass(Context context, String className) {
  Class<?> classObj = classMap.get(className);
  if (classObj != null) {
    return classObj;
  }
  try {
    classObj = context.getClassLoader().loadClass(className);
    classMap.put(className, classObj);
  } catch (ClassNotFoundException e) {
    Log.e(
        TAG,
        className + " is not available, please add "
            + className + " to the project.",
        e);
  }
  return classObj;
}

代码示例来源:origin: android-hacker/VirtualXposed

public ClassLoader getClassLoader(String packageName) {
  Context context = createPackageContext(packageName);
  return context.getClassLoader();
}

代码示例来源:origin: android-hacker/VirtualXposed

public ClassLoader getClassLoader(ApplicationInfo appInfo) {
  Context context = createPackageContext(appInfo.packageName);
  return context.getClassLoader();
}

代码示例来源:origin: facebook/facebook-android-sdk

private ParcelableResourceWithMimeType(Parcel in) {
    mimeType = in.readString();
    resource = in.readParcelable(FacebookSdk.getApplicationContext().getClassLoader());
  }
}

代码示例来源:origin: Tencent/tinker

@Override
public Activity newActivity(Class<?> clazz, Context context, IBinder token, Application application, Intent intent, ActivityInfo info, CharSequence title, Activity parent, String id, Object lastNonConfigurationInstance) throws InstantiationException, IllegalAccessException {
  processIntent(context.getClassLoader(), intent);
  return super.newActivity(clazz, context, token, application, intent, info, title, parent, id, lastNonConfigurationInstance);
}

代码示例来源:origin: oasisfeng/condom

@SuppressLint("PrivateApi") private static void installCondomProcessPackageManager(final CondomCore condom)
    throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
  final Class<?> ActivityThread = Class.forName("android.app.ActivityThread");
  final Field ActivityThread_sPackageManager = ActivityThread.getDeclaredField("sPackageManager");
  ActivityThread_sPackageManager.setAccessible(true);
  final Class<?> IPackageManager = Class.forName("android.content.pm.IPackageManager");
  final Object pm = ActivityThread_sPackageManager.get(null);
  final InvocationHandler handler;
  if (Proxy.isProxyClass(pm.getClass()) && (handler = Proxy.getInvocationHandler(pm)) instanceof CondomProcessPackageManager) {
    Log.w(TAG, "CondomPackageManager was already installed in this process.");
    ((CondomProcessPackageManager) handler).mCondom = condom;
  } else {
    final Object condom_pm = Proxy.newProxyInstance(condom.mBase.getClassLoader(), new Class[] { IPackageManager },
        new CondomProcessPackageManager(condom, pm));
    ActivityThread_sPackageManager.set(null, condom_pm);
  }
}

代码示例来源:origin: androidquery/androidquery

private static String getSource(Context context){
  
  if(template == null){
  
    try{
      InputStream is = context.getClassLoader().getResourceAsStream("com/androidquery/util/web_image.html");			
      template = new String(AQUtility.toBytes(is));
    }catch(Exception e){
      AQUtility.debug(e);
    }
    
  }
  
  return template;
  
}

代码示例来源:origin: android-hacker/VirtualXposed

public static IBinder getProxyService(Context context, ComponentName component, IBinder binder) {
  if (context == null || binder == null) {
    return null;
  }
  try {
    String description = binder.getInterfaceDescriptor();
    ServiceFetcher fetcher = sHookSecondaryServiceMap.get(description);
    if (fetcher != null) {
      IBinder res = fetcher.getService(context, context.getClassLoader(), binder);
      if (res != null) {
        return res;
      }
    }
  } catch (Throwable e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: mikepenz/AboutLibraries

public static List<Library> detect(Context mCtx, List<Library> libraries) {
    ArrayList<Library> foundLibraries = new ArrayList<>();
    // Loop through known libraries
    for (Library library : libraries) {
      if (!TextUtils.isEmpty(library.getClassPath())) {
        try {
          Context ctx = mCtx.createPackageContext(mCtx.getPackageName(),
              Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
          Class<?> clazz = Class.forName(library.getClassPath(), false, ctx.getClassLoader());

          // Detected a library!!!
          if (clazz != null) {
            foundLibraries.add(library);
          }
        } catch (ClassNotFoundException e) {
          //e.printStackTrace();
        } catch (PackageManager.NameNotFoundException e) {
          //e.printStackTrace();
        }
      }
    }
    // Only return AppSource if app has a library
    //return libraries.size() > 0 ? new AppSource(pkg, libraries) : null;

    return foundLibraries;
  }
}

代码示例来源:origin: k9mail/k-9

/**
 * InputStream and OutputStreams are always closed after operating on them!
 */
private Intent executeApi(Intent data, ParcelFileDescriptor input, int outputPipeId) {
  try {
    // always send version from client
    data.putExtra(EXTRA_API_VERSION, OpenPgpApi.API_VERSION);
    Intent result;
    // blocks until result is ready
    result = mService.execute(data, input, outputPipeId);
    // set class loader to current context to allow unparcelling
    // of OpenPgpError and OpenPgpSignatureResult
    // http://stackoverflow.com/a/3806769
    result.setExtrasClassLoader(mContext.getClassLoader());
    return result;
  } catch (Exception e) {
    Log.e(OpenPgpApi.TAG, "Exception in executeApi call", e);
    Intent result = new Intent();
    result.putExtra(RESULT_CODE, RESULT_CODE_ERROR);
    result.putExtra(RESULT_ERROR,
        new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
    return result;
  } finally {
    // close() is required to halt the TransferThread
    closeLoudly(input);
  }
}

代码示例来源:origin: tiann/understand-plugin-framework

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  Button t = new Button(this);
  t.setText("test button");
  setContentView(t);
  Log.d(TAG, "context classloader: " + getApplicationContext().getClassLoader());
  t.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      try {
        Intent t = new Intent();
        if (HOOK_METHOD == PATCH_BASE_CLASS_LOADER) {
          t.setComponent(new ComponentName("com.weishu.upf.dynamic_proxy_hook.app2",
              "com.weishu.upf.dynamic_proxy_hook.app2.MainActivity"));
        } else {
          t.setComponent(new ComponentName("com.weishu.upf.ams_pms_hook.app",
              "com.weishu.upf.ams_pms_hook.app.MainActivity"));
        }
        startActivity(t);
      } catch (Throwable e) {
        e.printStackTrace();
      }
    }
  });
}

代码示例来源:origin: Tencent/tinker

ShareIntentUtil.fixIntentClassLoader(maybeHackedIntent, mContext.getClassLoader());

代码示例来源:origin: andkulikov/Transitions-Everywhere

Constructor constructor = sConstructors.get(className);
if (constructor == null) {
  Class c = mContext.getClassLoader().loadClass(className)
      .asSubclass(expectedType);
  if (c != null) {

代码示例来源:origin: android-hacker/VirtualXposed

private void handleReceiver(ReceiverData data) {
  BroadcastReceiver.PendingResult result = data.resultData.build();
  try {
    if (!isBound()) {
      bindApplication(data.component.getPackageName(), data.processName);
    }
    Context context = mInitialApplication.getBaseContext();
    Context receiverContext = ContextImpl.getReceiverRestrictedContext.call(context);
    String className = data.component.getClassName();
    BroadcastReceiver receiver = (BroadcastReceiver) context.getClassLoader().loadClass(className).newInstance();
    mirror.android.content.BroadcastReceiver.setPendingResult.call(receiver, result);
    data.intent.setExtrasClassLoader(context.getClassLoader());
    if (data.intent.getComponent() == null) {
      data.intent.setComponent(data.component);
    }
    receiver.onReceive(receiverContext, data.intent);
    if (mirror.android.content.BroadcastReceiver.getPendingResult.call(receiver) != null) {
      result.finish();
    }
  } catch (Exception e) {
    // must be this for misjudge of anti-virus!!
    throw new RuntimeException(String.format("Unable to start receiver: %s ", data.component), e);
  }
  VActivityManager.get().broadcastFinish(data.resultData);
}

代码示例来源:origin: Tencent/tinker

return false;
ClassLoader classLoader = context.getClassLoader();
if (classLoader == null) {
  TinkerLog.e(TAG, "classloader is null");

代码示例来源:origin: tiann/understand-plugin-framework

@Override
protected void attachBaseContext(Context newBase) {
  super.attachBaseContext(newBase);
  try {
    Utils.extractAssets(newBase, "dynamic-proxy-hook.apk");
    Utils.extractAssets(newBase, "ams-pms-hook.apk");
    Utils.extractAssets(newBase, "test.apk");
    if (HOOK_METHOD == PATCH_BASE_CLASS_LOADER) {
      File dexFile = getFileStreamPath("test.apk");
      File optDexFile = getFileStreamPath("test.dex");
      BaseDexClassLoaderHookHelper.patchClassLoader(getClassLoader(), dexFile, optDexFile);
    } else {
      LoadedApkClassLoaderHookHelper.hookLoadedApkInActivityThread(getFileStreamPath("ams-pms-hook.apk"));
    }
    AMSHookHelper.hookActivityManagerNative();
    AMSHookHelper.hookActivityThreadHandler();
  } catch (Throwable e) {
    e.printStackTrace();
  }
}

相关文章

Context类方法