Skip to content

Commit ecc0c24

Browse files
MOBILE-4501 cordova-plugin-moodleapp: Add diagnostic plugin
1 parent 44a0cea commit ecc0c24

File tree

12 files changed

+264
-73
lines changed

12 files changed

+264
-73
lines changed

cordova-plugin-moodleapp/plugin.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,30 @@
1515
<param name="android-package" value="com.moodle.moodlemobile.InstallReferrer"/>
1616
</feature>
1717
</config-file>
18+
19+
<config-file target="res/xml/config.xml" parent="/*">
20+
<feature name="Diagnostic" >
21+
<param name="android-package" value="com.moodle.moodlemobile.Diagnostic"/>
22+
<param name="onload" value="true" />
23+
</feature>
24+
</config-file>
25+
26+
<js-module name="Diagnostic" src="www/android/diagnostic.js">
27+
<merges target="com.moodle.moodlemobile.diagnostic" />
28+
</js-module>
29+
30+
<source-file src="src/android/Diagnostic.java" target-dir="src/cordova/plugins" />
31+
<source-file src="src/android/Diagnostic_Location.java" target-dir="src/cordova/plugins" />
32+
33+
<preference name="ANDROIDX_VERSION" default="1.0.0" />
34+
<preference name="ANDROIDX_APPCOMPAT_VERSION" default="1.3.1" />
35+
<framework src="androidx.legacy:legacy-support-v4:$ANDROIDX_VERSION" />
36+
<framework src="androidx.appcompat:appcompat:$ANDROIDX_APPCOMPAT_VERSION" />
37+
1838
<source-file src="src/android/SecureStorage.java" target-dir="src/com/moodle/moodlemobile" />
1939
<source-file src="src/android/InstallReferrer.java" target-dir="src/com/moodle/moodlemobile" />
2040
</platform>
41+
2142
<platform name="ios">
2243
<config-file target="config.xml" parent="/*">
2344
<feature name="SecureStorage">
@@ -27,5 +48,68 @@
2748

2849
<header-file src="src/ios/SecureStorage.h" />
2950
<source-file src="src/ios/SecureStorage.m" />
51+
52+
<config-file target="config.xml" parent="/*">
53+
<feature name="Diagnostic">
54+
<param name="ios-package" value="Diagnostic" />
55+
<param name="onload" value="true" />
56+
</feature>
57+
</config-file>
58+
59+
<js-module src="www/ios/diagnostic.js" name="Diagnostic">
60+
<merges target="com.moodle.moodlemobile.diagnostic" />
61+
</js-module>
62+
63+
<header-file src="src/ios/Diagnostic.h" />
64+
<source-file src="src/ios/Diagnostic.m" />
65+
66+
<!--BEGIN_MODULE LOCATION-->
67+
<config-file target="config.xml" parent="/*">
68+
<feature name="Diagnostic_Location">
69+
<param name="ios-package" value="Diagnostic_Location" />
70+
<param name="onload" value="true" />
71+
</feature>
72+
</config-file>
73+
74+
<js-module src="www/ios/diagnostic.location.js" name="Diagnostic_Location">
75+
<merges target="com.moodle.moodlemobile.location" />
76+
</js-module>
77+
78+
<header-file src="src/ios/Diagnostic_Location.h" />
79+
<source-file src="src/ios/Diagnostic_Location.m" />
80+
81+
<framework src="CoreLocation.framework" />
82+
83+
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription" comment="Default usage descriptions: override as necessary in .plist">
84+
<string>This app requires access to your location when request location in database activities.</string>
85+
</config-file>
86+
87+
<config-file target="*-Info.plist" parent="NSLocationAlwaysUsageDescription" comment="iOS 10">
88+
<string>This app only require access to your location when request location in database activities, we don't use your location anywhere else.</string>
89+
</config-file>
90+
<!--END_MODULE LOCATION-->
91+
92+
<!--BEGIN_MODULE MICROPHONE-->
93+
<config-file target="config.xml" parent="/*">
94+
<feature name="Diagnostic_Microphone">
95+
<param name="ios-package" value="Diagnostic_Microphone" />
96+
<param name="onload" value="true" />
97+
</feature>
98+
</config-file>
99+
100+
<js-module src="www/ios/diagnostic.js" name="Diagnostic_Microphone">
101+
<merges target="com.moodle.moodlemobile.microphone" />
102+
</js-module>
103+
104+
<framework src="AVFoundation.framework" />
105+
106+
<config-file target="*-Info.plist" parent="NSMicrophoneUsageDescription">
107+
<string>This app requires microphone access to function properly.</string>
108+
</config-file>
109+
110+
<header-file src="src/ios/Diagnostic_Microphone.h" />
111+
<source-file src="src/ios/Diagnostic_Microphone.m" />
112+
<!--END_MODULE MICROPHONE-->
113+
30114
</platform>
31115
</plugin>

