mirror of
https://github.com/KeymonSoft/Monitor-Keymon.git
synced 2026-04-19 21:59:26 +00:00
09/09/23 - Panel de configuración y servicio al arranque
Se agregó´un panel para cambiar algunos parametros de la aplicación y se agregó´un servicio para que el monitor arranque junto con el dispositivo, para esto es necesario darle permisos para accesar las notificaciones del sistema.
This commit is contained in:
334
B4A/Starter.bas
334
B4A/Starter.bas
@@ -5,7 +5,7 @@ Type=Service
|
||||
Version=9.85
|
||||
@EndOfDesignText@
|
||||
#Region Service Attributes
|
||||
#StartAtBoot: False
|
||||
#StartAtBoot: true
|
||||
#ExcludeFromLibrary: True
|
||||
#End Region
|
||||
|
||||
@@ -13,25 +13,25 @@ Sub Process_Globals
|
||||
'These global variables will be declared once when the application starts.
|
||||
'These variables can be accessed from all modules.
|
||||
Public rp As RuntimePermissions
|
||||
Dim reqManager As DBRequestManager
|
||||
Dim server As String = "http://keymon.lat:1782"
|
||||
Dim Timer1 As Timer
|
||||
Dim Interval As Int = 5
|
||||
Public rp As RuntimePermissions
|
||||
' Dim reqManager As DBRequestManager
|
||||
Dim DBReqServer As String = "http://keymon.lat:1782"
|
||||
Dim skmt As SQL
|
||||
' Dim Timer1 As Timer
|
||||
' Dim Interval As Int = 30
|
||||
Dim s As C_Subs
|
||||
Dim nid As Int = 51042
|
||||
' Dim nid As Int = 51042
|
||||
Dim monitorActivo As Boolean = True
|
||||
Dim InternetOk As Boolean = True
|
||||
Dim DBReqServerOk As Boolean = True
|
||||
Dim DBOk As Boolean = True
|
||||
' Dim InternetOk As Boolean = True
|
||||
' Dim DBReqServerOk As Boolean = True
|
||||
' Dim DBOk As Boolean = True
|
||||
Dim logger As Boolean = False
|
||||
End Sub
|
||||
|
||||
Sub Service_Create
|
||||
'This is the program entry point.
|
||||
'This is a good place to load resources that are not specific to a single activity.
|
||||
Timer1.Initialize("Timer1", Interval * 1000)
|
||||
Timer1.Enabled = True
|
||||
' Timer1.Initialize("Timer1", Interval * 1000)
|
||||
' Timer1.Enabled = True
|
||||
#if not(DEBUG)
|
||||
logger = False
|
||||
#end if
|
||||
@@ -39,53 +39,56 @@ End Sub
|
||||
|
||||
Sub Service_Start (StartingIntent As Intent)
|
||||
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
|
||||
Service.StartForeground(nid, CreateNotification("..."))
|
||||
reqManager.Initialize(Me, server)
|
||||
s.Initialize
|
||||
Timer1_Tick
|
||||
End Sub
|
||||
|
||||
Sub CreateNotification (Body As String) As Notification
|
||||
Dim notification As Notification
|
||||
notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||
notification.Icon = "icon"
|
||||
notification.SetInfo("Tester", Body, Main)
|
||||
Return notification
|
||||
End Sub
|
||||
|
||||
'Genera una notificacion con importancia alta
|
||||
Sub notiHigh(title As String, body As String, id As String, activity As Object) 'ignore
|
||||
activity = Main
|
||||
Private notif As Notification
|
||||
notif.Initialize2(notif.IMPORTANCE_HIGH)
|
||||
notif.Icon = "icon"
|
||||
notif.Vibrate = False
|
||||
notif.Sound = False
|
||||
notif.AutoCancel = True
|
||||
if logger then Log("notiHigh: "&title)
|
||||
notif.SetInfo(title, body, activity)
|
||||
' Log("notiHigh SetInfo")
|
||||
notif.Notify(id)
|
||||
End Sub
|
||||
|
||||
'Regresa el objeto de una notificacion con importancia baja
|
||||
Sub notiLowReturn(title As String, Body As String, id As Int) As Notification 'ignore
|
||||
Private notification As Notification
|
||||
notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||
' Log("notiLowReturn: "&title)
|
||||
notification.Icon = "icon"
|
||||
notification.Sound = False
|
||||
notification.Vibrate = False
|
||||
notification.SetInfo(title, Body, Main)
|
||||
notification.Notify(id)
|
||||
' Log("notiLowReturn SetInfo")
|
||||
Return notification
|
||||
End Sub
|
||||
|
||||
Sub Timer1_Tick
|
||||
' Log("Next run " & DateTime.Time(DateTime.Now + Interval * 1000))
|
||||
If monitorActivo Then probamosConexion
|
||||
skmt = s.inicializaBD(File.DirInternal, "kmt.db")
|
||||
skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS cat_variables(nombre TEXT, valor text)")
|
||||
If s.traeDBReqServerDeBD <> "N/A" Then DBReqServer = s.traeDBReqServerDeBD
|
||||
' reqManager.Initialize(Me, DBReqServer)
|
||||
StartService(Monitor)
|
||||
End Sub
|
||||
'
|
||||
'Sub CreateNotification (Body As String) As Notification
|
||||
' Dim notification As Notification
|
||||
' notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||
' notification.Icon = "icon"
|
||||
' notification.SetInfo("Tester", Body, Main)
|
||||
' Return notification
|
||||
'End Sub
|
||||
'
|
||||
''Genera una notificacion con importancia alta
|
||||
'Sub notiHigh(title As String, body As String, id As String, activity As Object) 'ignore
|
||||
' activity = Main
|
||||
' Private notif As Notification
|
||||
' notif.Initialize2(notif.IMPORTANCE_HIGH)
|
||||
' notif.Icon = "icon"
|
||||
' notif.Vibrate = False
|
||||
' notif.Sound = False
|
||||
' notif.AutoCancel = True
|
||||
' If logger Then Log("notiHigh: "&title)
|
||||
' notif.SetInfo(title, body, activity)
|
||||
'' Log("notiHigh SetInfo")
|
||||
' notif.Notify(id)
|
||||
'End Sub
|
||||
'
|
||||
''Regresa el objeto de una notificacion con importancia baja
|
||||
'Sub notiLowReturn(title As String, Body As String, id As Int) As Notification 'ignore
|
||||
' Private notification As Notification
|
||||
' notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||
'' Log("notiLowReturn: "&title)
|
||||
' notification.Icon = "icon"
|
||||
' notification.Sound = False
|
||||
' notification.Vibrate = False
|
||||
' notification.SetInfo(title, Body, Main)
|
||||
' notification.Notify(id)
|
||||
'' Log("notiLowReturn SetInfo")
|
||||
' Return notification
|
||||
'End Sub
|
||||
'
|
||||
'Sub Timer1_Tick
|
||||
'' DateTime.DateFormat = "dd/MM HH:mm:ss"
|
||||
'' If B4XPages.IsInitialized Then B4XPages.MainPage.l_ultimoPing.Text = $"Último ping: ${DateTime.Date(DateTime.now)}"$
|
||||
'' If monitorActivo Then probamosConexion
|
||||
'End Sub
|
||||
|
||||
Sub Service_TaskRemoved
|
||||
'This event will be raised when the user removes the app from the recent apps list.
|
||||
@@ -94,109 +97,114 @@ End Sub
|
||||
Sub Service_Destroy
|
||||
|
||||
End Sub
|
||||
|
||||
Sub probamosConexion
|
||||
' Log("probamos probamosConexion")
|
||||
If B4XPages.IsInitialized Then
|
||||
B4XPages.MainPage.cb_internet.Checked = False
|
||||
B4XPages.MainPage.cb_dbreqserver.Checked = False
|
||||
B4XPages.MainPage.cb_db.Checked = False
|
||||
End If
|
||||
If IsConnectedToInternet Then
|
||||
InternetOk = True
|
||||
If B4XPages.IsInitialized Then B4XPages.MainPage.cb_internet.Checked = True
|
||||
Dim cmd As DBCommand
|
||||
notiLowReturn("Con internet", "Hay conexion a internet", nid)
|
||||
If B4XPages.IsInitialized Then B4XPages.MainPage.l_status.Text = "Hay conexion a internet!!"
|
||||
Dim cmd As DBCommand
|
||||
cmd.Initialize
|
||||
cmd.Name = "select_conexion"
|
||||
reqManager.ExecuteQuery(cmd, 0, "select_conexion", 750)
|
||||
'Reiniciamos el timer para cuando llamamos el Sub desde "seleccion"
|
||||
Timer1.Enabled = False
|
||||
Timer1.Interval = Interval * 1000
|
||||
Timer1.Enabled = True
|
||||
Else
|
||||
if logger then Log("Sin conexión a internet!!!")
|
||||
notiLowReturn("Sin internet", "NO hay conexion a internet", nid)
|
||||
If B4XPages.IsInitialized Then B4XPages.MainPage.l_status.Text = "NO hay conexion a internet!!"
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Sub reinicializaReqManager
|
||||
reqManager.Initialize(Me, server)
|
||||
' B4XPages.MainPage.reqManager.Initialize(Me, server)
|
||||
' If logger Then Log(server)
|
||||
End Sub
|
||||
|
||||
|
||||
'[b4xcollections=Null, B4XPages=Null, defaultscheme=https
|
||||
'[b4xcollections=null, b4xpages=null, defaultscheme=https
|
||||
', errormessage=, HttpUtils2Service=Null, invalidurl=https://invalid-url/
|
||||
', errormessage=, httputils2service=null, invalidurl=https://invalid-url/
|
||||
', jobname=DBRequest, Main=Null, out=(BufferedOutputStream) java.io.BufferedOutputStream@3406019
|
||||
', jobname=DBRequest, main=null, out=(BufferedOutputStream) java.io.BufferedOutputStream@3672b93
|
||||
', password=, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@c06b8de, response=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpResponse@4e48abf
|
||||
', password=, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@8e687d0, response=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpResponse@26963c9
|
||||
', starter=Null, success=True, tag=select_conexion>XXX
|
||||
', starter=null, success=true, tag=select_conexionXXX
|
||||
', target=class md.keymon.com.mx.starter, taskid=8, username=
|
||||
', target=class md.keymon.com.mx.starter, taskid=2, username=
|
||||
|
||||
|
||||
|
||||
|
||||
Sub JobDone(Job As HttpJob)
|
||||
' Log("JOBDONE -- " & Job.Success)
|
||||
' Log(Job)
|
||||
If Job.Success = False Then
|
||||
If Job.JobName = "DBRequest" Then DBReqServerOk = False
|
||||
notiHigh("Con internet", $"El servidor NO esta respondiendo!!"$, nid, Main)
|
||||
If Job.ErrorMessage.Contains("failed to connect") Or Job.ErrorMessage.Contains("Failed to connect") Then
|
||||
ToastMessageShow("¡Hubo un error contactando al servidor, por favor revise su conexión!", True)
|
||||
End If
|
||||
Else
|
||||
If Job.JobName = "DBRequest" Then DBReqServerOk = True
|
||||
if logger then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211027
|
||||
If Job.JobName = "DBRequest" Then
|
||||
Dim resultado As DBResult = reqManager.HandleJob(Job)
|
||||
If resultado.Tag = "select_conexion" Then
|
||||
For Each records() As Object In resultado.Rows
|
||||
Private valor As String = records(resultado.Columns.Get("VALOR"))
|
||||
If valor = "OK" Then
|
||||
DBOk = True
|
||||
notiLowReturn("Con internet", $"El servidor esta respondiendo!!"$, nid)
|
||||
If B4XPages.IsInitialized Then B4XPages.MainPage.l_status.Text = "El servidor esta respondiendo!!"
|
||||
Else
|
||||
notiHigh("Con internet", $"El servidor NO esta respondiendo!!"$, nid, Main)
|
||||
If B4XPages.IsInitialized Then B4XPages.MainPage.l_status.Text = "El servidor NO esta respondiendo!!"
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
' s.logJobDoneResultados(resultado)
|
||||
If resultado.Rows.Size = 0 Then DBOk = False
|
||||
' Log(resultado.Rows.Size)
|
||||
End If
|
||||
If B4XPages.IsInitialized Then
|
||||
B4XPages.MainPage.cb_internet.Checked = InternetOk
|
||||
B4XPages.MainPage.cb_dbreqserver.Checked = DBReqServerOk
|
||||
B4XPages.MainPage.cb_db.Checked = DBOk
|
||||
End If
|
||||
Job.Release
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Sub IsConnectedToInternet As Boolean 'ignore
|
||||
Dim r As Reflector
|
||||
r.Target = r.GetContext
|
||||
r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
|
||||
r.Target = r.RunMethod("getActiveNetworkInfo")
|
||||
If r.Target <> Null Then
|
||||
If logger Then LogColor("isConnectedOrConnecting", Colors.green)
|
||||
Return r.RunMethod("isConnectedOrConnecting")
|
||||
End If
|
||||
if logger then LogColor("Not connected", Colors.red)
|
||||
Return False
|
||||
End Sub
|
||||
'
|
||||
'Sub probamosConexion
|
||||
'' Log("probamos probamosConexion")
|
||||
' If B4XPages.IsInitialized Then
|
||||
' B4XPages.MainPage.cb_internet.Checked = False
|
||||
' B4XPages.MainPage.cb_dbreqserver.Checked = False
|
||||
' B4XPages.MainPage.cb_db.Checked = False
|
||||
' End If
|
||||
' If IsConnectedToInternet Then
|
||||
' InternetOk = True
|
||||
' If B4XPages.IsInitialized Then
|
||||
' B4XPages.MainPage.cb_internet.Checked = True
|
||||
' Dim cd1 As ColorDrawable
|
||||
' cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
|
||||
' B4XPages.MainPage.b_ping.Background = cd1
|
||||
' B4XPages.MainPage.b_ping.Text = "Internet Ok"
|
||||
' End If
|
||||
' Dim cmd As DBCommand
|
||||
' notiLowReturn("Con internet", "Hay conexion a internet", nid)
|
||||
' If B4XPages.IsInitialized Then B4XPages.MainPage.l_status.Text = "Hay conexion a internet!!"
|
||||
' Dim cmd As DBCommand
|
||||
' cmd.Initialize
|
||||
' cmd.Name = "select_conexion"
|
||||
' reqManager.ExecuteQuery(cmd, 0, "select_conexion", 1250)
|
||||
' 'Reiniciamos el timer para cuando llamamos el Sub desde "seleccion"
|
||||
' Timer1.Enabled = False
|
||||
' Timer1.Interval = Interval * 1000
|
||||
' Timer1.Enabled = True
|
||||
' Else
|
||||
' If logger Then Log("Sin conexión a internet!!!")
|
||||
' notiLowReturn("Sin internet", "NO hay conexion a internet", nid)
|
||||
' If B4XPages.IsInitialized Then B4XPages.MainPage.l_status.Text = "NO hay conexion a internet!!"
|
||||
' End If
|
||||
'
|
||||
'End Sub
|
||||
'
|
||||
'Sub reinicializaReqManager
|
||||
' reqManager.Initialize(Me, DBReqServer)
|
||||
' If logger Then Log("Inicializamos con: " & DBReqServer)
|
||||
'End Sub
|
||||
'
|
||||
'Sub JobDone(Job As HttpJob)
|
||||
'' Log("JOBDONE -- " & Job.Success)
|
||||
'' Log(Job)
|
||||
' If Job.Success = False Then
|
||||
' If Job.JobName = "DBRequest" Then DBReqServerOk = False
|
||||
'
|
||||
' Dim cd1 As ColorDrawable
|
||||
' cd1.Initialize(Colors.Red, 10dip)
|
||||
' B4XPages.MainPage.b_ping.Background = cd1
|
||||
' B4XPages.MainPage.b_ping.Text = "DBReqServer KO"
|
||||
' notiHigh("Con internet", $"El servidor ${DBReqServer} NO responde!!"$, nid, Main)
|
||||
' If Job.ErrorMessage.Contains("failed to connect") Or Job.ErrorMessage.Contains("Failed to connect") Then
|
||||
' ToastMessageShow("¡Hubo un error contactando al servidor, por favor revise su conexión!", True)
|
||||
' End If
|
||||
' Else
|
||||
' If Job.JobName = "DBRequest" Then DBReqServerOk = True
|
||||
' If logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211027
|
||||
' If Job.JobName = "DBRequest" Then
|
||||
' Dim resultado As DBResult = reqManager.HandleJob(Job)
|
||||
' If resultado.Tag = "select_conexion" Then
|
||||
' For Each records() As Object In resultado.Rows
|
||||
' Private valor As String = records(resultado.Columns.Get("VALOR"))
|
||||
' If valor = "OK" Then
|
||||
' DBOk = True
|
||||
' notiLowReturn("Con internet", $"El servidor esta respondiendo!!"$, nid)
|
||||
' If B4XPages.IsInitialized Then
|
||||
' B4XPages.MainPage.l_status.Text = "El servidor esta respondiendo!!"
|
||||
' Dim cd1 As ColorDrawable
|
||||
' cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
|
||||
' B4XPages.MainPage.b_ping.Background = cd1
|
||||
' B4XPages.MainPage.b_ping.Text = "Servidor Ok"
|
||||
' End If
|
||||
' Else
|
||||
' notiHigh("Con internet", $"El servidor NO esta respondiendo!!"$, nid, Main)
|
||||
' If B4XPages.IsInitialized Then
|
||||
' B4XPages.MainPage.l_status.Text = "El servidor NO esta respondiendo!!"
|
||||
' Dim cd1 As ColorDrawable
|
||||
' cd1.Initialize(Colors.Red, 10dip)
|
||||
' B4XPages.MainPage.b_ping.Background = cd1
|
||||
' B4XPages.MainPage.b_ping.Text = "Servidor KO"
|
||||
' End If
|
||||
' End If
|
||||
' Next
|
||||
' End If
|
||||
'' s.logJobDoneResultados(resultado)
|
||||
' If resultado.Rows.Size = 0 Then DBOk = False
|
||||
'' Log(resultado.Rows.Size)
|
||||
' End If
|
||||
' If B4XPages.IsInitialized Then
|
||||
' B4XPages.MainPage.cb_internet.Checked = InternetOk
|
||||
' B4XPages.MainPage.cb_dbreqserver.Checked = DBReqServerOk
|
||||
' B4XPages.MainPage.cb_db.Checked = DBOk
|
||||
' End If
|
||||
' Job.Release
|
||||
' End If
|
||||
'
|
||||
'End Sub
|
||||
'
|
||||
'Sub IsConnectedToInternet As Boolean 'ignore
|
||||
' Dim r As Reflector
|
||||
' r.Target = r.GetContext
|
||||
' r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
|
||||
' r.Target = r.RunMethod("getActiveNetworkInfo")
|
||||
' If r.Target <> Null Then
|
||||
' If logger Then LogColor("isConnectedOrConnecting", Colors.green)
|
||||
' Return r.RunMethod("isConnectedOrConnecting")
|
||||
' End If
|
||||
' If logger Then LogColor("Not connected", Colors.red)
|
||||
' Return False
|
||||
'End Sub
|
||||
|
||||
Reference in New Issue
Block a user