#Region Module Attributes
#StartAtBoot: true
#End Region
'Service module
Sub Process_Globals
Dim PE As PhoneEvents 'gives you the phone events as they are happening - lib Phone ver. 2.25
Dim AC As AnswerCall 'used for answering the call - lib AnswerCall ver. 1.00
Dim PhoneId As PhoneId 'needed for PE Initialization
Dim sNotif As Notification 'used for foreground services - required by android
' Dim pnum As String 'used for writing number to file - uses lib randomaccessfile ver. 2.00
Dim blklist As List 'used for checking numbers as they come in
' Dim r As Reflector ' uses lib Reflection ver. 2.40
Dim bnmatched As Boolean 'used for a match of a blacklisted/bad number
Dim tones As MediaPlayer
End Sub
Sub Service_Create
'Log("PID " & PhoneId)
PE.InitializeWithPhoneState("PE",PhoneId)
AC.Initialize("AnswerCall")
'Log("Service created")
sNotif.Initialize
sNotif.Icon = "icon"
sNotif.Vibrate = False
sNotif.SetInfo("AnswerCall","Service Running",Main)
sNotif.Sound = False
sNotif.Notify(1)
Service.StartForeground(1,sNotif)
End Sub
Sub Service_Start (StartingIntent As Intent)
'Log("Service started.")
ReadMeInfo
' tones.Initialize2("killIt")
End Sub
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
'Log("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber)
'Log(Intent.ExtrasToString)
bnmatched = False
'Log("State1: " & State)
' pnum = IncomingNumber
'ToastMessageShow(IncomingNumber,False)
' Dim bnmatched As Boolean
'If AC.isRinging == True Then
For Each badnum As String In blklist
If IncomingNumber = badnum Then
bnmatched = True
'Log("Number: " & badnum)
'ToastMessageShow("BlackListed Number: " & badnum,True)
'Return
End If
Next
If bnmatched = True Then
AC.LetPhoneRing(1000)
'answer the call to stop the call from going to voicemail.
AC.AnswerPhone
DoEvents
AC.enableSpeakerphone 'just for kicks
DoEvents
End If
'Log("State2: " & State)
'ToastMessageShow("Killing1: " & badnum,False)
If (bnmatched = True) Then
'Log("Killing2: " & badnum)
' Try
' Dim r As Reflector ' uses lib Reflection ver. 2.40
' r.Target = r.GetContext
' Dim TelephonyManager, TelephonyInterface As Object
' TelephonyManager = r.RunMethod2("getSystemService", "phone", "java.lang.String")
' r.Target = TelephonyManager
' TelephonyInterface = r.RunMethod("getITelephony")
' r.Target = TelephonyInterface
' r.RunMethod("endCall")
' Catch
' Log("Kill error: " & LastException)
' End Try
'Log("Finished killing " & badnum)
playIt
End If
'End If
'Log("State3: " & State)
End Sub
Sub Service_Destroy
End Sub
'Sub WriteMeInfo
'Dim TextWriter1 As TextWriter
'Log("Number " & pnum)
' Try
' If File.Exists(File.DirDefaultExternal, "blacklist.txt") Then
' TextWriter1.Initialize(File.openOutput(File.DirDefaultExternal, "blacklist.txt", True))
' TextWriter1.WriteLine(pnum)
' TextWriter1.Close
' Else
' TextWriter1.Initialize(File.openOutput(File.DirDefaultExternal, "blacklist.txt", False))
' TextWriter1.WriteLine(pnum)
' TextWriter1.Close
' End If
' Catch
' Log("Making new list: " &LastException.Message)
' End Try
'End Sub
Sub ReadMeInfo
Dim rdr As TextReader
'1. Read the file
Try
If File.Exists(File.DirDefaultExternal, "blacklist.txt") Then
rdr.Initialize(File.openInput(File.DirDefaultExternal,"blacklist.txt"))
blklist = rdr.ReadList
rdr.Close
Else
ToastMessageShow("Black List File Not Found", True)
DoEvents
Return
End If
Catch
Log("Getting List error: " &LastException.Message)
End Try
Log("Getting List Finished")
End Sub
Sub playIt
Log("Starting Tones")
Try
tones.Initialize'2("killIt")
If File.Exists(File.DirDefaultExternal, "tone.mp3") Then
tones.Load(File.DirDefaultExternal, "tone.mp3")
tones.Looping = False
tones.Play
End If
'ToastMessageShow("Playing tones", False)
'
DoEvents
DoEvents
DoEvents
Log("Stopping Tones")
'
Catch
Log("Player error: " &LastException.Message)
End Try
Do While tones.IsPlaying
'Log("Playing now")
Loop
killIt
tones.Stop
tones.Release
End Sub
Sub killIt
Log("Killing call")
Try
Dim r As Reflector ' uses lib Reflection ver. 2.40
r.Target = r.GetContext
Dim TelephonyManager, TelephonyInterface As Object
TelephonyManager = r.RunMethod2("getSystemService", "phone", "java.lang.String")
r.Target = TelephonyManager
TelephonyInterface = r.RunMethod("getITelephony")
r.Target = TelephonyInterface
r.RunMethod("endCall")
Catch
Log("Kill error: " & LastException)
End Try
End Sub
'Sub KillCall
' Dim r As Reflector ' uses lib Reflection ver. 2.40
' r.Target = r.GetContext
' Dim TelephonyManager, TelephonyInterface As Object
' TelephonyManager = r.RunMethod2("getSystemService", "phone", "java.lang.String")
' r.Target = TelephonyManager
' TelephonyInterface = r.RunMethod("getITelephony")
' r.Target = TelephonyInterface
' r.RunMethod("endCall")
'
'End Sub