Skip to content

[device] sim cards list#367

Merged
capcom6 merged 1 commit into
masterfrom
feature/sim-cards-list
May 29, 2026
Merged

[device] sim cards list#367
capcom6 merged 1 commit into
masterfrom
feature/sim-cards-list

Conversation

@capcom6
Copy link
Copy Markdown
Owner

@capcom6 capcom6 commented May 18, 2026

Summary by CodeRabbit

  • New Features

    • Devices now include active SIM card details (slot index, SIM number, phone number when available, carrier, ICCID) during registration, updates, and when retrieving device info.
    • Registration/update flows now gather SIM data at runtime using the app context so current SIMs are captured when sending.
  • Privacy

    • Phone numbers are included only when permission is granted.
    • SIM-related strings are masked/redacted before transmission.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 29535784-d776-4502-a484-bfceeba1658f

📥 Commits

Reviewing files that changed from the base of the PR and between a1e0e51 and ac26b79.

📒 Files selected for processing (8)
  • app/src/main/java/me/capcom/smsgateway/helpers/SubscriptionsHelper.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayApi.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/RegistrationWorker.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/WebService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/Device.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/SimCard.kt
  • app/src/main/java/me/capcom/smsgateway/ui/HomeFragment.kt

Walkthrough

Collect active SIM metadata, model it as SimCard, include simCards in gateway register/patch payloads (redacted), thread Context through callers, and expose simCards from the local /device endpoint.

Changes

SIM Card Tracking

Layer / File(s) Summary
SimCard domain model and Device schema updates
app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/SimCard.kt, app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/Device.kt
New SimCard data class defines slot/sim indices and optional phone number, carrier name, and ICCID. Device schema adds simCards list (default empty).
SIM card retrieval helper with permission and API-level awareness
app/src/main/java/me/capcom/smsgateway/helpers/SubscriptionsHelper.kt
getActiveSimCards(context) fetches subscriptions, guards on API level (pre-LOLLIPOP_MR1 returns empty), checks READ_PHONE_STATE permission before exposing phone numbers, handles SecurityException/null lists, and converts blank strings to null.
API request/response DTOs for SIM data transport
app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayApi.kt
DeviceRegisterRequest and DevicePatchRequest extend with simCards payload; nested SimCard DTO mirrors domain model shape.
Device registration and update with SIM collection and redaction
app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt
registerDevice and updateDevice now accept Context, fetch active SIM cards, map them into DTO payloads with String?.redact() applied to phone/carrier/iccid, and include simCards in patch requests.
Integration—threading Context through worker and UI
app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/RegistrationWorker.kt, app/src/main/java/me/capcom/smsgateway/ui/HomeFragment.kt
RegistrationWorker and HomeFragment now pass applicationContext/requireContext() as first argument to service calls, establishing the Context dependency chain.
Local server device endpoint response with SIM cards
app/src/main/java/me/capcom/smsgateway/modules/localserver/WebService.kt
GET /device endpoint fetches active SIM cards via SubscriptionsHelper and includes them in Device construction for client responses.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant GatewayService
  participant SubscriptionsHelper
  participant GatewayAPI

  Caller->>GatewayService: registerDevice(context, pushToken, mode)
  GatewayService->>SubscriptionsHelper: getActiveSimCards(context)
  SubscriptionsHelper-->>GatewayService: List<SimCard>
  GatewayService->>GatewayService: String?.redact() phone/carrier/iccid
  GatewayService->>GatewayAPI: DeviceRegisterRequest{simCards=[...]}
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

