Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class GatewayApi(

data class DevicePatchRequest(
val id: String,
val pushToken: String,
val pushToken: String?,
)

data class MessagePatchRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class GatewayService(
}
//endregion

//region Device
//region Device
internal suspend fun registerDevice(
pushToken: String?,
registerMode: RegistrationMode
Expand Down Expand Up @@ -162,15 +162,13 @@ class GatewayService(
val settings = settings.registrationInfo ?: return
val accessToken = settings.token

pushToken?.let {
api.devicePatch(
accessToken,
GatewayApi.DevicePatchRequest(
settings.id,
it
)
api.devicePatch(
accessToken,
GatewayApi.DevicePatchRequest(
settings.id,
pushToken
)
}
)

this.settings.fcmToken = pushToken

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import me.capcom.smsgateway.modules.settings.get
class GatewaySettings(
private val storage: KeyValueStorage,
) : Exporter, Importer {
enum class NotificationChannel {
AUTO,
SSE_ONLY,
}

var enabled: Boolean
get() = storage.get<Boolean>(ENABLED) ?: false
set(value) = storage.set(ENABLED, value)
Expand All @@ -33,20 +38,25 @@ class GatewaySettings(
val privateToken: String?
get() = storage.get<String>(PRIVATE_TOKEN)

val notificationChannel: NotificationChannel
get() = storage.get<NotificationChannel>(NOTIFICATION_CHANNEL) ?: NotificationChannel.AUTO

companion object {
private const val REGISTRATION_INFO = "REGISTRATION_INFO"
private const val ENABLED = "ENABLED"
private const val FCM_TOKEN = "fcm_token"

private const val CLOUD_URL = "cloud_url"
private const val PRIVATE_TOKEN = "private_token"
private const val NOTIFICATION_CHANNEL = "notification_channel"

const val PUBLIC_URL = "https://api.sms-gate.app/mobile/v1"
}

override fun export(): Map<String, *> {
return mapOf(
CLOUD_URL to serverUrl,
NOTIFICATION_CHANNEL to notificationChannel.name,
)
}

Expand Down Expand Up @@ -75,6 +85,16 @@ class GatewaySettings(
changed
}

NOTIFICATION_CHANNEL -> {
val newValue = it.value?.let { NotificationChannel.valueOf(it.toString()) }
?: NotificationChannel.AUTO
val changed = notificationChannel != newValue

storage.set(it.key, newValue.name)

changed
}

else -> false
}
}.any { it }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package me.capcom.smsgateway.modules.orchestrator

import android.app.ForegroundServiceStartNotAllowedException
import android.content.Context
import android.os.Build
import me.capcom.smsgateway.helpers.SettingsHelper
import me.capcom.smsgateway.modules.gateway.GatewayService
import me.capcom.smsgateway.modules.localserver.LocalServerService
Expand Down Expand Up @@ -38,18 +36,21 @@ class OrchestratorService(
pingSvc.start(context)
receiverService.start(context)
} catch (e: Throwable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
&& e is ForegroundServiceStartNotAllowedException
) {
logsSvc.insert(
LogEntry.Priority.WARN,
MODULE_NAME,
"Can't start foreground services while the app is running in the background"
)
return
}
logsSvc.insert(
LogEntry.Priority.WARN,
MODULE_NAME,
"Can't start foreground services while the app is running in the background"
)
}

throw e
try {
receiverService.start(context)
} catch (e: Throwable) {
logsSvc.insert(
LogEntry.Priority.WARN,
MODULE_NAME,
"Can't register receiver"
)
}
}

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/me/capcom/smsgateway/services/PushService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import me.capcom.smsgateway.modules.events.ExternalEvent
import me.capcom.smsgateway.modules.events.ExternalEventType
import me.capcom.smsgateway.modules.gateway.GatewaySettings
import me.capcom.smsgateway.modules.gateway.workers.RegistrationWorker
import me.capcom.smsgateway.modules.logs.LogsService
import me.capcom.smsgateway.modules.logs.db.LogEntry
Expand Down Expand Up @@ -53,6 +54,18 @@ class PushService : FirebaseMessagingService(), KoinComponent {
companion object : KoinComponent {
fun register(context: Context): Unit {
val logger = get<LogsService>()
val settings = get<GatewaySettings>()

if (settings.notificationChannel == GatewaySettings.NotificationChannel.SSE_ONLY) {
logger.insert(
priority = LogEntry.Priority.INFO,
module = PushService::class.java.simpleName,
message = "FCM registration skipped: SSE_ONLY channel configured"
)
RegistrationWorker.start(context, null, false)
return
}


logger.insert(
priority = LogEntry.Priority.INFO,
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_notifications.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
</vector>
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
<string name="not_registered">не зарегистрировано</string>
<string name="not_set">Не задано</string>
<string name="notification_title">SMSGate</string>
<string name="notification_channel">Канал уведомлений</string>
<string name="notifications">Уведомления</string>
<string name="online_status_at_the_cost_of_battery_life">Время автономной работы может быть
снижено</string>
<string name="passphrase">Ключ шифрования</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
<string name="not_registered">未注册</string>
<string name="not_set">未设置</string>
<string name="notification_title">短信网关</string>
<string name="notification_channel">通知渠道</string>
<string name="notifications">通知</string>
<string name="online_status_at_the_cost_of_battery_life">保持在线状态(可能消耗更多电量)</string>
<string name="passphrase">密码短语</string>
<string name="password">密码</string>
Expand Down Expand Up @@ -125,6 +127,8 @@
<plurals name="review_incoming_sms_webhooks">
<item quantity="other">您已注册 %1$d 个短信接收 Webhook。请检查以避免安全风险。</item>
</plurals>
<string name="processing">处理中</string>
<string name="processing_order_title">处理顺序</string>
<string name="queue_status">📊 队列状态</string>
<string name="total_messages">总计:%1$d</string>
<string name="pending_messages">待处理:%1$d</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@
<item>LIFO</item>
<item>FIFO</item>
</string-array>
<string-array name="notification_channels_titles">
<item>Auto</item>
<item>SSE Only</item>
</string-array>
<string-array name="notification_channels_values" translatable="false">
<item>AUTO</item>
<item>SSE_ONLY</item>
</string-array>
</resources>
40 changes: 28 additions & 12 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
<string name="app_name">SMSGate</string>
<string name="app_version_build">App version (build)</string>
<string name="battery_optimization_already_disabled">Battery optimization already disabled</string>
<string name="battery_optimization_is_not_supported_on_this_device">Battery optimization is not supported on this device</string>
<string name="battery_optimization_is_not_supported_on_this_device">Battery optimization is not
supported on this device</string>
<string name="battery_optimization">Battery optimization</string>
<string name="btn_cancel">Cancel</string>
<string name="btn_continue">Continue</string>
<string name="by_code">By Code</string>
<string name="can_affect_battery_life">can affect battery life</string>
<string name="click_continue_to_create_an_account_no_personal_information_is_required_nby_continuing_you_agree_to_our_privacy_policy_at_https_docs_sms_gate_app_privacy_policy">Click Continue to create an account. No personal information is required.\nBy continuing, you agree to our Privacy Policy at https://docs.sms-gate.app/privacy/policy/</string>
<string
name="click_continue_to_create_an_account_no_personal_information_is_required_nby_continuing_you_agree_to_our_privacy_policy_at_https_docs_sms_gate_app_privacy_policy">Click
Continue to create an account. No personal information is required.\nBy continuing, you
agree to our Privacy Policy at https://docs.sms-gate.app/privacy/policy/</string>
<string name="cloud_server_dotdotdot">Cloud server…</string>
<string name="cloud_server">Cloud server</string>
<string name="cloud">Cloud</string>
Expand All @@ -37,7 +41,8 @@
<string name="internet_connection_unavailable">Internet connection: unavailable</string>
<string name="interval_seconds">Interval (seconds)</string>
<string name="invalid_url">Invalid URL</string>
<string name="is_not_a_valid_port_must_be_between_1024_and_65535">%1$s is not a valid port. Must be between 1024 and 65535.</string>
<string name="is_not_a_valid_port_must_be_between_1024_and_65535">%1$s is not a valid port. Must
be between 1024 and 65535.</string>
<string name="label_password">Password</string>
<string name="label_username">Username</string>
<string name="limits">Limits</string>
Expand All @@ -62,7 +67,10 @@
<string name="not_registered">not registered</string>
<string name="not_set">Not set</string>
<string name="notification_title">SMSGate</string>
<string name="online_status_at_the_cost_of_battery_life">Online status at the cost of battery life</string>
<string name="notification_channel">Notification channel</string>
<string name="notifications">Notifications</string>
<string name="online_status_at_the_cost_of_battery_life">Online status at the cost of battery
life</string>
<string name="passphrase">Passphrase</string>
<string name="password_changed_successfully">Password changed successfully</string>
<string name="password_must_be_at_least_14_characters">Password must be at least 14 characters</string>
Expand All @@ -71,7 +79,8 @@
<string name="period">Period</string>
<string name="ping_service_is_active">Ping service is active</string>
<string name="ping">Ping</string>
<string name="please_enter_one_time_code_displayed_on_already_registered_device">Please enter the one-time code displayed on the already-registered device</string>
<string name="please_enter_one_time_code_displayed_on_already_registered_device">Please enter
the one-time code displayed on the already-registered device</string>
<string name="port_credentials_etc">Port, credentials, etc.</string>
<string name="port">Port</string>
<string name="private_token">Private Token</string>
Expand All @@ -87,7 +96,8 @@
<string name="server">Server</string>
<string name="set_maximum_value_to_activate">Set maximum value to activate</string>
<string name="settings_address_is_sms_capcom_me" translatable="false">api.sms-gate.app</string>
<string name="settings_changed_via_api_restart_the_app_to_apply_changes">Settings changed via API. Restart the app to apply changes.</string>
<string name="settings_changed_via_api_restart_the_app_to_apply_changes">Settings changed via
API. Restart the app to apply changes.</string>
<string name="settings_local_address_is">&lt;a href>%1$s:%2$d&lt;/a></string>
<string name="settings_local_address_not_found">Not available</string>
<string name="settings_local_server">Local server</string>
Expand All @@ -107,11 +117,15 @@
<string name="tab_text_home">Home</string>
<string name="tab_text_messages">MESSAGES</string>
<string name="tab_text_settings">SETTINGS</string>
<string name="the_webhook_request_will_wait_for_an_internet_connection">The webhook request will wait for an internet connection</string>
<string name="to_add_a_device_to_an_existing_account_please_fill_in_the_credentials_below">To add a device to an existing account, please fill in the credentials below.</string>
<string name="to_apply_the_changes_restart_the_app_using_the_button_below">To apply the changes, restart the app using the button below.</string>
<string name="the_webhook_request_will_wait_for_an_internet_connection">The webhook request will
wait for an internet connection</string>
<string name="to_add_a_device_to_an_existing_account_please_fill_in_the_credentials_below">To
add a device to an existing account, please fill in the credentials below.</string>
<string name="to_apply_the_changes_restart_the_app_using_the_button_below">To apply the changes,
restart the app using the button below.</string>
<string name="use_empty_to_disable">Use empty to disable</string>
<string name="use_this_code_to_sign_in_on_another_device">Use this code to sign in on another device</string>
<string name="use_this_code_to_sign_in_on_another_device">Use this code to sign in on another
device</string>
<string name="username_must_be_at_least_3_characters">Username must be at least 3 characters</string>
<string name="username">Username</string>
<string name="view">View</string>
Expand All @@ -121,8 +135,10 @@
<string name="webhooks_dotdotdot">Webhooks…</string>
<string name="webhooks">Webhooks</string>
<plurals name="review_incoming_sms_webhooks">
<item quantity="one">You have %1$d incoming SMS webhook registered. Please review it to avoid any security risks.</item>
<item quantity="other">You have %1$d incoming SMS webhooks registered. Please review them to avoid any security risks.</item>
<item quantity="one">You have %1$d incoming SMS webhook registered. Please review it to
avoid any security risks.</item>
<item quantity="other">You have %1$d incoming SMS webhooks registered. Please review them to
avoid any security risks.</item>
</plurals>
<string name="processing">Processing</string>
<string name="processing_order_title">Processing order</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/cloud_server_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
app:key="gateway.private_token"
app:summary="@string/ignored_for_public_server"
app:title="@string/private_token" />
<ListPreference
app:icon="@drawable/ic_notifications"
app:key="gateway.notification_channel"
app:defaultValue="AUTO"
app:entries="@array/notification_channels_titles"
app:entryValues="@array/notification_channels_values"
app:title="@string/notification_channel"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/credentials">
<EditTextPreference
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:icon="@drawable/ic_messages"
app:fragment="me.capcom.smsgateway.ui.settings.MessagesSettingsFragment"
app:title="@string/messages"
app:summary="@string/delays_limits_etc"/>
app:summary="@string/delays_limits_etc" />

<Preference
android:icon="@drawable/ic_webhook"
Expand Down