-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inicaliza servicios de monitoreo al inicio del telefono. Close #17
- Loading branch information
1 parent
75a4d1f
commit 1512633
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/main/java/cl/niclabs/adkintunmobile/services/StartUp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cl.niclabs.adkintunmobile.services; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
import cl.niclabs.adkintunmobile.services.monitors.ConnectivityMonitor; | ||
import cl.niclabs.adkintunmobile.services.monitors.TelephonyMonitor; | ||
import cl.niclabs.adkintunmobile.services.monitors.TrafficMonitor; | ||
import cl.niclabs.adkintunmobile.services.sync.SynchronizationBroadcastReceiver; | ||
import cl.niclabs.adkmobile.monitor.Device; | ||
|
||
public class StartUp extends Device{ | ||
@Override | ||
public void onBootCompleted(Context context) { | ||
super.onBootCompleted(context); | ||
bootOnSystem(context); | ||
} | ||
|
||
@Override | ||
public void onShutdown(Context context) { | ||
super.onShutdown(context); | ||
bootOffSystem(context); | ||
} | ||
|
||
/* | ||
* Static methods for service settings and timers | ||
*/ | ||
|
||
static public void bootOnSystem(Context context){ | ||
|
||
// Start Monitoring Services | ||
StartUp.startMonitoringServices(context); | ||
|
||
// Start Broadcast Receivers | ||
StartUp.schedulleBroadcastReceivers(context); | ||
} | ||
|
||
static public void startMonitoringServices(Context context){ | ||
if(!ConnectivityMonitor.isRunning()) | ||
context.startService(new Intent(context, ConnectivityMonitor.class)); | ||
if(!TelephonyMonitor.isRunning()) | ||
context.startService(new Intent(context, TelephonyMonitor.class)); | ||
if(!TrafficMonitor.isRunning()) | ||
context.startService(new Intent(context, TrafficMonitor.class)); | ||
} | ||
|
||
private void bootOffSystem(Context context) { | ||
if(ConnectivityMonitor.isRunning()) | ||
context.stopService(new Intent(context, ConnectivityMonitor.class)); | ||
if(TelephonyMonitor.isRunning()) | ||
context.stopService(new Intent(context, TelephonyMonitor.class)); | ||
if(TrafficMonitor.isRunning()) | ||
context.stopService(new Intent(context, TrafficMonitor.class)); | ||
} | ||
|
||
static public void schedulleBroadcastReceivers(Context context) { | ||
SynchronizationBroadcastReceiver sync = new SynchronizationBroadcastReceiver(); | ||
sync.setSchedulle(context); | ||
} | ||
|
||
|
||
|
||
} |