/** * Load the listeners specified via meta-data name="listener" in the AndroidManifest. */ private void addListenersFromManifest(List<RunListener> listeners, PrintStream writer) { PackageManager pm = getContext().getPackageManager(); try { InstrumentationInfo instrInfo = pm.getInstrumentationInfo(getComponentName(), PackageManager.GET_META_DATA); Bundle b = instrInfo.metaData; if (b == null) { return; } String extraListenerList = b.getString(ARGUMENT_LISTENER); addListenersFromClassString(extraListenerList, listeners, writer); } catch (NameNotFoundException e) { // should never happen Log.wtf(LOG_TAG, String.format("Could not find component %s", getComponentName())); } }
@Override public InstrumentationInfo getInstrumentationInfo(ComponentName component, int flags) throws NameNotFoundException { LoadedPlugin plugin = mPluginManager.getLoadedPlugin(component); if (null != plugin) { return plugin.mInstrumentationInfos.get(component); } return this.mHostPackageManager.getInstrumentationInfo(component, flags); }
public static InstrumentationInfo generateInstrumentationInfo( VPackage.InstrumentationComponent i, int flags) { if (i == null) return null; if ((flags & PackageManager.GET_META_DATA) == 0) { return i.info; } InstrumentationInfo ii = new InstrumentationInfo(i.info); ii.metaData = i.metaData; return ii; }
@Override public InstrumentationInfo generateInstrumentationInfo( Object instrumentation, int flags) throws Exception { /* public static final InstrumentationInfo generateInstrumentationInfo( Instrumentation i, int flags) */ return super.generateInstrumentationInfo(instrumentation, flags); }
@Override public InstrumentationInfo generateInstrumentationInfo( Object instrumentation, int flags) throws Exception { /* public static final InstrumentationInfo generateInstrumentationInfo( Instrumentation i, int flags)*/ return super.generateInstrumentationInfo(instrumentation, flags); }
public InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags) throws Exception { Object data; synchronized (mInstrumentationObjCache) { data = mInstrumentationObjCache.get(className); } if (data != null) { return mParser.generateInstrumentationInfo(data, flags); } return null; }
@Override public InstrumentationInfo generateInstrumentationInfo( Object instrumentation, int flags) throws Exception { /* public static final InstrumentationInfo generateInstrumentationInfo( Instrumentation i, int flags)*/ Method method = MethodUtils.getAccessibleMethod(sPackageParserClass, "generateInstrumentationInfo", sInstrumentationClass, int.class); return (InstrumentationInfo) method.invoke(null, instrumentation, flags); }
public static final InstrumentationInfo generateInstrumentationInfo( Instrumentation i, int flags) { if (i == null) return null; if ((flags&PackageManager.GET_META_DATA) == 0) { return i.info; } InstrumentationInfo ii = new InstrumentationInfo(i.info); ii.metaData = i.metaData; return ii; }
@Override public InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags) throws NameNotFoundException { return mBase.getInstrumentationInfo(className, flags); }
@Override public List<InstrumentationInfo> queryInstrumentation(String targetPackage, int flags) { return mBase.queryInstrumentation(targetPackage, flags); }
LoadedPlugin(PluginManager pluginManager, Context context, File apk) throws PackageParser.PackageParserException { this.mPluginManager = pluginManager; this.mHostContext = context; this.mLocation = apk.getAbsolutePath(); this.mPackage = PackageParserCompat.parsePackage(context, apk, PackageParser.PARSE_MUST_BE_APK); this.mPackage.applicationInfo.metaData = this.mPackage.mAppMetaData; this.mPackageInfo = new PackageInfo(); this.mPackageInfo.applicationInfo = this.mPackage.applicationInfo; this.mPackageInfo.applicationInfo.sourceDir = apk.getAbsolutePath(); this.mPackageInfo.signatures = this.mPackage.mSignatures; this.mPackageInfo.packageName = this.mPackage.packageName; if (pluginManager.getLoadedPlugin(mPackageInfo.packageName) != null) { throw new RuntimeException("plugin has already been loaded : " + mPackageInfo.packageName); } this.mPackageInfo.versionCode = this.mPackage.mVersionCode; this.mPackageInfo.versionName = this.mPackage.mVersionName; this.mPackageInfo.permissions = new PermissionInfo[0]; this.mPackageManager = new PluginPackageManager(); this.mPluginContext = new PluginContext(this); this.mNativeLibDir = context.getDir(Constants.NATIVE_DIR, Context.MODE_PRIVATE); this.mResources = createResources(context, apk); this.mClassLoader = createClassLoader(context, apk, this.mNativeLibDir, context.getClassLoader()); tryToCopyNativeLib(apk); // Cache instrumentations Map<ComponentName, InstrumentationInfo> instrumentations = new HashMap<ComponentName, InstrumentationInfo>(); for (PackageParser.Instrumentation instrumentation : this.mPackage.instrumentation) { instrumentations.put(instrumentation.getComponentName(), instrumentation.info); } this.mInstrumentationInfos = Collections.unmodifiableMap(instrumentations); this.mPackageInfo.instrumentation = instrumentations.values().toArray(new InstrumentationInfo[instrumentations.size()]); // Cache activities Map<ComponentName, ActivityInfo> activityInfos = new HashMap<ComponentName, ActivityInfo>(); for (PackageParser.Activity activity : this.mPackage.activities) { activityInfos.put(activity.getComponentName(), activity.info); } this.mActivityInfos = Collections.unmodifiableMap(activityInfos); this.mPackageInfo.activities = activityInfos.values().toArray(new ActivityInfo[activityInfos.size()]); // Cache services Map<ComponentName, ServiceInfo> serviceInfos = new HashMap<ComponentName, ServiceInfo>(); for (PackageParser.Service service : this.mPackage.services) { serviceInfos.put(service.getComponentName(), service.info); } this.mServiceInfos = Collections.unmodifiableMap(serviceInfos); this.mPackageInfo.services = serviceInfos.values().toArray(new ServiceInfo[serviceInfos.size()]); // Cache providers Map<String, ProviderInfo> providers = new HashMap<String, ProviderInfo>(); Map<ComponentName, ProviderInfo> providerInfos = new HashMap<ComponentName, ProviderInfo>(); for (PackageParser.Provider provider : this.mPackage.providers) { providers.put(provider.info.authority, provider.info); providerInfos.put(provider.getComponentName(), provider.info); } this.mProviders = Collections.unmodifiableMap(providers); this.mProviderInfos = Collections.unmodifiableMap(providerInfos); this.mPackageInfo.providers = providerInfos.values().toArray(new ProviderInfo[providerInfos.size()]); // Register broadcast receivers dynamically Map<ComponentName, ActivityInfo> receivers = new HashMap<ComponentName, ActivityInfo>(); for (PackageParser.Activity receiver : this.mPackage.receivers) { receivers.put(receiver.getComponentName(), receiver.info); try { BroadcastReceiver br = BroadcastReceiver.class.cast(getClassLoader().loadClass(receiver.getComponentName().getClassName()).newInstance()); for (PackageParser.ActivityIntentInfo aii : receiver.intents) { this.mHostContext.registerReceiver(br, aii); } } catch (Exception e) { e.printStackTrace(); } } this.mReceiverInfos = Collections.unmodifiableMap(receivers); this.mPackageInfo.receivers = receivers.values().toArray(new ActivityInfo[receivers.size()]); }
@Override public List<InstrumentationInfo> queryInstrumentation(String targetPackage, int flags) { return this.mHostPackageManager.queryInstrumentation(targetPackage, flags); }
public List<InstrumentationInfo> getInstrumentationInfos() { return new ArrayList<InstrumentationInfo>(mInstrumentationInfoCache.values()); }