Skip to content

Commit

Permalink
feat(device): Add realDiskTotal and realDiskFree properties (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Nov 17, 2021
1 parent e551ef7 commit 3f67643
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
28 changes: 15 additions & 13 deletions device/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,21 @@ Get the device's current language locale code.

#### DeviceInfo

| Prop | Type | Description | Since |
| --------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | ----- |
| **`name`** | <code>string</code> | The name of the device. For example, "John's iPhone". This is only supported on iOS and Android 7.1 or above. | 1.0.0 |
| **`model`** | <code>string</code> | The device model. For example, "iPhone". | 1.0.0 |
| **`platform`** | <code>'ios' \| 'android' \| 'web'</code> | The device platform (lowercase). | 1.0.0 |
| **`operatingSystem`** | <code><a href="#operatingsystem">OperatingSystem</a></code> | The operating system of the device. | 1.0.0 |
| **`osVersion`** | <code>string</code> | The version of the device OS. | 1.0.0 |
| **`manufacturer`** | <code>string</code> | The manufacturer of the device. | 1.0.0 |
| **`isVirtual`** | <code>boolean</code> | Whether the app is running in a simulator/emulator. | 1.0.0 |
| **`memUsed`** | <code>number</code> | Approximate memory used by the current app, in bytes. Divide by 1048576 to get the number of MBs used. | 1.0.0 |
| **`diskFree`** | <code>number</code> | How much free disk space is available on the the normal data storage. path for the os, in bytes | 1.0.0 |
| **`diskTotal`** | <code>number</code> | The total size of the normal data storage path for the OS, in bytes. | 1.0.0 |
| **`webViewVersion`** | <code>string</code> | The web view browser version | 1.0.0 |
| Prop | Type | Description | Since |
| --------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`name`** | <code>string</code> | The name of the device. For example, "John's iPhone". This is only supported on iOS and Android 7.1 or above. | 1.0.0 |
| **`model`** | <code>string</code> | The device model. For example, "iPhone". | 1.0.0 |
| **`platform`** | <code>'ios' \| 'android' \| 'web'</code> | The device platform (lowercase). | 1.0.0 |
| **`operatingSystem`** | <code><a href="#operatingsystem">OperatingSystem</a></code> | The operating system of the device. | 1.0.0 |
| **`osVersion`** | <code>string</code> | The version of the device OS. | 1.0.0 |
| **`manufacturer`** | <code>string</code> | The manufacturer of the device. | 1.0.0 |
| **`isVirtual`** | <code>boolean</code> | Whether the app is running in a simulator/emulator. | 1.0.0 |
| **`memUsed`** | <code>number</code> | Approximate memory used by the current app, in bytes. Divide by 1048576 to get the number of MBs used. | 1.0.0 |
| **`diskFree`** | <code>number</code> | How much free disk space is available on the the normal data storage path for the os, in bytes. On Android it returns the free disk space on the "system" partition holding the core Android OS. On iOS this value is not accurate. | 1.0.0 |
| **`diskTotal`** | <code>number</code> | The total size of the normal data storage path for the OS, in bytes. On Android it returns the disk space on the "system" partition holding the core Android OS. | 1.0.0 |
| **`realDiskFree`** | <code>number</code> | How much free disk space is available on the the normal data storage, in bytes. | 1.1.0 |
| **`realDiskTotal`** | <code>number</code> | The total size of the normal data storage path, in bytes. | 1.1.0 |
| **`webViewVersion`** | <code>string</code> | The web view browser version | 1.0.0 |


#### BatteryInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public long getDiskTotal() {
return statFs.getBlockCountLong() * statFs.getBlockSizeLong();
}

public long getRealDiskFree() {
StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
return statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();
}

public long getRealDiskTotal() {
StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
return statFs.getBlockCountLong() * statFs.getBlockSizeLong();
}

public String getPlatform() {
return "android";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public void getInfo(PluginCall call) {
r.put("memUsed", implementation.getMemUsed());
r.put("diskFree", implementation.getDiskFree());
r.put("diskTotal", implementation.getDiskTotal());
r.put("realDiskFree", implementation.getRealDiskFree());
r.put("realDiskTotal", implementation.getRealDiskTotal());
r.put("model", android.os.Build.MODEL);
r.put("operatingSystem", "android");
r.put("osVersion", android.os.Build.VERSION.RELEASE);
Expand Down
16 changes: 16 additions & 0 deletions device/ios/Plugin/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ import Foundation
return nil
}

/**
* Get real free disk space
*/
public func getRealFreeDiskSize() -> Int64? {
do {
let values = try URL(fileURLWithPath: NSHomeDirectory() as String).resourceValues(forKeys: [URLResourceKey.volumeAvailableCapacityForImportantUsageKey])
if let available = values.volumeAvailableCapacityForImportantUsage {
return available
} else {
return nil
}
} catch {
return nil
}
}

/**
* Get total disk size
*/
Expand Down
3 changes: 3 additions & 0 deletions device/ios/Plugin/DevicePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ public class DevicePlugin: CAPPlugin {

let memUsed = implementation.getMemoryUsage()
let diskFree = implementation.getFreeDiskSize() ?? 0
let realDiskFree = implementation.getRealFreeDiskSize() ?? 0
let diskTotal = implementation.getTotalDiskSize() ?? 0

call.resolve([
"memUsed": memUsed,
"diskFree": diskFree,
"diskTotal": diskTotal,
"realDiskFree": realDiskFree,
"realDiskTotal": diskTotal,
"name": UIDevice.current.name,
"model": UIDevice.current.model,
"operatingSystem": "ios",
Expand Down
27 changes: 25 additions & 2 deletions device/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,43 @@ export interface DeviceInfo {
memUsed?: number;

/**
* How much free disk space is available on the the normal data storage.
* path for the os, in bytes
* How much free disk space is available on the the normal data storage
* path for the os, in bytes.
*
* On Android it returns the free disk space on the "system"
* partition holding the core Android OS.
* On iOS this value is not accurate.
*
* @deprecated Use `realDiskFree`.
* @since 1.0.0
*/
diskFree?: number;

/**
* The total size of the normal data storage path for the OS, in bytes.
*
* On Android it returns the disk space on the "system"
* partition holding the core Android OS.
*
* @deprecated Use `realDiskTotal`.
* @since 1.0.0
*/
diskTotal?: number;

/**
* How much free disk space is available on the the normal data storage, in bytes.
*
* @since 1.1.0
*/
realDiskFree?: number;

/**
* The total size of the normal data storage path, in bytes.
*
* @since 1.1.0
*/
realDiskTotal?: number;

/**
* The web view browser version
*
Expand Down

0 comments on commit 3f67643

Please sign in to comment.