diff --git a/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js b/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js index 1850093f0f9060dde2ce28411b680c5eaba63fa6..22980cd79ca501fd8b9b281de2aea2f18b60c82c 100644 --- a/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js +++ b/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js @@ -1,3 +1,18 @@ +/* + Copyright (c) 2022 Huawei Device Co., 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. +*/ + import router from '@ohos.router' var timel = null; @@ -12,7 +27,6 @@ export default { seconds:60, }, onInit() { - console.info('getParams: ' + router.getParams()); callNativeHandler(EVENT_INIT, EVENT_INIT_CODE); }, onShow() { diff --git a/display/entry/src/main/js/default/pages/index/index.js b/display/entry/src/main/js/default/pages/index/index.js index 0304a8d5277a1108e143e24b9af20c91fd2f580f..12ef0837ee7cdf2e9cb72489ca4b3709ede47767 100644 --- a/display/entry/src/main/js/default/pages/index/index.js +++ b/display/entry/src/main/js/default/pages/index/index.js @@ -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; } diff --git a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js index b0405866e1fa6d464fb316930f6688999a28663e..48a242f2dc32917aa39b17556c37cfa62439a60f 100644 --- a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js @@ -1,3 +1,18 @@ +/* + Copyright (c) 2022 Huawei Device Co., 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. +*/ + import router from '@ohos.router'; var numbs = 0; diff --git a/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js index daef5ab44dd70c124f45c4db236a62c3b37cae8f..187dc8d02590c59a4610de15fd3b0c3533500060 100644 --- a/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js @@ -1,3 +1,18 @@ +/* + Copyright (c) 2022 Huawei Device Co., 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. +*/ + import router from '@ohos.router' var EVENT_CONFIRM = "EVENT_CONFIRM"; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 4b814a7a72dff37daaaa7f514780a1f920b47701..0dab46069fff25fee10cc407690aa43acdaea853 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -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 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 callback) = 0; virtual int32_t RegisterDeviceManagerFaCallback(const std::string &pkgName, diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index aee93d643a7538ec58e1c663a6f88df0b0d8edf6..791aab440ac2fc339ee459d123b3ef211ae9a335 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -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 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 callback) override; virtual int32_t RegisterDeviceManagerFaCallback(const std::string &packageName, diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 824231ad17fff20c120f1925c81f299a5a989de1..09dcb1780aef14b891af55e7aa9fb0468b962bfd 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -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 req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); 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; diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 3b0bafce233cd5ce65ee971333eb27b884fa85b9..4010a50f87c473a5db748c363d39a722ed0c3319 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -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(&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); }