|
| 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 | +} |
0 commit comments