blob: b82f6bfa086d3c832d49e5641c6f5a9e999d49fe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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());
}
}
|