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;
|
}
|
}
|
};
|
}
|
|
|
|
|
|
|
}
|