package com.jwipc.nodka_reboot_under; import com.jwipc.nodka_reboot_under.utils.Utils; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.util.Log; public class BroadcastReceiver_Power extends BroadcastReceiver{ Utils mUtils = null; SharedPreferences sharedPreferences; Editor editor; @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub mUtils = new Utils(context); sharedPreferences = context.getSharedPreferences(mUtils.shapre, context.MODE_PRIVATE); editor = sharedPreferences.edit(); String action = intent.getAction(); if(action.equals("android.intent.action.auto_power_shut")) { auto_power_shut(context, intent); } else if(action.equals("android.intent.action.NDJ_APP_ALIVE")) { mUtils.set_NDJ_APP_ALIVE_or_STOP(action); mUtils.set_broadcast_time(System.currentTimeMillis()); mUtils.thread_WatchDog(); } else if(action.equals("android.intent.action.NDJ_APP_STOP")) { mUtils.set_NDJ_APP_ALIVE_or_STOP(action); mUtils.set_broadcast_time(System.currentTimeMillis()); mUtils.thread_WatchDog(); } else if(action.equals("android.intent.action.NDJ_GET_ALARM_REBOOT")) { Intent it_ALARM_REBOOT = new Intent("android.intent.action.NDJ_RESPONE_ALARM_REBOOT"); it_ALARM_REBOOT.putExtra(mUtils.set_time_reboot_h, mUtils.get_int_From_SharedPreferences(mUtils.set_time_reboot_h)); it_ALARM_REBOOT.putExtra(mUtils.set_time_reboot_m, mUtils.get_int_From_SharedPreferences(mUtils.set_time_reboot_m)); it_ALARM_REBOOT.putExtra(mUtils.set_time_reboot_s, mUtils.get_int_From_SharedPreferences(mUtils.set_time_reboot_s)); it_ALARM_REBOOT.putExtra(mUtils.set_time_reboot_repeat, mUtils.get_String_From_SharedPreferences(mUtils.set_time_reboot_repeat)); it_ALARM_REBOOT.putExtra(mUtils.repeat_alarm_poweron_time, sharedPreferences.getString(mUtils.repeat_alarm_poweron_time, "")); it_ALARM_REBOOT.putExtra(mUtils.repeat_alarm_poweroff_time, sharedPreferences.getString(mUtils.repeat_alarm_poweroff_time, "")); context.sendBroadcast(it_ALARM_REBOOT); } else if(action.equals("android.intent.action.STOP_WATCH_DOG_APK_FEED")) { if(!mUtils.isServiceRunning(context, The_Service.class.getName())) { context.startService(new Intent(context, The_Service.class)); } else if(The_Service.handler != null) { The_Service.handler.sendEmptyMessage(The_Service.apk_feed_dog); } } else if(action.equals("android.intent.action.STOP_APK_FEED")) { mUtils.thread_STOP_APK_FEED(); } else if(action.equals("android.intent.action.TIMEZONE_CHANGED")) { if(!sharedPreferences.getString(mUtils.repeat_alarm_poweroff_time, "").equals("")) mUtils.set_alarmPower(sharedPreferences.getString(mUtils.repeat_alarm_poweroff_time, ""), sharedPreferences.getString(mUtils.repeat_alarm_poweron_time, ""), true, "true"); } else if(action.equals("android.intent.action.TIME_SET")) { if(!sharedPreferences.getString(mUtils.repeat_alarm_poweroff_time, "").equals("")) mUtils.set_alarmPower(sharedPreferences.getString(mUtils.repeat_alarm_poweroff_time, ""), sharedPreferences.getString(mUtils.repeat_alarm_poweron_time, ""), true, "true"); } } private void auto_power_shut(Context context, Intent intent) { if(intent.getExtras() == null) { return; } boolean effective = intent.getExtras().getBoolean("effective"); String power_on_time = intent.getExtras().getString("power_time", ""); String power_off_time = intent.getExtras().getString("shut_time", ""); String repeat = intent.getExtras().getString("repeat", ""); int power_type = intent.getExtras().getInt("power_type", -1); switch (power_type) { case 1: //mUtils.reboot(); mUtils.exe_cmd("reboot"); break; case 2: //mUtils.shut_Down(); mUtils.exe_cmd("reboot -p"); break; case 3: mUtils.set_alarmPower(power_off_time, power_on_time, effective, repeat); break; case 4: mUtils.set_time_reboot(power_off_time, effective, repeat); break; } } }