cordova-plugin-moodleapp/src/ts/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import { Diagnostic } from './plugins/Diagnostic';
1516
import { InstallReferrer } from './plugins/InstallReferrer';
1617
import { SecureStorage } from './plugins/SecureStorage';
1718

1819
const api: MoodleAppPlugins = {
1920
secureStorage: new SecureStorage(),
2021
installReferrer: new InstallReferrer(),
22+
diagnostic: new Diagnostic(),
2123
};
2224

2325
// This is necessary to work around the default transpilation behavior,
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// (C) Copyright 2015 Moodle Pty Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// (C) Copyright 2015 Moodle Pty Ltd.
15+
//
16+
// Licensed under the Apache License, Version 2.0 (the "License");
17+
// you may not use this file except in compliance with the License.
18+
// You may obtain a copy of the License at
19+
//
20+
// http://www.apache.org/licenses/LICENSE-2.0
21+
//
22+
// Unless required by applicable law or agreed to in writing, software
23+
// distributed under the License is distributed on an "AS IS" BASIS,
24+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
// See the License for the specific language governing permissions and
26+
// limitations under the License.
27+
// (C) Copyright 2015 Moodle Pty Ltd.
28+
//
29+
// Licensed under the Apache License, Version 2.0 (the "License");
30+
// you may not use this file except in compliance with the License.
31+
// You may obtain a copy of the License at
32+
//
33+
// http://www.apache.org/licenses/LICENSE-2.0
34+
//
35+
// Unless required by applicable law or agreed to in writing, software
36+
// distributed under the License is distributed on an "AS IS" BASIS,
37+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38+
// See the License for the specific language governing permissions and
39+
// limitations under the License.
40+
41+
/**
42+
* Checks whether device hardware features are enabled or available to the app, e.g. camera, GPS, wifi
43+
*/
44+
export class Diagnostic {
45+
46+
/**
47+
* Constants for requesting and reporting the various permission states.
48+
*/
49+
declare permissionStatus;
50+
51+
/**
52+
* ANDROID ONLY
53+
* "Dangerous" permissions that need to be requested at run-time (Android 6.0/API 23 and above)
54+
* See http://developer.android.com/guide/topics/security/permissions.html#perm-groups
55+
*
56+
*/
57+
declare permission;
58+
59+
constructor() {
60+
this.permissionStatus = {
61+
// Android only
62+
deniedOnce: 'DENIED_ONCE',
63+
64+
// iOS only
65+
restricted: 'restricted',
66+
ephimeral: 'ephemeral',
67+
provisional: 'provisional',
68+
69+
// Both iOS and Android
70+
granted: 'authorized' || 'GRANTED',
71+
grantedWhenInUse: 'authorized_when_in_use',
72+
notRequested: 'not_determined' || 'NOT_REQUESTED',
73+
deniedAlways: 'denied_always' || 'DENIED_ALWAYS',
74+
};
75+
76+
this.permission = {
77+
acceptHandover: 'ACCEPT_HANDOVER',
78+
accessBackgroundLocation: 'ACCESS_BACKGROUND_LOCATION',
79+
accessCoarseLocation: 'ACCESS_COARSE_LOCATION',
80+
accessFineLocation: 'ACCESS_FINE_LOCATION',
81+
accessMediaLocation: 'ACCESS_MEDIA_LOCATION',
82+
bodySensors: 'BODY_SENSORS',
83+
bodySensorsBackground: 'BODY_SENSORS_BACKGROUND',
84+
getAccounts: 'GET_ACCOUNTS',
85+
readExternalStorage: 'READ_EXTERNAL_STORAGE',
86+
readMediaAudio: 'READ_MEDIA_AUDIO',
87+
readMediaImages: 'READ_MEDIA_IMAGES',
88+
readMediaVideo: 'READ_MEDIA_VIDEO',
89+
readPhoneState: 'READ_PHONE_STATE',
90+
readSms: 'READ_SMS',
91+
receiveMms: 'RECEIVE_MMS',
92+
receiveSms: 'RECEIVE_SMS',
93+
receiveWapPush: 'RECEIVE_WAP_PUSH',
94+
recordAudio: 'RECORD_AUDIO',
95+
sendSms: 'SEND_SMS',
96+
useSip: 'USE_SIP',
97+
uwbRanging: 'UWB_RANGING',
98+
writeExternalStorage: 'WRITE_EXTERNAL_STORAGE',
99+
};
100+
}
101+
102+
isLocationEnabled(): Promise<boolean> {
103+
return new Promise<boolean>((resolve, reject) => cordova.exec(resolve, reject, 'Diagnostic', 'isLocationEnabled'));
104+
}
105+
106+
switchToLocationSettings(): Promise<void> {
107+
return new Promise<void>((resolve, reject) => cordova.exec(resolve, reject, 'Diagnostic', 'switchToLocationSettings'));
108+
}
109+
110+
switchToSettings(): Promise<void> {
111+
return new Promise<void>((resolve, reject) => cordova.exec(resolve, reject, 'Diagnostic', 'switchToSettings'));
112+
}
113+
114+
getLocationAuthorizationStatus(): Promise<unknown> {
115+
return new Promise<unknown>((resolve, reject) =>
116+
cordova.exec(resolve, reject, 'Diagnostic', 'getLocationAuthorizationStatus'));
117+
}
118+
119+
requestLocationAuthorization(): Promise<void> {
120+
return new Promise<void>((resolve, reject) => cordova.exec(resolve, reject, 'Diagnostic', 'requestLocationAuthorization'));
121+
}
122+
123+
requestMicrophoneAuthorization(): Promise<string> {
124+
return new Promise<string>((resolve, reject) =>
125+
cordova.exec(resolve, reject, 'Diagnostic', 'requestMicrophoneAuthorization'));
126+
}
127+
128+
}

