use of android.util.AndroidException in project android_frameworks_base by crdroidandroid.
the class Am method runProfile.
private void runProfile() throws Exception {
String profileFile = null;
boolean start = false;
boolean wall = false;
int userId = UserHandle.USER_CURRENT;
int profileType = 0;
mSamplingInterval = 0;
String process = null;
String cmd = nextArgRequired();
if ("start".equals(cmd)) {
start = true;
String opt;
while ((opt = nextOption()) != null) {
if (opt.equals("--user")) {
userId = parseUserArg(nextArgRequired());
} else if (opt.equals("--wall")) {
wall = true;
} else if (opt.equals("--sampling")) {
mSamplingInterval = Integer.parseInt(nextArgRequired());
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
process = nextArgRequired();
} else if ("stop".equals(cmd)) {
String opt;
while ((opt = nextOption()) != null) {
if (opt.equals("--user")) {
userId = parseUserArg(nextArgRequired());
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
process = nextArg();
} else {
// Compatibility with old syntax: process is specified first.
process = cmd;
cmd = nextArgRequired();
if ("start".equals(cmd)) {
start = true;
} else if (!"stop".equals(cmd)) {
throw new IllegalArgumentException("Profile command " + process + " not valid");
}
}
if (userId == UserHandle.USER_ALL) {
System.err.println("Error: Can't profile with user 'all'");
return;
}
ParcelFileDescriptor fd = null;
ProfilerInfo profilerInfo = null;
if (start) {
profileFile = nextArgRequired();
try {
fd = openForSystemServer(new File(profileFile), ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_WRITE_ONLY);
} catch (FileNotFoundException e) {
System.err.println("Error: Unable to open file: " + profileFile);
System.err.println("Consider using a file under /data/local/tmp/");
return;
}
profilerInfo = new ProfilerInfo(profileFile, fd, mSamplingInterval, false);
}
try {
if (wall) {
// XXX doesn't work -- this needs to be set before booting.
String props = SystemProperties.get("dalvik.vm.extra-opts");
if (props == null || !props.contains("-Xprofile:wallclock")) {
props = props + " -Xprofile:wallclock";
//SystemProperties.set("dalvik.vm.extra-opts", props);
}
} else if (start) {
//removeWallOption();
}
if (!mAm.profileControl(process, userId, start, profilerInfo, profileType)) {
wall = false;
throw new AndroidException("PROFILE FAILED on process " + process);
}
} finally {
if (!wall) {
//removeWallOption();
}
}
}
use of android.util.AndroidException in project platform_frameworks_base by android.
the class Am method runInstrument.
private void runInstrument() throws Exception {
String profileFile = null;
boolean wait = false;
boolean rawMode = false;
boolean no_window_animation = false;
int userId = UserHandle.USER_CURRENT;
Bundle args = new Bundle();
String argKey = null, argValue = null;
IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
String abi = null;
String opt;
while ((opt = nextOption()) != null) {
if (opt.equals("-p")) {
profileFile = nextArgRequired();
} else if (opt.equals("-w")) {
wait = true;
} else if (opt.equals("-r")) {
rawMode = true;
} else if (opt.equals("-e")) {
argKey = nextArgRequired();
argValue = nextArgRequired();
args.putString(argKey, argValue);
} else if (opt.equals("--no_window_animation") || opt.equals("--no-window-animation")) {
no_window_animation = true;
} else if (opt.equals("--user")) {
userId = parseUserArg(nextArgRequired());
} else if (opt.equals("--abi")) {
abi = nextArgRequired();
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
if (userId == UserHandle.USER_ALL) {
System.err.println("Error: Can't start instrumentation with user 'all'");
return;
}
String cnArg = nextArgRequired();
ComponentName cn;
if (cnArg.contains("/")) {
cn = ComponentName.unflattenFromString(cnArg);
if (cn == null)
throw new IllegalArgumentException("Bad component name: " + cnArg);
} else {
List<InstrumentationInfo> infos = mPm.queryInstrumentation(null, 0).getList();
final int numInfos = infos == null ? 0 : infos.size();
List<ComponentName> cns = new ArrayList<>();
for (int i = 0; i < numInfos; i++) {
InstrumentationInfo info = infos.get(i);
ComponentName c = new ComponentName(info.packageName, info.name);
if (cnArg.equals(info.packageName)) {
cns.add(c);
}
}
if (cns.size() == 0) {
throw new IllegalArgumentException("No instrumentation found for: " + cnArg);
} else if (cns.size() == 1) {
cn = cns.get(0);
} else {
StringBuilder cnsStr = new StringBuilder();
final int numCns = cns.size();
for (int i = 0; i < numCns; i++) {
cnsStr.append(cns.get(i).flattenToString());
cnsStr.append(", ");
}
// Remove last ", "
cnsStr.setLength(cnsStr.length() - 2);
throw new IllegalArgumentException("Found multiple instrumentations: " + cnsStr.toString());
}
}
InstrumentationWatcher watcher = null;
UiAutomationConnection connection = null;
if (wait) {
watcher = new InstrumentationWatcher();
watcher.setRawOutput(rawMode);
connection = new UiAutomationConnection();
}
float[] oldAnims = null;
if (no_window_animation) {
oldAnims = wm.getAnimationScales();
wm.setAnimationScale(0, 0.0f);
wm.setAnimationScale(1, 0.0f);
}
if (abi != null) {
final String[] supportedAbis = Build.SUPPORTED_ABIS;
boolean matched = false;
for (String supportedAbi : supportedAbis) {
if (supportedAbi.equals(abi)) {
matched = true;
break;
}
}
if (!matched) {
throw new AndroidException("INSTRUMENTATION_FAILED: Unsupported instruction set " + abi);
}
}
if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId, abi)) {
throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
}
if (watcher != null) {
if (!watcher.waitForFinish()) {
System.out.println("INSTRUMENTATION_ABORTED: System has crashed.");
}
}
if (oldAnims != null) {
wm.setAnimationScales(oldAnims);
}
}
use of android.util.AndroidException in project platform_frameworks_base by android.
the class Am method runDumpHeap.
private void runDumpHeap() throws Exception {
boolean managed = true;
int userId = UserHandle.USER_CURRENT;
String opt;
while ((opt = nextOption()) != null) {
if (opt.equals("--user")) {
userId = parseUserArg(nextArgRequired());
if (userId == UserHandle.USER_ALL) {
System.err.println("Error: Can't dump heap with user 'all'");
return;
}
} else if (opt.equals("-n")) {
managed = false;
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
String process = nextArgRequired();
String heapFile = nextArgRequired();
ParcelFileDescriptor fd = null;
try {
File file = new File(heapFile);
file.delete();
fd = openForSystemServer(file, ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_WRITE_ONLY);
} catch (FileNotFoundException e) {
System.err.println("Error: Unable to open file: " + heapFile);
System.err.println("Consider using a file under /data/local/tmp/");
return;
}
if (!mAm.dumpHeap(process, userId, managed, heapFile, fd)) {
throw new AndroidException("HEAP DUMP FAILED on process " + process);
}
}
use of android.util.AndroidException in project platform_frameworks_base by android.
the class Am method runTraceIpcStop.
private void runTraceIpcStop() throws Exception {
String opt;
String filename = null;
while ((opt = nextOption()) != null) {
if (opt.equals("--dump-file")) {
filename = nextArgRequired();
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
if (filename == null) {
System.err.println("Error: Specify filename to dump logs to.");
return;
}
ParcelFileDescriptor fd = null;
try {
File file = new File(filename);
file.delete();
fd = openForSystemServer(file, ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_WRITE_ONLY);
} catch (FileNotFoundException e) {
System.err.println("Error: Unable to open file: " + filename);
System.err.println("Consider using a file under /data/local/tmp/");
return;
}
;
if (!mAm.stopBinderTrackingAndDump(fd)) {
throw new AndroidException("STOP TRACE FAILED.");
}
System.out.println("Stopped IPC tracing. Dumping logs to: " + filename);
}
use of android.util.AndroidException in project android_frameworks_base by ParanoidAndroid.
the class Am method runDumpHeap.
private void runDumpHeap() throws Exception {
boolean managed = true;
int userId = UserHandle.USER_CURRENT;
String opt;
while ((opt = nextOption()) != null) {
if (opt.equals("--user")) {
userId = parseUserArg(nextArgRequired());
if (userId == UserHandle.USER_ALL) {
System.err.println("Error: Can't dump heap with user 'all'");
return;
}
} else if (opt.equals("-n")) {
managed = false;
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
String process = nextArgRequired();
String heapFile = nextArgRequired();
ParcelFileDescriptor fd = null;
try {
File file = new File(heapFile);
file.delete();
fd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_READ_WRITE);
} catch (FileNotFoundException e) {
System.err.println("Error: Unable to open file: " + heapFile);
return;
}
if (!mAm.dumpHeap(process, userId, managed, heapFile, fd)) {
throw new AndroidException("HEAP DUMP FAILED on process " + process);
}
}
Aggregations