| .. | .. |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | |
|---|
| 4 | 4 | import com.jwipc.nodka_reboot_under.utils.Utils; |
|---|
| 5 | +import com.nodka.api.NodkaAPI; |
|---|
| 5 | 6 | |
|---|
| 6 | 7 | import android.app.Service; |
|---|
| 8 | +import android.content.Context; |
|---|
| 7 | 9 | import android.content.Intent; |
|---|
| 8 | 10 | import android.content.IntentFilter; |
|---|
| 11 | +import android.os.Build; |
|---|
| 9 | 12 | import android.os.Handler; |
|---|
| 10 | 13 | import android.os.IBinder; |
|---|
| 11 | 14 | 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; |
|---|
| 12 | 20 | |
|---|
| 13 | 21 | public class The_Service extends Service{ |
|---|
| 14 | 22 | |
|---|
| 15 | | - |
|---|
| 23 | + |
|---|
| 16 | 24 | Utils mUtils = null; |
|---|
| 17 | 25 | public static Handler handler; |
|---|
| 18 | 26 | |
|---|
| 19 | 27 | 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 | + |
|---|
| 24 | 33 | @Override |
|---|
| 25 | 34 | public IBinder onBind(Intent arg0) { |
|---|
| 26 | 35 | // TODO Auto-generated method stub |
|---|
| .. | .. |
|---|
| 38 | 47 | |
|---|
| 39 | 48 | receive_BroadcastReceiver_byService(); |
|---|
| 40 | 49 | mUtils.stop_watch_dog_apk_feed(); |
|---|
| 41 | | - |
|---|
| 50 | + |
|---|
| 51 | + if (Build.DISPLAY.startsWith("Android-11-V7.009")) { |
|---|
| 52 | + |
|---|
| 53 | + // 霍盛版本红外感应功能 gpio口95 |
|---|
| 54 | + startGpioThread(); |
|---|
| 55 | + } |
|---|
| 42 | 56 | } |
|---|
| 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 | + } |
|---|
| 44 | 111 | |
|---|
| 45 | 112 | private void receive_BroadcastReceiver_byService() |
|---|
| 46 | 113 | { |
|---|