cordova-plugin-moodleapp/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
import { InstallReferrer } from '../src/ts/plugins/InstallReferrer';
1616
import { SecureStorage as SecureStorageImpl } from '../src/ts/plugins/SecureStorage';
17+
export { Diagnostic } from '../src/ts/plugins/Diagnostic';
1718

1819
declare global {
1920

2021
interface MoodleAppPlugins {
2122
secureStorage: SecureStorageImpl;
2223
installReferrer: InstallReferrer;
24+
diagnostic: Diagnostic;
2325
}
2426

2527
interface Cordova {

package-lock.json

Lines changed: 0 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"@awesome-cordova-plugins/clipboard": "^6.6.0",
5959
"@awesome-cordova-plugins/core": "^6.6.0",
6060
"@awesome-cordova-plugins/device": "^6.6.0",
61-
"@awesome-cordova-plugins/diagnostic": "^6.6.0",
6261
"@awesome-cordova-plugins/file": "^6.6.0",
6362
"@awesome-cordova-plugins/file-opener": "^6.6.0",
6463
"@awesome-cordova-plugins/geolocation": "^6.6.0",
@@ -114,7 +113,6 @@
114113
"cordova-plugin-wkuserscript": "^1.0.1",
115114
"cordova-plugin-wkwebview-cookies": "^1.0.1",
116115
"cordova-sqlite-storage": "^6.1.0",
117-
"cordova.plugins.diagnostic": "^7.1.4",
118116
"core-js": "^3.9.1",
119117
"es6-promise-plugin": "^4.2.2",
120118
"ionicons": "^7.0.0",
@@ -236,11 +234,6 @@
236234
"cordova-plugin-wkuserscript": {},
237235
"cordova-plugin-wkwebview-cookies": {},
238236
"cordova-sqlite-storage": {},
239-
"cordova.plugins.diagnostic": {
240-
"ANDROID_SUPPORT_VERSION": "28.+",
241-
"ANDROIDX_VERSION": "1.0.0",
242-
"ANDROIDX_APPCOMPAT_VERSION": "1.6.1"
243-
},
244237
"nl.kingsquare.cordova.background-audio": {}
245238
}
246239
}

0 commit comments

Comments
 (0)