summaryrefslogtreecommitdiff
path: root/src/jp/example/tethering/ControlReceiver.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jp/example/tethering/ControlReceiver.java')
-rw-r--r--src/jp/example/tethering/ControlReceiver.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/jp/example/tethering/ControlReceiver.java b/src/jp/example/tethering/ControlReceiver.java
new file mode 100644
index 0000000..b82f6bf
--- /dev/null
+++ b/src/jp/example/tethering/ControlReceiver.java
@@ -0,0 +1,55 @@
+package jp.example.tethering;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+
+/**
+ * Remote control from adb / the PC:
+ *
+ * adb shell am broadcast -a jp.example.tethering.USB_ON
+ * adb shell am broadcast -a jp.example.tethering.USB_OFF
+ *
+ * The broadcast sets manual_off so the USB receiver does not immediately
+ * turn tethering back on after a manual OFF.
+ */
+public class ControlReceiver extends BroadcastReceiver {
+ public static final String ACTION_ON = "jp.example.tethering.USB_ON";
+ public static final String ACTION_OFF = "jp.example.tethering.USB_OFF";
+ public static final String ACTION_EXPORT = "jp.example.tethering.EXPORT_PS1";
+ public static final String ACTION_EXPORT_SCRIPTS = "jp.example.tethering.EXPORT_SCRIPTS";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (ACTION_EXPORT.equals(action) || ACTION_EXPORT_SCRIPTS.equals(action)) {
+ try {
+ Ps1Exporter.exportAll(context);
+ } catch (Exception e) {
+ android.util.Log.e("TetheringApp", "export failed", e);
+ }
+ return;
+ }
+
+ boolean enable = ACTION_ON.equals(action);
+ if (!enable && !ACTION_OFF.equals(action)) {
+ return;
+ }
+
+ SharedPreferences prefs = context.getSharedPreferences("tethering", Context.MODE_PRIVATE);
+ prefs.edit().putBoolean("manual_off", !enable).apply();
+
+ StringBuilder cmd = new StringBuilder();
+ if (enable) {
+ cmd.append(RootRelay.acceptMobileData());
+ cmd.append("pm disable-user --user 0 jp.softbank.mb.tetherAuthNfp >/dev/null 2>&1\n");
+ cmd.append("am force-stop jp.softbank.mb.tetherAuthNfp\n");
+ }
+ cmd.append("CLASSPATH=").append(context.getPackageCodePath())
+ .append(" /system/bin/app_process /system/bin ")
+ .append("jp.example.tethering.TetherCli usb ")
+ .append(enable).append("\n");
+ RootRelay.run(cmd.toString());
+ }
+}