Unverified Commit 48180070 authored by Mehdi Achour's avatar Mehdi Achour Committed by GitHub

feat(windows): catch up (#345)

Made the following methods compatible with UWP:
getMaxMemory(), getFirstIntallTime(), isPinOrFingerprintSet(), getBatteryLevel(), getIPAddress()
parent a2cc61a6
......@@ -196,7 +196,7 @@ var DeviceInfo = require('react-native-device-info');
| ------------------------------------------------- | ------------------- | :--: | :-----: | :-----: | ------ |
| [getAPILevel()](#getapilevel) | `number` | ❌ | ✅ | ❌ | 0.12.0 |
| [getApplicationName()](#getapplicationname) | `string` | ✅ | ✅ | ✅ | 0.14.0 |
| [getBatteryLevel()](#getbatterylevel) | `Promise<number>` | ✅ | ✅ | | 0.18.0 |
| [getBatteryLevel()](#getbatterylevel) | `Promise<number>` | ✅ | ✅ | | 0.18.0 |
| [getBrand()](#getbrand) | `string` | ✅ | ✅ | ✅ | 0.9.3 |
| [getBuildNumber()](#getbuildnumber) | `string` | ✅ | ✅ | ✅ | ? |
| [getBundleId()](#getbundleid) | `string` | ✅ | ✅ | ✅ | ? |
......@@ -205,16 +205,16 @@ var DeviceInfo = require('react-native-device-info');
| [getDeviceId()](#getdeviceid) | `string` | ✅ | ✅ | ✅ | 0.5.0 |
| [getDeviceLocale()](#getdevicelocale) | `string` | ✅ | ✅ | ✅ | 0.7.0 |
| [getDeviceName()](#getdevicename) | `string` | ✅ | ✅ | ✅ | ? |
| [getFirstInstallTime()](#getfirstinstalltime) | `number` | ❌ | ✅ | | 0.12.0 |
| [getFirstInstallTime()](#getfirstinstalltime) | `number` | ❌ | ✅ | | 0.12.0 |
| [getFontScale()](#getfontscale) | `number` | ✅ | ✅ | ❌ | 0.15.0 |
| [getFreeDiskStorage()](#getfreediskstorage) | `number` | ✅ | ✅ | ❌ | 0.15.0 |
| [getIPAddress()](#getipaddress) | `Promise<string>` | ❌ | ✅ | | 0.12.0 |
| [getIPAddress()](#getipaddress) | `Promise<string>` | ❌ | ✅ | | 0.12.0 |
| [getInstallReferrer()](#getinstallreferrer) | `string` | ❌ | ✅ | ❌ | 0.19.0 |
| [getInstanceID()](#getinstanceid) | `string` | ❌ | ✅ | ❌ | ? |
| [getLastUpdateTime()](#getlastupdatetime) | `number` | ❌ | ✅ | ❌ | 0.12.0 |
| [getMACAddress()](#getmacaddress) | `Promise<string>` | ❌ | ✅ | ❌ | 0.12.0 |
| [getManufacturer()](#getmanufacturer) | `string` | ✅ | ✅ | ✅ | ? |
| [getMaxMemory()](#getmaxmemory) | `number` | ❌ | ✅ | | 0.14.0 |
| [getMaxMemory()](#getmaxmemory) | `number` | ❌ | ✅ | | 0.14.0 |
| [getModel()](#getmodel) | `string` | ✅ | ✅ | ✅ | ? |
| [getPhoneNumber()](#getphonenumber) | `string` | ❌ | ✅ | ❌ | 0.12.0 |
| [getReadableVersion()](#getreadableversion) | `string` | ✅ | ✅ | ✅ | ? |
......@@ -229,7 +229,7 @@ var DeviceInfo = require('react-native-device-info');
| [getVersion()](#getversion) | `string` | ✅ | ✅ | ✅ | ? |
| [is24Hour()](#is24hour) | `boolean` | ✅ | ✅ | ✅ | 0.13.0 |
| [isEmulator()](#isemulator) | `boolean` | ✅ | ✅ | ✅ | ? |
| [isPinOrFingerprintSet()](#ispinorfingerprintset) | (callback)`boolean` | ✅ | ✅ | | 0.10.1 |
| [isPinOrFingerprintSet()](#ispinorfingerprintset) | (callback)`boolean` | ✅ | ✅ | | 0.10.1 |
| [isTablet()](#istablet) | `boolean` | ✅ | ✅ | ✅ | ? |
---
......@@ -564,16 +564,12 @@ const manufacturer = DeviceInfo.getManufacturer();
### getMaxMemory()
Returns the maximum amount of memory that the JVM will attempt to use, in bytes.
Returns the maximum amount of memory that the VM will attempt to use, in bytes.
**Examples**
```js
const maxMemory = DeviceInfo.getMaxMemory();
// iOS: undefined
// Android: 402653184
// Windows: ?
const maxMemory = DeviceInfo.getMaxMemory(); // 402653183
```
---
......@@ -714,11 +710,7 @@ Gets the device total memory, in bytes.
**Examples**
```js
const totalMemory = DeviceInfo.getTotalMemory();
// iOS: ?
// Android: 1995018240
// Windows: ?
const totalMemory = DeviceInfo.getTotalMemory(); // 1995018240
```
---
......@@ -808,9 +800,9 @@ Tells if a PIN number or a fingerprint was set for the device.
```js
DeviceInfo.isPinOrFingerprintSet()(isPinOrFingerprintSet => {
if (!isPinOrFingerprintSet) {
...
// ...
}
}
});
```
**Notes**
......
......@@ -7,6 +7,12 @@ using System.Text.RegularExpressions;
using Windows.ApplicationModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.Devices.Power;
using Windows.System;
using Windows.Security.Credentials.UI;
using Windows.Networking;
using Windows.Networking.Connectivity;
using System.Linq;
namespace RNDeviceInfo
{
......@@ -42,6 +48,65 @@ namespace RNDeviceInfo
return DateTimeFormatInfo.CurrentInfo.ShortTimePattern.Contains("H");
}
[ReactMethod]
public async void isPinOrFingerprintSet(ICallback actionCallback)
{
try
{
var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();
actionCallback.Invoke(ucvAvailability == UserConsentVerifierAvailability.Available);
}
catch (Exception ex)
{
actionCallback.Invoke(false);
}
}
[ReactMethod]
public async void getIpAddress(IPromise promise)
{
var hostNameType = HostNameType.Ipv4;
var icp = NetworkInformation.GetInternetConnectionProfile();
if (icp?.NetworkAdapter == null)
{
promise.Reject(new InvalidOperationException("Network adapter not found."));
}
else
{
var hostname = NetworkInformation.GetHostNames()
.FirstOrDefault(
hn =>
hn.Type == hostNameType &&
hn.IPInformation?.NetworkAdapter != null &&
hn.IPInformation.NetworkAdapter.NetworkAdapterId == icp.NetworkAdapter.NetworkAdapterId);
promise.Resolve(hostname?.CanonicalName);
}
}
[ReactMethod]
public async void getBatteryLevel(IPromise promise)
{
// Create aggregate battery object
var aggBattery = Battery.AggregateBattery;
// Get report
var report = aggBattery.GetReport();
if ((report.FullChargeCapacityInMilliwattHours == null) ||
(report.RemainingCapacityInMilliwattHours == null))
{
promise.Reject(new InvalidOperationException("Could not fetch battery information."));
}
else
{
var max = Convert.ToDouble(report.FullChargeCapacityInMilliwattHours);
var value = Convert.ToDouble(report.RemainingCapacityInMilliwattHours);
promise.Resolve(value / max);
}
}
public override IReadOnlyDictionary<string, object> Constants
{
......@@ -120,6 +185,8 @@ namespace RNDeviceInfo
constants["isTablet"] = IsTablet(os);
constants["carrier"] = "not available";
constants["is24Hour"] = is24Hour();
constants["maxMemory"] = MemoryManager.AppMemoryUsageLimit;
constants["firstInstallTime"] = package.InstalledDate.ToUnixTimeMilliseconds();
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