下面列出了怎么用android.content.pm.InstrumentationInfo的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
/** Populate the arg data from the instrumentation:metadata attribute in Manifest. */
public Builder fromManifest(Instrumentation instr) {
PackageManager pm = instr.getContext().getPackageManager();
try {
InstrumentationInfo instrInfo =
pm.getInstrumentationInfo(instr.getComponentName(), PackageManager.GET_META_DATA);
Bundle b = instrInfo.metaData;
if (b == null) {
// metadata not present - skip
return this;
}
// parse the metadata using same key names
return fromBundle(instr, b);
} catch (PackageManager.NameNotFoundException e) {
// should never happen
Log.wtf(LOG_TAG, String.format("Could not find component %s", instr.getComponentName()));
}
return this;
}
@Override
@SuppressWarnings("unchecked")
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
ParceledListSlice<InstrumentationInfo> parceledList =
mPM.queryInstrumentation(targetPackage, flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
@SuppressWarnings("unchecked")
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
ParceledListSlice<InstrumentationInfo> parceledList =
mPM.queryInstrumentation(targetPackage, flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
return mPM.queryInstrumentation(targetPackage, flags);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
@SuppressWarnings("unchecked")
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
ParceledListSlice<InstrumentationInfo> parceledList =
mPM.queryInstrumentation(targetPackage, flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
@SuppressWarnings("unchecked")
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
ParceledListSlice<InstrumentationInfo> parceledList =
mPM.queryInstrumentation(targetPackage, flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
return mPM.queryInstrumentation(targetPackage, flags);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
return mPM.queryInstrumentation(targetPackage, flags);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
@SuppressWarnings("unchecked")
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
ParceledListSlice<InstrumentationInfo> parceledList =
mPM.queryInstrumentation(targetPackage, flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
@SuppressWarnings("unchecked")
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
ParceledListSlice<InstrumentationInfo> parceledList =
mPM.queryInstrumentation(targetPackage, flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
@SuppressWarnings("unchecked")
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
ParceledListSlice<InstrumentationInfo> parceledList =
mPM.queryInstrumentation(targetPackage, flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
@SuppressWarnings("unchecked")
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
ParceledListSlice<InstrumentationInfo> parceledList =
mPM.queryInstrumentation(targetPackage, flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@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 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 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);
}
/** Returns the package of the app under test. */
private String getTargetPackage(Bundle arguments) {
String instrPackage = getTargetInstrPackage(arguments);
String instrumentation = getTargetInstrumentation(arguments).split("/", -1)[1];
PackageManager packageManager = getContext().getPackageManager();
try {
InstrumentationInfo instrInfo =
packageManager.getInstrumentationInfo(
new ComponentName(instrPackage, instrumentation), 0 /* no flags */);
return instrInfo.targetPackage;
} catch (NameNotFoundException e) {
throw new IllegalStateException(
"Package [" + instrPackage + "] cannot be found on the system.");
}
}