mirror of
https://github.com/openharmony/device_manager.git
synced 2026-07-20 21:58:27 -04:00
@@ -12,7 +12,6 @@ export default {
|
||||
seconds:60,
|
||||
},
|
||||
onInit() {
|
||||
console.info('getParams: ' + router.getParams());
|
||||
callNativeHandler(EVENT_INIT, EVENT_INIT_CODE);
|
||||
},
|
||||
onShow() {
|
||||
|
||||
@@ -17,11 +17,14 @@ import router from '@system.router';
|
||||
import deviceManager from '@ohos.distributedHardware.deviceManager';
|
||||
function uint8ArrayToBase64(array) {
|
||||
array = new Uint8Array(array);
|
||||
let table = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'],
|
||||
let table = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y',
|
||||
'Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x',
|
||||
'y','z','0','1','2','3','4','5','6','7','8','9','+','/'],
|
||||
base64Str = '', length = array.byteLength, i = 0;
|
||||
for(i = 0; length - i >= 3; i += 3) {
|
||||
let num1 = array[i], num2 = array[i + 1], num3 = array[i + 2];
|
||||
base64Str += table[num1 >>> 2] + table[((num1 & 0b11) << 4) | (num2 >>> 4)] + table[((num2 & 0b1111) << 2) | (num3 >>> 6)] + table[num3 & 0b111111];
|
||||
base64Str += table[num1 >>> 2] + table[((num1 & 0b11) << 4) | (num2 >>> 4)] + table[((num2 & 0b1111) << 2) |
|
||||
(num3 >>> 6)] + table[num3 & 0b111111];
|
||||
}
|
||||
const lastByte = length - i;
|
||||
if (lastByte === 1) {
|
||||
@@ -30,7 +33,8 @@ function uint8ArrayToBase64(array) {
|
||||
} else if (lastByte === 2) {
|
||||
const lastNum1 = array[i];
|
||||
const lastNum2 = array[i + 1];
|
||||
base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4) | (lastNum2 >>> 4)] + table[(lastNum2 & 0b1111) << 2] + '=';
|
||||
base64Str += table[lastNum1 >>> 2] + table[((lastNum1 & 0b11) << 4) | (lastNum2 >>> 4)] +
|
||||
table[(lastNum2 & 0b1111) << 2] + '=';
|
||||
}
|
||||
return 'data:image/png;base64,' + base64Str;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
virtual int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) = 0;
|
||||
virtual int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo,
|
||||
const std::string &extra, std::shared_ptr<AuthenticateCallback> callback) = 0;
|
||||
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) = 0;
|
||||
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo) = 0;
|
||||
virtual int32_t VerifyAuthentication(const std::string &pkgName, const std::string &authPara,
|
||||
std::shared_ptr<VerifyAuthCallback> callback) = 0;
|
||||
virtual int32_t RegisterDeviceManagerFaCallback(const std::string &pkgName,
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
virtual int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo,
|
||||
const std::string &extra,
|
||||
std::shared_ptr<AuthenticateCallback> callback) override;
|
||||
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) override;
|
||||
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo) override;
|
||||
virtual int32_t VerifyAuthentication(const std::string &pkgName, const std::string &authPara,
|
||||
std::shared_ptr<VerifyAuthCallback> callback) override;
|
||||
virtual int32_t RegisterDeviceManagerFaCallback(const std::string &packageName,
|
||||
|
||||
@@ -275,26 +275,20 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId)
|
||||
int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
|
||||
{
|
||||
LOGI("DeviceManager::UnAuthenticateDevice start , pkgName: %s, deviceId: %s", pkgName.c_str(), deviceId.c_str());
|
||||
LOGI("DeviceManager::UnAuthenticateDevice start , pkgName: %s, deviceId: %s", pkgName.c_str(), deviceInfo.deviceId);
|
||||
|
||||
if (deviceId.empty()) {
|
||||
if (pkgName.empty() || (deviceInfo.deviceId[0] == '\0')) {
|
||||
LOGE("UnAuthenticateDevice error: Invalid para");
|
||||
return DM_INVALID_VALUE;
|
||||
}
|
||||
|
||||
DmDeviceInfo deviceInfo;
|
||||
int32_t ret = strcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, deviceId.c_str());
|
||||
if (ret != DM_OK) {
|
||||
LOGE("UnAuthenticateDevice error: copy deviceId failed");
|
||||
return DM_INVALID_VALUE;
|
||||
}
|
||||
std::shared_ptr<IpcUnAuthenticateDeviceReq> req = std::make_shared<IpcUnAuthenticateDeviceReq>();
|
||||
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
|
||||
req->SetPkgName(pkgName);
|
||||
req->SetDeviceInfo(deviceInfo);
|
||||
ret = ipcClientProxy_->SendRequest(UNAUTHENTICATE_DEVICE, req, rsp);
|
||||
int32_t ret = ipcClientProxy_->SendRequest(UNAUTHENTICATE_DEVICE, req, rsp);
|
||||
if (ret != DM_OK) {
|
||||
LOGE("UnAuthenticateDevice error: Send Request failed ret: %d", ret);
|
||||
return DM_IPC_SEND_REQUEST_FAILED;
|
||||
|
||||
@@ -1539,15 +1539,17 @@ napi_value DeviceManagerNapi::UnAuthenticateDevice(napi_env env, napi_callback_i
|
||||
{
|
||||
LOGI("UnAuthenticateDevice");
|
||||
napi_value result = nullptr;
|
||||
napi_valuetype deviceInfoType;
|
||||
GET_PARAMS(env, info, DM_NAPI_ARGS_TWO);
|
||||
napi_valuetype deviceInfoType = napi_undefined;
|
||||
napi_typeof(env, argv[0], &deviceInfoType);
|
||||
NAPI_ASSERT(env, deviceInfoType == napi_string, "Wrong argument type. String expected.");
|
||||
std::string deviceId = JsObjectToString(env, argv[0]);
|
||||
LOGI("UnAuthenticateDevice deviceId=%s", deviceId.c_str());
|
||||
NAPI_ASSERT(env, deviceInfoType == napi_object, "Wrong argument type. Object expected.");
|
||||
|
||||
DmDeviceInfo deviceInfo;
|
||||
JsToDmDeviceInfo(env, argv[0], deviceInfo);
|
||||
LOGI("UnAuthenticateDevice deviceId = %s", deviceInfo.deviceId);
|
||||
DeviceManagerNapi *deviceManagerWrapper = nullptr;
|
||||
napi_unwrap(env, thisVar, reinterpret_cast<void **>(&deviceManagerWrapper));
|
||||
int32_t ret = DeviceManager::GetInstance().UnAuthenticateDevice(deviceManagerWrapper->bundleName_, deviceId);
|
||||
int32_t ret = DeviceManager::GetInstance().UnAuthenticateDevice(deviceManagerWrapper->bundleName_, deviceInfo);
|
||||
if (ret != 0) {
|
||||
LOGE("UnAuthenticateDevice for bunderName %s failed, ret %d", deviceManagerWrapper->bundleName_.c_str(), ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user