mirror of
https://github.com/openharmony/miscservices_time.git
synced 2026-07-18 17:34:34 -04:00
@@ -168,7 +168,7 @@ public:
|
||||
* @param isProxy true if set proxy, false if remove proxy.
|
||||
* @return bool true on success, false on failure.
|
||||
*/
|
||||
bool ProxyTimer(int32_t uid, bool isProxy);
|
||||
bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger);
|
||||
|
||||
/**
|
||||
* ResetAllProxy
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
bool DestroyTimer(uint64_t timerId) override;
|
||||
void NetworkTimeStatusOff() override;
|
||||
void NetworkTimeStatusOn() override;
|
||||
bool ProxyTimer(int32_t uid, bool isProxy) override;
|
||||
bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) override;
|
||||
bool ResetAllProxy() override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -186,7 +186,7 @@ public:
|
||||
* @param isProxy true if proxy, false if not proxy
|
||||
* @return bool true on success, false on failure.
|
||||
*/
|
||||
virtual bool ProxyTimer(int32_t uid, bool isProxy) = 0;
|
||||
virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0;
|
||||
|
||||
/**
|
||||
* ResetAllProxy
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
bool DestroyTimer(uint64_t timerId) override;
|
||||
void NetworkTimeStatusOff() override;
|
||||
void NetworkTimeStatusOn() override;
|
||||
bool ProxyTimer(int32_t uid, bool isProxy) override;
|
||||
bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) override;
|
||||
bool ResetAllProxy() override;
|
||||
private:
|
||||
static inline BrokerDelegator<TimeServiceProxy> delegator_;
|
||||
|
||||
@@ -580,7 +580,7 @@ void TimeService::NetworkTimeStatusOn()
|
||||
DelayedSingleton<NtpUpdateTime>::GetInstance()->UpdateStatusOn();
|
||||
}
|
||||
|
||||
bool TimeService::ProxyTimer(int32_t uid, bool isProxy)
|
||||
bool TimeService::ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger)
|
||||
{
|
||||
auto hasPerm = DelayedSingleton<TimePermission>::GetInstance()->CheckProxyCallingPermission();
|
||||
if (!hasPerm) {
|
||||
@@ -597,7 +597,7 @@ bool TimeService::ProxyTimer(int32_t uid, bool isProxy)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return timerManagerHandler_->ProxyTimer(uid, isProxy);
|
||||
return timerManagerHandler_->ProxyTimer(uid, isProxy, needRetrigger);
|
||||
}
|
||||
|
||||
bool TimeService::ResetAllProxy()
|
||||
|
||||
@@ -435,7 +435,7 @@ void TimeSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
TimeServiceClient::GetInstance()->OnRemoteSaDied(object);
|
||||
}
|
||||
|
||||
bool TimeServiceClient::ProxyTimer(int32_t uid, bool isProxy)
|
||||
bool TimeServiceClient::ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger)
|
||||
{
|
||||
TIME_HILOGD(TIME_MODULE_CLIENT, "ProxyTimer start uid: %{public}d, isProxy: %{public}d",
|
||||
uid, isProxy);
|
||||
@@ -447,7 +447,7 @@ bool TimeServiceClient::ProxyTimer(int32_t uid, bool isProxy)
|
||||
TIME_HILOGE(TIME_MODULE_CLIENT, "ProxyTimer ConnectService failed.");
|
||||
return false;
|
||||
}
|
||||
return timeServiceProxy_->ProxyTimer(uid, isProxy);
|
||||
return timeServiceProxy_->ProxyTimer(uid, isProxy, needRetrigger);
|
||||
}
|
||||
|
||||
bool TimeServiceClient::ResetAllProxy()
|
||||
|
||||
@@ -390,7 +390,7 @@ void TimeServiceProxy::NetworkTimeStatusOff()
|
||||
return;
|
||||
}
|
||||
|
||||
bool TimeServiceProxy::ProxyTimer(int32_t uid, bool isProxy)
|
||||
bool TimeServiceProxy::ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
@@ -407,6 +407,10 @@ bool TimeServiceProxy::ProxyTimer(int32_t uid, bool isProxy)
|
||||
TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write parcelable");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteBool(needRetrigger)) {
|
||||
TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write parcelable");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(PROXY_TIMER, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
|
||||
@@ -317,7 +317,8 @@ int32_t TimeServiceStub::OnTimerProxy(MessageParcel &data, MessageParcel &reply)
|
||||
return E_TIME_READ_PARCEL_ERROR;
|
||||
}
|
||||
auto isProxy = data.ReadBool();
|
||||
if (!ProxyTimer(uid, isProxy)) {
|
||||
auto needRetrigger = data.ReadBool();
|
||||
if (!ProxyTimer(uid, isProxy, needRetrigger)) {
|
||||
return E_TIME_DEAL_FAILED;
|
||||
}
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "end.");
|
||||
|
||||
@@ -317,9 +317,9 @@ HWTEST_F(TimeServiceTest, CreateTimer006, TestSize.Level0)
|
||||
HWTEST_F(TimeServiceTest, ProxyTimer001, TestSize.Level0)
|
||||
{
|
||||
int32_t uid = 99999;
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true);
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true, true);
|
||||
EXPECT_TRUE(ret);
|
||||
ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false);
|
||||
ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false, true);
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ HWTEST_F(TimeServiceTest, ProxyTimer001, TestSize.Level0)
|
||||
HWTEST_F(TimeServiceTest, ProxyTimer002, TestSize.Level0)
|
||||
{
|
||||
int32_t uid = 99999;
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true);
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true, true);
|
||||
EXPECT_TRUE(ret);
|
||||
ret = TimeServiceClient::GetInstance()->ResetAllProxy();
|
||||
EXPECT_TRUE(ret);
|
||||
@@ -347,6 +347,21 @@ HWTEST_F(TimeServiceTest, ProxyTimer002, TestSize.Level0)
|
||||
HWTEST_F(TimeServiceTest, ProxyTimer003, TestSize.Level0)
|
||||
{
|
||||
int32_t uid = 99999;
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false);
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false, true);
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProxyTimer004.
|
||||
* @tc.desc: proxy timer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: SR000H0GQ6 AR000H2VTQ
|
||||
*/
|
||||
HWTEST_F(TimeServiceTest, ProxyTimer004, TestSize.Level0)
|
||||
{
|
||||
int32_t uid = 99999;
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true, false);
|
||||
EXPECT_FALSE(ret);
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false, false);
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
bool StartTimer(uint64_t timerNumber, uint64_t triggerTime) override;
|
||||
bool StopTimer(uint64_t timerNumber) override;
|
||||
bool DestroyTimer(uint64_t timerNumber) override;
|
||||
bool ProxyTimer(int32_t uid, bool isProxy) override;
|
||||
bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) override;
|
||||
bool ResetAllProxy() override;
|
||||
~TimerManager() override;
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
virtual bool StopTimer(uint64_t timerNumber) = 0;
|
||||
virtual bool DestroyTimer(uint64_t timerNumber) = 0;
|
||||
virtual ~ITimerManager() = default;
|
||||
virtual bool ProxyTimer(int32_t uid, bool isProxy) = 0;
|
||||
virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0;
|
||||
virtual bool ResetAllProxy() = 0;
|
||||
}; // ITimerManager
|
||||
} // MiscService
|
||||
|
||||
@@ -134,6 +134,21 @@ bool TimerManager::StopTimer(uint64_t timerNumber)
|
||||
return false;
|
||||
}
|
||||
RemoveHandler(timerNumber);
|
||||
int32_t uid = it->second->uid;
|
||||
auto itMap = proxyMap_.find(uid);
|
||||
if (itMap != proxyMap_.end()) {
|
||||
auto alarms = itMap->second;
|
||||
for (auto itAlarm = alarms.begin(); itAlarm != alarms.end();) {
|
||||
if ((*itAlarm)->id == timerNumber) {
|
||||
alarms.erase(itAlarm);
|
||||
} else {
|
||||
itAlarm++;
|
||||
}
|
||||
}
|
||||
if (alarms.empty()) {
|
||||
proxyMap_.erase(uid);
|
||||
}
|
||||
}
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "end.");
|
||||
return true;
|
||||
}
|
||||
@@ -148,6 +163,21 @@ bool TimerManager::DestroyTimer(uint64_t timerNumber)
|
||||
return false;
|
||||
}
|
||||
RemoveHandler(timerNumber);
|
||||
int32_t uid = it->second->uid;
|
||||
auto itMap = proxyMap_.find(uid);
|
||||
if (itMap != proxyMap_.end()) {
|
||||
auto alarms = itMap->second;
|
||||
for (auto itAlarm = alarms.begin(); itAlarm != alarms.end();) {
|
||||
if ((*itAlarm)->id == timerNumber) {
|
||||
alarms.erase(itAlarm);
|
||||
} else {
|
||||
itAlarm++;
|
||||
}
|
||||
}
|
||||
if (alarms.empty()) {
|
||||
proxyMap_.erase(uid);
|
||||
}
|
||||
}
|
||||
timerEntryMap_.erase(it);
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "end.");
|
||||
return true;
|
||||
@@ -581,7 +611,7 @@ void TimerManager::CallbackAlarmIfNeed(std::shared_ptr<TimerInfo> alarm)
|
||||
}
|
||||
}
|
||||
|
||||
bool TimerManager::ProxyTimer(int32_t uid, bool isProxy)
|
||||
bool TimerManager::ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "start");
|
||||
@@ -596,15 +626,21 @@ bool TimerManager::ProxyTimer(int32_t uid, bool isProxy)
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "Uid: %{public}d doesn't exist in the proxy list." PRId64 "", uid);
|
||||
return false;
|
||||
}
|
||||
if (!needRetrigger) {
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "ProxyTimer doesn't need retrigger, clear all callbacks!");
|
||||
proxyMap_.erase(uid);
|
||||
return true;
|
||||
}
|
||||
auto itMap = proxyMap_.find(uid);
|
||||
if (itMap != proxyMap_.end()) {
|
||||
auto timeInfoVec = itMap->second;
|
||||
for (auto alarm : timeInfoVec) {
|
||||
if (!alarm->callback) {
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "Callback is nullptr!");
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "ProxyTimer Callback is nullptr!");
|
||||
continue;
|
||||
}
|
||||
alarm->callback(alarm->id);
|
||||
timeInfoVec.clear();
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "Shut down proxy, proxyUid: %{public}d, alarmId: %{public}" PRId64 "",
|
||||
uid, alarm->id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user