aboutsummaryrefslogtreecommitdiffstats
path: root/wpadebug
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2013-05-04 22:46:07 (GMT)
committerJouni Malinen <j@w1.fi>2013-05-04 23:42:09 (GMT)
commitcb54718c501e2b37231a849a0469deddbf18225a (patch)
treee0d4f060bc5f38f96a87782a51db86c10535d587 /wpadebug
parentd1f7a9b3316afddb3af7d2242ac6108a95f7bf68 (diff)
downloadhostap-cb54718c501e2b37231a849a0469deddbf18225a.zip
hostap-cb54718c501e2b37231a849a0469deddbf18225a.tar.gz
hostap-cb54718c501e2b37231a849a0469deddbf18225a.tar.bz2
wpadebug: Add generic shell command mechanism
Signed-hostap: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'wpadebug')
-rw-r--r--wpadebug/AndroidManifest.xml4
-rw-r--r--wpadebug/README5
-rw-r--r--wpadebug/res/layout/main.xml9
-rw-r--r--wpadebug/res/raw/shell_commands.txt2
-rw-r--r--wpadebug/src/w1/fi/wpadebug/CommandListActivity.java124
-rw-r--r--wpadebug/src/w1/fi/wpadebug/MainActivity.java8
6 files changed, 139 insertions, 13 deletions
diff --git a/wpadebug/AndroidManifest.xml b/wpadebug/AndroidManifest.xml
index 535e3d2..f351b08 100644
--- a/wpadebug/AndroidManifest.xml
+++ b/wpadebug/AndroidManifest.xml
@@ -28,5 +28,9 @@
<data android:mimeType="application/vnd.wfa.wsc" />
</intent-filter>
</activity>
+ <activity android:name="w1.fi.wpadebug.CommandListActivity"
+ android:label="Command list"
+ android:parentActivityName="w1.fi.wpadebug.MainActivity">
+ </activity>
</application>
</manifest>
diff --git a/wpadebug/README b/wpadebug/README
index 73ebdf3..ada07ba 100644
--- a/wpadebug/README
+++ b/wpadebug/README
@@ -44,6 +44,11 @@ adb root
adb remount
adb shell chmod 6755 /system/bin/mksh-su
+Optionally, a text file with a set of command can be installed to allow
+arbitrary shell commands to be executed. This text file need to be in
+/data/local/wpadebug.cmds and use title@command format per line. For
+example:
+version@cat /proc/version
Uninstallation
diff --git a/wpadebug/res/layout/main.xml b/wpadebug/res/layout/main.xml
index 3e9059f..b3337e4 100644
--- a/wpadebug/res/layout/main.xml
+++ b/wpadebug/res/layout/main.xml
@@ -122,11 +122,6 @@
android:onClick="runWpaCliCmd"
/>
</LinearLayout>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Shell commands"
- />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -135,8 +130,8 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="id"
- android:onClick="runId"
+ android:text="Shell commands"
+ android:onClick="runCommands"
/>
</LinearLayout>
<TextView
diff --git a/wpadebug/res/raw/shell_commands.txt b/wpadebug/res/raw/shell_commands.txt
new file mode 100644
index 0000000..9b45d65
--- /dev/null
+++ b/wpadebug/res/raw/shell_commands.txt
@@ -0,0 +1,2 @@
+id@id
+version@cat /proc/version
diff --git a/wpadebug/src/w1/fi/wpadebug/CommandListActivity.java b/wpadebug/src/w1/fi/wpadebug/CommandListActivity.java
new file mode 100644
index 0000000..fb4268e
--- /dev/null
+++ b/wpadebug/src/w1/fi/wpadebug/CommandListActivity.java
@@ -0,0 +1,124 @@
+/*
+ * wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
+ * Copyright (c) 2013, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+package w1.fi.wpadebug;
+
+import java.util.ArrayList;
+import java.util.Scanner;
+import java.io.FileReader;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.InputStream;
+import java.io.IOException;
+
+import android.app.ListActivity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.view.View;
+import android.widget.ListView;
+import android.widget.ArrayAdapter;
+import android.widget.Toast;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+
+class CmdList
+{
+ String title;
+ String command;
+
+ public CmdList(String _title, String _command)
+ {
+ title = _title;
+ command = _command;
+ }
+
+ @Override
+ public String toString()
+ {
+ return title;
+ }
+}
+
+public class CommandListActivity extends ListActivity
+{
+ private static final String TAG = "wpadebug";
+ private static final String cmdfile = "/data/local/wpadebug.cmds";
+
+ private void read_commands(ArrayList<CmdList> list, Scanner in)
+ {
+ in.useDelimiter("@");
+ while (in.hasNext()) {
+ String title = in.next();
+ String cmd = in.nextLine().substring(1);
+ list.add(new CmdList(title, cmd));
+ }
+ in.close();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+
+ ArrayList<CmdList> list = new ArrayList<CmdList>();
+
+ FileReader in;
+ try {
+ in = new FileReader(cmdfile);
+ read_commands(list, new Scanner(in));
+ } catch (IOException e) {
+ Toast.makeText(this, "Could not read " + cmdfile,
+ Toast.LENGTH_SHORT).show();
+ }
+
+ InputStream inres = getResources().openRawResource(R.raw.shell_commands);
+ read_commands(list, new Scanner(inres));
+
+ ArrayAdapter<CmdList> listAdapter;
+ listAdapter = new ArrayAdapter<CmdList>(this, android.R.layout.simple_list_item_1, list);
+
+ setListAdapter(listAdapter);
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id)
+ {
+ CmdList item = (CmdList) getListAdapter().getItem(position);
+ Toast.makeText(this, "Running: " + item.command,
+ Toast.LENGTH_SHORT).show();
+ String message = run(item.command);
+ if (message == null)
+ return;
+ Intent intent = new Intent(this, DisplayMessageActivity.class);
+ intent.putExtra(MainActivity.EXTRA_MESSAGE, message);
+ startActivity(intent);
+ }
+
+ private String run(String cmd)
+ {
+ try {
+ Process proc = Runtime.getRuntime().exec(new String[]{"/system/bin/mksh-su", "-c", cmd});
+ BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ StringBuffer output = new StringBuffer();
+ int read;
+ char[] buffer = new char[1024];
+ while ((read = reader.read(buffer)) > 0)
+ output.append(buffer, 0, read);
+ reader.close();
+ proc.waitFor();
+ return output.toString();
+ } catch (IOException e) {
+ Toast.makeText(this, "Could not run command",
+ Toast.LENGTH_LONG).show();
+ return null;
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/wpadebug/src/w1/fi/wpadebug/MainActivity.java b/wpadebug/src/w1/fi/wpadebug/MainActivity.java
index 1407932..f135440 100644
--- a/wpadebug/src/w1/fi/wpadebug/MainActivity.java
+++ b/wpadebug/src/w1/fi/wpadebug/MainActivity.java
@@ -41,13 +41,9 @@ public class MainActivity extends Activity
setContentView(R.layout.main);
}
- public void runId(View view)
+ public void runCommands(View view)
{
- Intent intent = new Intent(this, DisplayMessageActivity.class);
- String message = run("/system/bin/id");
- if (message == null)
- return;
- intent.putExtra(EXTRA_MESSAGE, message);
+ Intent intent = new Intent(this, CommandListActivity.class);
startActivity(intent);
}