Skip to content

Commit

Permalink
MOBILE-4501 cordova-plugin-moodleapp: Add diagnostic plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonso-salces committed Feb 12, 2024
1 parent 44a0cea commit ecc0c24
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 73 deletions.
84 changes: 84 additions & 0 deletions cordova-plugin-moodleapp/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,30 @@
<param name="android-package" value="com.moodle.moodlemobile.InstallReferrer"/>
</feature>
</config-file>

<config-file target="res/xml/config.xml" parent="/*">
<feature name="Diagnostic" >
<param name="android-package" value="com.moodle.moodlemobile.Diagnostic"/>
<param name="onload" value="true" />
</feature>
</config-file>

<js-module name="Diagnostic" src="www/android/diagnostic.js">
<merges target="com.moodle.moodlemobile.diagnostic" />
</js-module>

<source-file src="src/android/Diagnostic.java" target-dir="src/cordova/plugins" />
<source-file src="src/android/Diagnostic_Location.java" target-dir="src/cordova/plugins" />

<preference name="ANDROIDX_VERSION" default="1.0.0" />
<preference name="ANDROIDX_APPCOMPAT_VERSION" default="1.3.1" />
<framework src="androidx.legacy:legacy-support-v4:$ANDROIDX_VERSION" />
<framework src="androidx.appcompat:appcompat:$ANDROIDX_APPCOMPAT_VERSION" />

<source-file src="src/android/SecureStorage.java" target-dir="src/com/moodle/moodlemobile" />
<source-file src="src/android/InstallReferrer.java" target-dir="src/com/moodle/moodlemobile" />
</platform>

<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="SecureStorage">
Expand All @@ -27,5 +48,68 @@

<header-file src="src/ios/SecureStorage.h" />
<source-file src="src/ios/SecureStorage.m" />

<config-file target="config.xml" parent="/*">
<feature name="Diagnostic">
<param name="ios-package" value="Diagnostic" />
<param name="onload" value="true" />
</feature>
</config-file>

<js-module src="www/ios/diagnostic.js" name="Diagnostic">
<merges target="com.moodle.moodlemobile.diagnostic" />
</js-module>

<header-file src="src/ios/Diagnostic.h" />
<source-file src="src/ios/Diagnostic.m" />

<!--BEGIN_MODULE LOCATION-->
<config-file target="config.xml" parent="/*">
<feature name="Diagnostic_Location">
<param name="ios-package" value="Diagnostic_Location" />
<param name="onload" value="true" />
</feature>
</config-file>

<js-module src="www/ios/diagnostic.location.js" name="Diagnostic_Location">
<merges target="com.moodle.moodlemobile.location" />
</js-module>

<header-file src="src/ios/Diagnostic_Location.h" />
<source-file src="src/ios/Diagnostic_Location.m" />

<framework src="CoreLocation.framework" />

<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription" comment="Default usage descriptions: override as necessary in .plist">
<string>This app requires access to your location when request location in database activities.</string>
</config-file>

<config-file target="*-Info.plist" parent="NSLocationAlwaysUsageDescription" comment="iOS 10">
<string>This app only require access to your location when request location in database activities, we don't use your location anywhere else.</string>
</config-file>
<!--END_MODULE LOCATION-->

<!--BEGIN_MODULE MICROPHONE-->
<config-file target="config.xml" parent="/*">
<feature name="Diagnostic_Microphone">
<param name="ios-package" value="Diagnostic_Microphone" />
<param name="onload" value="true" />
</feature>
</config-file>

<js-module src="www/ios/diagnostic.js" name="Diagnostic_Microphone">
<merges target="com.moodle.moodlemobile.microphone" />
</js-module>

<framework src="AVFoundation.framework" />

<config-file target="*-Info.plist" parent="NSMicrophoneUsageDescription">
<string>This app requires microphone access to function properly.</string>
</config-file>

<header-file src="src/ios/Diagnostic_Microphone.h" />
<source-file src="src/ios/Diagnostic_Microphone.m" />
<!--END_MODULE MICROPHONE-->

</platform>
</plugin>
2 changes: 2 additions & 0 deletions cordova-plugin-moodleapp/src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { Diagnostic } from './plugins/Diagnostic';
import { InstallReferrer } from './plugins/InstallReferrer';
import { SecureStorage } from './plugins/SecureStorage';

const api: MoodleAppPlugins = {
secureStorage: new SecureStorage(),
installReferrer: new InstallReferrer(),
diagnostic: new Diagnostic(),
};

