@capawesome/capacitor-sim 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorSim.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +202 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/sim/Sim.java +126 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/sim/SimPlugin.java +77 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/sim/classes/results/GetSimCardsResult.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/sim/classes/results/SimCard.java +68 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/sim/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/sim/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/sim/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +289 -0
- package/dist/esm/definitions.d.ts +127 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +7 -0
- package/dist/esm/web.js +13 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +27 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +30 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/SimPlugin.swift +27 -0
- package/package.json +91 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapawesomeCapacitorSim'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin Genz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapawesomeCapacitorSim",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorSim",
|
|
10
|
+
targets: ["SimPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "SimPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Plugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "SimPluginTests",
|
|
25
|
+
dependencies: ["SimPlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# @capawesome/capacitor-sim
|
|
2
|
+
|
|
3
|
+
Capacitor plugin for reading SIM card and carrier information.
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 📇 **SIM cards**: Read information about the SIM cards installed on the device.
|
|
14
|
+
- 🔀 **Multi-SIM**: Supports devices with multiple SIM slots.
|
|
15
|
+
- 🌐 **Carrier details**: Read carrier name, country code, MCC and MNC.
|
|
16
|
+
- 🔒 **Permissions**: Built-in handling of the required runtime permission.
|
|
17
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
18
|
+
|
|
19
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
20
|
+
|
|
21
|
+
## Newsletter
|
|
22
|
+
|
|
23
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
24
|
+
|
|
25
|
+
## Compatibility
|
|
26
|
+
|
|
27
|
+
| Plugin Version | Capacitor Version | Status |
|
|
28
|
+
| -------------- | ----------------- | -------------- |
|
|
29
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
34
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then use the following prompt:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-sim` plugin in my project.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @capawesome/capacitor-sim
|
|
50
|
+
npx cap sync
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This plugin is only available on **Android**. On iOS and Web, all methods reject as unimplemented (see [iOS](#ios) below).
|
|
54
|
+
|
|
55
|
+
### Android
|
|
56
|
+
|
|
57
|
+
The `READ_PHONE_STATE` permission is declared in the plugin's `AndroidManifest.xml` and is merged into your app automatically. You must request it at runtime via the `requestPermissions(...)` method before calling `getSimCards(...)`.
|
|
58
|
+
|
|
59
|
+
### iOS
|
|
60
|
+
|
|
61
|
+
Reading SIM card and carrier information is **not supported** on iOS. Apple deprecated the `CTCarrier` APIs of the Core Telephony framework with iOS 16, and they return placeholder values (e.g. `"--"` and `65535`) on iOS 16.4 and later. Because there is no reliable system API left, all methods reject as unimplemented on iOS.
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
No configuration required for this plugin.
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Sim } from '@capawesome/capacitor-sim';
|
|
71
|
+
|
|
72
|
+
const checkPermissions = async () => {
|
|
73
|
+
const { readSimCards } = await Sim.checkPermissions();
|
|
74
|
+
return readSimCards;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const requestPermissions = async () => {
|
|
78
|
+
const { readSimCards } = await Sim.requestPermissions();
|
|
79
|
+
return readSimCards;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const getSimCards = async () => {
|
|
83
|
+
const { simCards } = await Sim.getSimCards();
|
|
84
|
+
return simCards;
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## API
|
|
89
|
+
|
|
90
|
+
<docgen-index>
|
|
91
|
+
|
|
92
|
+
* [`checkPermissions()`](#checkpermissions)
|
|
93
|
+
* [`getSimCards()`](#getsimcards)
|
|
94
|
+
* [`requestPermissions()`](#requestpermissions)
|
|
95
|
+
* [Interfaces](#interfaces)
|
|
96
|
+
* [Type Aliases](#type-aliases)
|
|
97
|
+
|
|
98
|
+
</docgen-index>
|
|
99
|
+
|
|
100
|
+
<docgen-api>
|
|
101
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
102
|
+
|
|
103
|
+
### checkPermissions()
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
checkPermissions() => Promise<PermissionStatus>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Check the permission to read the SIM cards.
|
|
110
|
+
|
|
111
|
+
Only available on Android.
|
|
112
|
+
|
|
113
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
114
|
+
|
|
115
|
+
**Since:** 0.1.0
|
|
116
|
+
|
|
117
|
+
--------------------
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### getSimCards()
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
getSimCards() => Promise<GetSimCardsResult>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Get information about the SIM cards installed on the device.
|
|
127
|
+
|
|
128
|
+
On devices with multiple SIM slots, all active SIM cards are returned.
|
|
129
|
+
|
|
130
|
+
Only available on Android.
|
|
131
|
+
|
|
132
|
+
**Returns:** <code>Promise<<a href="#getsimcardsresult">GetSimCardsResult</a>></code>
|
|
133
|
+
|
|
134
|
+
**Since:** 0.1.0
|
|
135
|
+
|
|
136
|
+
--------------------
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### requestPermissions()
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
requestPermissions() => Promise<PermissionStatus>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Request the permission to read the SIM cards.
|
|
146
|
+
|
|
147
|
+
Only available on Android.
|
|
148
|
+
|
|
149
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
150
|
+
|
|
151
|
+
**Since:** 0.1.0
|
|
152
|
+
|
|
153
|
+
--------------------
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
### Interfaces
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
#### PermissionStatus
|
|
160
|
+
|
|
161
|
+
| Prop | Type | Description | Since |
|
|
162
|
+
| ------------------ | ----------------------------------------------------------- | ---------------------------------------------- | ----- |
|
|
163
|
+
| **`readSimCards`** | <code><a href="#permissionstate">PermissionState</a></code> | The permission state of reading the SIM cards. | 0.1.0 |
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
#### GetSimCardsResult
|
|
167
|
+
|
|
168
|
+
| Prop | Type | Description | Since |
|
|
169
|
+
| -------------- | ---------------------- | -------------------------------------- | ----- |
|
|
170
|
+
| **`simCards`** | <code>SimCard[]</code> | The SIM cards installed on the device. | 0.1.0 |
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
#### SimCard
|
|
174
|
+
|
|
175
|
+
| Prop | Type | Description | Since |
|
|
176
|
+
| ----------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
177
|
+
| **`carrierName`** | <code>string \| null</code> | The name of the carrier. Returns `null` if the carrier name is not available. | 0.1.0 |
|
|
178
|
+
| **`displayName`** | <code>string \| null</code> | The user-editable display name of the SIM card. Returns `null` if the display name is not available. | 0.1.0 |
|
|
179
|
+
| **`isEmbedded`** | <code>boolean \| null</code> | Whether the SIM card is an embedded SIM (eSIM). Returns `null` if the information is not available. | 0.1.0 |
|
|
180
|
+
| **`isoCountryCode`** | <code>string \| null</code> | The two-letter ISO 3166-1 country code of the carrier. Returns `null` if the country code is not available. | 0.1.0 |
|
|
181
|
+
| **`mobileCountryCode`** | <code>string \| null</code> | The Mobile Country Code (MCC) of the carrier. Returns `null` if the mobile country code is not available. | 0.1.0 |
|
|
182
|
+
| **`mobileNetworkCode`** | <code>string \| null</code> | The Mobile Network Code (MNC) of the carrier. Returns `null` if the mobile network code is not available. | 0.1.0 |
|
|
183
|
+
| **`phoneNumber`** | <code>string \| null</code> | The phone number associated with the SIM card. This value is often empty because carriers do not reliably store the phone number on the SIM card. In that case, `null` is returned. | 0.1.0 |
|
|
184
|
+
| **`slotIndex`** | <code>number</code> | The index of the SIM slot on the device. | 0.1.0 |
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
### Type Aliases
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
#### PermissionState
|
|
191
|
+
|
|
192
|
+
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
|
|
193
|
+
|
|
194
|
+
</docgen-api>
|
|
195
|
+
|
|
196
|
+
## Changelog
|
|
197
|
+
|
|
198
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/sim/CHANGELOG.md).
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/sim/LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.sim"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.sim;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.os.Build;
|
|
5
|
+
import android.telephony.SubscriptionInfo;
|
|
6
|
+
import android.telephony.SubscriptionManager;
|
|
7
|
+
import androidx.annotation.NonNull;
|
|
8
|
+
import androidx.annotation.Nullable;
|
|
9
|
+
import io.capawesome.capacitorjs.plugins.sim.classes.results.GetSimCardsResult;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.sim.classes.results.SimCard;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.sim.interfaces.NonEmptyResultCallback;
|
|
12
|
+
import java.util.ArrayList;
|
|
13
|
+
import java.util.List;
|
|
14
|
+
|
|
15
|
+
public class Sim {
|
|
16
|
+
|
|
17
|
+
@NonNull
|
|
18
|
+
private final SimPlugin plugin;
|
|
19
|
+
|
|
20
|
+
public Sim(@NonNull SimPlugin plugin) {
|
|
21
|
+
this.plugin = plugin;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public void getSimCards(@NonNull NonEmptyResultCallback<GetSimCardsResult> callback) {
|
|
25
|
+
try {
|
|
26
|
+
List<SimCard> simCards = new ArrayList<>();
|
|
27
|
+
SubscriptionManager subscriptionManager = getSubscriptionManager();
|
|
28
|
+
if (subscriptionManager != null) {
|
|
29
|
+
List<SubscriptionInfo> subscriptionInfos = subscriptionManager.getActiveSubscriptionInfoList();
|
|
30
|
+
if (subscriptionInfos != null) {
|
|
31
|
+
for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
|
|
32
|
+
simCards.add(createSimCard(subscriptionManager, subscriptionInfo));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
callback.success(new GetSimCardsResult(simCards));
|
|
37
|
+
} catch (Exception exception) {
|
|
38
|
+
callback.error(exception);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Nullable
|
|
43
|
+
private String charSequenceToString(@Nullable CharSequence value) {
|
|
44
|
+
if (value == null) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return emptyToNull(value.toString());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@NonNull
|
|
51
|
+
private SimCard createSimCard(@NonNull SubscriptionManager subscriptionManager, @NonNull SubscriptionInfo subscriptionInfo) {
|
|
52
|
+
int slotIndex = subscriptionInfo.getSimSlotIndex();
|
|
53
|
+
String carrierName = charSequenceToString(subscriptionInfo.getCarrierName());
|
|
54
|
+
String displayName = charSequenceToString(subscriptionInfo.getDisplayName());
|
|
55
|
+
String isoCountryCode = emptyToNull(subscriptionInfo.getCountryIso());
|
|
56
|
+
String mobileCountryCode = getMobileCountryCode(subscriptionInfo);
|
|
57
|
+
String mobileNetworkCode = getMobileNetworkCode(subscriptionInfo);
|
|
58
|
+
Boolean isEmbedded = getIsEmbedded(subscriptionInfo);
|
|
59
|
+
String phoneNumber = getPhoneNumber(subscriptionManager, subscriptionInfo);
|
|
60
|
+
return new SimCard(
|
|
61
|
+
slotIndex,
|
|
62
|
+
carrierName,
|
|
63
|
+
displayName,
|
|
64
|
+
isoCountryCode,
|
|
65
|
+
mobileCountryCode,
|
|
66
|
+
mobileNetworkCode,
|
|
67
|
+
isEmbedded,
|
|
68
|
+
phoneNumber
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Nullable
|
|
73
|
+
private String emptyToNull(@Nullable String value) {
|
|
74
|
+
if (value == null || value.isEmpty()) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Nullable
|
|
81
|
+
private Boolean getIsEmbedded(@NonNull SubscriptionInfo subscriptionInfo) {
|
|
82
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return subscriptionInfo.isEmbedded();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Nullable
|
|
89
|
+
private String getMobileCountryCode(@NonNull SubscriptionInfo subscriptionInfo) {
|
|
90
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
91
|
+
return emptyToNull(subscriptionInfo.getMccString());
|
|
92
|
+
}
|
|
93
|
+
int mcc = subscriptionInfo.getMcc();
|
|
94
|
+
return mcc == 0 ? null : String.valueOf(mcc);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Nullable
|
|
98
|
+
private String getMobileNetworkCode(@NonNull SubscriptionInfo subscriptionInfo) {
|
|
99
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
100
|
+
return emptyToNull(subscriptionInfo.getMncString());
|
|
101
|
+
}
|
|
102
|
+
int mnc = subscriptionInfo.getMnc();
|
|
103
|
+
return mnc == 0 ? null : String.valueOf(mnc);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Nullable
|
|
107
|
+
private String getPhoneNumber(@NonNull SubscriptionManager subscriptionManager, @NonNull SubscriptionInfo subscriptionInfo) {
|
|
108
|
+
try {
|
|
109
|
+
String phoneNumber;
|
|
110
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
111
|
+
phoneNumber = subscriptionManager.getPhoneNumber(subscriptionInfo.getSubscriptionId());
|
|
112
|
+
} else {
|
|
113
|
+
phoneNumber = subscriptionInfo.getNumber();
|
|
114
|
+
}
|
|
115
|
+
return emptyToNull(phoneNumber);
|
|
116
|
+
} catch (Exception exception) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Nullable
|
|
122
|
+
private SubscriptionManager getSubscriptionManager() {
|
|
123
|
+
Context context = plugin.getContext();
|
|
124
|
+
return (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.sim;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
import androidx.annotation.NonNull;
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
import com.getcapacitor.Logger;
|
|
7
|
+
import com.getcapacitor.PermissionState;
|
|
8
|
+
import com.getcapacitor.Plugin;
|
|
9
|
+
import com.getcapacitor.PluginCall;
|
|
10
|
+
import com.getcapacitor.PluginMethod;
|
|
11
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
12
|
+
import com.getcapacitor.annotation.Permission;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.sim.classes.results.GetSimCardsResult;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.sim.interfaces.NonEmptyResultCallback;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.sim.interfaces.Result;
|
|
16
|
+
|
|
17
|
+
@CapacitorPlugin(
|
|
18
|
+
name = "Sim",
|
|
19
|
+
permissions = { @Permission(strings = { Manifest.permission.READ_PHONE_STATE }, alias = SimPlugin.PERMISSION_READ_SIM_CARDS) }
|
|
20
|
+
)
|
|
21
|
+
public class SimPlugin extends Plugin {
|
|
22
|
+
|
|
23
|
+
public static final String ERROR_PERMISSION_DENIED = "Permission to read the SIM cards is denied.";
|
|
24
|
+
public static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
|
|
25
|
+
public static final String PERMISSION_READ_SIM_CARDS = "readSimCards";
|
|
26
|
+
public static final String TAG = "Sim";
|
|
27
|
+
|
|
28
|
+
private Sim implementation;
|
|
29
|
+
|
|
30
|
+
@Override
|
|
31
|
+
public void load() {
|
|
32
|
+
implementation = new Sim(this);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@PluginMethod
|
|
36
|
+
public void getSimCards(PluginCall call) {
|
|
37
|
+
try {
|
|
38
|
+
if (getPermissionState(PERMISSION_READ_SIM_CARDS) != PermissionState.GRANTED) {
|
|
39
|
+
rejectCall(call, new Exception(ERROR_PERMISSION_DENIED));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
NonEmptyResultCallback<GetSimCardsResult> callback = new NonEmptyResultCallback<>() {
|
|
44
|
+
@Override
|
|
45
|
+
public void success(@NonNull GetSimCardsResult result) {
|
|
46
|
+
resolveCall(call, result);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Override
|
|
50
|
+
public void error(@NonNull Exception exception) {
|
|
51
|
+
rejectCall(call, exception);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
implementation.getSimCards(callback);
|
|
56
|
+
} catch (Exception exception) {
|
|
57
|
+
rejectCall(call, exception);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
62
|
+
String message = exception.getMessage();
|
|
63
|
+
if (message == null) {
|
|
64
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
65
|
+
}
|
|
66
|
+
Logger.error(TAG, message, exception);
|
|
67
|
+
call.reject(message);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
|
|
71
|
+
if (result == null) {
|
|
72
|
+
call.resolve();
|
|
73
|
+
} else {
|
|
74
|
+
call.resolve(result.toJSObject());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.sim.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSArray;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.sim.interfaces.Result;
|
|
7
|
+
import java.util.List;
|
|
8
|
+
|
|
9
|
+
public class GetSimCardsResult implements Result {
|
|
10
|
+
|
|
11
|
+
@NonNull
|
|
12
|
+
private final List<SimCard> simCards;
|
|
13
|
+
|
|
14
|
+
public GetSimCardsResult(@NonNull List<SimCard> simCards) {
|
|
15
|
+
this.simCards = simCards;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
@NonNull
|
|
20
|
+
public JSObject toJSObject() {
|
|
21
|
+
JSArray simCardsArray = new JSArray();
|
|
22
|
+
for (SimCard simCard : simCards) {
|
|
23
|
+
simCardsArray.put(simCard.toJSObject());
|
|
24
|
+
}
|
|
25
|
+
JSObject result = new JSObject();
|
|
26
|
+
result.put("simCards", simCardsArray);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/sim/classes/results/SimCard.java
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.sim.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.sim.interfaces.Result;
|
|
7
|
+
import org.json.JSONObject;
|
|
8
|
+
|
|
9
|
+
public class SimCard implements Result {
|
|
10
|
+
|
|
11
|
+
@Nullable
|
|
12
|
+
private final String carrierName;
|
|
13
|
+
|
|
14
|
+
@Nullable
|
|
15
|
+
private final String displayName;
|
|
16
|
+
|
|
17
|
+
@Nullable
|
|
18
|
+
private final Boolean isEmbedded;
|
|
19
|
+
|
|
20
|
+
@Nullable
|
|
21
|
+
private final String isoCountryCode;
|
|
22
|
+
|
|
23
|
+
@Nullable
|
|
24
|
+
private final String mobileCountryCode;
|
|
25
|
+
|
|
26
|
+
@Nullable
|
|
27
|
+
private final String mobileNetworkCode;
|
|
28
|
+
|
|
29
|
+
@Nullable
|
|
30
|
+
private final String phoneNumber;
|
|
31
|
+
|
|
32
|
+
private final int slotIndex;
|
|
33
|
+
|
|
34
|
+
public SimCard(
|
|
35
|
+
int slotIndex,
|
|
36
|
+
@Nullable String carrierName,
|
|
37
|
+
@Nullable String displayName,
|
|
38
|
+
@Nullable String isoCountryCode,
|
|
39
|
+
@Nullable String mobileCountryCode,
|
|
40
|
+
@Nullable String mobileNetworkCode,
|
|
41
|
+
@Nullable Boolean isEmbedded,
|
|
42
|
+
@Nullable String phoneNumber
|
|
43
|
+
) {
|
|
44
|
+
this.slotIndex = slotIndex;
|
|
45
|
+
this.carrierName = carrierName;
|
|
46
|
+
this.displayName = displayName;
|
|
47
|
+
this.isoCountryCode = isoCountryCode;
|
|
48
|
+
this.mobileCountryCode = mobileCountryCode;
|
|
49
|
+
this.mobileNetworkCode = mobileNetworkCode;
|
|
50
|
+
this.isEmbedded = isEmbedded;
|
|
51
|
+
this.phoneNumber = phoneNumber;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Override
|
|
55
|
+
@NonNull
|
|
56
|
+
public JSObject toJSObject() {
|
|
57
|
+
JSObject result = new JSObject();
|
|
58
|
+
result.put("slotIndex", slotIndex);
|
|
59
|
+
result.put("carrierName", carrierName == null ? JSONObject.NULL : carrierName);
|
|
60
|
+
result.put("displayName", displayName == null ? JSONObject.NULL : displayName);
|
|
61
|
+
result.put("isoCountryCode", isoCountryCode == null ? JSONObject.NULL : isoCountryCode);
|
|
62
|
+
result.put("mobileCountryCode", mobileCountryCode == null ? JSONObject.NULL : mobileCountryCode);
|
|
63
|
+
result.put("mobileNetworkCode", mobileNetworkCode == null ? JSONObject.NULL : mobileNetworkCode);
|
|
64
|
+
result.put("isEmbedded", isEmbedded == null ? JSONObject.NULL : isEmbedded);
|
|
65
|
+
result.put("phoneNumber", phoneNumber == null ? JSONObject.NULL : phoneNumber);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
File without changes
|