Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 1cda5a1

Browse files
committed
oh god
1 parent d8c1f38 commit 1cda5a1

File tree

12 files changed

+149
-120
lines changed

12 files changed

+149
-120
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.class
2+
node_modules
23

34
# Mobile Tools for Java (J2ME)
45
.mtj.tmp/

LICENCE

Whitespace-only changes.

RNSimInfo.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @providesModule RNSimInfo
3+
*/
4+
'use strict'
5+
6+
import { NativeModules } from 'react-native'
7+
8+
export default NativeModules.RNSimInfo

android/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 16
99
targetSdkVersion 22
10-
versionCode 2
11-
versionName "0.1"
10+
versionCode 1
11+
versionName "1.0"
1212
ndk {
1313
abiFilters "armeabi-v7a", "x86"
1414
}
@@ -19,6 +19,8 @@ android {
1919
}
2020

2121
dependencies {
22+
compile fileTree(include: ['*.jar'], dir: 'libs')
23+
compile "com.android.support:appcompat-v7:23.0.1"
2224
compile 'com.facebook.react:react-native:+'
2325
compile 'com.google.android.gms:play-services-gcm:+'
2426
}

android/eu.sigrlami/sim/RNSimModule.java

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="eu.sigrlami.sim">
3+
4+
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
5+
</manifest>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package eu.sigrlami.sim;
2+
3+
import java.util.HashMap;
4+
import java.util.Locale;
5+
import java.util.Map;
6+
import java.util.TimeZone;
7+
8+
import com.facebook.react.bridge.ReactApplicationContext;
9+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
10+
11+
import javax.annotation.Nullable;
12+
13+
public class RNSimModule extends ReactContextBaseJavaModule {
14+
15+
ReactApplicationContext reactContext;
16+
17+
public RNSimModule(ReactApplicationContext reactContext) {
18+
super(reactContext);
19+
this.reactContext = reactContext;
20+
}
21+
22+
@Override
23+
public String getName() {
24+
return "RNSimInfo";
25+
}
26+
27+
@Override
28+
public @Nullable Map<String, Object> getConstants() {
29+
30+
final Map<String, Object> constants = new HashMap<>();
31+
32+
PackageManager packageManager = this.reactContext.getPackageManager();
33+
String packageName = this.reactContext.getPackageName();
34+
35+
TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
36+
37+
int phoneCount = 0;
38+
int activeSubscriptionInfoCount = 0;
39+
int activeSubscriptionInfoCountMax = 0;
40+
41+
try {
42+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
43+
if (simPermissionGranted(Manifest.permission.READ_PHONE_STATE)) {
44+
phoneCount = manager.getPhoneCount();
45+
SubscriptionManager manager = (SubscriptionManager) cntx.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
46+
activeSubscriptionInfoCount = manager.getActiveSubscriptionInfoCount();
47+
activeSubscriptionInfoCountMax = manager.getActiveSubscriptionInfoCountMax();
48+
49+
List<SubscriptionInfo> subscriptionInfos = manager.getActiveSubscriptionInfoList();
50+
int sub = 1;
51+
for (SubscriptionInfo subInfo : subscriptionInfos) {
52+
sub++;
53+
CharSequence carrierName = subInfo.getCarrierName();
54+
String countryIso = subInfo.getCountryIso();
55+
int dataRoaming = subInfo.getDataRoaming(); // 1 is enabled ; 0 is disabled
56+
CharSequence displayName = subInfo.getDisplayName();
57+
String iccId = subInfo.getIccId();
58+
int mcc = subInfo.getMcc();
59+
int mnc = subInfo.getMnc();
60+
String number = subInfo.getNumber();
61+
int simSlotIndex = subInfo.getSimSlotIndex();
62+
int subscriptionId = subInfo.getSubscriptionId();
63+
boolean networkRoaming = telManager.isNetworkRoaming(simSlotIndex);
64+
String deviceId = telManager.getDeviceId(simSlotIndex);
65+
66+
constants.put("carrierName" + sub, carrierName.toString());
67+
constants.put("displayName" + sub, displayName.toString());
68+
constants.put("countryCode" + sub, countryIso);
69+
constants.put("mcc" + sub, mcc);
70+
constants.put("mnc" + sub, mnc);
71+
constants.put("isNetworkRoaming" + sub, networkRoaming);
72+
constants.put("isDataRoaming" + sub, (dataRoaming == 1));
73+
constants.put("simSlotIndex" + sub, simSlotIndex);
74+
constants.put("phoneNumber" + sub, number);
75+
constants.put("deviceId" + sub, deviceId);
76+
constants.put("simSerialNumber" + sub, iccId);
77+
constants.put("subscriptionId" + sub, subscriptionId);
78+
79+
sims.put(simData);
80+
}
81+
}
82+
}
83+
} catch (JSONException e) {
84+
e.printStackTrace();
85+
} catch (Exception e) {
86+
e.printStackTrace();
87+
}
88+
89+
return constants;
90+
}
91+
}

android/eu.sigrlami/sim/RNSim.java renamed to android/src/main/java/eu/sigrlami/sim/RNSimReactPackage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import java.util.List;
77

88
import com.facebook.react.ReactPackage;
9+
import eu.sigrlami.sim.RNSimModule;
10+
911
import com.facebook.react.bridge.NativeModule;
1012
import com.facebook.react.bridge.ReactApplicationContext;
1113
import com.facebook.react.uimanager.ViewManager;
1214
import com.facebook.react.bridge.JavaScriptModule;
1315

14-
public class RNSim implements ReactPackage {
16+
public class RNSimReactPackage implements ReactPackage {
1517

1618
@Override
1719
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {

index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
import RNSimInfo from './RNSimInfo'
4+
5+
export default {
6+
getSimInfo() {
7+
return RNSimInfo
8+
},
9+
getTelephoneNumber() {
10+
return RNSimInfo.telephoneNumber1
11+
},
12+
getCarrierName() {
13+
return RNSimInfo.carrierName1
14+
},
15+
getCountryCode() {
16+
return RNSimInfo.countryCode1
17+
}
18+
}

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"name": "react-native-sim",
33
"version": "0.1.0",
44
"description": "",
5-
"main": "sim.js",
5+
"main": "index.js",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/sigrlami/react-native-sim"
99
},
10+
"typings": "index.d.ts",
1011
"keywords": [
1112
"react-component",
1213
"react-native",
@@ -16,6 +17,13 @@
1617
"sim",
1718
"phone number"
1819
],
20+
"dependencies": {
21+
"@types/react-native": "^0.37.1"
22+
},
23+
"peerDependencies": {
24+
"react": "^15.4.1",
25+
"react-native": "^0.39.2"
26+
},
1927
"author": "Sergey Bushnyak <[email protected]> (https://github.com/sigrlami)",
2028
"license": "MIT"
2129
}

0 commit comments

Comments
 (0)