Skip to content

Commit

Permalink
添加啓動服務
Browse files Browse the repository at this point in the history
  • Loading branch information
qwe7002 committed Nov 30, 2024
1 parent f587e2f commit 8dc16a9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ class BeaconReceiverService : Service() {
call.enqueue(object : Callback {

override fun onFailure(call: Call, e: IOException) {
Resend.addResendLoop(requestBody.text)
Resend.addResendLoop(applicationContext,requestBody.text)
e.printStackTrace()
}

Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/qwe7002/telegram_rc/CallReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ class CallReceiver : BroadcastReceiver() {
slot,
preferences.read("display_dual_sim_display_name", false)!!
)
/*
requestBody.text = """
[$dualSim${context.getString(R.string.missed_call_head)}]
${context.getString(R.string.Incoming_number)}$incomingNumber
""".trimIndent()
*/
requestBody.text = "[" + dualSim + context.getString(R.string.missed_call_head) + "]" + "\n" + context.getString(R.string.Incoming_number) + incomingNumber

val requestBodyRaw = Gson().toJson(requestBody)
val body: RequestBody = requestBodyRaw.toRequestBody(Const.JSON)
Expand All @@ -105,7 +108,7 @@ class CallReceiver : BroadcastReceiver() {
requestBody.text,
Other.getSubId(context, slot)
)
Resend.addResendLoop(requestBody.text)
Resend.addResendLoop(context,requestBody.text)
}

@Throws(IOException::class)
Expand All @@ -116,7 +119,7 @@ class CallReceiver : BroadcastReceiver() {
errorHead + response.code + " " + Objects.requireNonNull(response.body)
.string()
)
Resend.addResendLoop(requestBody.text)
Resend.addResendLoop(context,requestBody.text)
} else {
val result = Objects.requireNonNull(response.body).string()
if (!Other.isPhoneNumber(incomingNumber)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ class NotifyListenerService : NotificationListenerService() {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
LogManage.writeLog(applicationContext, errorHead + e.message)
Resend.addResendLoop(requestBody.text)
Resend.addResendLoop(applicationContext, requestBody.text)
}

@Throws(IOException::class)
override fun onResponse(call: Call, response: Response) {
val result = Objects.requireNonNull(response.body).string()
if (response.code != 200) {
LogManage.writeLog(applicationContext, errorHead + response.code + " " + result)
Resend.addResendLoop(requestBody.text)
Resend.addResendLoop(applicationContext, requestBody.text)
}
}
})
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/qwe7002/telegram_rc/SMSReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,11 @@ class SMSReceiver : BroadcastReceiver() {
if (messageBody.contains(blockListItem)) {
val simpleDateFormat =
SimpleDateFormat(context.getString(R.string.time_format), Locale.UK)
val writeMessage = """
/* val writeMessage = """
${requestBody.text}
${context.getString(R.string.time)}${simpleDateFormat.format(Date(System.currentTimeMillis()))}
""".trimIndent()
""".trimIndent()*/
val writeMessage = requestBody.text + "\n" + context.getString(R.string.time) + simpleDateFormat.format(Date(System.currentTimeMillis()))
Paper.init(context)
val spamSmsList = Paper.book().read("spam_sms_list", ArrayList<String>())!!
if (spamSmsList.size >= 5) {
Expand All @@ -254,7 +255,7 @@ class SMSReceiver : BroadcastReceiver() {
Log.d(logTag, e.toString())
writeLog(context, errorHead + e.message)
SMS.sendFallbackSMS(context, finalRawRequestBodyText, subId)
addResendLoop(requestBody.text)
addResendLoop(context,requestBody.text)
commandHandle(messageBody, dataEnable)
}

Expand All @@ -266,7 +267,7 @@ class SMSReceiver : BroadcastReceiver() {
if (!finalIsFlash) {
SMS.sendFallbackSMS(context, finalRawRequestBodyText, subId)
}
addResendLoop(requestBody.text)
addResendLoop(context,requestBody.text)
} else {
if (!Other.isPhoneNumber(messageAddress)) {
writeLog(context, "[$messageAddress] Not a regular phone number.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SMSSendResultReceiver : BroadcastReceiver() {
e.printStackTrace()
writeLog(context, errorHead + e.message)
SMS.sendFallbackSMS(context, requestBody.text, sub)
addResendLoop(requestBody.text)
addResendLoop(context,requestBody.text)
}

@Throws(IOException::class)
Expand All @@ -87,7 +87,7 @@ class SMSSendResultReceiver : BroadcastReceiver() {
errorHead + response.code + " " + Objects.requireNonNull(response.body)
.string()
)
addResendLoop(requestBody.text)
addResendLoop(context,requestBody.text)
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/qwe7002/telegram_rc/USSDCallBack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class USSDCallBack(
Log.d("ussdRequest", "onFailure: $e")
LogManage.writeLog(context, errorHead + e.message)
SMS.sendFallbackSMS(context, requestBody.text, -1)
addResendLoop(requestBody.text)
addResendLoop(context,requestBody.text)
}

@Throws(IOException::class)
Expand All @@ -100,7 +100,7 @@ class USSDCallBack(
.string()
)
SMS.sendFallbackSMS(context, requestBody.text, -1)
addResendLoop(requestBody.text)
addResendLoop(context,requestBody.text)
}
}
})
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/com/qwe7002/telegram_rc/static_class/Resend.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package com.qwe7002.telegram_rc.static_class

import android.content.Context
import com.qwe7002.telegram_rc.R
import com.qwe7002.telegram_rc.ReSendJob
import io.paperdb.Paper
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

object Resend {
@JvmStatic
fun addResendLoop(message: String) {
val resendList = Paper.book().read(
"resend_list",
ArrayList<String>()
)!!
fun addResendLoop(context: Context, msg: String) {
var message = msg
Paper.init(context)
val resendList = Paper.book().read("resend_list", ArrayList<String>())
val simpleDateFormat = SimpleDateFormat(context.getString(R.string.time), Locale.UK)
message += "\n"+context.getString(R.string.time) + simpleDateFormat.format(Date(System.currentTimeMillis()))
checkNotNull(resendList)
resendList.add(message)
Paper.book().write("resend_list", resendList)
ReSendJob.startJob(context)
}
}

0 comments on commit 8dc16a9

Please sign in to comment.