mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
add check access camera
This commit is contained in:
@@ -104,7 +104,8 @@ bool AndroidController::initialize()
|
||||
{"onImeInsetsChanged", "(I)V", reinterpret_cast<void *>(onImeInsetsChanged)},
|
||||
{"onSystemBarsInsetsChanged", "(II)V", reinterpret_cast<void *>(onSystemBarsInsetsChanged)},
|
||||
{"onActivityPaused", "()V", reinterpret_cast<void *>(onActivityPaused)},
|
||||
{"onActivityResumed", "()V", reinterpret_cast<void *>(onActivityResumed)}
|
||||
{"onActivityResumed", "()V", reinterpret_cast<void *>(onActivityResumed)},
|
||||
{"onCameraPermissionResult", "(Z)V", reinterpret_cast<void *>(onCameraPermissionResult)}
|
||||
};
|
||||
|
||||
QJniEnvironment env;
|
||||
@@ -202,6 +203,21 @@ bool AndroidController::isCameraPresent()
|
||||
return callActivityMethod<jboolean>("isCameraPresent", "()Z");
|
||||
}
|
||||
|
||||
bool AndroidController::isCameraPermissionGranted()
|
||||
{
|
||||
return callActivityMethod<jboolean>("isCameraPermissionGranted", "()Z");
|
||||
}
|
||||
|
||||
void AndroidController::requestCameraPermissionForQrPairing()
|
||||
{
|
||||
callActivityMethod("requestCameraPermissionForQrPairing", "()V");
|
||||
}
|
||||
|
||||
void AndroidController::openApplicationDetailsSettings()
|
||||
{
|
||||
callActivityMethod("openApplicationDetailsSettings", "()V");
|
||||
}
|
||||
|
||||
bool AndroidController::isOnTv()
|
||||
{
|
||||
return callActivityMethod<jboolean>("isOnTv", "()Z");
|
||||
@@ -583,4 +599,13 @@ void AndroidController::onActivityResumed(JNIEnv *env, jobject thiz)
|
||||
emit AndroidController::instance()->activityResumed();
|
||||
}
|
||||
|
||||
// static
|
||||
void AndroidController::onCameraPermissionResult(JNIEnv *env, jobject thiz, jboolean granted)
|
||||
{
|
||||
Q_UNUSED(env);
|
||||
Q_UNUSED(thiz);
|
||||
|
||||
emit AndroidController::instance()->cameraPermissionResult(static_cast<bool>(granted));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@ public:
|
||||
void closeFd();
|
||||
QString getFileName(const QString &uri);
|
||||
bool isCameraPresent();
|
||||
bool isCameraPermissionGranted();
|
||||
void requestCameraPermissionForQrPairing();
|
||||
void openApplicationDetailsSettings();
|
||||
bool isOnTv();
|
||||
bool isEdgeToEdgeEnabled();
|
||||
int getStatusBarHeight();
|
||||
@@ -77,6 +80,7 @@ signals:
|
||||
void systemBarsInsetsChanged(int navBarHeightDp, int statusBarHeightDp);
|
||||
void activityPaused();
|
||||
void activityResumed();
|
||||
void cameraPermissionResult(bool granted);
|
||||
|
||||
private:
|
||||
bool isWaitingStatus = true;
|
||||
@@ -109,6 +113,7 @@ private:
|
||||
static void onSystemBarsInsetsChanged(JNIEnv *env, jobject thiz, jint navBarHeightDp, jint statusBarHeightDp);
|
||||
static void onActivityPaused(JNIEnv *env, jobject thiz);
|
||||
static void onActivityResumed(JNIEnv *env, jobject thiz);
|
||||
static void onCameraPermissionResult(JNIEnv *env, jobject thiz, jboolean granted);
|
||||
|
||||
template <typename Ret, typename ...Args>
|
||||
static auto callActivityMethod(const char *methodName, const char *signature, Args &&...args);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef IOS_PAIRING_CAMERA_ACCESS_H
|
||||
#define IOS_PAIRING_CAMERA_ACCESS_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
bool amneziaIosPairingCameraAccessGranted();
|
||||
void amneziaIosRequestPairingCameraAccess(const std::function<void(bool)> &onDone);
|
||||
void amneziaIosOpenApplicationSettings();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "platforms/ios/iosPairingCameraAccess.h"
|
||||
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
bool amneziaIosPairingCameraAccessGranted()
|
||||
{
|
||||
const AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||
return status == AVAuthorizationStatusAuthorized;
|
||||
}
|
||||
|
||||
void amneziaIosRequestPairingCameraAccess(const std::function<void(bool)> &onDone)
|
||||
{
|
||||
const AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||
if (status == AVAuthorizationStatusAuthorized) {
|
||||
onDone(true);
|
||||
return;
|
||||
}
|
||||
if (status == AVAuthorizationStatusDenied || status == AVAuthorizationStatusRestricted) {
|
||||
onDone(false);
|
||||
return;
|
||||
}
|
||||
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
|
||||
completionHandler:^(BOOL granted) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
onDone(static_cast<bool>(granted));
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
void amneziaIosOpenApplicationSettings()
|
||||
{
|
||||
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
||||
if (url != nil) {
|
||||
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "platforms/ios/iosPairingCameraAccess.h"
|
||||
|
||||
bool amneziaIosPairingCameraAccessGranted()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void amneziaIosRequestPairingCameraAccess(const std::function<void(bool)> &onDone)
|
||||
{
|
||||
onDone(true);
|
||||
}
|
||||
|
||||
void amneziaIosOpenApplicationSettings() {}
|
||||
Reference in New Issue
Block a user