app/src/main/java/com/jwipc/nodka_reboot_under/The_Service.java
....@@ -2,25 +2,34 @@
22
33
44 import com.jwipc.nodka_reboot_under.utils.Utils;
5
+import com.nodka.api.NodkaAPI;
56
67 import android.app.Service;
8
+import android.content.Context;
79 import android.content.Intent;
810 import android.content.IntentFilter;
11
+import android.os.Build;
912 import android.os.Handler;
1013 import android.os.IBinder;
1114 import android.os.Message;
15
+import android.os.PowerManager;
16
+import android.os.SystemClock;
17
+
18
+import java.io.DataOutputStream;
19
+import java.io.IOException;
1220
1321 public class The_Service extends Service{
1422
15
-
23
+
1624 Utils mUtils = null;
1725 public static Handler handler;
1826
1927 public static final int apk_feed_dog = 1;
20
-
21
-
22
-
23
-
28
+
29
+ private NodkaAPI mNodkaAPI = MyApplication.getApplication().getNodkaAPI();
30
+ private Thread gpioThread;
31
+ private static boolean gpioRead;
32
+
2433 @Override
2534 public IBinder onBind(Intent arg0) {
2635 // TODO Auto-generated method stub
....@@ -38,9 +47,67 @@
3847
3948 receive_BroadcastReceiver_byService();
4049 mUtils.stop_watch_dog_apk_feed();
41
-
50
+
51
+ if (Build.DISPLAY.startsWith("Android-11-V7.009")) {
52
+
53
+ // 霍盛版本红外感应功能 gpio口95
54
+ startGpioThread();
55
+ }
4256 }
43
-
57
+
58
+ private void startGpioThread() {
59
+ mNodkaAPI.gpio_export(95);
60
+ gpioRead = true;
61
+ gpioThread = new Thread(() -> {
62
+ while (gpioRead) {
63
+ if (!isInteractive() && isActive()) {
64
+ keycodePower();
65
+ }
66
+ SystemClock.sleep(500);
67
+ }
68
+ });
69
+ gpioThread.start();
70
+ }
71
+
72
+ private boolean isActive() {
73
+ return mNodkaAPI.gpio_read(95) == 1;
74
+ }
75
+
76
+ private void keycodePower() {
77
+ execRootCmdSilent("input keyevent KEYCODE_POWER");
78
+ }
79
+
80
+ private boolean isInteractive(){
81
+ PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
82
+ return powerManager.isInteractive();
83
+ }
84
+
85
+ public static int execRootCmdSilent(String cmd) {
86
+ int result = -1;
87
+ DataOutputStream dos = null;
88
+
89
+ try {
90
+ Process p = Runtime.getRuntime().exec("su");
91
+ dos = new DataOutputStream(p.getOutputStream());
92
+ dos.writeBytes(cmd + "\n");
93
+ dos.flush();
94
+ dos.writeBytes("exit\n");
95
+ dos.flush();
96
+ p.waitFor();
97
+ result = p.exitValue();
98
+ } catch (Exception e) {
99
+ e.printStackTrace();
100
+ } finally {
101
+ if (dos != null) {
102
+ try {
103
+ dos.close();
104
+ } catch (IOException e) {
105
+ e.printStackTrace();
106
+ }
107
+ }
108
+ }
109
+ return result;
110
+ }
44111
45112 private void receive_BroadcastReceiver_byService()
46113 {