Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nativescript-dna-deviceinfo

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativescript-dna-deviceinfo - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

network-provider.d.ts

10

deviceinfo.android.d.ts

@@ -0,1 +1,2 @@

import { Carrier } from './deviceinfo.interface';
export declare function staticDecorator<T>(): (constructor: T) => void;

@@ -19,2 +20,3 @@ export declare class DeviceInfo {

static batteryLevel(): number;
static cellularServiceProvider(): Carrier[];
static isTablet(): boolean;

@@ -27,2 +29,10 @@ static is24Hour(): boolean;

private static freeSpace;
private static prepareCarrier;
private static activeProviderRadioAccessTechnology;
private static activeProviderMcc;
private static activeProviderMnc;
private static activeProviderName;
private static networkProviderInfos;
private static subscriptionManager;
private static telephonyManager;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var application_1 = require("tns-core-modules/application");
var deviceinfo_interface_1 = require("./deviceinfo.interface");
var network_provider_1 = require("./network-provider");
function staticDecorator() {

@@ -109,2 +111,43 @@ return function (constructor) { };

};
DeviceInfo.cellularServiceProvider = function () {
var carriers = [];
var sm = DeviceInfo_1.subscriptionManager();
if (sm) {
var cellularProviders = sm.getActiveSubscriptionInfoList();
for (var i = 0; i < cellularProviders.size(); i++) {
var carrier = DeviceInfo_1.prepareCarrier(cellularProviders.get(i));
if (carrier.mobileCountryCode === DeviceInfo_1.activeProviderMcc() &&
carrier.mobileNetworkCode === DeviceInfo_1.activeProviderMnc()) {
carrier.networkType = DeviceInfo_1.activeProviderRadioAccessTechnology();
carrier.generation = deviceinfo_interface_1.wirelessCellularGenerator(carrier.networkType);
}
carriers.push(carrier);
}
}
else {
var tm_1 = DeviceInfo_1.telephonyManager();
if (tm_1) {
var carrier = {};
carrier.carrierName = tm_1.getSimOperatorName();
carrier.displayName = tm_1.getNetworkOperatorName();
carrier.isoCountryCode = tm_1.getNetworkCountryIso();
carrier.mobileCountryCode = DeviceInfo_1.activeProviderMcc();
carrier.mobileNetworkCode = DeviceInfo_1.activeProviderMnc();
var provider = network_provider_1.networkProviderByMccMnc(carrier.mobileCountryCode, carrier.mobileNetworkCode);
if (provider == null) {
provider = network_provider_1.networkProviderByMcc(carrier.mobileCountryCode);
}
carrier.country = provider ? provider.country : "";
carrier.countryCode = provider ? provider.country_code : "";
carrier.carrierName = carrier.carrierName === "" && provider ?
provider.network : carrier.carrierName;
carrier.isoCountryCode = carrier.isoCountryCode === "" && provider ?
provider.iso : carrier.isoCountryCode;
carrier.networkType = DeviceInfo_1.activeProviderRadioAccessTechnology();
carrier.generation = deviceinfo_interface_1.wirelessCellularGenerator(carrier.networkType);
carriers.push(carrier);
}
}
return carriers;
};
DeviceInfo.isTablet = function () {

@@ -166,2 +209,148 @@ var Configuration = android.content.res.Configuration;

};
DeviceInfo.prepareCarrier = function (cellularProvider) {
var carrier = {};
carrier.carrierName = cellularProvider.getCarrierName();
carrier.displayName = cellularProvider.getDisplayName();
carrier.isoCountryCode = cellularProvider.getCountryIso();
carrier.mobileCountryCode = cellularProvider.getMcc().toString();
var mnc = cellularProvider.getMnc().toString();
carrier.mobileNetworkCode = mnc.length === 1 ? "0" + mnc : mnc;
var provider = network_provider_1.networkProviderByMccMnc(carrier.mobileCountryCode, carrier.mobileNetworkCode);
if (provider == null) {
provider = network_provider_1.networkProviderByMcc(carrier.mobileCountryCode);
}
carrier.country = provider ? provider.country : "";
carrier.countryCode = provider ? provider.country_code : "";
carrier.carrierName = carrier.carrierName === "" && provider ?
provider.network : carrier.carrierName;
carrier.isoCountryCode = carrier.isoCountryCode === "" && provider ?
provider.iso : carrier.isoCountryCode;
return carrier;
};
DeviceInfo.activeProviderRadioAccessTechnology = function () {
var TelephonyManager = android.telephony.TelephonyManager;
var tm = DeviceInfo_1.telephonyManager();
if (tm == null) {
return 0;
}
var NETWORK_TYPE_NR = 20;
switch (tm.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_CDMA: return 1;
case TelephonyManager.NETWORK_TYPE_EDGE: return 5;
case TelephonyManager.NETWORK_TYPE_EVDO_0: return 2;
case TelephonyManager.NETWORK_TYPE_EVDO_A: return 3;
case TelephonyManager.NETWORK_TYPE_EVDO_B: return 4;
case TelephonyManager.NETWORK_TYPE_GPRS: return 7;
case TelephonyManager.NETWORK_TYPE_HSDPA: return 9;
case TelephonyManager.NETWORK_TYPE_HSPA: return 8;
case TelephonyManager.NETWORK_TYPE_HSUPA: return 11;
case TelephonyManager.NETWORK_TYPE_HSPAP: return 10;
case TelephonyManager.NETWORK_TYPE_UMTS: return 15;
case TelephonyManager.NETWORK_TYPE_EHRPD: return 6;
case TelephonyManager.NETWORK_TYPE_IDEN: return 13;
case TelephonyManager.NETWORK_TYPE_LTE: return 16;
case TelephonyManager.NETWORK_TYPE_IWLAN: return 14;
case NETWORK_TYPE_NR: return 12;
default: return 0;
}
};
DeviceInfo.activeProviderMcc = function () {
var tm = DeviceInfo_1.telephonyManager();
if (tm) {
var operator = tm.getSimOperator();
if (operator !== "") {
return operator.substring(0, 3);
}
}
return "";
};
DeviceInfo.activeProviderMnc = function () {
var tm = DeviceInfo_1.telephonyManager();
if (tm) {
var operator = tm.getSimOperator();
if (operator !== "") {
return operator.substring(3);
}
}
return "";
};
DeviceInfo.activeProviderName = function () {
var tm = DeviceInfo_1.telephonyManager();
if (tm) {
var operator = tm.getSimOperatorName();
if (operator !== "") {
return operator.substring(3);
}
}
return "";
};
DeviceInfo.networkProviderInfos = function () {
var tm = DeviceInfo_1.telephonyManager();
if (tm == null) {
return [];
}
var networkProviderList = [];
var allCellInfo = tm.getAllCellInfo();
for (var i = 0; i < allCellInfo.size(); i++) {
var carrier = {};
if (allCellInfo.get(i) instanceof android.telephony.CellInfoCdma) {
networkProviderList.push({
mcc: 0,
mnc: 0,
generation: "UnKnown"
});
}
else if (allCellInfo.get(i) instanceof android.telephony.CellInfoGsm) {
var ci = allCellInfo.get(i);
networkProviderList.push({
mcc: ci.getCellIdentity().getMcc(),
mnc: ci.getCellIdentity().getMnc(),
generation: "2G"
});
}
else if (allCellInfo.get(i) instanceof android.telephony.CellInfoWcdma) {
var ci = allCellInfo.get(i);
networkProviderList.push({
mcc: ci.getCellIdentity().getMcc(),
mnc: ci.getCellIdentity().getMnc(),
generation: "3G"
});
}
else if (allCellInfo.get(i) instanceof android.telephony.CellInfoLte) {
var ci = allCellInfo.get(i);
networkProviderList.push({
mcc: ci.getCellIdentity().getMcc(),
mnc: ci.getCellIdentity().getMnc(),
generation: "4G"
});
}
}
return networkProviderList;
};
DeviceInfo.subscriptionManager = function () {
var Build = android.os.Build;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
var ctx = application_1.android.context;
var permission = android.Manifest.permission.READ_PHONE_STATE;
var contextCompat = android.support.v4.content.ContextCompat;
var permissionStatus = contextCompat.checkSelfPermission(ctx, permission);
if (permissionStatus === android.content.pm.PackageManager.PERMISSION_GRANTED) {
return android.telephony.SubscriptionManager.from(ctx);
}
}
return null;
};
DeviceInfo.telephonyManager = function () {
var Build = android.os.Build;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
var ctx = application_1.android.context;
var permission = android.Manifest.permission.ACCESS_COARSE_LOCATION;
var contextCompat = android.support.v4.content.ContextCompat;
var permissionStatus = contextCompat.checkSelfPermission(ctx, permission);
if (permissionStatus === android.content.pm.PackageManager.PERMISSION_GRANTED) {
return ctx.getSystemService(android.content.Context.TELEPHONY_SERVICE);
}
}
return null;
};
var DeviceInfo_1;

