@capgo/capacitor-android-usagestatsmanager 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapgoCapacitorAndroidUsagestatsmanager.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +164 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/ee/forgr/capacitor_android_usagestatsmanager/CapacitorUsageStatsManagerPlugin.java +163 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +266 -0
- package/dist/esm/definitions.d.ts +118 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +10 -0
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +30 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +33 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapacitorUsageStatsManagerPlugin/CapacitorUsageStatsManagerPlugin.swift +29 -0
- package/ios/Tests/CapacitorUsageStatsManagerPluginTests/CapacitorUsageStatsManagerPluginTests.swift +15 -0
- package/package.json +80 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapgoCapacitorAndroidUsagestatsmanager'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '13.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapgoCapacitorAndroidUsagestatsmanager",
|
|
6
|
+
platforms: [.iOS(.v13)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapgoCapacitorAndroidUsagestatsmanager",
|
|
10
|
+
targets: ["CapacitorUsageStatsManagerPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "CapacitorUsageStatsManagerPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/CapacitorUsageStatsManagerPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "CapacitorUsageStatsManagerPluginTests",
|
|
25
|
+
dependencies: ["CapacitorUsageStatsManagerPlugin"],
|
|
26
|
+
path: "ios/Tests/CapacitorUsageStatsManagerPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @capgo/capacitor-android-usagestatsmanager
|
|
2
|
+
<a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
|
|
3
|
+
|
|
4
|
+
<div align="center">
|
|
5
|
+
<h2><a href="https://capgo.app/?ref=plugin"> ➡️ Get Instant updates for your App with Capgo 🚀</a></h2>
|
|
6
|
+
<h2><a href="https://capgo.app/consulting/?ref=plugin"> Fix your annoying bug now, Hire a Capacitor expert 💪</a></h2>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
Exposes the Android's UsageStatsManager SDK to Capacitor
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Requires the following permissions in your `AndroidManifest.xml`:
|
|
16
|
+
|
|
17
|
+
```xml
|
|
18
|
+
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
|
|
19
|
+
tools:ignore="ProtectedPermissions" />
|
|
20
|
+
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
|
21
|
+
tools:ignore="QueryAllPackagesPermission" />
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @capgo/capacitor-android-usagestatsmanager
|
|
30
|
+
npx cap sync
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
<docgen-index>
|
|
36
|
+
|
|
37
|
+
* [`queryAndAggregateUsageStats(...)`](#queryandaggregateusagestats)
|
|
38
|
+
* [`isUsageStatsPermissionGranted()`](#isusagestatspermissiongranted)
|
|
39
|
+
* [`openUsageStatsSettings()`](#openusagestatssettings)
|
|
40
|
+
* [`queryAllPackages()`](#queryallpackages)
|
|
41
|
+
* [Interfaces](#interfaces)
|
|
42
|
+
* [Type Aliases](#type-aliases)
|
|
43
|
+
|
|
44
|
+
</docgen-index>
|
|
45
|
+
|
|
46
|
+
<docgen-api>
|
|
47
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
48
|
+
|
|
49
|
+
### queryAndAggregateUsageStats(...)
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
queryAndAggregateUsageStats(options: UsageStatsOptions) => Promise<Record<string, UsageStats>>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Queries and aggregates usage stats for the given options.
|
|
56
|
+
|
|
57
|
+
| Param | Type | Description |
|
|
58
|
+
| ------------- | --------------------------------------------------------------- | ---------------------------- |
|
|
59
|
+
| **`options`** | <code><a href="#usagestatsoptions">UsageStatsOptions</a></code> | - The options for the query. |
|
|
60
|
+
|
|
61
|
+
**Returns:** <code>Promise<<a href="#record">Record</a><string, <a href="#usagestats">UsageStats</a>>></code>
|
|
62
|
+
|
|
63
|
+
--------------------
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### isUsageStatsPermissionGranted()
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
isUsageStatsPermissionGranted() => Promise<UsageStatsPermissionResult>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Checks if the usage stats permission is granted.
|
|
73
|
+
|
|
74
|
+
**Returns:** <code>Promise<<a href="#usagestatspermissionresult">UsageStatsPermissionResult</a>></code>
|
|
75
|
+
|
|
76
|
+
--------------------
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
### openUsageStatsSettings()
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
openUsageStatsSettings() => Promise<void>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Open the usage stats settings screen.
|
|
86
|
+
This will open the usage stats settings screen, which allows the user to grant the usage stats permission.
|
|
87
|
+
This will always open the settings screen, even if the permission is already granted.
|
|
88
|
+
|
|
89
|
+
--------------------
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### queryAllPackages()
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
queryAllPackages() => Promise<{ packages: PackageInfo[]; }>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Queries all installed packages on the device.
|
|
99
|
+
Requires the QUERY_ALL_PACKAGES permission.
|
|
100
|
+
|
|
101
|
+
**Returns:** <code>Promise<{ packages: PackageInfo[]; }></code>
|
|
102
|
+
|
|
103
|
+
**Since:** 1.2.0
|
|
104
|
+
|
|
105
|
+
--------------------
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
### Interfaces
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
#### UsageStats
|
|
112
|
+
|
|
113
|
+
| Prop | Type | Description |
|
|
114
|
+
| ----------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| **`firstTimeStamp`** | <code>number</code> | The first timestamp of the usage stats. |
|
|
116
|
+
| **`lastTimeStamp`** | <code>number</code> | The last timestamp of the usage stats. |
|
|
117
|
+
| **`lastTimeForegroundServiceUsed`** | <code>number</code> | Only available on Android Q (API level 29) and above. Will be undefined on lower Android versions. |
|
|
118
|
+
| **`lastTimeUsed`** | <code>number</code> | The last time the app was used. |
|
|
119
|
+
| **`lastTimeVisible`** | <code>number</code> | Only available on Android Q (API level 29) and above. Will be undefined on lower Android versions. |
|
|
120
|
+
| **`packageName`** | <code>string</code> | The name of the package. |
|
|
121
|
+
| **`totalForegroundServiceUsed`** | <code>number</code> | Only available on Android Q (API level 29) and above. Will be undefined on lower Android versions. |
|
|
122
|
+
| **`totalTimeInForeground`** | <code>number</code> | The total time the app was in the foreground. |
|
|
123
|
+
| **`totalTimeVisible`** | <code>number</code> | Only available on Android Q (API level 29) and above. Will be undefined on lower Android versions. |
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
#### UsageStatsOptions
|
|
127
|
+
|
|
128
|
+
| Prop | Type | Description |
|
|
129
|
+
| --------------- | ------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
130
|
+
| **`beginTime`** | <code>number</code> | The inclusive beginning of the range of stats to include in the results. Defined in terms of "Unix time" |
|
|
131
|
+
| **`endTime`** | <code>number</code> | The exclusive end of the range of stats to include in the results. Defined in terms of "Unix time" |
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
#### UsageStatsPermissionResult
|
|
135
|
+
|
|
136
|
+
| Prop | Type | Description |
|
|
137
|
+
| ------------- | -------------------- | ---------------------------------------------- |
|
|
138
|
+
| **`granted`** | <code>boolean</code> | Whether the usage stats permission is granted. |
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
#### PackageInfo
|
|
142
|
+
|
|
143
|
+
Represents basic information about an installed package.
|
|
144
|
+
|
|
145
|
+
| Prop | Type |
|
|
146
|
+
| ---------------------- | ------------------- |
|
|
147
|
+
| **`packageName`** | <code>string</code> |
|
|
148
|
+
| **`appName`** | <code>string</code> |
|
|
149
|
+
| **`versionName`** | <code>string</code> |
|
|
150
|
+
| **`versionCode`** | <code>number</code> |
|
|
151
|
+
| **`firstInstallTime`** | <code>number</code> |
|
|
152
|
+
| **`lastUpdateTime`** | <code>number</code> |
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
### Type Aliases
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
#### Record
|
|
159
|
+
|
|
160
|
+
Construct a type with a set of properties K of type T
|
|
161
|
+
|
|
162
|
+
<code>{
|
|
163
|
[P in K]: T;
|
|
1
164
|
}</code>
|
|
165
|
+
|
|
166
|
+
</docgen-api>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "ee.forgr.capacitor_android_usagestatsmanager"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
package ee.forgr.capacitor_android_usagestatsmanager;
|
|
2
|
+
|
|
3
|
+
import android.app.AppOpsManager;
|
|
4
|
+
import android.app.usage.UsageStats;
|
|
5
|
+
import android.app.usage.UsageStatsManager;
|
|
6
|
+
import android.content.Context;
|
|
7
|
+
import android.content.Intent;
|
|
8
|
+
import android.content.pm.ApplicationInfo;
|
|
9
|
+
import android.content.pm.PackageInfo;
|
|
10
|
+
import android.content.pm.PackageManager;
|
|
11
|
+
import android.os.Build;
|
|
12
|
+
import android.provider.Settings;
|
|
13
|
+
import android.util.Log;
|
|
14
|
+
import androidx.annotation.NonNull;
|
|
15
|
+
import com.getcapacitor.JSObject;
|
|
16
|
+
import com.getcapacitor.Plugin;
|
|
17
|
+
import com.getcapacitor.PluginCall;
|
|
18
|
+
import com.getcapacitor.PluginMethod;
|
|
19
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
20
|
+
import java.io.PrintWriter;
|
|
21
|
+
import java.io.StringWriter;
|
|
22
|
+
import java.util.List;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
|
|
25
|
+
@CapacitorPlugin(name = "CapacitorUsageStatsManager")
|
|
26
|
+
public class CapacitorUsageStatsManagerPlugin extends Plugin {
|
|
27
|
+
|
|
28
|
+
@PluginMethod
|
|
29
|
+
public void queryAndAggregateUsageStats(final PluginCall call) {
|
|
30
|
+
// I cannot use the primitive long here because it would create an NPE
|
|
31
|
+
final Long beginTime = call.getLong("beginTime");
|
|
32
|
+
if (beginTime == null) {
|
|
33
|
+
call.reject("beginTime is null");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
final Long endTime = call.getLong("endTime");
|
|
38
|
+
if (endTime == null) {
|
|
39
|
+
call.reject("endTime is null");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
final boolean isAllowedToQueryUsageStats = this.checkUsageStatsPermission(this.getContext());
|
|
44
|
+
if (!isAllowedToQueryUsageStats) {
|
|
45
|
+
call.reject("Not allowed to query usage stats");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
final UsageStatsManager usageStatsManager = (UsageStatsManager) this.getContext().getSystemService(Context.USAGE_STATS_SERVICE);
|
|
51
|
+
final Map<String, UsageStats> response = usageStatsManager.queryAndAggregateUsageStats(beginTime, endTime);
|
|
52
|
+
final JSObject finalResponse = new JSObject();
|
|
53
|
+
for (final Map.Entry<String, UsageStats> stat : response.entrySet()) {
|
|
54
|
+
final String key = stat.getKey();
|
|
55
|
+
final JSObject encodedValue = getJsObject(stat);
|
|
56
|
+
finalResponse.put(key, encodedValue);
|
|
57
|
+
}
|
|
58
|
+
call.resolve(finalResponse);
|
|
59
|
+
} catch (Throwable t) {
|
|
60
|
+
Log.e("CapacitorUsageStatsManager", "Error during fetching stats", t);
|
|
61
|
+
StringWriter sw = new StringWriter();
|
|
62
|
+
PrintWriter pw = new PrintWriter(sw);
|
|
63
|
+
t.printStackTrace(pw);
|
|
64
|
+
call.reject("Error during fetching stats: " + sw);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@PluginMethod
|
|
69
|
+
public void isUsageStatsPermissionGranted(final PluginCall call) {
|
|
70
|
+
try {
|
|
71
|
+
final boolean response = this.checkUsageStatsPermission(this.getContext());
|
|
72
|
+
final JSObject jsResponse = new JSObject();
|
|
73
|
+
jsResponse.put("granted", response);
|
|
74
|
+
call.resolve(jsResponse);
|
|
75
|
+
} catch (Throwable t) {
|
|
76
|
+
Log.e("CapacitorUsageStatsManager", "Error during fetching stats", t);
|
|
77
|
+
StringWriter sw = new StringWriter();
|
|
78
|
+
PrintWriter pw = new PrintWriter(sw);
|
|
79
|
+
t.printStackTrace(pw);
|
|
80
|
+
call.reject("Error during isUsageStatsPermissionGranted: " + sw);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@PluginMethod
|
|
85
|
+
public void openUsageStatsSettings(final PluginCall call) {
|
|
86
|
+
try {
|
|
87
|
+
final Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
|
|
88
|
+
this.getContext().startActivity(intent);
|
|
89
|
+
call.resolve();
|
|
90
|
+
} catch (Throwable t) {
|
|
91
|
+
Log.e("CapacitorUsageStatsManager", "Error during fetching stats", t);
|
|
92
|
+
StringWriter sw = new StringWriter();
|
|
93
|
+
PrintWriter pw = new PrintWriter(sw);
|
|
94
|
+
t.printStackTrace(pw);
|
|
95
|
+
call.reject("Error during openUsageStatsSettings: " + sw);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@PluginMethod
|
|
100
|
+
public void queryAllPackages(final PluginCall call) {
|
|
101
|
+
PackageManager pm = getContext().getPackageManager();
|
|
102
|
+
List<PackageInfo> packages = pm.getInstalledPackages(0);
|
|
103
|
+
JSObject result = new JSObject();
|
|
104
|
+
com.getcapacitor.JSArray packagesJA = new com.getcapacitor.JSArray();
|
|
105
|
+
|
|
106
|
+
for (PackageInfo packageInfo : packages) {
|
|
107
|
+
JSObject packageJS = new JSObject();
|
|
108
|
+
packageJS.put("packageName", packageInfo.packageName);
|
|
109
|
+
try {
|
|
110
|
+
ApplicationInfo appInfo = pm.getApplicationInfo(packageInfo.packageName, 0);
|
|
111
|
+
packageJS.put("appName", pm.getApplicationLabel(appInfo).toString());
|
|
112
|
+
} catch (PackageManager.NameNotFoundException e) {
|
|
113
|
+
packageJS.put("appName", packageInfo.packageName);
|
|
114
|
+
}
|
|
115
|
+
packageJS.put("versionName", packageInfo.versionName);
|
|
116
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
117
|
+
packageJS.put("versionCode", packageInfo.getLongVersionCode());
|
|
118
|
+
} else {
|
|
119
|
+
@SuppressWarnings("deprecation")
|
|
120
|
+
long versionCode = packageInfo.versionCode;
|
|
121
|
+
packageJS.put("versionCode", versionCode);
|
|
122
|
+
}
|
|
123
|
+
packageJS.put("firstInstallTime", packageInfo.firstInstallTime);
|
|
124
|
+
packageJS.put("lastUpdateTime", packageInfo.lastUpdateTime);
|
|
125
|
+
packagesJA.put(packageJS);
|
|
126
|
+
}
|
|
127
|
+
result.put("packages", packagesJA);
|
|
128
|
+
call.resolve(result);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@NonNull
|
|
132
|
+
private static JSObject getJsObject(Map.Entry<String, UsageStats> stat) {
|
|
133
|
+
final UsageStats value = stat.getValue();
|
|
134
|
+
final JSObject encodedValue = new JSObject();
|
|
135
|
+
|
|
136
|
+
encodedValue.put("firstTimeStamp", value.getFirstTimeStamp());
|
|
137
|
+
encodedValue.put("lastTimeStamp", value.getLastTimeStamp());
|
|
138
|
+
encodedValue.put("lastTimeUsed", value.getLastTimeUsed());
|
|
139
|
+
encodedValue.put("packageName", value.getPackageName());
|
|
140
|
+
encodedValue.put("totalTimeInForeground", value.getTotalTimeInForeground());
|
|
141
|
+
|
|
142
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
143
|
+
encodedValue.put("totalTimeVisible", value.getTotalTimeVisible());
|
|
144
|
+
encodedValue.put("totalForegroundServiceUsed", value.getTotalTimeForegroundServiceUsed());
|
|
145
|
+
encodedValue.put("lastTimeVisible", value.getLastTimeVisible());
|
|
146
|
+
encodedValue.put("lastTimeForegroundServiceUsed", value.getLastTimeForegroundServiceUsed());
|
|
147
|
+
}
|
|
148
|
+
return encodedValue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public boolean checkUsageStatsPermission(final Context context) {
|
|
152
|
+
final AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
|
153
|
+
int mode;
|
|
154
|
+
|
|
155
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
156
|
+
mode = appOps.unsafeCheckOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, android.os.Process.myUid(), context.getPackageName());
|
|
157
|
+
} else {
|
|
158
|
+
mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, android.os.Process.myUid(), context.getPackageName());
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return mode == AppOpsManager.MODE_ALLOWED;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "CapacitorUsageStatsManagerPlugin",
|
|
4
|
+
"slug": "capacitorusagestatsmanagerplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "queryAndAggregateUsageStats",
|
|
10
|
+
"signature": "(options: UsageStatsOptions) => Promise<Record<string, UsageStats>>",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "options",
|
|
14
|
+
"docs": "- The options for the query.",
|
|
15
|
+
"type": "UsageStatsOptions"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"returns": "Promise<Record<string, UsageStats>>",
|
|
19
|
+
"tags": [
|
|
20
|
+
{
|
|
21
|
+
"name": "param",
|
|
22
|
+
"text": "options - The options for the query."
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "returns",
|
|
26
|
+
"text": "A promise that resolves to a record of package names and their corresponding usage stats."
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"docs": "Queries and aggregates usage stats for the given options.",
|
|
30
|
+
"complexTypes": [
|
|
31
|
+
"Record",
|
|
32
|
+
"UsageStats",
|
|
33
|
+
"UsageStatsOptions"
|
|
34
|
+
],
|
|
35
|
+
"slug": "queryandaggregateusagestats"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "isUsageStatsPermissionGranted",
|
|
39
|
+
"signature": "() => Promise<UsageStatsPermissionResult>",
|
|
40
|
+
"parameters": [],
|
|
41
|
+
"returns": "Promise<UsageStatsPermissionResult>",
|
|
42
|
+
"tags": [
|
|
43
|
+
{
|
|
44
|
+
"name": "returns",
|
|
45
|
+
"text": "A promise that resolves to a UsageStatsPermissionResult object."
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"docs": "Checks if the usage stats permission is granted.",
|
|
49
|
+
"complexTypes": [
|
|
50
|
+
"UsageStatsPermissionResult"
|
|
51
|
+
],
|
|
52
|
+
"slug": "isusagestatspermissiongranted"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "openUsageStatsSettings",
|
|
56
|
+
"signature": "() => Promise<void>",
|
|
57
|
+
"parameters": [],
|
|
58
|
+
"returns": "Promise<void>",
|
|
59
|
+
"tags": [],
|
|
60
|
+
"docs": "Open the usage stats settings screen.\nThis will open the usage stats settings screen, which allows the user to grant the usage stats permission.\nThis will always open the settings screen, even if the permission is already granted.",
|
|
61
|
+
"complexTypes": [],
|
|
62
|
+
"slug": "openusagestatssettings"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "queryAllPackages",
|
|
66
|
+
"signature": "() => Promise<{ packages: PackageInfo[]; }>",
|
|
67
|
+
"parameters": [],
|
|
68
|
+
"returns": "Promise<{ packages: PackageInfo[]; }>",
|
|
69
|
+
"tags": [
|
|
70
|
+
{
|
|
71
|
+
"name": "since",
|
|
72
|
+
"text": "1.2.0"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"docs": "Queries all installed packages on the device.\nRequires the QUERY_ALL_PACKAGES permission.",
|
|
76
|
+
"complexTypes": [
|
|
77
|
+
"PackageInfo"
|
|
78
|
+
],
|
|
79
|
+
"slug": "queryallpackages"
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
"properties": []
|
|
83
|
+
},
|
|
84
|
+
"interfaces": [
|
|
85
|
+
{
|
|
86
|
+
"name": "UsageStats",
|
|
87
|
+
"slug": "usagestats",
|
|
88
|
+
"docs": "",
|
|
89
|
+
"tags": [],
|
|
90
|
+
"methods": [],
|
|
91
|
+
"properties": [
|
|
92
|
+
{
|
|
93
|
+
"name": "firstTimeStamp",
|
|
94
|
+
"tags": [],
|
|
95
|
+
"docs": "The first timestamp of the usage stats.",
|
|
96
|
+
"complexTypes": [],
|
|
97
|
+
"type": "number"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"name": "lastTimeStamp",
|
|
101
|
+
"tags": [],
|
|
102
|
+
"docs": "The last timestamp of the usage stats.",
|
|
103
|
+
"complexTypes": [],
|
|
104
|
+
"type": "number"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "lastTimeForegroundServiceUsed",
|
|
108
|
+
"tags": [],
|
|
109
|
+
"docs": "Only available on Android Q (API level 29) and above.\nWill be undefined on lower Android versions.",
|
|
110
|
+
"complexTypes": [],
|
|
111
|
+
"type": "number | undefined"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "lastTimeUsed",
|
|
115
|
+
"tags": [],
|
|
116
|
+
"docs": "The last time the app was used.",
|
|
117
|
+
"complexTypes": [],
|
|
118
|
+
"type": "number"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"name": "lastTimeVisible",
|
|
122
|
+
"tags": [],
|
|
123
|
+
"docs": "Only available on Android Q (API level 29) and above.\nWill be undefined on lower Android versions.",
|
|
124
|
+
"complexTypes": [],
|
|
125
|
+
"type": "number | undefined"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"name": "packageName",
|
|
129
|
+
"tags": [],
|
|
130
|
+
"docs": "The name of the package.",
|
|
131
|
+
"complexTypes": [],
|
|
132
|
+
"type": "string"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": "totalForegroundServiceUsed",
|
|
136
|
+
"tags": [],
|
|
137
|
+
"docs": "Only available on Android Q (API level 29) and above.\nWill be undefined on lower Android versions.",
|
|
138
|
+
"complexTypes": [],
|
|
139
|
+
"type": "number | undefined"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"name": "totalTimeInForeground",
|
|
143
|
+
"tags": [],
|
|
144
|
+
"docs": "The total time the app was in the foreground.",
|
|
145
|
+
"complexTypes": [],
|
|
146
|
+
"type": "number"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"name": "totalTimeVisible",
|
|
150
|
+
"tags": [],
|
|
151
|
+
"docs": "Only available on Android Q (API level 29) and above.\nWill be undefined on lower Android versions.",
|
|
152
|
+
"complexTypes": [],
|
|
153
|
+
"type": "number | undefined"
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "UsageStatsOptions",
|
|
159
|
+
"slug": "usagestatsoptions",
|
|
160
|
+
"docs": "",
|
|
161
|
+
"tags": [],
|
|
162
|
+
"methods": [],
|
|
163
|
+
"properties": [
|
|
164
|
+
{
|
|
165
|
+
"name": "beginTime",
|
|
166
|
+
"tags": [],
|
|
167
|
+
"docs": "The inclusive beginning of the range of stats to include in the results.\nDefined in terms of \"Unix time\"",
|
|
168
|
+
"complexTypes": [],
|
|
169
|
+
"type": "number"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"name": "endTime",
|
|
173
|
+
"tags": [],
|
|
174
|
+
"docs": "The exclusive end of the range of stats to include in the results.\nDefined in terms of \"Unix time\"",
|
|
175
|
+
"complexTypes": [],
|
|
176
|
+
"type": "number"
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"name": "UsageStatsPermissionResult",
|
|
182
|
+
"slug": "usagestatspermissionresult",
|
|
183
|
+
"docs": "",
|
|
184
|
+
"tags": [],
|
|
185
|
+
"methods": [],
|
|
186
|
+
"properties": [
|
|
187
|
+
{
|
|
188
|
+
"name": "granted",
|
|
189
|
+
"tags": [],
|
|
190
|
+
"docs": "Whether the usage stats permission is granted.",
|
|
191
|
+
"complexTypes": [],
|
|
192
|
+
"type": "boolean"
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"name": "PackageInfo",
|
|
198
|
+
"slug": "packageinfo",
|
|
199
|
+
"docs": "Represents basic information about an installed package.",
|
|
200
|
+
"tags": [],
|
|
201
|
+
"methods": [],
|
|
202
|
+
"properties": [
|
|
203
|
+
{
|
|
204
|
+
"name": "packageName",
|
|
205
|
+
"tags": [],
|
|
206
|
+
"docs": "",
|
|
207
|
+
"complexTypes": [],
|
|
208
|
+
"type": "string"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"name": "appName",
|
|
212
|
+
"tags": [],
|
|
213
|
+
"docs": "",
|
|
214
|
+
"complexTypes": [],
|
|
215
|
+
"type": "string"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"name": "versionName",
|
|
219
|
+
"tags": [],
|
|
220
|
+
"docs": "",
|
|
221
|
+
"complexTypes": [],
|
|
222
|
+
"type": "string"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"name": "versionCode",
|
|
226
|
+
"tags": [],
|
|
227
|
+
"docs": "",
|
|
228
|
+
"complexTypes": [],
|
|
229
|
+
"type": "number"
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"name": "firstInstallTime",
|
|
233
|
+
"tags": [],
|
|
234
|
+
"docs": "",
|
|
235
|
+
"complexTypes": [],
|
|
236
|
+
"type": "number"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"name": "lastUpdateTime",
|
|
240
|
+
"tags": [],
|
|
241
|
+
"docs": "",
|
|
242
|
+
"complexTypes": [],
|
|
243
|
+
"type": "number"
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
"enums": [],
|
|
249
|
+
"typeAliases": [
|
|
250
|
+
{
|
|
251
|
+
"name": "Record",
|
|
252
|
+
"slug": "record",
|
|
253
|
+
"docs": "Construct a type with a set of properties K of type T",
|
|
254
|
+
"types": [
|
|
255
|
+
{
|
|
256
|
+
"text": "{\r\n [P in K]: T;\r\n}",
|
|
257
|
+
"complexTypes": [
|
|
258
|
+
"K",
|
|
259
|
+
"T"
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
"pluginConfigs": []
|
|
266
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
interface UsageStats {
|
|
2
|
+
/**
|
|
3
|
+
* The first timestamp of the usage stats.
|
|
4
|
+
*/
|
|
5
|
+
firstTimeStamp: number;
|
|
6
|
+
/**
|
|
7
|
+
* The last timestamp of the usage stats.
|
|
8
|
+
*/
|
|
9
|
+
lastTimeStamp: number;
|
|
10
|
+
/**
|
|
11
|
+
* Only available on Android Q (API level 29) and above.
|
|
12
|
+
* Will be undefined on lower Android versions.
|
|
13
|
+
*/
|
|
14
|
+
lastTimeForegroundServiceUsed?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The last time the app was used.
|
|
17
|
+
*/
|
|
18
|
+
lastTimeUsed: number;
|
|
19
|
+
/**
|
|
20
|
+
* Only available on Android Q (API level 29) and above.
|
|
21
|
+
* Will be undefined on lower Android versions.
|
|
22
|
+
*/
|
|
23
|
+
lastTimeVisible?: number;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the package.
|
|
26
|
+
*/
|
|
27
|
+
packageName: string;
|
|
28
|
+
/**
|
|
29
|
+
* Only available on Android Q (API level 29) and above.
|
|
30
|
+
* Will be undefined on lower Android versions.
|
|
31
|
+
*/
|
|
32
|
+
totalForegroundServiceUsed?: number;
|
|
33
|
+
/**
|
|
34
|
+
* The total time the app was in the foreground.
|
|
35
|
+
*/
|
|
36
|
+
totalTimeInForeground: number;
|
|
37
|
+
/**
|
|
38
|
+
* Only available on Android Q (API level 29) and above.
|
|
39
|
+
* Will be undefined on lower Android versions.
|
|
40
|
+
*/
|
|
41
|
+
totalTimeVisible?: number;
|
|
42
|
+
}
|
|
43
|
+
interface UsageStatsOptions {
|
|
44
|
+
/**
|
|
45
|
+
* The inclusive beginning of the range of stats to include in the results.
|
|
46
|
+
* Defined in terms of "Unix time"
|
|
47
|
+
*/
|
|
48
|
+
beginTime: number;
|
|
49
|
+
/**
|
|
50
|
+
* The exclusive end of the range of stats to include in the results.
|
|
51
|
+
* Defined in terms of "Unix time"
|
|
52
|
+
*/
|
|
53
|
+
endTime: number;
|
|
54
|
+
}
|
|
55
|
+
interface UsageStatsPermissionResult {
|
|
56
|
+
/**
|
|
57
|
+
* Whether the usage stats permission is granted.
|
|
58
|
+
*/
|
|
59
|
+
granted: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface CapacitorUsageStatsManagerPlugin {
|
|
62
|
+
/**
|
|
63
|
+
* Queries and aggregates usage stats for the given options.
|
|
64
|
+
*
|
|
65
|
+
* @param options - The options for the query.
|
|
66
|
+
* @returns A promise that resolves to a record of package names and their corresponding usage stats.
|
|
67
|
+
*/
|
|
68
|
+
queryAndAggregateUsageStats(options: UsageStatsOptions): Promise<Record<string, UsageStats>>;
|
|
69
|
+
/**
|
|
70
|
+
* Checks if the usage stats permission is granted.
|
|
71
|
+
*
|
|
72
|
+
* @returns A promise that resolves to a UsageStatsPermissionResult object.
|
|
73
|
+
*/
|
|
74
|
+
isUsageStatsPermissionGranted(): Promise<UsageStatsPermissionResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Open the usage stats settings screen.
|
|
77
|
+
* This will open the usage stats settings screen, which allows the user to grant the usage stats permission.
|
|
78
|
+
* This will always open the settings screen, even if the permission is already granted.
|
|
79
|
+
*/
|
|
80
|
+
openUsageStatsSettings(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Queries all installed packages on the device.
|
|
83
|
+
* Requires the QUERY_ALL_PACKAGES permission.
|
|
84
|
+
*
|
|
85
|
+
* @since 1.2.0
|
|
86
|
+
*/
|
|
87
|
+
queryAllPackages(): Promise<{
|
|
88
|
+
packages: PackageInfo[];
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Represents a single usage event.
|
|
93
|
+
*/
|
|
94
|
+
export interface UsageEvent {
|
|
95
|
+
packageName: string;
|
|
96
|
+
className?: string;
|
|
97
|
+
timeStamp: number;
|
|
98
|
+
eventType: number;
|
|
99
|
+
configuration?: any;
|
|
100
|
+
shortcutId?: string;
|
|
101
|
+
standbyBucket?: number;
|
|
102
|
+
notificationChannelId?: string;
|
|
103
|
+
instanceId?: number;
|
|
104
|
+
taskRootPackageName?: string;
|
|
105
|
+
taskRootClassName?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Represents basic information about an installed package.
|
|
109
|
+
*/
|
|
110
|
+
export interface PackageInfo {
|
|
111
|
+
packageName: string;
|
|
112
|
+
appName: string;
|
|
113
|
+
versionName: string;
|
|
114
|
+
versionCode: number;
|
|
115
|
+
firstInstallTime: number;
|
|
116
|
+
lastUpdateTime: number;
|
|
117
|
+
}
|
|
118
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["interface UsageStats {\n /**\n * The first timestamp of the usage stats.\n */\n firstTimeStamp: number;\n /**\n * The last timestamp of the usage stats.\n */\n lastTimeStamp: number;\n /**\n * Only available on Android Q (API level 29) and above.\n * Will be undefined on lower Android versions.\n */\n lastTimeForegroundServiceUsed?: number;\n /**\n * The last time the app was used.\n */\n lastTimeUsed: number;\n /**\n * Only available on Android Q (API level 29) and above.\n * Will be undefined on lower Android versions.\n */\n lastTimeVisible?: number;\n /**\n * The name of the package.\n */\n packageName: string;\n /**\n * Only available on Android Q (API level 29) and above.\n * Will be undefined on lower Android versions.\n */\n totalForegroundServiceUsed?: number;\n /**\n * The total time the app was in the foreground.\n */\n totalTimeInForeground: number;\n /**\n * Only available on Android Q (API level 29) and above.\n * Will be undefined on lower Android versions.\n */\n totalTimeVisible?: number;\n}\n\ninterface UsageStatsOptions {\n /**\n * The inclusive beginning of the range of stats to include in the results.\n * Defined in terms of \"Unix time\"\n */\n beginTime: number;\n\n /**\n * The exclusive end of the range of stats to include in the results.\n * Defined in terms of \"Unix time\"\n */\n endTime: number;\n}\n\ninterface UsageStatsPermissionResult {\n /**\n * Whether the usage stats permission is granted.\n */\n granted: boolean;\n}\n\nexport interface CapacitorUsageStatsManagerPlugin {\n /**\n * Queries and aggregates usage stats for the given options.\n *\n * @param options - The options for the query.\n * @returns A promise that resolves to a record of package names and their corresponding usage stats.\n */\n queryAndAggregateUsageStats(options: UsageStatsOptions): Promise<Record<string, UsageStats>>;\n /**\n * Checks if the usage stats permission is granted.\n *\n * @returns A promise that resolves to a UsageStatsPermissionResult object.\n */\n isUsageStatsPermissionGranted(): Promise<UsageStatsPermissionResult>;\n /**\n * Open the usage stats settings screen.\n * This will open the usage stats settings screen, which allows the user to grant the usage stats permission.\n * This will always open the settings screen, even if the permission is already granted.\n */\n openUsageStatsSettings(): Promise<void>;\n /**\n * Queries all installed packages on the device.\n * Requires the QUERY_ALL_PACKAGES permission.\n *\n * @since 1.2.0\n */\n queryAllPackages(): Promise<{ packages: PackageInfo[] }>;\n}\n\n/**\n * Represents a single usage event.\n */\nexport interface UsageEvent {\n packageName: string;\n className?: string; // Might be null\n timeStamp: number; // Milliseconds since epoch\n eventType: number; // Event type constant (e.g., MOVE_TO_FOREGROUND, MOVE_TO_BACKGROUND)\n configuration?: any; // Configuration object (requires API 28+)\n shortcutId?: string; // Shortcut ID (requires API 28+)\n standbyBucket?: number; // App standby bucket (requires API 28+)\n notificationChannelId?: string; // Notification channel ID (requires API 29+)\n instanceId?: number; // Instance ID (requires API 30+)\n taskRootPackageName?: string; // Task root package name (requires API 31+)\n taskRootClassName?: string; // Task root class name (requires API 31+)\n}\n\n/**\n * Represents basic information about an installed package.\n */\nexport interface PackageInfo {\n packageName: string;\n appName: string;\n versionName: string;\n versionCode: number;\n firstInstallTime: number; // Milliseconds since epoch\n lastUpdateTime: number; // Milliseconds since epoch\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const CapacitorUsageStatsManager = registerPlugin('CapacitorUsageStatsManager', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.CapacitorUsageStatsManagerWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { CapacitorUsageStatsManager };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,0BAA0B,GAAG,cAAc,CAAmC,4BAA4B,EAAE;IAChH,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;CAC9E,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,0BAA0B,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CapacitorUsageStatsManagerPlugin } from './definitions';\n\nconst CapacitorUsageStatsManager = registerPlugin<CapacitorUsageStatsManagerPlugin>('CapacitorUsageStatsManager', {\n web: () => import('./web').then((m) => new m.CapacitorUsageStatsManagerWeb()),\n});\n\nexport * from './definitions';\nexport { CapacitorUsageStatsManager };\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CapacitorUsageStatsManagerPlugin, PackageInfo } from './definitions';
|
|
3
|
+
export declare class CapacitorUsageStatsManagerWeb extends WebPlugin implements CapacitorUsageStatsManagerPlugin {
|
|
4
|
+
isUsageStatsPermissionGranted(): Promise<any>;
|
|
5
|
+
openUsageStatsSettings(): Promise<void>;
|
|
6
|
+
queryAndAggregateUsageStats(_options: any): Promise<Record<string, any>>;
|
|
7
|
+
queryAllPackages(): Promise<{
|
|
8
|
+
packages: PackageInfo[];
|
|
9
|
+
}>;
|
|
10
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class CapacitorUsageStatsManagerWeb extends WebPlugin {
|
|
3
|
+
isUsageStatsPermissionGranted() {
|
|
4
|
+
throw new Error('Method not implemented.');
|
|
5
|
+
}
|
|
6
|
+
openUsageStatsSettings() {
|
|
7
|
+
throw new Error('Method not implemented.');
|
|
8
|
+
}
|
|
9
|
+
queryAndAggregateUsageStats(_options) {
|
|
10
|
+
throw new Error('Method not implemented.');
|
|
11
|
+
}
|
|
12
|
+
queryAllPackages() {
|
|
13
|
+
throw new Error('Method not implemented.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,6BAA8B,SAAQ,SAAS;IAC1D,6BAA6B;QAC3B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,sBAAsB;QACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,2BAA2B,CAAC,QAAa;QACvC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,gBAAgB;QACd,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { CapacitorUsageStatsManagerPlugin, PackageInfo } from './definitions';\n\nexport class CapacitorUsageStatsManagerWeb extends WebPlugin implements CapacitorUsageStatsManagerPlugin {\n isUsageStatsPermissionGranted(): Promise<any> {\n throw new Error('Method not implemented.');\n }\n openUsageStatsSettings(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n queryAndAggregateUsageStats(_options: any): Promise<Record<string, any>> {\n throw new Error('Method not implemented.');\n }\n queryAllPackages(): Promise<{ packages: PackageInfo[] }> {\n throw new Error('Method not implemented.');\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const CapacitorUsageStatsManager = core.registerPlugin('CapacitorUsageStatsManager', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorUsageStatsManagerWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class CapacitorUsageStatsManagerWeb extends core.WebPlugin {
|
|
10
|
+
isUsageStatsPermissionGranted() {
|
|
11
|
+
throw new Error('Method not implemented.');
|
|
12
|
+
}
|
|
13
|
+
openUsageStatsSettings() {
|
|
14
|
+
throw new Error('Method not implemented.');
|
|
15
|
+
}
|
|
16
|
+
queryAndAggregateUsageStats(_options) {
|
|
17
|
+
throw new Error('Method not implemented.');
|
|
18
|
+
}
|
|
19
|
+
queryAllPackages() {
|
|
20
|
+
throw new Error('Method not implemented.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
25
|
+
__proto__: null,
|
|
26
|
+
CapacitorUsageStatsManagerWeb: CapacitorUsageStatsManagerWeb
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
exports.CapacitorUsageStatsManager = CapacitorUsageStatsManager;
|
|
30
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorUsageStatsManager = registerPlugin('CapacitorUsageStatsManager', {\n web: () => import('./web').then((m) => new m.CapacitorUsageStatsManagerWeb()),\n});\nexport * from './definitions';\nexport { CapacitorUsageStatsManager };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorUsageStatsManagerWeb extends WebPlugin {\n isUsageStatsPermissionGranted() {\n throw new Error('Method not implemented.');\n }\n openUsageStatsSettings() {\n throw new Error('Method not implemented.');\n }\n queryAndAggregateUsageStats(_options) {\n throw new Error('Method not implemented.');\n }\n queryAllPackages() {\n throw new Error('Method not implemented.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,0BAA0B,GAAGA,mBAAc,CAAC,4BAA4B,EAAE;AAChF,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;AACjF,CAAC;;ACFM,MAAM,6BAA6B,SAASC,cAAS,CAAC;AAC7D,IAAI,6BAA6B,GAAG;AACpC,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;AAClD;AACA,IAAI,sBAAsB,GAAG;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;AAClD;AACA,IAAI,2BAA2B,CAAC,QAAQ,EAAE;AAC1C,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;AAClD;AACA,IAAI,gBAAgB,GAAG;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;AAClD;AACA;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var capacitorCapacitorUsageStatsManager = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const CapacitorUsageStatsManager = core.registerPlugin('CapacitorUsageStatsManager', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorUsageStatsManagerWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class CapacitorUsageStatsManagerWeb extends core.WebPlugin {
|
|
9
|
+
isUsageStatsPermissionGranted() {
|
|
10
|
+
throw new Error('Method not implemented.');
|
|
11
|
+
}
|
|
12
|
+
openUsageStatsSettings() {
|
|
13
|
+
throw new Error('Method not implemented.');
|
|
14
|
+
}
|
|
15
|
+
queryAndAggregateUsageStats(_options) {
|
|
16
|
+
throw new Error('Method not implemented.');
|
|
17
|
+
}
|
|
18
|
+
queryAllPackages() {
|
|
19
|
+
throw new Error('Method not implemented.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
24
|
+
__proto__: null,
|
|
25
|
+
CapacitorUsageStatsManagerWeb: CapacitorUsageStatsManagerWeb
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
exports.CapacitorUsageStatsManager = CapacitorUsageStatsManager;
|
|
29
|
+
|
|
30
|
+
return exports;
|
|
31
|
+
|
|
32
|
+
})({}, capacitorExports);
|
|
33
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorUsageStatsManager = registerPlugin('CapacitorUsageStatsManager', {\n web: () => import('./web').then((m) => new m.CapacitorUsageStatsManagerWeb()),\n});\nexport * from './definitions';\nexport { CapacitorUsageStatsManager };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorUsageStatsManagerWeb extends WebPlugin {\n isUsageStatsPermissionGranted() {\n throw new Error('Method not implemented.');\n }\n openUsageStatsSettings() {\n throw new Error('Method not implemented.');\n }\n queryAndAggregateUsageStats(_options) {\n throw new Error('Method not implemented.');\n }\n queryAllPackages() {\n throw new Error('Method not implemented.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,0BAA0B,GAAGA,mBAAc,CAAC,4BAA4B,EAAE;IAChF,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;IACjF,CAAC;;ICFM,MAAM,6BAA6B,SAASC,cAAS,CAAC;IAC7D,IAAI,6BAA6B,GAAG;IACpC,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;IAClD;IACA,IAAI,sBAAsB,GAAG;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;IAClD;IACA,IAAI,2BAA2B,CAAC,QAAQ,EAAE;IAC1C,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;IAClD;IACA,IAAI,gBAAgB,GAAG;IACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC;IAClD;IACA;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(CapacitorUsageStatsManagerPlugin)
|
|
9
|
+
public class CapacitorUsageStatsManagerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
public let identifier = "CapacitorUsageStatsManagerPlugin"
|
|
11
|
+
public let jsName = "CapacitorUsageStatsManager"
|
|
12
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
13
|
+
CAPPluginMethod(name: "queryAndAggregateUsageStats", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "isUsageStatsPermissionGranted", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "openUsageStatsSettings", returnType: CAPPluginReturnPromise)
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
@objc func queryAndAggregateUsageStats(_ call: CAPPluginCall) {
|
|
19
|
+
call.reject("Usage statistics are not available on iOS. This functionality is only supported on Android.")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@objc func isUsageStatsPermissionGranted(_ call: CAPPluginCall) {
|
|
23
|
+
call.reject("Usage statistics are not available on iOS. This functionality is only supported on Android.")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@objc func openUsageStatsSettings(_ call: CAPPluginCall) {
|
|
27
|
+
call.reject("Usage statistics are not available on iOS. This functionality is only supported on Android.")
|
|
28
|
+
}
|
|
29
|
+
}
|
package/ios/Tests/CapacitorUsageStatsManagerPluginTests/CapacitorUsageStatsManagerPluginTests.swift
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import CapacitorUsageStatsManagerPlugin
|
|
3
|
+
|
|
4
|
+
class CapacitorUsageStatsManagerTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = CapacitorUsageStatsManager()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capgo/capacitor-android-usagestatsmanager",
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"description": "Exposes the Android's UsageStatsManager SDK to Capacitor",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"CapgoCapacitorAndroidUsagestatsmanager.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "Martin Donadieu <martin@capgo.app>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Cap-go/capacitor-android-usagestatsmanager.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Cap-go/capacitor-android-usagestatsmanager/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"native"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
+
"verify:ios": "xcodebuild -scheme CapgoCapacitorAndroidUsagestatsmanager -destination generic/platform=iOS",
|
|
35
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
|
+
"verify:web": "npm run build",
|
|
37
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
38
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
39
|
+
"eslint": "eslint . --ext ts",
|
|
40
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
41
|
+
"swiftlint": "node-swiftlint",
|
|
42
|
+
"docgen": "docgen --api CapacitorUsageStatsManagerPlugin --output-readme README.md --output-json dist/docs.json",
|
|
43
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
44
|
+
"clean": "rimraf ./dist",
|
|
45
|
+
"watch": "tsc --watch",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@capacitor/android": "^6.0.0",
|
|
50
|
+
"@capacitor/core": "^6.0.0",
|
|
51
|
+
"@capacitor/docgen": "^0.2.2",
|
|
52
|
+
"@capacitor/ios": "^6.0.0",
|
|
53
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
54
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
55
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
56
|
+
"eslint": "^8.57.0",
|
|
57
|
+
"prettier": "^3.3.3",
|
|
58
|
+
"prettier-plugin-java": "^2.6.4",
|
|
59
|
+
"rimraf": "^6.0.1",
|
|
60
|
+
"rollup": "^4.24.0",
|
|
61
|
+
"swiftlint": "^2.0.0",
|
|
62
|
+
"typescript": "~4.1.5"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@capacitor/core": "^6.0.0"
|
|
66
|
+
},
|
|
67
|
+
"prettier": "@ionic/prettier-config",
|
|
68
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
69
|
+
"eslintConfig": {
|
|
70
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
71
|
+
},
|
|
72
|
+
"capacitor": {
|
|
73
|
+
"ios": {
|
|
74
|
+
"src": "ios"
|
|
75
|
+
},
|
|
76
|
+
"android": {
|
|
77
|
+
"src": "android"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|