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.2.1 to 1.3.0

7

deviceinfo.android.d.ts

@@ -8,2 +8,4 @@ import { Carrier } from './deviceinfo.interface';

static freeStorageSpace(): number;
static totalExternalStorageSpace(): number;
static freeExternalStorageSpace(): number;
static deviceId(): string;

@@ -22,2 +24,3 @@ static deviceName(): string;

static cellularServiceProvider(): Carrier[];
static externalStoragePaths(): string[];
static isTablet(): boolean;

@@ -27,2 +30,3 @@ static is24Hour(): boolean;

static isBatteryCharging(): boolean;
static isExternalStorageAvailable(): boolean;
private static memoryInfo;

@@ -35,6 +39,5 @@ private static totalSpace;

private static activeProviderMnc;
private static activeProviderName;
private static networkProviderInfos;
private static subscriptionManager;
private static telephonyManager;
private static checkStorageMountState;
}

@@ -10,2 +10,23 @@ "use strict";

exports.staticDecorator = staticDecorator;
var JELLY_BEAN_MR1 = 17;
var JELLY_BEAN_MR2 = 18;
var LOLLIPOP = 21;
var LOLLIPOP_MR1 = 22;
var NETWORK_TYPE_GPRS = 1;
var NETWORK_TYPE_EDGE = 2;
var NETWORK_TYPE_UMTS = 3;
var NETWORK_TYPE_CDMA = 4;
var NETWORK_TYPE_EVDO_0 = 5;
var NETWORK_TYPE_EVDO_A = 6;
var NETWORK_TYPE_HSDPA = 8;
var NETWORK_TYPE_HSUPA = 9;
var NETWORK_TYPE_HSPA = 10;
var NETWORK_TYPE_IDEN = 11;
var NETWORK_TYPE_EVDO_B = 12;
var NETWORK_TYPE_LTE = 13;
var NETWORK_TYPE_EHRPD = 14;
var NETWORK_TYPE_HSPAP = 15;
var NETWORK_TYPE_IWLAN = 18;
var Context = android.content.Context;
var StorageManager = android.os.storage.StorageManager;
var DeviceInfo = (function () {

@@ -37,2 +58,8 @@ function DeviceInfo() {

};
DeviceInfo.totalExternalStorageSpace = function () {
return null;
};
DeviceInfo.freeExternalStorageSpace = function () {
return null;
};
DeviceInfo.deviceId = function () {

@@ -66,3 +93,3 @@ var deviceId = android.os.Build.BOARD;

var current = ctx.getResources().getConfiguration().locale;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
if (android.os.Build.VERSION.SDK_INT >= LOLLIPOP) {
return current.toLanguageTag();

@@ -155,2 +182,23 @@ }

};
DeviceInfo.externalStoragePaths = function () {
var paths = [];
var ctx = application_1.android.context;
var sm = ctx.getSystemService(Context.STORAGE_SERVICE);
try {
var method = StorageManager.class.getMethod("getVolumePaths", []);
method.setAccessible(true);
var invoke = method.invoke(sm, []);
var externalPaths = invoke;
for (var i = 0; i < externalPaths.length; i++) {
var path = externalPaths[i];
if (DeviceInfo_1.checkStorageMountState(path)) {
paths.push(path);
}
}
}
catch (error) {
console.log(error.message);
}
return paths;
};
DeviceInfo.isTablet = function () {

@@ -191,5 +239,8 @@ var Configuration = android.content.res.Configuration;

};
DeviceInfo.isExternalStorageAvailable = function () {
return false;
};
DeviceInfo.memoryInfo = function () {
var actMgr = (application_1.getNativeApplication()
.getSystemService(android.content.Context.ACTIVITY_SERVICE));
.getSystemService(Context.ACTIVITY_SERVICE));
var memInfo = new android.app.ActivityManager.MemoryInfo();

@@ -201,3 +252,3 @@ actMgr.getMemoryInfo(memInfo);

var statFs = new android.os.StatFs(file.getAbsolutePath());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (android.os.Build.VERSION.SDK_INT >= JELLY_BEAN_MR2) {
return statFs.getBlockCountLong() * statFs.getBlockSizeLong();

@@ -209,3 +260,3 @@ }

var statFs = new android.os.StatFs(file.getAbsolutePath());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (android.os.Build.VERSION.SDK_INT >= JELLY_BEAN_MR2) {
return statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();

@@ -236,3 +287,2 @@ }

DeviceInfo.activeProviderRadioAccessTechnology = function () {
var TelephonyManager = android.telephony.TelephonyManager;
var tm = DeviceInfo_1.telephonyManager();

@@ -244,17 +294,17 @@ if (tm == null) {

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_CDMA: return 1;
case NETWORK_TYPE_EDGE: return 5;
case NETWORK_TYPE_EVDO_0: return 2;
case NETWORK_TYPE_EVDO_A: return 3;
case NETWORK_TYPE_EVDO_B: return 4;
case NETWORK_TYPE_GPRS: return 7;
case NETWORK_TYPE_HSDPA: return 9;
case NETWORK_TYPE_HSPA: return 8;
case NETWORK_TYPE_HSUPA: return 11;
case NETWORK_TYPE_HSPAP: return 10;
case NETWORK_TYPE_UMTS: return 15;
case NETWORK_TYPE_EHRPD: return 6;
case NETWORK_TYPE_IDEN: return 13;
case NETWORK_TYPE_LTE: return 16;
case NETWORK_TYPE_IWLAN: return 14;
case NETWORK_TYPE_NR: return 12;

@@ -284,58 +334,5 @@ default: return 0;

};
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) {
if (Build.VERSION.SDK_INT >= LOLLIPOP_MR1) {
var ctx = application_1.android.context;

@@ -353,3 +350,3 @@ var permission = android.Manifest.permission.READ_PHONE_STATE;

var Build = android.os.Build;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (Build.VERSION.SDK_INT >= JELLY_BEAN_MR1) {
var ctx = application_1.android.context;

@@ -360,3 +357,3 @@ var permission = android.Manifest.permission.ACCESS_COARSE_LOCATION;

if (permissionStatus === android.content.pm.PackageManager.PERMISSION_GRANTED) {
return ctx.getSystemService(android.content.Context.TELEPHONY_SERVICE);
return ctx.getSystemService(Context.TELEPHONY_SERVICE);
}

@@ -366,2 +363,19 @@ }

};
DeviceInfo.checkStorageMountState = function (mountPoint) {
if (mountPoint == null) {
return false;
}
var context = application_1.android.context;
var storageManager = context.getSystemService(Context.STORAGE_SERVICE);
try {
var method = StorageManager.class.getDeclaredMethod("getVolumeState", [java.lang.String.class]);
method.setAccessible(true);
var mountStatus = method.invoke(storageManager, [mountPoint]);
return android.os.Environment.MEDIA_MOUNTED === mountStatus;
}
catch (error) {
console.log(error.message);
}
return false;
};
var DeviceInfo_1;

@@ -368,0 +382,0 @@ DeviceInfo = DeviceInfo_1 = __decorate([

@@ -32,2 +32,3 @@ import { RadioAccessTechnology, WCTGeneration } from "./index.d";

cellularServiceProvider(): Carrier[];
externalStoragePaths(): string[];
isTablet(): boolean;

@@ -34,0 +35,0 @@ is24Hour(): boolean;

@@ -10,2 +10,4 @@ import { Carrier } from './deviceinfo.interface';

static freeStorageSpace(): number;
static totalExternalStorageSpace(): number;
static freeExternalStorageSpace(): number;
static deviceId(): string;

@@ -24,2 +26,3 @@ static deviceName(): string;

static cellularServiceProvider(): Carrier[];
static externalStoragePaths(): string[];
static isTablet(): boolean;

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

@@ -61,2 +61,8 @@ "use strict";

};
DeviceInfo.totalExternalStorageSpace = function () {
return null;
};
DeviceInfo.freeExternalStorageSpace = function () {
return null;
};
DeviceInfo.deviceId = function () {

@@ -153,2 +159,5 @@ var systemInfo = new interop.Reference();

};
DeviceInfo.externalStoragePaths = function () {
return [];
};
DeviceInfo.isTablet = function () {

@@ -155,0 +164,0 @@ return UIDevice.currentDevice.userInterfaceIdiom === 1;

@@ -34,4 +34,2 @@ import { Carrier } from './deviceinfo.interface';

export declare class DeviceInfo {
private static radioAccessTechnology;
private static deviceNameByCode;
static totalMemory(): number;

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

static cellularServiceProvider(): Carrier[];
static externalStoragePaths(): string[];
static isTablet(): boolean;

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

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

@@ -62,3 +62,8 @@ "main": "deviceinfo",

"3G",
"5G"
"5G",
"SD Card",
"SDCard",
"USB OTG",
"USB On The Go",
"External Storage Card"
],

@@ -65,0 +70,0 @@ "author": {

@@ -22,4 +22,4 @@

- 1.2.1: Removed unwanted dependencies.
- 1.3.0: Added externalStoragePaths API. Fixed crashes and compatibility issues with the Android platform.
## Installation

@@ -100,2 +100,5 @@

- Notes for Android users:
* Permission BLUETOOTH is needed.
### - deviceLocale

@@ -223,8 +226,15 @@

- Note for Android users:
- Notes 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).
### - externalStoragePaths
Returns a list of paths for all mountable volumes (external storage cards, USB O-T-G). The empty list means that no mountable volumes found.
```javascript
DeviceInfo.externalStoragePaths();
```
## APIs in Action

@@ -250,2 +260,3 @@

console.log("Battery level: ", Math.round(DeviceInfo.batteryLevel()));
console.log("Storage paths: ", DeviceInfo.externalStoragePaths());
console.log("Is tablet: ", DeviceInfo.isTablet());

@@ -252,0 +263,0 @@ console.log("Is 24 hour: ", DeviceInfo.is24Hour());

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