Skip to content

Commit c0c02b5

Browse files
committed
add field IsDualSIM to the Phone model.
1 parent 6f9e4e6 commit c0c02b5

11 files changed

Lines changed: 33 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
6767

6868
if (Settings.isLoggedIn(this)) {
6969
Timber.d("updating phone with new fcm token")
70-
HttpSmsApiService.create(this).updatePhone(Settings.getOwnerOrDefault(this), token)
70+
HttpSmsApiService.create(this).updatePhone(Settings.getOwnerOrDefault(this), token, SmsManagerService.isDualSIM(this))
7171
}
7272

7373
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
156156
}
157157

158158

159-
fun updatePhone(phoneNumber: String, fcmToken: String): Boolean {
159+
fun updatePhone(phoneNumber: String, fcmToken: String, isDualSIM: Boolean): Boolean {
160160
val body = """
161161
{
162162
"fcm_token": "$fcmToken",
163-
"phone_number": "$phoneNumber"
163+
"phone_number": "$phoneNumber",
164+
"is_dual_sim": $isDualSIM
164165
}
165166
""".trimIndent()
166167

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class MainActivity : AppCompatActivity() {
146146
}
147147

148148
Thread {
149-
val updated = HttpSmsApiService.create(context).updatePhone(Settings.getOwnerOrDefault(context), Settings.getFcmToken(context) ?: "")
149+
val updated = HttpSmsApiService.create(context).updatePhone(Settings.getOwnerOrDefault(context), Settings.getFcmToken(context) ?: "", SmsManagerService.isDualSIM(this))
150150
if (updated) {
151151
Settings.setFcmTokenLastUpdateTimestampAsync(context, currentTimeStamp)
152152
Timber.i("fcm token uploaded successfully")

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class SmsManagerService {
2020
fun deliveredAction(messageID: String): String {
2121
return "$ACTION_SMS_DELIVERED.$messageID"
2222
}
23+
24+
@SuppressLint("MissingPermission")
25+
fun isDualSIM(context: Context) : Boolean {
26+
val localSubscriptionManager: SubscriptionManager = if (Build.VERSION.SDK_INT < 31) {
27+
SubscriptionManager.from(context)
28+
} else {
29+
context.getSystemService(SubscriptionManager::class.java)
30+
}
31+
return localSubscriptionManager.activeSubscriptionInfoList.size > 1
32+
}
2333
}
2434

2535
fun messageParts(context: Context, content: String): ArrayList<String> {

api/pkg/entities/phone.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Phone struct {
1313
FcmToken *string `json:"fcm_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....."`
1414
PhoneNumber string `json:"phone_number" example:"+18005550199"`
1515
MessagesPerMinute uint `json:"messages_per_minute" example:"1"`
16+
IsDualSIM bool `json:"is_dual_sim" example:"false"`
1617

1718
// MaxSendAttempts determines how many times to retry sending an SMS message
1819
MaxSendAttempts uint `json:"max_send_attempts" example:"1"`

api/pkg/events/phone_deleted_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ type PhoneDeletedPayload struct {
1616
UserID entities.UserID `json:"user_id"`
1717
Timestamp time.Time `json:"timestamp"`
1818
Owner string `json:"owner"`
19+
IsDualSIM bool `json:"is_dual_sim"`
1920
}

api/pkg/events/phone_updated_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ type PhoneUpdatedPayload struct {
1616
UserID entities.UserID `json:"user_id"`
1717
Timestamp time.Time `json:"timestamp"`
1818
Owner string `json:"owner"`
19+
IsDualSIM bool `json:"is_dual_sim"`
1920
}

api/pkg/requests/phone_update_request.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ type PhoneUpsert struct {
2323
MaxSendAttempts uint `json:"max_send_attempts" example:"2"`
2424

2525
FcmToken string `json:"fcm_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzd....."`
26+
27+
// IsDualSIM is true if the phone has more than one SIM active
28+
IsDualSIM bool `json:"is_dual_sim" example:"false"`
2629
}
2730

2831
// Sanitize sets defaults to MessageOutstanding
@@ -68,5 +71,6 @@ func (input *PhoneUpsert) ToUpsertParams(user entities.AuthUser, source string)
6871
MaxSendAttempts: maxSendAttempts,
6972
FcmToken: fcmToken,
7073
UserID: user.ID,
74+
IsDualSIM: input.IsDualSIM,
7175
}
7276
}

api/pkg/services/emulator_push_queue.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ func (queue *emulatorPushQueue) push(task PushQueueTask, queueID string) func()
7373
// add content type
7474
request.Header("Content-Type", "application/json")
7575

76-
err := request.Fetch(ctx)
77-
if err != nil {
76+
if err := request.Fetch(ctx); err != nil {
7877
queue.logger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot send http request to [%s] for queue task [%s]", task.URL, queueID)))
7978
return
8079
}

api/pkg/services/phone_service.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type PhoneUpsertParams struct {
7474
MessagesPerMinute *uint
7575
MaxSendAttempts *uint
7676
MessageExpirationDuration *time.Duration
77+
IsDualSIM bool
7778
Source string
7879
UserID entities.UserID
7980
}
@@ -106,9 +107,10 @@ func (service *PhoneService) Upsert(ctx context.Context, params PhoneUpsertParam
106107
UserID: phone.UserID,
107108
Timestamp: phone.UpdatedAt,
108109
Owner: phone.PhoneNumber,
110+
IsDualSIM: phone.IsDualSIM,
109111
})
110112
if err != nil {
111-
msg := fmt.Sprintf("cannot create event when phone is updated")
113+
msg := "cannot create event when phone is updated"
112114
return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
113115
}
114116

@@ -145,9 +147,10 @@ func (service *PhoneService) Delete(ctx context.Context, source string, userID e
145147
UserID: phone.UserID,
146148
Timestamp: phone.UpdatedAt,
147149
Owner: phone.PhoneNumber,
150+
IsDualSIM: phone.IsDualSIM,
148151
})
149152
if err != nil {
150-
msg := fmt.Sprintf("cannot create event when phone is deleted")
153+
msg := "cannot create event when phone is deleted"
151154
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
152155
}
153156

@@ -172,6 +175,7 @@ func (service *PhoneService) createPhone(ctx context.Context, params PhoneUpsert
172175
MessagesPerMinute: 29,
173176
MessageExpirationSeconds: 15 * 60, // 30 minutes
174177
MaxSendAttempts: 2,
178+
IsDualSIM: params.IsDualSIM,
175179
PhoneNumber: phonenumbers.Format(&params.PhoneNumber, phonenumbers.E164),
176180
CreatedAt: time.Now().UTC(),
177181
UpdatedAt: time.Now().UTC(),
@@ -208,5 +212,8 @@ func (service *PhoneService) update(phone *entities.Phone, params PhoneUpsertPar
208212
if params.MessageExpirationDuration != nil {
209213
phone.MessageExpirationSeconds = uint(params.MessageExpirationDuration.Seconds())
210214
}
215+
216+
phone.IsDualSIM = params.IsDualSIM
217+
211218
return phone
212219
}

0 commit comments

Comments
 (0)