ready

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[device] sim cards list' directly corresponds to the main feature: adding SIM card retrieval and tracking functionality across the device gateway and local server modules.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/sim-cards-list

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/me/capcom/smsgateway/helpers/SubscriptionsHelper.kt`:
- Around line 125-127: The unguarded access to
subscriptionManager.activeSubscriptionInfoList can throw SecurityException when
READ_PHONE_STATE is denied; wrap each access (including the one at lines
130-141) in a try-catch(SecurityException) block inside the SubscriptionsHelper
method (e.g., the function that reads active subscriptions) so that on catch you
return an emptyList or otherwise safely handle the absence of permissions,
optionally logging the exception; do not rely on
`@SuppressLint`("MissingPermission") to prevent runtime crashes.

In `@app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayApi.kt`:
- Around line 167-168: DevicePatchRequest currently types simCards as
List<SimCard>? using the wrong domain SimCard; change DevicePatchRequest to use
the same nested DTO SimCard used by DeviceRegisterRequest (the redacted DTO) and
update GatewayService.updateDevice to map
SubscriptionsHelper.getActiveSimCards() into that DTO (applying the same
redaction of phone number/ICCID as registerDevice does) so serialization and
sensitive-field handling match; locate DevicePatchRequest.simCards,
DeviceRegisterRequest.SimCard, GatewayService.updateDevice, and
SubscriptionsHelper.getActiveSimCards() to implement the type swap and
mapping/redaction.

In `@app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt`:
- Around line 176-184: The updateDevice call is sending raw simCards from
SubscriptionsHelper.getActiveSimCards(context) without redaction; modify the
code that builds GatewayApi.DevicePatchRequest in GatewayService.updateDevice to
map each sim card into GatewayApi.DeviceRegisterRequest.SimCard and call
redact() (same mapping used in registerDevice), so only redacted phone/ICCID are
sent via api.devicePatch; also update the DevicePatchRequest.simCards type in
GatewayApi.kt to List<DeviceRegisterRequest.SimCard>? to match the patched
payload.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 925ded56-d36f-4324-b05b-0582648dbc36

📥 Commits

Reviewing files that changed from the base of the PR and between c1f0cba and 7c2bfed.

📒 Files selected for processing (8)
  • app/src/main/java/me/capcom/smsgateway/helpers/SubscriptionsHelper.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayApi.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/RegistrationWorker.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/WebService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/Device.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/SimCard.kt
  • app/src/main/java/me/capcom/smsgateway/ui/HomeFragment.kt

Comment thread app/src/main/java/me/capcom/smsgateway/helpers/SubscriptionsHelper.kt Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

🤖 Pull request artifacts

file commit
app-release.apk ac26b79
app-release.aab ac26b79
app-insecure.apk ac26b79
app-insecure.aab ac26b79

@capcom6 capcom6 force-pushed the feature/sim-cards-list branch from 189106a to bb935b8 Compare May 19, 2026 04:16
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayApi.kt`:
- Around line 146-147: Remove the empty class body for DeviceRegisterRequest to
satisfy detekt.empty-blocks.EmptyClassBlock; replace the trailing "{ }" after
the constructor/parameter list with nothing so the declaration is just the class
header (i.e., close the declaration immediately after the parameter list),
keeping the class signature (DeviceRegisterRequest) intact and ensuring no
behavior or annotations are removed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f38c0a53-d9f4-455b-9c5c-017d834494ae

📥 Commits

Reviewing files that changed from the base of the PR and between 189106a and bb935b8.

📒 Files selected for processing (8)
  • app/src/main/java/me/capcom/smsgateway/helpers/SubscriptionsHelper.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayApi.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/RegistrationWorker.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/WebService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/Device.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/SimCard.kt
  • app/src/main/java/me/capcom/smsgateway/ui/HomeFragment.kt
🚧 Files skipped from review as they are similar to previous changes (5)
  • app/src/main/java/me/capcom/smsgateway/helpers/SubscriptionsHelper.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/SimCard.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/RegistrationWorker.kt
  • app/src/main/java/me/capcom/smsgateway/ui/HomeFragment.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt

Comment thread app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayApi.kt Outdated
@capcom6 capcom6 force-pushed the feature/sim-cards-list branch from 1443eb1 to 6649db8 Compare May 20, 2026 07:23
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt (1)

135-143: ⚡ Quick win

Extract SIM-card mapping/redaction into one helper.

The same mapping logic is duplicated in register and update paths; centralizing it will prevent payload drift in future edits.

Proposed refactor
+    private fun mapSimCards(simCards: List<me.capcom.smsgateway.modules.localserver.domain.SimCard>): List<GatewayApi.SimCard> {
+        return simCards.map {
+            GatewayApi.SimCard(
+                it.slotIndex,
+                it.simNumber,
+                it.phoneNumber.redact(),
+                it.carrierName.redact(),
+                it.iccid.redact(),
+            )
+        }
+    }
@@
-                simCards.map {
-                    GatewayApi.SimCard(
-                        it.slotIndex,
-                        it.simNumber,
-                        it.phoneNumber.redact(),
-                        it.carrierName.redact(),
-                        it.iccid.redact(),
-                    )
-                }
+                mapSimCards(simCards)
@@
-                simCards.map {
-                    GatewayApi.SimCard(
-                        it.slotIndex,
-                        it.simNumber,
-                        it.phoneNumber.redact(),
-                        it.carrierName.redact(),
-                        it.iccid.redact(),
-                    )
-                }
+                mapSimCards(simCards)

Also applies to: 188-196

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt`
around lines 135 - 143, Duplicate mapping of sim card entities to
GatewayApi.SimCard needs consolidation: add a single helper (e.g., a private
function mapSimCardsToApi(simCards: List<...>) or an extension
List<...>.toGatewaySimCards()) that returns List<GatewayApi.SimCard> and
performs the exact mapping and redact() calls (preserve slotIndex and simNumber,
redact phoneNumber, carrierName, iccid). Replace the inline map blocks that
construct GatewayApi.SimCard (the one using simCards.map {
GatewayApi.SimCard(...) } in both the register and update code paths) with a
call to this helper so both paths share the same mapping logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt`:
- Around line 135-143: Duplicate mapping of sim card entities to
GatewayApi.SimCard needs consolidation: add a single helper (e.g., a private
function mapSimCardsToApi(simCards: List<...>) or an extension
List<...>.toGatewaySimCards()) that returns List<GatewayApi.SimCard> and
performs the exact mapping and redact() calls (preserve slotIndex and simNumber,
redact phoneNumber, carrierName, iccid). Replace the inline map blocks that
construct GatewayApi.SimCard (the one using simCards.map {
GatewayApi.SimCard(...) } in both the register and update code paths) with a
call to this helper so both paths share the same mapping logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6ae6ff6-ab7e-485a-9745-881669c68920

📥 Commits

Reviewing files that changed from the base of the PR and between 1443eb1 and 6649db8.

📒 Files selected for processing (8)
  • app/src/main/java/me/capcom/smsgateway/helpers/SubscriptionsHelper.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayApi.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/GatewayService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/RegistrationWorker.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/WebService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/Device.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/SimCard.kt
  • app/src/main/java/me/capcom/smsgateway/ui/HomeFragment.kt

@capcom6 capcom6 force-pushed the feature/sim-cards-list branch from ad096ff to 55f90ac Compare May 21, 2026 04:41
@capcom6 capcom6 added the ready label May 21, 2026
@capcom6 capcom6 force-pushed the feature/sim-cards-list branch from 55f90ac to a1e0e51 Compare May 22, 2026 00:42
@github-actions github-actions Bot removed the ready label May 22, 2026
@capcom6 capcom6 added the ready label May 22, 2026
@capcom6 capcom6 force-pushed the feature/sim-cards-list branch from a1e0e51 to ac26b79 Compare May 26, 2026 02:18
@github-actions github-actions Bot removed the ready label May 26, 2026
@capcom6 capcom6 merged commit d485d59 into master May 29, 2026
4 checks passed
@capcom6 capcom6 deleted the feature/sim-cards-list branch May 29, 2026 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant