@capawesome/capacitor-age-signals 0.1.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.
Files changed (35) hide show
  1. package/CapawesomeCapacitorAgeSignals.podspec +17 -0
  2. package/LICENSE +201 -0
  3. package/Package.swift +28 -0
  4. package/README.md +111 -0
  5. package/android/build.gradle +60 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/AgeSignals.java +75 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/AgeSignalsPlugin.java +69 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/classes/CustomException.java +20 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/classes/CustomExceptions.java +36 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/classes/results/CheckAgeSignalsResult.java +73 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/enums/UserStatus.java +10 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/interfaces/Callback.java +5 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/interfaces/EmptyCallback.java +5 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/interfaces/NonEmptyCallback.java +7 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/interfaces/NonEmptyResultCallback.java +7 -0
  17. package/android/src/main/java/io/capawesome/capacitorjs/plugins/agesignals/interfaces/Result.java +7 -0
  18. package/android/src/main/res/.gitkeep +0 -0
  19. package/dist/docs.json +203 -0
  20. package/dist/esm/definitions.d.ts +173 -0
  21. package/dist/esm/definitions.js +115 -0
  22. package/dist/esm/definitions.js.map +1 -0
  23. package/dist/esm/index.d.ts +4 -0
  24. package/dist/esm/index.js +7 -0
  25. package/dist/esm/index.js.map +1 -0
  26. package/dist/esm/web.d.ts +5 -0
  27. package/dist/esm/web.js +7 -0
  28. package/dist/esm/web.js.map +1 -0
  29. package/dist/plugin.cjs.js +136 -0
  30. package/dist/plugin.cjs.js.map +1 -0
  31. package/dist/plugin.js +139 -0
  32. package/dist/plugin.js.map +1 -0
  33. package/ios/Plugin/AgeSignalsPlugin.swift +15 -0
  34. package/ios/Plugin/Info.plist +24 -0
  35. package/package.json +93 -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 = 'CapawesomeCapacitorAgeSignals'
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/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '14.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Robin Genz
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/Package.swift ADDED
@@ -0,0 +1,28 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapawesomeCapacitorAgeSignals",
6
+ platforms: [.iOS(.v14)],
7
+ products: [
8
+ .library(
9
+ name: "CapawesomeCapacitorAgeSignals",
10
+ targets: ["AgeSignalsPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
14
+ ],
15
+ targets: [
16
+ .target(
17
+ name: "AgeSignalsPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Plugin"),
23
+ .testTarget(
24
+ name: "AgeSignalsPluginTests",
25
+ dependencies: ["AgeSignalsPlugin"],
26
+ path: "ios/PluginTests")
27
+ ]
28
+ )
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @capawesome/capacitor-age-signals
2
+
3
+ Capacitor plugin to use the [Play Age Signals API](https://developer.android.com/google/play/age-signals/overview) to retrieve age-related signals for users.
4
+
5
+ <div class="capawesome-z29o10a">
6
+ <a href="https://cloud.capawesome.io/" target="_blank">
7
+ <img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-deploy-real-time-app-updates.png?t=1" />
8
+ </a>
9
+ </div>
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @capawesome/capacitor-age-signals
15
+ npx cap sync
16
+ ```
17
+
18
+ ### Android
19
+
20
+ #### Variables
21
+
22
+ If needed, you can define the following project variable in your app's `variables.gradle` file to change the default version of the dependency:
23
+
24
+ - `$androidPlayAgeSignalsVersion` version of `com.google.android.play:age-signals` (default: `0.0.1-beta01`)
25
+
26
+ This can be useful if you encounter dependency conflicts with other plugins in your project.
27
+
28
+ ## Configuration
29
+
30
+ No configuration required for this plugin.
31
+
32
+ ## Usage
33
+
34
+ ```typescript
35
+ import { AgeSignals } from '@capawesome/capacitor-age-signals';
36
+
37
+ const checkAgeSignals = async () => {
38
+ const result = await AgeSignals.checkAgeSignals();
39
+ console.log('User Status:', result.userStatus);
40
+ console.log('Age Lower:', result.ageLower);
41
+ console.log('Age Upper:', result.ageUpper);
42
+ };
43
+ ```
44
+
45
+ ## API
46
+
47
+ <docgen-index>
48
+
49
+ * [`checkAgeSignals()`](#checkagesignals)
50
+ * [Interfaces](#interfaces)
51
+ * [Enums](#enums)
52
+
53
+ </docgen-index>
54
+
55
+ <docgen-api>
56
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
57
+
58
+ ### checkAgeSignals()
59
+
60
+ ```typescript
61
+ checkAgeSignals() => Promise<CheckAgeSignalsResult>
62
+ ```
63
+
64
+ Request the user's age signals from Google Play.
65
+
66
+ Only available on Android.
67
+
68
+ **Returns:** <code>Promise&lt;<a href="#checkagesignalsresult">CheckAgeSignalsResult</a>&gt;</code>
69
+
70
+ **Since:** 0.0.1
71
+
72
+ --------------------
73
+
74
+
75
+ ### Interfaces
76
+
77
+
78
+ #### CheckAgeSignalsResult
79
+
80
+ | Prop | Type | Description | Since |
81
+ | ---------------------------- | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
82
+ | **`userStatus`** | <code><a href="#userstatus">UserStatus</a></code> | The user's verification status. | 0.0.1 |
83
+ | **`ageLower`** | <code>number</code> | The (inclusive) lower bound of a supervised user's age range. Only available when `userStatus` is `SUPERVISED`, `SUPERVISED_APPROVAL_PENDING`, or `SUPERVISED_APPROVAL_DENIED`. | 0.0.1 |
84
+ | **`ageUpper`** | <code>number</code> | The (inclusive) upper bound of a supervised user's age range. Only available when `userStatus` is `SUPERVISED`, `SUPERVISED_APPROVAL_PENDING`, or `SUPERVISED_APPROVAL_DENIED` and the user's age is under 18. | 0.0.1 |
85
+ | **`mostRecentApprovalDate`** | <code>string</code> | The effective from date of the most recent significant change that was approved. When an app is installed, the date of the most recent significant change prior to install is used. Only available when `userStatus` is `SUPERVISED_APPROVAL_PENDING` or `SUPERVISED_APPROVAL_DENIED`. | 0.0.1 |
86
+ | **`installId`** | <code>string</code> | An ID assigned to supervised user installs by Google Play, used for the purposes of notifying you of revoked app approval. Only available when `userStatus` is `SUPERVISED`, `SUPERVISED_APPROVAL_PENDING`, or `SUPERVISED_APPROVAL_DENIED`. | 0.0.1 |
87
+
88
+
89
+ ### Enums
90
+
91
+
92
+ #### UserStatus
93
+
94
+ | Members | Value | Description | Since |
95
+ | ------------------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
96
+ | **`Verified`** | <code>'VERIFIED'</code> | The user is over 18. Google verified the user's age using a commercially reasonable method such as a government-issued ID, credit card, or facial age estimation. | 0.0.1 |
97
+ | **`Supervised`** | <code>'SUPERVISED'</code> | The user has a supervised Google Account managed by a parent who sets their age. Use `ageLower` and `ageUpper` to determine the user's age range. | 0.0.1 |
98
+ | **`SupervisedApprovalPending`** | <code>'SUPERVISED_APPROVAL_PENDING'</code> | The user has a supervised Google Account, and their supervising parent has not yet approved one or more pending significant changes. Use `ageLower` and `ageUpper` to determine the user's age range. Use `mostRecentApprovalDate` to determine the last significant change that was approved. | 0.0.1 |
99
+ | **`SupervisedApprovalDenied`** | <code>'SUPERVISED_APPROVAL_DENIED'</code> | The user has a supervised Google Account, and their supervising parent denied approval for one or more significant changes. Use `ageLower` and `ageUpper` to determine the user's age range. Use `mostRecentApprovalDate` to determine the last significant change that was approved. | 0.0.1 |
100
+ | **`Unknown`** | <code>'UNKNOWN'</code> | The user is not verified or supervised in applicable jurisdictions and regions. These users could be over or under 18. To obtain an age signal from Google Play, ask the user to visit the Play Store to resolve their status. | 0.0.1 |
101
+ | **`Empty`** | <code>'EMPTY'</code> | All other users return this value. | 0.0.1 |
102
+
103
+ </docgen-api>
104
+
105
+ ## Changelog
106
+
107
+ See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/age-signals/CHANGELOG.md).
108
+
109
+ ## License
110
+
111
+ See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/age-signals/LICENSE).
@@ -0,0 +1,60 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
+ androidPlayAgeSignalsVersion = project.hasProperty('androidPlayAgeSignalsVersion') ? rootProject.ext.androidPlayAgeSignalsVersion : '0.0.1-beta01'
7
+ }
8
+
9
+ buildscript {
10
+ repositories {
11
+ google()
12
+ mavenCentral()
13
+ }
14
+ dependencies {
15
+ classpath 'com.android.tools.build:gradle:8.7.2'
16
+ }
17
+ }
18
+
19
+ apply plugin: 'com.android.library'
20
+
21
+ android {
22
+ namespace "io.capawesome.capacitorjs.plugins.agesignals"
23
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
24
+ defaultConfig {
25
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
26
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
27
+ versionCode 1
28
+ versionName "1.0"
29
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
30
+ }
31
+ buildTypes {
32
+ release {
33
+ minifyEnabled false
34
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
35
+ }
36
+ }
37
+ lintOptions {
38
+ abortOnError false
39
+ }
40
+ compileOptions {
41
+ sourceCompatibility JavaVersion.VERSION_21
42
+ targetCompatibility JavaVersion.VERSION_21
43
+ }
44
+ }
45
+
46
+ repositories {
47
+ google()
48
+ mavenCentral()
49
+ }
50
+
51
+
52
+ dependencies {
53
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
54
+ implementation project(':capacitor-android')
55
+ implementation "com.google.android.play:age-signals:$androidPlayAgeSignalsVersion"
56
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
57
+ testImplementation "junit:junit:$junitVersion"
58
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
59
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
60
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,75 @@
1
+ package io.capawesome.capacitorjs.plugins.agesignals;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.google.android.gms.tasks.Task;
5
+ import com.google.android.play.agesignals.AgeSignalsManager;
6
+ import com.google.android.play.agesignals.AgeSignalsManagerFactory;
7
+ import com.google.android.play.agesignals.AgeSignalsRequest;
8
+ import com.google.android.play.agesignals.AgeSignalsResult;
9
+ import io.capawesome.capacitorjs.plugins.agesignals.classes.CustomExceptions;
10
+ import io.capawesome.capacitorjs.plugins.agesignals.classes.results.CheckAgeSignalsResult;
11
+ import io.capawesome.capacitorjs.plugins.agesignals.interfaces.NonEmptyResultCallback;
12
+
13
+ public class AgeSignals {
14
+
15
+ @NonNull
16
+ private final AgeSignalsPlugin plugin;
17
+
18
+ public AgeSignals(@NonNull AgeSignalsPlugin plugin) {
19
+ this.plugin = plugin;
20
+ }
21
+
22
+ public void checkAgeSignals(@NonNull NonEmptyResultCallback<CheckAgeSignalsResult> callback) {
23
+ AgeSignalsManager manager = AgeSignalsManagerFactory.create(plugin.getActivity());
24
+ AgeSignalsRequest request = AgeSignalsRequest.builder().build();
25
+
26
+ Task<AgeSignalsResult> task = manager.checkAgeSignals(request);
27
+ task.addOnSuccessListener(ageSignalsResult -> {
28
+ try {
29
+ CheckAgeSignalsResult result = new CheckAgeSignalsResult(ageSignalsResult);
30
+ callback.success(result);
31
+ } catch (Exception exception) {
32
+ callback.error(exception);
33
+ }
34
+ });
35
+ task.addOnFailureListener(exception -> {
36
+ Exception mappedException = mapErrorCodeToException(exception);
37
+ callback.error(mappedException);
38
+ });
39
+ }
40
+
41
+ @NonNull
42
+ private Exception mapErrorCodeToException(@NonNull Exception exception) {
43
+ if (!(exception instanceof com.google.android.gms.common.api.ApiException)) {
44
+ return exception;
45
+ }
46
+
47
+ com.google.android.gms.common.api.ApiException apiException = (com.google.android.gms.common.api.ApiException) exception;
48
+ int statusCode = apiException.getStatusCode();
49
+
50
+ switch (statusCode) {
51
+ case 25000:
52
+ return CustomExceptions.API_NOT_AVAILABLE;
53
+ case 25001:
54
+ return CustomExceptions.PLAY_STORE_NOT_FOUND;
55
+ case 25002:
56
+ return CustomExceptions.NETWORK_ERROR;
57
+ case 25003:
58
+ return CustomExceptions.PLAY_SERVICES_NOT_FOUND;
59
+ case 25004:
60
+ return CustomExceptions.CANNOT_BIND_TO_SERVICE;
61
+ case 25005:
62
+ return CustomExceptions.PLAY_STORE_VERSION_OUTDATED;
63
+ case 25006:
64
+ return CustomExceptions.PLAY_SERVICES_VERSION_OUTDATED;
65
+ case 25007:
66
+ return CustomExceptions.CLIENT_TRANSIENT_ERROR;
67
+ case 25008:
68
+ return CustomExceptions.APP_NOT_OWNED;
69
+ case 25009:
70
+ return CustomExceptions.INTERNAL_ERROR;
71
+ default:
72
+ return exception;
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,69 @@
1
+ package io.capawesome.capacitorjs.plugins.agesignals;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.JSObject;
6
+ import com.getcapacitor.Logger;
7
+ import com.getcapacitor.Plugin;
8
+ import com.getcapacitor.PluginCall;
9
+ import com.getcapacitor.PluginMethod;
10
+ import com.getcapacitor.annotation.CapacitorPlugin;
11
+ import io.capawesome.capacitorjs.plugins.agesignals.classes.results.CheckAgeSignalsResult;
12
+ import io.capawesome.capacitorjs.plugins.agesignals.interfaces.NonEmptyResultCallback;
13
+ import io.capawesome.capacitorjs.plugins.agesignals.interfaces.Result;
14
+
15
+ @CapacitorPlugin(name = "AgeSignals")
16
+ public class AgeSignalsPlugin extends Plugin {
17
+
18
+ public static final String TAG = "AgeSignals";
19
+ private static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
20
+
21
+ private AgeSignals implementation;
22
+
23
+ public void load() {
24
+ try {
25
+ implementation = new AgeSignals(this);
26
+ } catch (Exception exception) {
27
+ Logger.error(TAG, "Failed to load AgeSignals plugin.", exception);
28
+ }
29
+ }
30
+
31
+ @PluginMethod
32
+ public void checkAgeSignals(PluginCall call) {
33
+ try {
34
+ NonEmptyResultCallback<CheckAgeSignalsResult> callback = new NonEmptyResultCallback<>() {
35
+ @Override
36
+ public void success(@NonNull CheckAgeSignalsResult result) {
37
+ resolveCall(call, result);
38
+ }
39
+
40
+ @Override
41
+ public void error(@NonNull Exception exception) {
42
+ rejectCall(call, exception);
43
+ }
44
+ };
45
+
46
+ assert implementation != null;
47
+ implementation.checkAgeSignals(callback);
48
+ } catch (Exception exception) {
49
+ rejectCall(call, exception);
50
+ }
51
+ }
52
+
53
+ private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
54
+ String message = exception.getMessage();
55
+ if (message == null) {
56
+ message = ERROR_UNKNOWN_ERROR;
57
+ }
58
+ Logger.error(TAG, message, exception);
59
+ call.reject(message);
60
+ }
61
+
62
+ private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
63
+ if (result == null) {
64
+ call.resolve();
65
+ } else {
66
+ call.resolve(result.toJSObject());
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,20 @@
1
+ package io.capawesome.capacitorjs.plugins.agesignals.classes;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ public class CustomException extends Exception {
7
+
8
+ @Nullable
9
+ private final String code;
10
+
11
+ public CustomException(@Nullable String code, @NonNull String message) {
12
+ super(message);
13
+ this.code = code;
14
+ }
15
+
16
+ @Nullable
17
+ public String getCode() {
18
+ return code;
19
+ }
20
+ }
@@ -0,0 +1,36 @@
1
+ package io.capawesome.capacitorjs.plugins.agesignals.classes;
2
+
3
+ public class CustomExceptions {
4
+
5
+ public static final CustomException API_NOT_AVAILABLE = new CustomException(
6
+ "API_NOT_AVAILABLE",
7
+ "The Play Age Signals API is not available. The Play Store app version installed on the device might be old."
8
+ );
9
+ public static final CustomException PLAY_STORE_NOT_FOUND = new CustomException(
10
+ "PLAY_STORE_NOT_FOUND",
11
+ "No Play Store app is found on the device."
12
+ );
13
+ public static final CustomException NETWORK_ERROR = new CustomException("NETWORK_ERROR", "No available network is found.");
14
+ public static final CustomException PLAY_SERVICES_NOT_FOUND = new CustomException(
15
+ "PLAY_SERVICES_NOT_FOUND",
16
+ "Play Services is not available or its version is too old."
17
+ );
18
+ public static final CustomException CANNOT_BIND_TO_SERVICE = new CustomException(
19
+ "CANNOT_BIND_TO_SERVICE",
20
+ "Binding to the service in the Play Store has failed. This can be due to having an old Play Store version installed on the device or device memory is overloaded."
21
+ );
22
+ public static final CustomException PLAY_STORE_VERSION_OUTDATED = new CustomException(
23
+ "PLAY_STORE_VERSION_OUTDATED",
24
+ "The Play Store app needs to be updated."
25
+ );
26
+ public static final CustomException PLAY_SERVICES_VERSION_OUTDATED = new CustomException(
27
+ "PLAY_SERVICES_VERSION_OUTDATED",
28
+ "Play Services needs to be updated."
29
+ );
30
+ public static final CustomException CLIENT_TRANSIENT_ERROR = new CustomException(
31
+ "CLIENT_TRANSIENT_ERROR",
32
+ "There was a transient error in the client device."
33
+ );
34
+ public static final CustomException APP_NOT_OWNED = new CustomException("APP_NOT_OWNED", "The app was not installed by Google Play.");
35
+ public static final CustomException INTERNAL_ERROR = new CustomException("INTERNAL_ERROR", "Unknown internal error.");
36
+ }