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