Commit 53d75f1e authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #157 from kacynMedallia/security-callback

Change PIN/Fingerprint check from constant to callback
parents 4d812f2d f87253f4
...@@ -161,25 +161,35 @@ var DeviceInfo = require('react-native-device-info'); ...@@ -161,25 +161,35 @@ var DeviceInfo = require('react-native-device-info');
// or import DeviceInfo from 'react-native-device-info'; // or import DeviceInfo from 'react-native-device-info';
``` ```
| Name | Method | Return | Notes | | Name | Method | Return | Notes |
| :------------------------- | :--------------------- | :-------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------- | | :------------------------- | :------------------------------- | :-------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------- |
| Device Unique ID | `getUniqueID()` | FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9 | This is IDFV on iOS so it will change if all apps from the current apps vendor have been previously uninstalled. | | Device Unique ID | `getUniqueID()` | FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9 | This is IDFV on iOS so it will change if all apps from the current apps vendor have been previously uninstalled. |
| Device Manufacturer | `getManufacturer()` | Apple | | | Device Manufacturer | `getManufacturer()` | Apple | |
| Device Brand | `getBrand()` | Apple / htc / Xiaomi | | | Device Brand | `getBrand()` | Apple / htc / Xiaomi | |
| Device Model | `getModel()` | iPhone 6 | | | Device Model | `getModel()` | iPhone 6 | |
| Device ID | `getDeviceId()` | iPhone7,2 | Or the board on Android e.g. goldfish | | Device ID | `getDeviceId()` | iPhone7,2 | Or the board on Android e.g. goldfish |
| System Name | `getSystemName()` | iPhone OS | | | System Name | `getSystemName()` | iPhone OS | |
| System Version | `getSystemVersion()` | 9.0 | | | System Version | `getSystemVersion()` | 9.0 | |
| Bundle ID | `getBundleId()` | com.learnium.mobile | | | Bundle ID | `getBundleId()` | com.learnium.mobile | |
| Build Number | `getBuildNumber()` | 89 | | | Build Number | `getBuildNumber()` | 89 | |
| App Version | `getVersion()` | 1.1.0 | | | App Version | `getVersion()` | 1.1.0 | |
| App Version (Readable) | `getReadableVersion()` | 1.1.0.89 | | | App Version (Readable) | `getReadableVersion()` | 1.1.0.89 | |
| Device Name | `getDeviceName()` | Becca's iPhone 6 | | | Device Name | `getDeviceName()` | Becca's iPhone 6 | |
| User Agent | `getUserAgent()` | Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 4 - 5.1.0 - API 22 - 768x1280 Build/LMY47D) | | | User Agent | `getUserAgent()` | Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 4 - 5.1.0 - API 22 - 768x1280 Build/LMY47D) | |
| Device Locale | `getDeviceLocale()` | en-US | | | Device Locale | `getDeviceLocale()` | en-US | |
| Device Country | `getDeviceCountry()` | US | | | Device Country | `getDeviceCountry()` | US | |
| Timezone | `getTimezone()` | America/Mexico_City | | | Timezone | `getTimezone()` | America/Mexico_City | |
| App Instance ID | `getInstanceID()` | | ANDROID ONLY - see https://developers.google.com/instance-id/ | | 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 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 | | 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 | PIN or fingerprint set | `isPinOrFingerprintSet(callback)`| | Only supported in Android and iOS 9.0 and above
Since the device setting for PIN/Fingerprint can be modified while the app is still open, this is available via callback instead of as a constant. To use, pass a callback function in your javascript:
```js
RNDeviceInfo.isPinOrFingerprintSet(isPinOrFingerprintSet => {
if (!isPinOrFingerprintSet) {
...
}
}
```
...@@ -163,12 +163,6 @@ RCT_EXPORT_MODULE() ...@@ -163,12 +163,6 @@ RCT_EXPORT_MODULE()
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad; return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
} }
- (bool) isPinOrFingerprintSet
{
LAContext *context = [[LAContext alloc] init];
return ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:nil]);
}
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {
UIDevice *currentDevice = [UIDevice currentDevice]; UIDevice *currentDevice = [UIDevice currentDevice];
...@@ -193,8 +187,14 @@ RCT_EXPORT_MODULE() ...@@ -193,8 +187,14 @@ RCT_EXPORT_MODULE()
@"timezone": self.timezone, @"timezone": self.timezone,
@"isEmulator": @(self.isEmulator), @"isEmulator": @(self.isEmulator),
@"isTablet": @(self.isTablet), @"isTablet": @(self.isTablet),
@"isPinOrFingerprintSet": @(self.isPinOrFingerprintSet),
}; };
} }
RCT_EXPORT_METHOD(isPinOrFingerprintSet:(RCTResponseSenderBlock)callback)
{
LAContext *context = [[LAContext alloc] init];
BOOL isPinOrFingerprintSet = ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:nil]);
callback(@[[NSNumber numberWithBool:isPinOrFingerprintSet]]);
}
@end @end
...@@ -13,6 +13,8 @@ import com.google.android.gms.iid.InstanceID; ...@@ -13,6 +13,8 @@ import com.google.android.gms.iid.InstanceID;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
...@@ -71,9 +73,10 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -71,9 +73,10 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
return layout == Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE; return layout == Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE;
} }
private Boolean isPinOrFingerprintSet() { @ReactMethod
public void isPinOrFingerprintSet(Callback callback) {
KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getSystemService(Context.KEYGUARD_SERVICE); //api 16+ KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getSystemService(Context.KEYGUARD_SERVICE); //api 16+
return keyguardManager.isKeyguardSecure(); callback.invoke(keyguardManager.isKeyguardSecure());
} }
@Override @Override
...@@ -99,7 +102,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -99,7 +102,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
try { try {
BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter(); BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
if(mDevice!=null){ if(myDevice!=null){
deviceName = myDevice.getName(); deviceName = myDevice.getName();
} }
} catch(Exception e) { } catch(Exception e) {
...@@ -122,7 +125,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -122,7 +125,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("timezone", TimeZone.getDefault().getID()); constants.put("timezone", TimeZone.getDefault().getID());
constants.put("isEmulator", this.isEmulator()); constants.put("isEmulator", this.isEmulator());
constants.put("isTablet", this.isTablet()); constants.put("isTablet", this.isTablet());
constants.put("isPinOrFingerprintSet", this.isPinOrFingerprintSet());
return constants; return constants;
} }
} }
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