Unverified Commit 1cc5b53f authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #289 from IjzerenHein/feature-max-memory

Added memory functions
parents c1e93065 222af3fe
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
- Make play-services optional (https://github.com/rebeccahughes/react-native-device-info/pull/226) - Make play-services optional (https://github.com/rebeccahughes/react-native-device-info/pull/226)
- Critical fix on WIFI STATE (https://github.com/rebeccahughes/react-native-device-info/pull/249) - Critical fix on WIFI STATE (https://github.com/rebeccahughes/react-native-device-info/pull/249)
- Added `getTotalMemory` and `getMaxMemory` (https://github.com/rebeccahughes/react-native-device-info/pull/289)
### 0.12.0 ### 0.12.0
......
...@@ -178,7 +178,7 @@ var DeviceInfo = require('react-native-device-info'); ...@@ -178,7 +178,7 @@ var DeviceInfo = require('react-native-device-info');
| App Version | `getVersion()` | `string` e.g. "1.1.0" | | | App Version | `getVersion()` | `string` e.g. "1.1.0" | |
| App Version (Readable) | `getReadableVersion()` | `string` e.g. "1.1.0.89" | | | App Version (Readable) | `getReadableVersion()` | `string` e.g. "1.1.0.89" | |
| Device Name | `getDeviceName()` | `string` e.g. "Becca's iPhone 6" | | | Device Name | `getDeviceName()` | `string` e.g. "Becca's iPhone 6" | |
| User Agent | `getUserAgent()` | `string` e.g. "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.009; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36" | | | User Agent | `getUserAgent()` | `string` e.g. "Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.009; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36" | |
| Device Locale | `getDeviceLocale()` | `string` e.g. "en-US" | | | Device Locale | `getDeviceLocale()` | `string` e.g. "en-US" | |
| Device Country | `getDeviceCountry()` | `string` e.g. "US" | | | Device Country | `getDeviceCountry()` | `string` e.g. "US" | |
| Timezone | `getTimezone()` | `string` e.g. "America/Mexico_City" | | | Timezone | `getTimezone()` | `string` e.g. "America/Mexico_City" | |
...@@ -190,10 +190,13 @@ var DeviceInfo = require('react-native-device-info'); ...@@ -190,10 +190,13 @@ var DeviceInfo = require('react-native-device-info');
| Phone Number | `getPhoneNumber()` | `?string` e.g. "2348675309" or "" | Only supported in Android | | Phone Number | `getPhoneNumber()` | `?string` e.g. "2348675309" or "" | Only supported in Android |
| First Install Time | `getFirstInstallTime()` | `number` e.g. 1505607068808 | Only supported in Android | | First Install Time | `getFirstInstallTime()` | `number` e.g. 1505607068808 | Only supported in Android |
| Last Install Time | `getLastUpdateTime()` | `number` e.g. 1505607068808 | Only supported in Android | | Last Install Time | `getLastUpdateTime()` | `number` e.g. 1505607068808 | Only supported in Android |
| Serial Number | `getSerialNumber()` | `string` | Only supported in Android | Serial Number | `getSerialNumber()` | `string` | Only supported in Android |
| IP Address | `getIPAddress()` | `Promise<string>` | Only supported in Android | IP Address | `getIPAddress()` | `Promise<string>` | Only supported in Android |
| MAC Address | `getMACAddress()` | `Promise<string>` | Only supported in Android | MAC Address | `getMACAddress()` | `Promise<string>` | Only supported in Android |
| Carrier | `getCarrier()` | `string` e.g. "SOFTBANK" | | | | Carrier | `getCarrier()` | `string` e.g. "SOFTBANK" | |
| Total Memory | `getTotalMemory()` | `number` e.g. 1995018240 | Total ammount of memory on the device |
| Max Memory | `getMaxMemory()` | `number` e.g. 268435456 | ANDROID ONLY - see https://developer.android.com/reference/java/lang/Runtime.html#maxMemory() |
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 to the returned bridge function in your javascript: 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 to the returned bridge function in your javascript:
```js ```js
......
...@@ -200,6 +200,10 @@ RCT_EXPORT_MODULE(RNDeviceInfo) ...@@ -200,6 +200,10 @@ RCT_EXPORT_MODULE(RNDeviceInfo)
return ([format rangeOfString:@"a"].location == NSNotFound); return ([format rangeOfString:@"a"].location == NSNotFound);
} }
- (unsigned long long) totalMemory {
return [NSProcessInfo processInfo].physicalMemory;
}
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {
UIDevice *currentDevice = [UIDevice currentDevice]; UIDevice *currentDevice = [UIDevice currentDevice];
...@@ -227,6 +231,7 @@ RCT_EXPORT_MODULE(RNDeviceInfo) ...@@ -227,6 +231,7 @@ RCT_EXPORT_MODULE(RNDeviceInfo)
@"isEmulator": @(self.isEmulator), @"isEmulator": @(self.isEmulator),
@"isTablet": @(self.isTablet), @"isTablet": @(self.isTablet),
@"is24Hour": @(self.is24Hour), @"is24Hour": @(self.is24Hour),
@"totalMemory": @(self.totalMemory)
}; };
} }
......
...@@ -14,6 +14,7 @@ import android.provider.Settings.Secure; ...@@ -14,6 +14,7 @@ import android.provider.Settings.Secure;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.app.ActivityManager;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
...@@ -25,6 +26,7 @@ import java.util.HashMap; ...@@ -25,6 +26,7 @@ import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import java.lang.Runtime;
import javax.annotation.Nullable; import javax.annotation.Nullable;
...@@ -172,7 +174,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -172,7 +174,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
try { try {
constants.put("userAgent", WebSettings.getDefaultUserAgent(this.reactContext)); constants.put("userAgent", WebSettings.getDefaultUserAgent(this.reactContext));
} catch (PackageManager.NameNotFoundException e) { } catch (RuntimeException e) {
constants.put("userAgent", System.getProperty("http.agent")); constants.put("userAgent", System.getProperty("http.agent"));
} }
} }
...@@ -188,6 +190,14 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -188,6 +190,14 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("phoneNumber", telMgr.getLine1Number()); constants.put("phoneNumber", telMgr.getLine1Number());
} }
constants.put("carrier", this.getCarrier()); constants.put("carrier", this.getCarrier());
Runtime rt = Runtime.getRuntime();
constants.put("maxMemory", rt.maxMemory());
ActivityManager actMgr = (ActivityManager) this.reactContext.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actMgr.getMemoryInfo(memInfo);
constants.put("totalMemory", memInfo.totalMem);
return constants; return constants;
} }
} }
...@@ -30,3 +30,5 @@ export function getMACAddress(): Promise<string>; ...@@ -30,3 +30,5 @@ export function getMACAddress(): Promise<string>;
export function getPhoneNumber(): string; export function getPhoneNumber(): string;
export function getAPILevel(): number; export function getAPILevel(): number;
export function getCarrier(): string; export function getCarrier(): string;
export function getTotalMemory(): number;
export function getMaxMemory(): number;
...@@ -92,4 +92,10 @@ module.exports = { ...@@ -92,4 +92,10 @@ module.exports = {
getCarrier: function() { getCarrier: function() {
return RNDeviceInfo.carrier; return RNDeviceInfo.carrier;
}, },
getTotalMemory: function() {
return RNDeviceInfo.totalMemory;
},
getMaxMemory: function() {
return RNDeviceInfo.maxMemory;
},
}; };
...@@ -30,4 +30,6 @@ declare module.exports: { ...@@ -30,4 +30,6 @@ declare module.exports: {
getIPAddress: () => Promise<string>, getIPAddress: () => Promise<string>,
getMACAddress: () => Promise<string>, getMACAddress: () => Promise<string>,
getCarrier: () => string, getCarrier: () => string,
getTotalMemory: () => number,
getMaxMemory: () => number,
} }
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