diff --git a/BUILD.gn b/BUILD.gn index c79f253a8d19cad570c3801947aa15b2ce8864be..c4157ed289ae79b9c8571e622e72bd9d3739b8ea 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("tel_state_registry") { external_deps = [ "ability_base:want", + "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "core_service:libtel_common", diff --git a/bundle.json b/bundle.json index 8300a95adbc791d8083a743340ce3b8db77f4b4f..5b886b64ac94c8f95fcc789046468f42e6c3980e 100755 --- a/bundle.json +++ b/bundle.json @@ -31,6 +31,7 @@ "deps": { "components": [ "ability_base", + "access_token", "c_utils", "common_event_service", "core_service", diff --git a/services/include/telephony_state_registry_service.h b/services/include/telephony_state_registry_service.h index 36a1b26aaff04ff06818a398b1b0d7aca1a7d3cc..f3f15627c25f652549cdc4b90e30c2a65d1f3000 100644 --- a/services/include/telephony_state_registry_service.h +++ b/services/include/telephony_state_registry_service.h @@ -79,7 +79,8 @@ private: bool VerifySlotId(int32_t slotId); std::u16string GetCallIncomingNumberForSlotId(TelephonyStateRegistryRecord record, int32_t slotId); bool PublishCommonEvent(const AAFwk::Want &want, int32_t eventCode, const std::string &eventData); - void SendCallStateChanged(int32_t slotId, int32_t state, const std::u16string &number); + void SendCallStateChanged(int32_t slotId, int32_t state); + void SendCallStateChangedAsUserMultiplePermission(int32_t slotId, int32_t state, const std::u16string &number); void SendSignalInfoChanged(int32_t slotId, const std::vector> &vec); void SendNetworkStateChanged(int32_t slotId, const sptr &networkState); void SendSimStateChanged(int32_t slotId, CardType type, SimState state, LockReason reason); diff --git a/services/src/telephony_state_registry_record.cpp b/services/src/telephony_state_registry_record.cpp index 056715f5e55bb1dcbe2f32b3eecfb1ae1b3b9b11..14c41cbfdf0f71b823e729bcc2094f570e764e3e 100644 --- a/services/src/telephony_state_registry_record.cpp +++ b/services/src/telephony_state_registry_record.cpp @@ -17,12 +17,15 @@ #include "telephony_permission.h" #include "telephony_log_wrapper.h" +#include "accesstoken_kit.h" +#include "access_token.h" namespace OHOS { namespace Telephony { +using namespace OHOS::Security::AccessToken; bool TelephonyStateRegistryRecord::IsCanReadCallHistory() { - if (!TelephonyPermission::CheckPermission(Permission::READ_CALL_LOG)) { + if (AccessTokenKit::VerifyAccessToken(tokenId_, Permission::READ_CALL_LOG) == PERMISSION_DENIED) { return false; } return true; diff --git a/services/src/telephony_state_registry_service.cpp b/services/src/telephony_state_registry_service.cpp index 443a97121917b71013ec086876e6be1bd0a6850a..25c2585a00ee4bc9bf1ed931ff7d5701a0e916d2 100644 --- a/services/src/telephony_state_registry_service.cpp +++ b/services/src/telephony_state_registry_service.cpp @@ -88,7 +88,7 @@ void TelephonyStateRegistryService::OnStart() if (IsCommonEventServiceAbilityExist()) { for (int32_t i = 0; i < slotSize_; i++) { TELEPHONY_LOGI("TelephonyStateRegistryService send disconnected call state."); - SendCallStateChanged(i, static_cast(CallStatus::CALL_STATUS_DISCONNECTED), u""); + SendCallStateChanged(i, static_cast(CallStatus::CALL_STATUS_DISCONNECTED)); } } }); @@ -192,7 +192,8 @@ int32_t TelephonyStateRegistryService::UpdateCallState(int32_t callState, const result = TELEPHONY_SUCCESS; } } - SendCallStateChanged(-1, callState, number); + SendCallStateChanged(-1, callState); + SendCallStateChangedAsUserMultiplePermission(-1, callState, number); return result; } @@ -220,7 +221,8 @@ int32_t TelephonyStateRegistryService::UpdateCallStateForSlotId( result = TELEPHONY_SUCCESS; } } - SendCallStateChanged(slotId, callState, number); + SendCallStateChanged(slotId, callState); + SendCallStateChangedAsUserMultiplePermission(slotId, callState, number); return result; } @@ -605,12 +607,11 @@ bool TelephonyStateRegistryService::PublishCommonEvent( return publishResult; } -void TelephonyStateRegistryService::SendCallStateChanged(int32_t slotId, int32_t state, const std::u16string &number) +void TelephonyStateRegistryService::SendCallStateChanged(int32_t slotId, int32_t state) { AAFwk::Want want; want.SetParam("slotId", slotId); want.SetParam("state", state); - want.SetParam("number", Str16ToStr8(number)); want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); EventFwk::CommonEventData data; @@ -626,6 +627,29 @@ void TelephonyStateRegistryService::SendCallStateChanged(int32_t slotId, int32_t } } +void TelephonyStateRegistryService::SendCallStateChangedAsUserMultiplePermission( + int32_t slotId, int32_t state, const std::u16string &number) +{ + AAFwk::Want want; + want.SetParam("slotId", slotId); + want.SetParam("state", state); + want.SetParam("number", Str16ToStr8(number)); + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + + EventFwk::CommonEventData data; + data.SetWant(want); + EventFwk::CommonEventPublishInfo publishInfo; + publishInfo.SetOrdered(false); + std::vector callPermissions; + callPermissions.emplace_back(Permission::GET_TELEPHONY_STATE); + callPermissions.emplace_back(Permission::READ_CALL_LOG); + publishInfo.SetSubscriberPermissions(callPermissions); + bool publishResult = EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr); + if (!publishResult) { + TELEPHONY_LOGE("SendCallStateChangedAsUserMultiplePermission PublishBroadcastEvent result fail"); + } +} + void TelephonyStateRegistryService::SendCellularDataConnectStateChanged( int32_t slotId, int32_t dataState, int32_t networkType) { diff --git a/test/unittest/state_test/state_registry_test.cpp b/test/unittest/state_test/state_registry_test.cpp index d67f3b747d5b03af788edf6ce9bc2837229059b6..10e3a0015c3257a2d880007ae6de0ba0d9d1ca60 100644 --- a/test/unittest/state_test/state_registry_test.cpp +++ b/test/unittest/state_test/state_registry_test.cpp @@ -937,7 +937,8 @@ HWTEST_F(StateRegistryTest, TelephonyStateRegistryServiceTest_002, Function | Me vec.push_back(std::make_unique().release()); service->SendSignalInfoChanged(0, vec); std::u16string number = u"123456"; - service->SendCallStateChanged(0, 0, number); + service->SendCallStateChanged(0, 0); + service->SendCallStateChangedAsUserMultiplePermission(0, 0, number); TelephonyStateRegistryRecord record; service->UpdateData(record); record.telephonyObserver_ = std::make_unique().release();