mirror of
https://github.com/openharmony/miscservices_time.git
synced 2026-07-18 17:34:34 -04:00
@@ -165,7 +165,7 @@ public:
|
||||
/**
|
||||
* ProxyTimer
|
||||
* @param uid the uid
|
||||
* @param isProxy true if proxy, false if not proxy
|
||||
* @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);
|
||||
|
||||
@@ -582,13 +582,18 @@ void TimeService::NetworkTimeStatusOn()
|
||||
|
||||
bool TimeService::ProxyTimer(int32_t uid, bool isProxy)
|
||||
{
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "service ProxyTimer start uid: %{public}d, isProxy: %{public}d",
|
||||
auto hasPerm = DelayedSingleton<TimePermission>::GetInstance()->CheckProxyCallingPermission();
|
||||
if (!hasPerm) {
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "ProxyTimer permission check failed");
|
||||
return E_TIME_NO_PERMISSION;
|
||||
}
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "ProxyTimer service start uid: %{public}d, isProxy: %{public}d",
|
||||
uid, isProxy);
|
||||
if (timerManagerHandler_ == nullptr) {
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "ProxyTimer Timer manager nullptr.");
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "ProxyTimer manager nullptr.");
|
||||
timerManagerHandler_ = TimerManager::Create();
|
||||
if (timerManagerHandler_ == nullptr) {
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "ProxyTimer Timer manager Init Failed.");
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "Proxytimer manager init failed.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -597,11 +602,16 @@ bool TimeService::ProxyTimer(int32_t uid, bool isProxy)
|
||||
|
||||
bool TimeService::ResetAllProxy()
|
||||
{
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "service ResetAllProxy");
|
||||
auto hasPerm = DelayedSingleton<TimePermission>::GetInstance()->CheckProxyCallingPermission();
|
||||
if (!hasPerm) {
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "ResetAllProxy permission check failed");
|
||||
return E_TIME_NO_PERMISSION;
|
||||
}
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "ResetAllProxy service");
|
||||
if (timerManagerHandler_ == nullptr) {
|
||||
timerManagerHandler_ = TimerManager::Create();
|
||||
if (timerManagerHandler_ == nullptr) {
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "ResetAllProxy Timer manager init failed");
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "ResetAllProxy timer manager init failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ HWTEST_F(TimeServiceTest, CreateTimer006, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(TimeServiceTest, ProxyTimer001, TestSize.Level0)
|
||||
{
|
||||
int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
int32_t uid = 99999;
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true);
|
||||
EXPECT_TRUE(ret);
|
||||
ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false);
|
||||
@@ -331,7 +331,10 @@ HWTEST_F(TimeServiceTest, ProxyTimer001, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(TimeServiceTest, ProxyTimer002, TestSize.Level0)
|
||||
{
|
||||
auto ret = TimeServiceClient::GetInstance()->ResetAllProxy();
|
||||
int32_t uid = 99999;
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true);
|
||||
EXPECT_TRUE(ret);
|
||||
ret = TimeServiceClient::GetInstance()->ResetAllProxy();
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
@@ -343,7 +346,7 @@ HWTEST_F(TimeServiceTest, ProxyTimer002, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(TimeServiceTest, ProxyTimer003, TestSize.Level0)
|
||||
{
|
||||
int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
int32_t uid = 99999;
|
||||
auto ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false);
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
@@ -31,6 +31,7 @@ namespace MiscServices {
|
||||
class TimePermission {
|
||||
public:
|
||||
static bool CheckCallingPermission(const std::string &permissionName);
|
||||
static bool CheckProxyCallingPermission();
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -45,5 +45,12 @@ bool TimePermission::CheckCallingPermission(const std::string &permissionName)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TimePermission::CheckProxyCallingPermission()
|
||||
{
|
||||
auto callerToken = IPCSkeleton::GetCallingTokenID();
|
||||
auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken);
|
||||
return tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE;
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user