Commit cf5075db authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #156 from kacynMedallia/security

Add PIN/Fingerprint Check to Device Info
parents 96965f14 c58a9187
......@@ -182,4 +182,4 @@ var DeviceInfo = require('react-native-device-info');
| App Instance ID | `getInstanceID()` | | ANDROID ONLY - see https://developers.google.com/instance-id/ |
| App is running in emulator | `isEmulator()` | true | if app is running in emulator return true |
| App is running on a tablet | `isTablet()` | true | if app is running on a tablet return true |
| PIN or fingerprint set | `isPinOrFingerprintSet`| true | return true if PIN or fingerprint is configured. Only supported in Android and iOS 9.0 and above
......@@ -8,6 +8,7 @@
#import "RNDeviceInfo.h"
#import "DeviceUID.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface RNDeviceInfo()
......@@ -162,6 +163,12 @@ RCT_EXPORT_MODULE()
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
}
- (bool) isPinOrFingerprintSet
{
LAContext *context = [[LAContext alloc] init];
return ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:nil]);
}
- (NSDictionary *)constantsToExport
{
UIDevice *currentDevice = [UIDevice currentDevice];
......@@ -186,6 +193,7 @@ RCT_EXPORT_MODULE()
@"timezone": self.timezone,
@"isEmulator": @(self.isEmulator),
@"isTablet": @(self.isTablet),
@"isPinOrFingerprintSet": @(self.isPinOrFingerprintSet),
};
}
......
package com.learnium.RNDeviceInfo;
import android.app.KeyguardManager;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
......@@ -69,6 +71,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
return layout == Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
private Boolean isPinOrFingerprintSet() {
KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getSystemService(Context.KEYGUARD_SERVICE); //api 16+
return keyguardManager.isKeyguardSecure();
}
@Override
public @Nullable Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>();
......@@ -115,6 +122,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("timezone", TimeZone.getDefault().getID());
constants.put("isEmulator", this.isEmulator());
constants.put("isTablet", this.isTablet());
constants.put("isPinOrFingerprintSet", this.isPinOrFingerprintSet());
return constants;
}
}
......@@ -62,4 +62,7 @@ module.exports = {
isTablet: function() {
return RNDeviceInfo.isTablet;
},
isPinOrFingerprintSet: function () {
return RNDeviceInfo.isPinOrFingerprintSet;
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment