Skip to content

Commit a8e7052

Browse files
committed
More cosmetic fixes
1 parent 91ea5c1 commit a8e7052

7 files changed

Lines changed: 40 additions & 27 deletions

File tree

android/app/src/main/java/com/httpsms/SmsManagerService.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.httpsms
22

3+
import android.Manifest
34
import android.annotation.SuppressLint
45
import android.app.PendingIntent
56
import android.content.Context
7+
import android.content.pm.PackageManager
68
import android.os.Build
79
import android.telephony.SmsManager
810
import android.telephony.SubscriptionManager
11+
import androidx.core.app.ActivityCompat
912

1013

1114
class SmsManagerService {
@@ -21,8 +24,11 @@ class SmsManagerService {
2124
return "$ACTION_SMS_DELIVERED.$messageID"
2225
}
2326

24-
@SuppressLint("MissingPermission")
2527
fun isDualSIM(context: Context) : Boolean {
28+
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED
29+
) {
30+
return false
31+
}
2632
val localSubscriptionManager: SubscriptionManager = if (Build.VERSION.SDK_INT < 31) {
2733
SubscriptionManager.from(context)
2834
} else {

android/app/src/main/java/com/httpsms/receivers/SimChangeReceiver.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ import timber.log.Timber
1212
class SimChangeReceiver : BroadcastReceiver() {
1313
private var lastDualSIMState: Boolean = false
1414
override fun onReceive(context: Context, intent: Intent) {
15-
Timber.d("SIM state changed")
15+
if (intent.action == "android.intent.action.SIM_STATE_CHANGED") {
16+
updateDualSimState(context)
17+
} else {
18+
Timber.e("invalid intent [${intent.action}]")
19+
}
20+
}
1621

22+
private fun updateDualSimState(context: Context) {
1723
Thread {
1824
val currentTimeStamp = System.currentTimeMillis()
1925
val isDualSIM = SmsManagerService.isDualSIM(context)
@@ -25,15 +31,15 @@ class SimChangeReceiver : BroadcastReceiver() {
2531
Settings.getFcmToken(context) ?: "",
2632
isDualSIM
2733
)
34+
Timber.d("SIM state change pushed to server")
2835

2936
if (updated) {
3037
lastDualSIMState = isDualSIM
3138
Settings.setFcmTokenLastUpdateTimestampAsync(context, currentTimeStamp)
3239
Timber.i("fcm token uploaded successfully")
3340
return@Thread
3441
}
35-
3642
Timber.e("could not update fcm token")
3743
}.start()
3844
}
39-
}
45+
}

api/pkg/entities/message.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ const (
6060
MessageEventNameFailed = MessageEventName("FAILED")
6161
)
6262

63+
// SIM is the SIM card to use to send the message
6364
type SIM string
6465

6566
const (
66-
// SIM_1 use the SIM card in slot 1 to send the message
67-
SIM_1 = SIM("SIM1")
68-
// SIM_2 use the SIM card in slot 2 to send the message
69-
SIM_2 = SIM("SIM2")
70-
// SIM_DEFAULT use the SIM card configured as default communication card to send the message
71-
SIM_DEFAULT = SIM("DEFAULT")
67+
// SIM1 use the SIM card in slot 1 to send the message
68+
SIM1 = SIM("SIM1")
69+
// SIM2 use the SIM card in slot 2 to send the message
70+
SIM2 = SIM("SIM2")
71+
// SIMDefault use the SIM card configured as default communication card to send the message
72+
SIMDefault = SIM("DEFAULT")
7273
)
7374

7475
// Message represents a message sent between 2 phone numbers
@@ -80,9 +81,9 @@ type Message struct {
8081
Content string `json:"content" example:"This is a sample text message"`
8182
Type MessageType `json:"type" example:"mobile-terminated"`
8283
Status MessageStatus `json:"status" gorm:"index:idx_messages_status" example:"pending"`
83-
// SIM is the type of event
84-
// * ISMS: use the SIM card in slot 1
85-
// * ISMS2: use the SIM card in slot 2
84+
// SIM is the SIM card to use to send the message
85+
// * SMS1: use the SIM card in slot 1
86+
// * SMS2: use the SIM card in slot 2
8687
// * DEFAULT: used the default communication SIM card
8788
SIM SIM `json:"sim" example:"DEFAULT"`
8889

api/pkg/requests/message_bulk_send_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (input *MessageBulkSend) Sanitize() MessageBulkSend {
3030
input.To = to
3131
input.From = input.sanitizeAddress(input.From)
3232
if strings.TrimSpace(string(input.SIM)) == "" {
33-
input.SIM = entities.SIM_DEFAULT
33+
input.SIM = entities.SIMDefault
3434
}
3535
return *input
3636
}

api/pkg/requests/message_receive_request.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type MessageReceive struct {
1717
From string `json:"from" example:"+18005550199"`
1818
To string `json:"to" example:"+18005550100"`
1919
Content string `json:"content" example:"This is a sample text message received on a phone"`
20-
// sim card that received the message
20+
// SIM card that received the message
2121
SIM entities.SIM `json:"sim" example:"DEFAULT"`
2222
// Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible
2323
Timestamp time.Time `json:"timestamp" example:"2022-06-05T14:26:09.527976+03:00"`
@@ -28,13 +28,13 @@ func (input *MessageReceive) Sanitize() MessageReceive {
2828
input.To = input.sanitizeAddress(input.To)
2929
input.From = input.sanitizeAddress(input.From)
3030
if strings.TrimSpace(string(input.SIM)) == "" {
31-
input.SIM = entities.SIM_DEFAULT
31+
input.SIM = entities.SIMDefault
3232
}
3333
return *input
3434
}
3535

3636
// ToMessageReceiveParams converts MessageReceive to services.MessageReceiveParams
37-
func (input MessageReceive) ToMessageReceiveParams(userID entities.UserID, source string) services.MessageReceiveParams {
37+
func (input *MessageReceive) ToMessageReceiveParams(userID entities.UserID, source string) services.MessageReceiveParams {
3838
phone, _ := phonenumbers.Parse(input.To, phonenumbers.UNKNOWN_REGION)
3939
return services.MessageReceiveParams{
4040
Source: source,

api/pkg/requests/message_send_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (input *MessageSend) Sanitize() MessageSend {
2626
input.To = input.sanitizeAddress(input.To)
2727
input.From = input.sanitizeAddress(input.From)
2828
if strings.TrimSpace(string(input.SIM)) == "" {
29-
input.SIM = entities.SIM_DEFAULT
29+
input.SIM = entities.SIMDefault
3030
}
3131
return *input
3232
}

api/pkg/validators/message_handler_validator.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func (validator MessageHandlerValidator) ValidateMessageReceive(_ context.Contex
5858
"sim": []string{
5959
"required",
6060
"in:" + strings.Join([]string{
61-
string(entities.SIM_1),
62-
string(entities.SIM_2),
63-
string(entities.SIM_DEFAULT),
61+
string(entities.SIM1),
62+
string(entities.SIM2),
63+
string(entities.SIMDefault),
6464
}, ","),
6565
},
6666
},
@@ -95,9 +95,9 @@ func (validator MessageHandlerValidator) ValidateMessageSend(ctx context.Context
9595
"sim": []string{
9696
"required",
9797
"in:" + strings.Join([]string{
98-
string(entities.SIM_1),
99-
string(entities.SIM_2),
100-
string(entities.SIM_DEFAULT),
98+
string(entities.SIM1),
99+
string(entities.SIM2),
100+
string(entities.SIMDefault),
101101
}, ","),
102102
},
103103
},
@@ -149,9 +149,9 @@ func (validator MessageHandlerValidator) ValidateMessageBulkSend(ctx context.Con
149149
"sim": []string{
150150
"required",
151151
"in:" + strings.Join([]string{
152-
string(entities.SIM_1),
153-
string(entities.SIM_2),
154-
string(entities.SIM_DEFAULT),
152+
string(entities.SIM1),
153+
string(entities.SIM2),
154+
string(entities.SIMDefault),
155155
}, ","),
156156
},
157157
},

0 commit comments

Comments
 (0)