// This is necessary to work around the default transpilation behavior,
Expand Down
128 changes: 128 additions & 0 deletions cordova-plugin-moodleapp/src/ts/plugins/Diagnostic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Checks whether device hardware features are enabled or available to the app, e.g. camera, GPS, wifi
*/
export class Diagnostic {

/**
* Constants for requesting and reporting the various permission states.
*/
declare permissionStatus;

/**
* ANDROID ONLY
* "Dangerous" permissions that need to be requested at run-time (Android 6.0/API 23 and above)
* See http://developer.android.com/guide/topics/security/permissions.html#perm-groups
*
*/
declare permission;

constructor() {
this.permissionStatus = {
// Android only
deniedOnce: 'DENIED_ONCE',

// iOS only
restricted: 'restricted',
ephimeral: 'ephemeral',
provisional: 'provisional',

// Both iOS and Android
granted: 'authorized' || 'GRANTED',
grantedWhenInUse: 'authorized_when_in_use',
notRequested: 'not_determined' || 'NOT_REQUESTED',
deniedAlways: 'denied_always' || 'DENIED_ALWAYS',
};

this.permission = {
acceptHandover: 'ACCEPT_HANDOVER',
accessBackgroundLocation: 'ACCESS_BACKGROUND_LOCATION',
accessCoarseLocation: 'ACCESS_COARSE_LOCATION',
accessFineLocation: 'ACCESS_FINE_LOCATION',
accessMediaLocation: 'ACCESS_MEDIA_LOCATION',
bodySensors: 'BODY_SENSORS',
bodySensorsBackground: 'BODY_SENSORS_BACKGROUND',
getAccounts: 'GET_ACCOUNTS',
readExternalStorage: 'READ_EXTERNAL_STORAGE',
readMediaAudio: 'READ_MEDIA_AUDIO',
readMediaImages: 'READ_MEDIA_IMAGES',
readMediaVideo: 'READ_MEDIA_VIDEO',
readPhoneState: 'READ_PHONE_STATE',
readSms: 'READ_SMS',
receiveMms: 'RECEIVE_MMS',
receiveSms: 'RECEIVE_SMS',
receiveWapPush: 'RECEIVE_WAP_PUSH',
recordAudio: 'RECORD_AUDIO',
sendSms: 'SEND_SMS',
useSip: 'USE_SIP',
uwbRanging: 'UWB_RANGING',
writeExternalStorage: 'WRITE_EXTERNAL_STORAGE',
};
}

isLocationEnabled(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => cordova.exec(resolve, reject, 'Diagnostic', 'isLocationEnabled'));
}

switchToLocationSettings(): Promise<void> {
return new Promise<void>((resolve, reject) => cordova.exec(resolve, reject, 'Diagnostic', 'switchToLocationSettings'));
}

switchToSettings(): Promise<void> {
return new Promise<void>((resolve, reject) => cordova.exec(resolve, reject, 'Diagnostic', 'switchToSettings'));
}

getLocationAuthorizationStatus(): Promise<unknown> {
return new Promise<unknown>((resolve, reject) =>
cordova.exec(resolve, reject, 'Diagnostic', 'getLocationAuthorizationStatus'));
}

requestLocationAuthorization(): Promise<void> {
return new Promise<void>((resolve, reject) => cordova.exec(resolve, reject, 'Diagnostic', 'requestLocationAuthorization'));
}

requestMicrophoneAuthorization(): Promise<string> {
return new Promise<string>((resolve, reject) =>
cordova.exec(resolve, reject, 'Diagnostic', 'requestMicrophoneAuthorization'));
}

}
2 changes: 2 additions & 0 deletions cordova-plugin-moodleapp/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

import { InstallReferrer } from '../src/ts/plugins/InstallReferrer';
import { SecureStorage as SecureStorageImpl } from '../src/ts/plugins/SecureStorage';
export { Diagnostic } from '../src/ts/plugins/Diagnostic';

declare global {

interface MoodleAppPlugins {
secureStorage: SecureStorageImpl;
installReferrer: InstallReferrer;
diagnostic: Diagnostic;
}

interface Cordova {
Expand Down
39 changes: 0 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@awesome-cordova-plugins/clipboard": "^6.6.0",
"@awesome-cordova-plugins/core": "^6.6.0",
"@awesome-cordova-plugins/device": "^6.6.0",
"@awesome-cordova-plugins/diagnostic": "^6.6.0",
"@awesome-cordova-plugins/file": "^6.6.0",
"@awesome-cordova-plugins/file-opener": "^6.6.0",
"@awesome-cordova-plugins/geolocation": "^6.6.0",
Expand Down Expand Up @@ -114,7 +113,6 @@
"cordova-plugin-wkuserscript": "^1.0.1",
"cordova-plugin-wkwebview-cookies": "^1.0.1",
"cordova-sqlite-storage": "^6.1.0",
"cordova.plugins.diagnostic": "^7.1.4",
"core-js": "^3.9.1",
"es6-promise-plugin": "^4.2.2",
"ionicons": "^7.0.0",
Expand Down Expand Up @@ -236,11 +234,6 @@
"cordova-plugin-wkuserscript": {},
"cordova-plugin-wkwebview-cookies": {},
"cordova-sqlite-storage": {},
"cordova.plugins.diagnostic": {
"ANDROID_SUPPORT_VERSION": "28.+",
"ANDROIDX_VERSION": "1.0.0",
"ANDROIDX_APPCOMPAT_VERSION": "1.6.1"
},
"nl.kingsquare.cordova.background-audio": {}
}
}
Expand Down
Loading

0 comments on commit ecc0c24

Please sign in to comment.