@@ -168,0 +357,0 @@ DeviceInfo = DeviceInfo_1 = __decorate([

@@ -0,1 +1,14 @@

import { RadioAccessTechnology, WCTGeneration } from "./index.d";
export { RadioAccessTechnology, WCTGeneration };
export interface Carrier {
carrierName: string;
displayName: string;
country: string;
mobileCountryCode: string;
isoCountryCode: string;
countryCode: string;
mobileNetworkCode: string;
generation: WCTGeneration;
networkType: RadioAccessTechnology;
}
export interface DeviceInfoInterface {

@@ -18,2 +31,3 @@ totalMemory(): number;

batteryLevel(): number;
cellularServiceProvider(): Carrier[];
isTablet(): boolean;

@@ -24,1 +38,2 @@ is24Hour(): boolean;

}
export declare function wirelessCellularGenerator(rat: RadioAccessTechnology): WCTGeneration;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function wirelessCellularGenerator(rat) {
switch (rat) {
case 1:
case 7:
case 5:
case 13:
return "2G";
case 2:
case 3:
case 4:
case 17:
case 9:
case 11:
case 10:
case 8:
case 6:
case 15:
return "3G";
case 14:
case 16:
return "4G";
case 12:
return "5G";
default:
return "UnKnown";
}
}
exports.wirelessCellularGenerator = wirelessCellularGenerator;
//# sourceMappingURL=deviceinfo.interface.js.map

4

deviceinfo.ios.d.ts

@@ -0,3 +1,5 @@

import { Carrier } from './deviceinfo.interface';
export declare function staticDecorator<T>(): (constructor: T) => void;
export declare class DeviceInfo {
private static radioAccessTechnology;
private static deviceNameByCode;

@@ -20,2 +22,3 @@ static totalMemory(): number;

static batteryLevel(): number;
static cellularServiceProvider(): Carrier[];
static isTablet(): boolean;

@@ -26,2 +29,3 @@ static is24Hour(): boolean;

private static fileSystemAttributes;
private static prepareCarrier;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var deviceinfo_interface_1 = require("./deviceinfo.interface");
var network_provider_1 = require("./network-provider");
function staticDecorator() {

@@ -117,2 +119,35 @@ return function (constructor) { };

};
DeviceInfo.cellularServiceProvider = function () {
var carriers = [];
var telephonyInfo = CTTelephonyNetworkInfo.alloc().init();
var sysVer = Number.parseInt(UIDevice.currentDevice.systemVersion);
var sysName = UIDevice.currentDevice.systemName.toLocaleLowerCase();
if (sysName === "ios" && sysVer >= 12) {
var cellularProviders = telephonyInfo.serviceSubscriberCellularProviders.allValues;
for (var i = 0; i < cellularProviders.count; i++) {
var carrier = DeviceInfo_1.prepareCarrier(cellularProviders[i]);
var ratValues = telephonyInfo.serviceCurrentRadioAccessTechnology.allValues;
if (ratValues.count) {
var rat = DeviceInfo_1.radioAccessTechnology.get(ratValues.objectAtIndex(0));
carrier.networkType = rat ? rat : 0;
carrier.generation = deviceinfo_interface_1.wirelessCellularGenerator(rat);
}
carriers.push(carrier);
}
}
else {
var cellularProvider = telephonyInfo.subscriberCellularProvider;
if (cellularProvider) {
var carrier = DeviceInfo_1.prepareCarrier(cellularProvider);
var ratValues = telephonyInfo.serviceCurrentRadioAccessTechnology.allValues;
if (ratValues.count) {
var rat = DeviceInfo_1.radioAccessTechnology.get(ratValues.objectAtIndex(0));
carrier.networkType = rat ? rat : 0;
carrier.generation = deviceinfo_interface_1.wirelessCellularGenerator(rat);
}
carriers.push(carrier);
}
}
return carriers;
};
DeviceInfo.isTablet = function () {

@@ -139,3 +174,28 @@ return UIDevice.currentDevice.userInterfaceIdiom === 1;

};
DeviceInfo.prepareCarrier = function (cellularProvider) {
var carrier = {};
carrier.isoCountryCode = cellularProvider.isoCountryCode;
carrier.mobileCountryCode = cellularProvider.mobileCountryCode;
carrier.mobileNetworkCode = cellularProvider.mobileNetworkCode;
var provider = network_provider_1.networkProviderByMccMnc(carrier.mobileCountryCode, carrier.mobileNetworkCode);
carrier.country = provider ? provider.country : "";
carrier.countryCode = provider ? provider.country_code : "";
carrier.displayName = provider ? provider.network : cellularProvider.carrierName;
carrier.carrierName = cellularProvider.carrierName;
return carrier;
};
var DeviceInfo_1;
DeviceInfo.radioAccessTechnology = new Map([
[CTRadioAccessTechnologyGPRS, 7],
[CTRadioAccessTechnologyEdge, 5],
[CTRadioAccessTechnologyWCDMA, 17],
[CTRadioAccessTechnologyHSDPA, 9],
[CTRadioAccessTechnologyHSUPA, 11],
[CTRadioAccessTechnologyCDMA1x, 1],
[CTRadioAccessTechnologyCDMAEVDORev0, 2],
[CTRadioAccessTechnologyCDMAEVDORevA, 3],
[CTRadioAccessTechnologyCDMAEVDORevB, 4],
[CTRadioAccessTechnologyeHRPD, 6],
[CTRadioAccessTechnologyLTE, 16],
]);
DeviceInfo.deviceNameByCode = {

@@ -142,0 +202,0 @@ "i386": "iPhone Simulator",

@@ -0,3 +1,36 @@

import { Carrier } from './deviceinfo.interface';
export const enum RadioAccessTechnology {
UNKNOWN,
CDMA,
CDMAEVDORev0,
CDMAEVDORevA,
CDMAEVDORevB,
EDGE,
EHRPD,
GPRS,
HSPA,
HSDPA,
HSPAP,
HSUPA,
NR,
IDEN,
IWLAN,
UMTS,
LTE,
WCDMA,
}
export const enum WCTGeneration {
_UNKNOWN = "UnKnown",
_2G = "2G",
_3G = "3G",
_4G = "4G",
_5G = "5G"
}
export declare function staticDecorator<T>(): (constructor: T) => void;
export declare class DeviceInfo {
private static radioAccessTechnology;
private static deviceNameByCode;
static totalMemory(): number;

@@ -19,2 +52,3 @@ static freeMemory(): number;

static batteryLevel(): number;
static cellularServiceProvider(): Carrier[];
static isTablet(): boolean;

@@ -24,2 +58,4 @@ static is24Hour(): boolean;

static isBatteryCharging(): boolean;
private static fileSystemAttributes;
private static prepareCarrier;
}
{
"name": "nativescript-dna-deviceinfo",
"version": "1.1.1",
"version": "1.2.0",
"description": "NativeScript plugin to acquire device information.",

@@ -50,3 +50,15 @@ "main": "deviceinfo",

"Battery",
"Charging"
"Charging",
"Tablet",
"Cellular",
"Network Provider",
"SIM",
"Operator",
"Carrier",
"CDMA",
"GSM",
"LTE",
"4G",
"3G",
"5G"
],

@@ -72,4 +84,6 @@ "author": {

},
"dependencies": {},
"dependencies": {
"nativescript-webworkers": "^2.0.0"
},
"bootstrapper": "nativescript-plugin-seed"
}

@@ -6,4 +6,5 @@

NativeScript plugin to acquire device info.
NativeScript plugin to acquire device info.
### Features

@@ -15,2 +16,10 @@

## Changelogs:
- 1.0.0: First release.
- 1.0.1: Minor document correction.
- 1.1.0: New APIs related to battery charging status and its charge level.
- 1.1.1: Updated document.
- 1.2.0: Added an API to retrieve Network Providers, Carriers, related information.
## Installation

@@ -45,81 +54,176 @@

Retrieves total memory(RAM) size in bytes.
Returns the total memory(RAM) size of a device in bytes.
```javascript
DeviceInfo.totalMemory();
```
### - freeMemory
Retrieves available free memory(RAM) size in bytes.
Returns the free memory(RAM) size of a device in bytes.
```javascript
DeviceInfo.freeMemory();
```
### - totalStorageSpace
Retrieves total storage(internal) space in bytes.
Returns the total storage(internal) space of a device in bytes.
```javascript
DeviceInfo.totalStorageSpace();
```
### - freeStorageSpace
Retrieves free storage(internal) space in bytes.
Returns the free storage(internal) space of a device in bytes.
```javascript
DeviceInfo.freeStorageSpace();
```
### - deviceId
Retrieves device ID.
Returns a device ID.
```javascript
DeviceInfo.deviceId();
```
### - deviceName
Retrieves the device name.
Returns a device name.
```javascript
DeviceInfo.deviceName();
```
### - deviceLocale
Retrieves the device configured locale.
Returns the locale of a device.
```javascript
DeviceInfo.deviceLocale();
```
### - deviceCountry
Retrieves the device country.
Returns the device country.
```javascript
DeviceInfo.deviceCountry();
```
### - timezone
Retrieves the device time zone.
Returns the time zone of a device.
```javascript
DeviceInfo.timezone();
```
### - userAgent
Retrieves the device user agent.
Returns the user agent string of a device.
```javascript
DeviceInfo.userAgent();
```
### - appName
Retrieves the app name.
Returns the app name.
```javascript
DeviceInfo.appName();
```
### - appVersion
Retrieves the app version.
Returns an app version.
```javascript
DeviceInfo.appVersion();
```
### - bundleId
Retrieves the app bundle id.
Returns an app bundle id.
```javascript
DeviceInfo.bundleId();
```
### - bundleNumber
Retrieves the app bundle number.
Returns an app bundle number.
```javascript
DeviceInfo.bundleNumber();
```
### - systemManufacturer
Retrieves the device manufacturer.
Returns a device manufacturer.
```javascript
DeviceInfo.systemManufacturer();
```
### - batteryLevel
Returns the current battery charge level of the device.
Returns the charge level of a device battery.
```javascript
DeviceInfo.batteryLevel();
```
### - isTablet
Returns 'true' if the device is tablet, otherwise 'false'.
Returns 'true' if a device is a tablet, otherwise 'false'.
```javascript
DeviceInfo.isTablet();
```
### - is24Hour
Returns 'true' if the device configured to 24-hour clock, otherwise 'false'.
Returns 'true' if a device configured to a 24-hour clock, otherwise 'false'.
```javascript
DeviceInfo.is24Hour();
```
### - isEmulator
Returns 'true' if the app is running on emulator, otherwise 'false'.
Returns 'true' if an app is running on an emulator, otherwise 'false'.
```javascript
DeviceInfo.isEmulator();
```
### - isBatteryCharging
Returns 'true' if the device is plugged in and charging, otherwise 'false'.
Returns 'true' if a device is plugged in and charging, otherwise 'false'.
```javascript
DeviceInfo.isBatteryCharging();
```
### - cellularServiceProvider
Returns a list of GSM network providers, carriers, of a device is equipped with.
```javascript
DeviceInfo.cellularServiceProvider();
```
Besides other helpful information returned from the API, it can be used to know whether the device has a fast internet connection or not.
- Note for Android users:
* If the **targetSdkVersion is 17**, a device with dual sim, the API returns an "active" carrier. Permission ACCESS_COARSE_LOCATION is needed.
* If the **targetSdkVersion is >= 22**, a device with dual sim, the API returns both the carriers. Permission READ_PHONE_STATE is needed. To know more about the request permissions process, please visit the link [Request App Permissions](https://developer.android.com/training/permissions/requesting).
## APIs in Action

@@ -164,11 +268,5 @@

## Changelogs:
- 1.0.0: First release.
- 1.0.1: Minor document correction.
- 1.1.0: New APIs related to battery charging status and its charge level.
- 1.1.1: Updated document.
## License
MIT license (see LICENSE file)

2

references.d.ts
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android-21.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android-28.d.ts" />

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc