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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.jwipc.nodka_reboot_under;
 
 
import com.jwipc.nodka_reboot_under.utils.Utils;
import com.nodka.api.NodkaAPI;
 
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.os.SystemClock;
 
import java.io.DataOutputStream;
import java.io.IOException;
 
public class The_Service extends Service{
 
 
   Utils mUtils = null;
   public static Handler handler;
   
   public static final int apk_feed_dog = 1;
 
   private NodkaAPI mNodkaAPI = MyApplication.getApplication().getNodkaAPI();
   private Thread gpioThread;
   private static boolean gpioRead;
 
   @Override
   public IBinder onBind(Intent arg0) {
       // TODO Auto-generated method stub
       return null;
   }
 
   
   @Override
   public void onCreate() {
       // TODO Auto-generated method stub
       super.onCreate();
       
       mUtils = new Utils(this);
       handler();
       
       receive_BroadcastReceiver_byService();
       mUtils.stop_watch_dog_apk_feed();
 
       if (Build.DISPLAY.startsWith("Android-11-V7.009")) {
 
           // 霍盛版本红外感应功能 gpio口95
           startGpioThread();
       }
   }
 
   private void startGpioThread() {
       mNodkaAPI.gpio_export(95);
       gpioRead = true;
       gpioThread = new Thread(() -> {
           while (gpioRead) {
               if (!isInteractive() && isActive()) {
                   keycodePower();
               }
               SystemClock.sleep(500);
           }
       });
       gpioThread.start();
   }
 
   private boolean isActive() {
       return mNodkaAPI.gpio_read(95) == 1;
   }
 
   private void keycodePower() {
       execRootCmdSilent("input keyevent KEYCODE_POWER");
   }
 
   private boolean isInteractive(){
       PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
       return powerManager.isInteractive();
   }
 
   public static int execRootCmdSilent(String cmd) {
       int result = -1;
       DataOutputStream dos = null;
 
       try {
           Process p = Runtime.getRuntime().exec("su");
           dos = new DataOutputStream(p.getOutputStream());
           dos.writeBytes(cmd + "\n");
           dos.flush();
           dos.writeBytes("exit\n");
           dos.flush();
           p.waitFor();
           result = p.exitValue();
       } catch (Exception e) {
           e.printStackTrace();
       } finally {
           if (dos != null) {
               try {
                   dos.close();
               } catch (IOException e) {
                   e.printStackTrace();
               }
           }
       }
       return result;
   }
   
   private void receive_BroadcastReceiver_byService()
   {
       IntentFilter filter = new IntentFilter();
       filter.addAction("android.intent.action.auto_power_shut");
       filter.addAction("android.intent.action.NDJ_APP_ALIVE");
       registerReceiver(new BroadcastReceiver_Power(), filter);
   }
   
   
   private void handler()
   {
       handler = new Handler()
       {
           @Override
           public void handleMessage(Message msg) {
               // TODO Auto-generated method stub
               super.handleMessage(msg);
               
               switch (msg.what) {
               case apk_feed_dog:
                   mUtils.stop_watch_dog_apk_feed();
                   break;
               }
           }
       };
   }
   
   
   
   
   
   
}