Android アプリ内で「am profile start」を実行して、別の PID をプロファイリングしようとしています。ADB からはすべて正常に動作します。たとえば、 adb shell am profile 5397 start /sdcard/my.app.trace が動作します。ただし、「am」または「pm」、または app_process を実行するものを実行しようとすると、次のエラーが発生します。
/system/bin/am[8]: app_process: 実行できません: アクセス許可が拒否されました
端末エミュレータからも機能しません。同じエラーです。ルートで(adbまたはデバイスの両方で)実行すると、次のようなセグメンテーション違反が発生します。そこでの答えは、ルートで「am」にアクセスするという問題を解決しませんでしたが、ルートなしでコマンドを実行する問題を解決したいと思います。デバイスで app_process を実行すると解決できない問題があります。Android L Preview でルート化された Nexus 5 を使用しています。私の古いルート化された Motorola Milestone では、コマンドはターミナル エミュレーターで実行されます。これは、アプリ内で「am」コマンドを実行しようとするだけのコードで、そのコマンドのオプションをリストする必要がありますが、上記のエラーが発生します。
try {
String outputString;
String command = "am";
Log.d(TAG, "EXECUTING CMD: " + command);
// execute command and read output
process = Runtime.getRuntime().exec(command);
BufferedReader stdError = new BufferedReader(new InputStreamReader(
process.getErrorStream()));
BufferedReader stdInput = new BufferedReader(new InputStreamReader(
process.getInputStream()));
while ((outputString = stdInput.readLine()) != null) {
Log.d(TAG, " EXECUTING CMD Here is the standard output of the command (if any):\n");
Log.d(TAG, outputString);
}
while ((outputString = stdError.readLine()) != null) {
Log.d(TAG, "EXECUTING CMD Here is the standard error of the command (if any):\n");
Log.d(TAG, outputString);
}
Log.d(TAG, "****** / " + sCmd + " *******");
} catch (IOException exception) {
exception.printStackTrace();
}