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