use of dalvik.system.DexFile in project android_frameworks_base by crdroidandroid.
the class RunTestCommand method addTestClassesFromJars.
/**
* Add test classes from jars passed on the command line. Use this if nothing was explicitly
* specified on the command line.
*/
private void addTestClassesFromJars() {
String jars = mParams.getString(JARS_PARAM);
if (jars == null)
return;
String[] jarFileNames = jars.split(JARS_SEPARATOR);
for (String fileName : jarFileNames) {
fileName = fileName.trim();
if (fileName.isEmpty())
continue;
try {
DexFile dexFile = new DexFile(fileName);
for (Enumeration<String> e = dexFile.entries(); e.hasMoreElements(); ) {
String className = e.nextElement();
if (isTestClass(className)) {
mTestClasses.add(className);
}
}
dexFile.close();
} catch (IOException e) {
Log.w(LOGTAG, String.format("Could not read %s: %s", fileName, e.getMessage()));
}
}
}
use of dalvik.system.DexFile in project android_frameworks_base by crdroidandroid.
the class ClassPathPackageInfoSource method findClassesInApk.
/**
* Finds all classes and sub packages that are below the packageName and
* add them to the respective sets. Searches the package in a single apk file.
*/
private void findClassesInApk(String apkPath, String packageName, Set<String> classNames, Set<String> subpackageNames) throws IOException {
DexFile dexFile = null;
try {
dexFile = new DexFile(apkPath);
Enumeration<String> apkClassNames = dexFile.entries();
while (apkClassNames.hasMoreElements()) {
String className = apkClassNames.nextElement();
if (className.startsWith(packageName)) {
String subPackageName = packageName;
int lastPackageSeparator = className.lastIndexOf('.');
if (lastPackageSeparator > 0) {
subPackageName = className.substring(0, lastPackageSeparator);
}
if (subPackageName.length() > packageName.length()) {
subpackageNames.add(subPackageName);
} else if (isToplevelClass(className)) {
classNames.add(className);
}
}
}
} catch (IOException e) {
if (false) {
Log.w("ClassPathPackageInfoSource", "Error finding classes at apk path: " + apkPath, e);
}
} finally {
if (dexFile != null) {
// Todo: figure out why closing causes a dalvik error resulting in vm shutdown.
// dexFile.close();
}
}
}
use of dalvik.system.DexFile in project BetterBatteryStats by asksven.
the class SystemPropertiesProxy method set.
/**
* Set the value for the given key.
* @throws IllegalArgumentException if the key exceeds 32 characters
* @throws IllegalArgumentException if the value exceeds 92 characters
*/
public static void set(Context context, String key, String val) throws IllegalArgumentException {
try {
@SuppressWarnings("unused") DexFile df = new DexFile(new File("/system/app/Settings.apk"));
@SuppressWarnings("unused") ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes") Class SystemProperties = Class.forName("android.os.SystemProperties");
// Parameters Types
@SuppressWarnings("rawtypes") Class[] paramTypes = new Class[2];
paramTypes[0] = String.class;
paramTypes[1] = String.class;
Method set = SystemProperties.getMethod("set", paramTypes);
// Parameters
Object[] params = new Object[2];
params[0] = new String(key);
params[1] = new String(val);
set.invoke(SystemProperties, params);
} catch (IllegalArgumentException iAE) {
throw iAE;
} catch (Exception e) {
// TODO
}
}
use of dalvik.system.DexFile in project BaseProject by fly803.
the class SystemPropertiesProxy method set.
/**
* 根据给定的key和值设置属性, 该方法需要特定的权限才能操作.
*
* @throws IllegalArgumentException
* 如果key超过32个字符则抛出该异常
* @throws IllegalArgumentException
* 如果value超过92个字符则抛出该异常
*/
public static void set(Context context, String key, String val) throws IllegalArgumentException {
try {
@SuppressWarnings("unused") DexFile df = new DexFile(new File("/system/app/Settings.apk"));
@SuppressWarnings("unused") ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes") Class SystemProperties = Class.forName("android.os.SystemProperties");
// 参数类型
@SuppressWarnings("rawtypes") Class[] paramTypes = new Class[2];
paramTypes[0] = String.class;
paramTypes[1] = String.class;
Method set = SystemProperties.getMethod("set", paramTypes);
// 参数
Object[] params = new Object[2];
params[0] = new String(key);
params[1] = new String(val);
set.invoke(SystemProperties, params);
} catch (IllegalArgumentException iAE) {
throw iAE;
} catch (Exception e) {
// TODO
}
}
use of dalvik.system.DexFile in project sugar by satyan.
the class MultiDexHelper method getAllClasses.
/**
* get all the classes name in "classes.dex", "classes2.dex", ....
*
* @return all the classes name
* @throws PackageManager.NameNotFoundException
* @throws IOException
*/
public static List<String> getAllClasses() throws PackageManager.NameNotFoundException, IOException {
List<String> classNames = new ArrayList<>();
for (String path : getSourcePaths()) {
try {
DexFile dexfile;
if (path.endsWith(EXTRACTED_SUFFIX)) {
// NOT use new DexFile(path), because it will throw "permission error in /data/dalvik-cache"
dexfile = DexFile.loadDex(path, path + ".tmp", 0);
} else {
dexfile = new DexFile(path);
}
Enumeration<String> dexEntries = dexfile.entries();
while (dexEntries.hasMoreElements()) {
classNames.add(dexEntries.nextElement());
}
} catch (IOException e) {
throw new IOException("Error at loading dex file '" + path + "'");
}
}
return classNames;
}
Aggregations