|
|
|
|
@ -13,22 +13,25 @@ import { OpenNativeSettings } from '@ionic-native/open-native-settings/ngx';
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class DevicePermissionsService {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
public diagnostic: Diagnostic,
|
|
|
|
|
public cs: CommonService,
|
|
|
|
|
public nativeStorage: NativeStorage,
|
|
|
|
|
public ts: TranslatorService,
|
|
|
|
|
public nativeSettings: OpenNativeSettings) { }
|
|
|
|
|
public static GRANTED = 'GRANTED';
|
|
|
|
|
public static DENIED_ALWAYS = 'DENIED_ALWAYS';
|
|
|
|
|
|
|
|
|
|
public static CAMERA_MIC = 'camera_mic_permission';
|
|
|
|
|
public static LOCATION = 'location_permission';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static APP_SETTINGS = 'application_details';
|
|
|
|
|
|
|
|
|
|
public onSucess;
|
|
|
|
|
public onerror;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
public diagnostic: Diagnostic,
|
|
|
|
|
public cs: CommonService,
|
|
|
|
|
public nativeStorage: NativeStorage,
|
|
|
|
|
public ts: TranslatorService,
|
|
|
|
|
public nativeSettings: OpenNativeSettings) { }
|
|
|
|
|
|
|
|
|
|
public requestCameraPermission(): Observable<boolean> {
|
|
|
|
|
|
|
|
|
|
return Observable.create(observer => {
|
|
|
|
|
@ -37,16 +40,17 @@ export class DevicePermissionsService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private requestCamera(observer: any) {
|
|
|
|
|
//console.log("Camera permission????????")
|
|
|
|
|
this.hasCameraPermission().then((isAvailable) => {
|
|
|
|
|
if (isAvailable) {
|
|
|
|
|
// this.requestMicophonePermission(observer);
|
|
|
|
|
this.observerDone(observer, true);
|
|
|
|
|
} else {
|
|
|
|
|
this.diagnostic.requestCameraAuthorization(true).then((value) => {
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
if (value == DevicePermissionsService.GRANTED) {
|
|
|
|
|
//this.requestMicophonePermission(observer);
|
|
|
|
|
// this.requestMicophonePermission(observer);
|
|
|
|
|
this.observerDone(observer, true);
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
} else if (value == DevicePermissionsService.DENIED_ALWAYS) {
|
|
|
|
|
// this.setAlwaysDenied(DevicePermissionsService.CAMERA_MIC, true);
|
|
|
|
|
this.observerDone(observer, false);
|
|
|
|
|
@ -77,8 +81,10 @@ export class DevicePermissionsService {
|
|
|
|
|
this.observerDone(observer, true);
|
|
|
|
|
} else {
|
|
|
|
|
this.diagnostic.requestMicrophoneAuthorization().then((value) => {
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
if (value == DevicePermissionsService.GRANTED) {
|
|
|
|
|
this.observerDone(observer, true);
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
} else if (value == DevicePermissionsService.DENIED_ALWAYS) {
|
|
|
|
|
this.setAlwaysDenied(DevicePermissionsService.CAMERA_MIC, true);
|
|
|
|
|
this.observerDone(observer, false);
|
|
|
|
|
@ -112,8 +118,8 @@ export class DevicePermissionsService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async hasCameraAndMicPermissions(): Promise<boolean> {
|
|
|
|
|
let camera = await this.hasCameraPermission();
|
|
|
|
|
//let mic = await this.diagnostic.isMicrophoneAuthorized();
|
|
|
|
|
const camera = await this.hasCameraPermission();
|
|
|
|
|
// let mic = await this.diagnostic.isMicrophoneAuthorized();
|
|
|
|
|
if (camera) {
|
|
|
|
|
// await this.setAlwaysDenied(DevicePermissionsService.CAMERA_MIC, false);
|
|
|
|
|
return true;
|
|
|
|
|
@ -128,7 +134,7 @@ export class DevicePermissionsService {
|
|
|
|
|
resolve(true);
|
|
|
|
|
}, this.ts.trPK('general', 'accept'),
|
|
|
|
|
() => {
|
|
|
|
|
resolve(false)
|
|
|
|
|
resolve(false);
|
|
|
|
|
}, this.ts.trPK('general', 'not-now'), this.ts.trPK('general', 'confirm'), message
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
@ -140,15 +146,12 @@ export class DevicePermissionsService {
|
|
|
|
|
resolve(true);
|
|
|
|
|
}, this.ts.trPK('general', 'settings'),
|
|
|
|
|
() => {
|
|
|
|
|
resolve(false)
|
|
|
|
|
resolve(false);
|
|
|
|
|
}, this.ts.trPK('general', 'not-now'), this.ts.trPK('general', 'confirm'), message
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static APP_SETTINGS = 'application_details';
|
|
|
|
|
|
|
|
|
|
public async openApplicationSettings() {
|
|
|
|
|
// return new Promise((resolver, reject) => {
|
|
|
|
|
// this.nativeSettings.open(DevicePermissionsService.APP_SETTINGS).then(result => {
|
|
|
|
|
@ -208,13 +211,13 @@ export class DevicePermissionsService {
|
|
|
|
|
if (await this.hasCameraAndMicPermissions()) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
let message = this.ts.trPK('permissions', 'camera');
|
|
|
|
|
const message = this.ts.trPK('permissions', 'camera');
|
|
|
|
|
// if (await this.isPermissionAlwaysDenied(DevicePermissionsService.CAMERA_MIC)) {
|
|
|
|
|
// if (await this.permissionSettingsDialog(message)) {
|
|
|
|
|
// return this.openCameraAndMicSettings();
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
if (await this.permissionRequestDialog(message)) {
|
|
|
|
|
if (await this.permissionRequestDialog(message)) {
|
|
|
|
|
return this.requestCameraPermission().toPromise();
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
@ -227,17 +230,16 @@ export class DevicePermissionsService {
|
|
|
|
|
|
|
|
|
|
public async requestLocationAutherization() {
|
|
|
|
|
if ( await this.isLocationEnabled()) {
|
|
|
|
|
|
|
|
|
|
if (await this.hasLocationPermissions()) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
let message = this.ts.trPK('permissions', 'location');
|
|
|
|
|
const message = this.ts.trPK('permissions', 'location');
|
|
|
|
|
// if (await this.isPermissionAlwaysDenied(DevicePermissionsService.LOCATION)) {
|
|
|
|
|
// if (await this.permissionSettingsDialog(message)) {
|
|
|
|
|
// return this.openLocationSettings();
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
if (await this.permissionRequestDialog(message)) {
|
|
|
|
|
if (await this.permissionRequestDialog(message)) {
|
|
|
|
|
return this.requestLocationPermission();
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
@ -249,7 +251,7 @@ export class DevicePermissionsService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async isLocationEnabled() {
|
|
|
|
|
let isAvailable = await this.diagnostic.isLocationEnabled();
|
|
|
|
|
const isAvailable = await this.diagnostic.isLocationEnabled();
|
|
|
|
|
if (!isAvailable) {
|
|
|
|
|
this.cs.presentAlert(this.ts.trPK('permissions', 'enable-location'), () => {
|
|
|
|
|
});
|
|
|
|
|
@ -258,7 +260,7 @@ export class DevicePermissionsService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async hasLocationPermissions(): Promise<boolean> {
|
|
|
|
|
let location = await this.diagnostic.isLocationAvailable();
|
|
|
|
|
const location = await this.diagnostic.isLocationAvailable();
|
|
|
|
|
if (location) {
|
|
|
|
|
await this.setAlwaysDenied(DevicePermissionsService.LOCATION, false);
|
|
|
|
|
return true;
|
|
|
|
|
@ -280,12 +282,14 @@ export class DevicePermissionsService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async requestLocationPermission() {
|
|
|
|
|
let hasPermissions = await this.hasLocationPermissions();
|
|
|
|
|
const hasPermissions = await this.hasLocationPermissions();
|
|
|
|
|
if (!hasPermissions) {
|
|
|
|
|
|
|
|
|
|
let value = await this.diagnostic.requestLocationAuthorization();
|
|
|
|
|
const value = await this.diagnostic.requestLocationAuthorization();
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
if (value == DevicePermissionsService.GRANTED) {
|
|
|
|
|
return true;
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
} else if (value == DevicePermissionsService.DENIED_ALWAYS) {
|
|
|
|
|
this.setAlwaysDenied(DevicePermissionsService.LOCATION, true);
|
|
|
|
|
}
|
|
|
|
|
|