Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Fix log collector and app name
Acho Arnold03902b85c62d
diff --git a/android/app/build.gradle b/android/app/build.gradleindex e961af1d..918c9b54 100644--- a/android/app/build.gradle+++ b/android/app/build.gradle@@ -17,15 +17,12 @@ def getGitHash = { ->android {compileSdk 33- buildToolsVersion "32.0.0"-defaultConfig {applicationId "com.httpsms"minSdk 26targetSdk 33versionCode 1versionName "${getGitHash()}"-testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"}@@ -55,7 +52,7 @@ dependencies {implementation 'com.google.firebase:firebase-messaging-ktx'implementation 'com.squareup.okhttp3:okhttp:4.10.0'implementation 'com.jakewharton.timber:timber:5.0.1'- implementation 'androidx.preference:preference:1.2.0'+ implementation 'androidx.preference:preference:1.2.1'implementation 'androidx.work:work-runtime-ktx:2.7.1'implementation 'androidx.core:core-ktx:1.9.0'implementation "androidx.cardview:cardview:1.0.0"diff --git a/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt b/android/app/src/main/java/com/httpsms/FirebaseMessagingService.ktindex e6521349..128b7de7 100644--- a/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt+++ b/android/app/src/main/java/com/httpsms/FirebaseMessagingService.kt@@ -109,7 +109,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {if (BuildConfig.DEBUG) {Timber.plant(Timber.DebugTree())- Timber.plant(LogtailTree(this.applicationContext))+ Timber.plant(LogzTree(this.applicationContext))}}diff --git a/android/app/src/main/java/com/httpsms/LogtailTree.kt b/android/app/src/main/java/com/httpsms/LogzTree.ktsimilarity index 80%rename from android/app/src/main/java/com/httpsms/LogtailTree.ktrename to android/app/src/main/java/com/httpsms/LogzTree.ktindex 2455af72..82899b05 100644--- a/android/app/src/main/java/com/httpsms/LogtailTree.kt+++ b/android/app/src/main/java/com/httpsms/LogzTree.kt@@ -1,84 +1,89 @@-package com.httpsms--import android.content.Context-import android.os.Build-import com.beust.klaxon.Klaxon-import okhttp3.MediaType.Companion.toMediaType-import okhttp3.OkHttpClient-import okhttp3.Request-import okhttp3.RequestBody.Companion.toRequestBody-import timber.log.Timber-import java.time.ZoneOffset-import java.time.ZonedDateTime-import java.time.format.DateTimeFormatter-import java.util.concurrent.ConcurrentLinkedQueue--class LogtailTree(val context: Context): Timber.DebugTree() {- private val client = OkHttpClient()- private val jsonMediaType = "application/json; charset=utf-8".toMediaType()- private val queue: ConcurrentLinkedQueue<LogEntry> = ConcurrentLinkedQueue<LogEntry>()-- override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {- val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")- val logEntry = LogEntry(- BuildConfig.VERSION_NAME,- priority,- severity(priority),- tag,- message,- Build.MODEL,- Build.BRAND,- Build.DEVICE,- Build.VERSION.SDK_INT,- ZonedDateTime.now(ZoneOffset.UTC).format(formatter),- Settings.getUserID(context),- t- )- queue.add(logEntry)- if (queue.size < 100) {- return- }-- val logEntries = queue.toArray()- queue.clear()-- val request: Request = Request.Builder()- .url("https://in.logtail.com")- .post(Klaxon().toJsonString(logEntries).toRequestBody(jsonMediaType))- .header("Authorization", "Bearer m7ZoA8u5KRYNe6RnEdWeZqsZ")- .build()-- Thread {- try {- val response = client.newCall(request).execute()- response.body?.close()- } catch(_: Exception) {- }- }.start()- }-- private fun severity(priority: Int): String {- return when(priority) {- 3 -> "DEBUG"- 4 -> "INFO"- 5 -> "WARNING"- 6 -> "ERROR"- 7 -> "ASSERT"- else -> "VERBOSE"- }- }-- class LogEntry(- val release: String,- val priority: Int,- val severity: String,- val tag: String?,- val message: String,- val model: String,- val brand: String,- val device: String,- val version: Int,- val dt: String,- val userID: String,- val throwable: Throwable?)-}+package com.httpsms++import android.content.Context+import android.os.Build+import com.beust.klaxon.Json+import com.beust.klaxon.Klaxon+import okhttp3.MediaType.Companion.toMediaType+import okhttp3.OkHttpClient+import okhttp3.Request+import okhttp3.RequestBody.Companion.toRequestBody+import timber.log.Timber+import java.time.ZoneOffset+import java.time.ZonedDateTime+import java.time.format.DateTimeFormatter+import java.util.concurrent.ConcurrentLinkedQueue++class LogzTree(val context: Context): Timber.DebugTree() {+ private val client = OkHttpClient()+ private val jsonMediaType = "application/json; charset=utf-8".toMediaType()+ private val queue: ConcurrentLinkedQueue<LogEntry> = ConcurrentLinkedQueue<LogEntry>()++ override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {+ val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")+ val logEntry = LogEntry(+ BuildConfig.VERSION_NAME,+ priority,+ severity(priority),+ tag,+ message,+ Build.MODEL,+ Build.BRAND,+ Build.DEVICE,+ Build.VERSION.SDK_INT,+ ZonedDateTime.now(ZoneOffset.UTC).format(formatter),+ Settings.getUserID(context),+ t+ )+ queue.add(logEntry)+ if (queue.size < 100) {+ return+ }++ val logEntries = queue.toArray()+ queue.clear()++ val body = logEntries.joinToString(separator = "\n") { x -> Klaxon().toJsonString(x) }+ .toRequestBody("application/x-www-form-urlencoded".toMediaType())++ val request: Request = Request.Builder()+ .url("https://listener.logz.io:8071?token=cTCUVJoTDrPjaFcanAPRzIsYyThyrIDw&type=http-bulk")+ .post(body)+ .header("Content-Type", "application/x-www-form-urlencoded")+ .build()++ Thread {+ try {+ val response = client.newCall(request).execute()+ response.body?.close()+ } catch(ex: Exception) {+ }+ }.start()+ }++ private fun severity(priority: Int): String {+ return when(priority) {+ 3 -> "DEBUG"+ 4 -> "INFO"+ 5 -> "WARNING"+ 6 -> "ERROR"+ 7 -> "ASSERT"+ else -> "VERBOSE"+ }+ }++ class LogEntry(+ val release: String,+ val priority: Int,+ val severity: String,+ val tag: String?,+ val message: String,+ val model: String,+ val brand: String,+ val device: String,+ val version: Int,+ @Json(name = "@timestamp")+ val dt: String,+ val userID: String,+ val throwable: Throwable?)+}diff --git a/android/app/src/main/java/com/httpsms/MainActivity.kt b/android/app/src/main/java/com/httpsms/MainActivity.ktindex ed597a8f..37fb1edb 100644--- a/android/app/src/main/java/com/httpsms/MainActivity.kt+++ b/android/app/src/main/java/com/httpsms/MainActivity.kt@@ -216,7 +216,7 @@ class MainActivity : AppCompatActivity() {if (BuildConfig.DEBUG) {Timber.plant(Timber.DebugTree())- Timber.plant(LogtailTree(this.applicationContext))+ Timber.plant(LogzTree(this.applicationContext))}}diff --git a/android/app/src/main/java/com/httpsms/SettingsActivity.kt b/android/app/src/main/java/com/httpsms/SettingsActivity.ktindex bc89e793..948082e0 100644--- a/android/app/src/main/java/com/httpsms/SettingsActivity.kt+++ b/android/app/src/main/java/com/httpsms/SettingsActivity.kt@@ -82,7 +82,7 @@ class SettingsActivity : AppCompatActivity() {Timber.d("logout button clicked")MaterialAlertDialogBuilder(this).setTitle("Confirm")- .setMessage("Are you sure you want to logout of the Http SMS App?")+ .setMessage("Are you sure you want to logout of the httpSMS App?").setNeutralButton("Cancel"){ _, _ -> Timber.d("logout dialog canceled") }.setPositiveButton("Logout"){_, _ ->Timber.d("logging out user")diff --git a/android/app/src/main/java/com/httpsms/services/StickyNotificationService.kt b/android/app/src/main/java/com/httpsms/services/StickyNotificationService.ktindex c47d7658..5eb7f3e3 100644--- a/android/app/src/main/java/com/httpsms/services/StickyNotificationService.kt+++ b/android/app/src/main/java/com/httpsms/services/StickyNotificationService.kt@@ -68,8 +68,8 @@ class StickyNotificationService: Service() {)return builder- .setContentTitle("SMS Listener")- .setContentText("HTTP SMS is listening for sent and received SMS messages in the background.")+ .setContentTitle("httpSMS Listener")+ .setContentText("httpSMS is listening for sent and received SMS messages in the background.").setContentIntent(pendingIntent).setOngoing(true).setSmallIcon(R.drawable.ic_stat_name)diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xmlindex 14cbd7b4..a3083e47 100644--- a/android/app/src/main/res/values/strings.xml+++ b/android/app/src/main/res/values/strings.xml@@ -1,5 +1,5 @@<resources>- <string name="app_name">HTTP SMS</string>+ <string name="app_name">httpSMS</string><string name="nextRefreshTime">23/06/2022 18:58:30</string><string name="menuIconDescription">Menu Icon</string><string name="menuIconName">More</string>diff --git a/android/build.gradle b/android/build.gradleindex 32e3cd73..90a843f6 100644--- a/android/build.gradle+++ b/android/build.gradle@@ -12,8 +12,8 @@ buildscript {}plugins {- id 'com.android.application' version '8.0.2' apply false- id 'com.android.library' version '8.0.2' apply false+ id 'com.android.application' version '8.1.0' apply false+ id 'com.android.library' version '8.1.0' apply falseid 'org.jetbrains.kotlin.android' version '1.6.21' apply false}