Files
FLP_2.0/Starter.bas
Jose Alberto Guerra Ugalde 59b0831740 - Se paso la logica y restricciones de Tracker.FLP_LocationChanged a Subs.mandaLoc2.
- Se puso que con cualquier notificacion revise si puede mandar la ubicacion.
- Se puso que cuando se solicite la ubicacion con FirebaseMessaging, se mande tambien a PUSH_INFO.
2024-05-11 04:27:54 -06:00

137 lines
4.2 KiB
QBasic

B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Service
Version=9.9
@EndOfDesignText@
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
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 'Para obtener permisos android 6+
Public FLP As FusedLocationProvider 'Para Tracker
Dim reqManager As DBRequestManager
Dim cmd As DBCommand
Dim Timer1 As Timer
Dim interval As Int = 1800 '1800 segs (30 mins)
Dim UUC As Location
Dim run As Int = 0 'ignore
Dim devModel As String
Dim lastLocUpdate As String = 0
Dim errorLog As SQL
Dim PE As PhoneEvents
Dim PhId As PhoneId
Dim callStartTime, callEndTime As Long
Dim isIncoming As Boolean
Dim lastState As String = "IDLE"
Dim savedNumber As String
Dim locAntTime As String = "0"
Dim logger As Boolean = True
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.
Subs.revisaBD
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'Para FirebaseMessaging
lastState = "IDLE"
PE.InitializeWithPhoneState("PE",PhId)
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
reqManager.Initialize(Me, "http://keymon.lat:1781")
Timer1.Initialize("Timer1", interval * 1000)
Timer1.Enabled = True
UUC.Initialize
UUC.Accuracy = 1000
Subs.getPhnId
Subs.bitacora($"Starter - Service_Start"$)
StartService(Tracker)
StartServiceAt(Tracker, DateTime.Now + 30 * DateTime.TicksPerMinute, True)
#if RELEASE
logger = False
#end if
Subs.revisaYmandaUUC
End Sub
Private Sub Timer1_Tick
' Log("TIMER1: " & Timer1)
Subs.borraArribaDeXXXBitacora(3000)
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Subs.bitacora($"ERROR -> ${Error}"$)
Return True
End Sub
Sub Service_Destroy
Subs.bitacora($"Starter - Service destroyed"$)
' Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${devModel}', 'Starter - Service destroyed')"$)
End Sub
Sub restartTracker
If logger Then Log("Llamamos RESTART-TRACKER")
Subs.bitacora("Llamamos RESTART-TRACKER")
StopService(Tracker)
Sleep(1000)
StartService(Tracker)
End Sub
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
'Incoming call- goes from IDLE To RINGING when it rings, To OFFHOOK when it's answered, to IDLE when its hung up
'Outgoing call- goes from IDLE To OFFHOOK when it dials out, To IDLE when hung up
Log($">>>>> Phone State Changed -> ${State} -> "$ & IncomingNumber)
If IncomingNumber = "" Then
Return
End If
Log($">>>>> Phone State Changed 2 -> ${State} -> "$ & IncomingNumber)
Select State
Case "RINGING"
'calling in progress
isIncoming = True
callStartTime = DateTime.Now
savedNumber = IncomingNumber
Subs.bitacora($"RINGING - ${IncomingNumber}"$)
Exit
Case "OFFHOOK"
'Transition of ringing->offhook are pickups of incoming calls. Nothing donw on them
If lastState <> "RINGING" Then
'outgoing call start
isIncoming = False
callStartTime = DateTime.Now
Subs.bitacora($"OFFHOOK - ${savedNumber}"$)
End If
Exit
Case "IDLE"
'Went to idle- this is the end of a call. What type depends on previous state(s)
If lastState = "RINGING" Then
'missed call
callEndTime = 0
Subs.bitacora($"IDLE - Missed call (${IncomingNumber}): ${callEndTime}"$)
else if isIncoming Then
'incoming call is finished
callEndTime = DateTime.Now
Subs.bitacora($"IDLE - Incoming call is finished (${IncomingNumber}): ${callEndTime}"$)
Else
'outgoing call is finished
callEndTime = DateTime.Now
Subs.bitacora($"IDLE - Outgoing call is finished (${IncomingNumber}): ${callEndTime}"$)
End If
Exit
End Select
lastState = State
'Log("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber & "; PhoneFlag = " & PhoneFlag)
End Sub