diff --git a/BUILD.gn b/BUILD.gn index 4eea17eb3e3502218d0a179a03fa6996ede6d872..1a9d6724d82300c3c140c9e7936fd6489cb35eb2 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -128,6 +128,7 @@ ohos_shared_library("usagestatservice") { ] external_deps = [ + "ability_base:configuration", "ability_base:want", "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", @@ -139,9 +140,9 @@ ohos_shared_library("usagestatservice") { "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "native_appdatamgr:native_rdb", "permission_standard:libpermissionsdk_standard", "power_manager_native:powermgr_client", + "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "startup_l2:syspara", diff --git a/README.md b/README.md index f28be986a2664edae4fb546d7b98beeabcd843b9..b0efeabb09a11cdbf6214cb6c5a5bdd6e6e423af 100644 --- a/README.md +++ b/README.md @@ -97,4 +97,4 @@ resource_schedule_service appexecfwk_standard -native_appdatamgr \ No newline at end of file +relational_store \ No newline at end of file diff --git a/init/device_usage_statistics_service.cfg b/init/device_usage_statistics_service.cfg index 193ac5da3de3bfd67ba68bfb10797288be375ad5..fe224844abef7213d1e3c861f79fc4e64892623f 100644 --- a/init/device_usage_statistics_service.cfg +++ b/init/device_usage_statistics_service.cfg @@ -2,6 +2,7 @@ "jobs" : [{ "name" : "post-fs-data", "cmds" : [ + "mkdir /data/service/el1/public/bundle_usage 0711 device_usage_stats device_usage_stats", "start device_usage_stats_service" ] } @@ -9,9 +10,10 @@ "services" : [{ "name" : "device_usage_stats_service", "path" : ["/system/bin/sa_main", "/system/profile/device_usage_stats_service.xml"], - "uid" : "system", - "gid" : ["system", "shell"], - "secon" : "u:r:device_usage_stats_service:s0" + "uid" : "device_usage_stats", + "gid" : ["device_usage_stats", "shell"], + "secon" : "u:r:device_usage_stats_service:s0", + "apl" : "system_basic" } ] } \ No newline at end of file diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index e20b850c7dc002c4d37d6f91fcad0ac0c537ba1e..82bf37e637b0716c61507e2978d5664c2ad387d3 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -121,7 +121,7 @@ const std::string BUNDLE_ACTIVE_DB_BUNDLE_DAILY_TIMEOUT_TIME = "bundleDailyTimeo const std::string BUNDLE_ACTIVE_DB_BOOT_BASED_DURATION = "bootBasedDuration"; const std::string BUNDLE_ACTIVE_DB_SCREEN_ON_DURATION = "screenOnDuration"; const std::string REFRESH_DATABASE_RUNNER_NAME = "RefreshDatabase"; -const std::string BUNDLE_ACTIVE_DATABASE_DIR = "/data/system_ce/bundle_usage/"; +const std::string BUNDLE_ACTIVE_DATABASE_DIR = "/data/service/el1/public/bundle_usage/"; const std::string BUNDLE_ACTIVE_VERSION_FILE = "/version"; const std::string DATABASE_FILE_TABLE_NAME = "table"; const std::string SQLITE_MASTER_NAME = "name"; diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 08754af6078d8f34f2d93c92fe20be67e5715de9..d21188902487a5e8348f8fd939bb14852909e792 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -458,20 +458,15 @@ bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int32_t u } std::string bundleName = ""; sptrBundleMgr_->GetBundleNameForUid(uid, bundleName); - bool bundleIsSystemApp = sptrBundleMgr_->CheckIsSystemAppByUid(uid); int32_t bundleHasPermission = AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, NEEDED_PERMISSION); - if (!bundleIsSystemApp) { - errCode = BUNDLE_ACTIVE_FAIL; - BUNDLE_ACTIVE_LOGE("%{public}s is not system app", bundleName.c_str()); - return false; - } else if (bundleHasPermission != 0) { + if (bundleHasPermission != 0) { errCode = bundleHasPermission; BUNDLE_ACTIVE_LOGE("%{public}s hasn't permission", bundleName.c_str()); return false; } else { - BUNDLE_ACTIVE_LOGI(" %{public}s is system app %{public}d, has permission %{public}d", - bundleName.c_str(), bundleIsSystemApp, bundleHasPermission); + BUNDLE_ACTIVE_LOGI(" %{public}s has permission %{public}d", + bundleName.c_str(), bundleHasPermission); return true; } } diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 119dd4750e043e48a840d64159095d2afbb9a115..234086632e7be3e9c5ca607d28485437ed6ad1d3 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -298,7 +298,6 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN if (newGroup >= ACTIVE_GROUP_ALIVE && oneBundleHistory->bundleAliveTimeoutTimeStamp_ > bootBasedTimeStampAdjusted) { newGroup = ACTIVE_GROUP_ALIVE; - groupReason = oneBundleHistory->reasonInGroup_; groupReason = GROUP_CONTROL_REASON_USAGE | GROUP_EVENT_REASON_ALIVE_NOT_TIMEOUT; notTimeout = true; } else if (newGroup >= ACTIVE_GROUP_DAILY && oneBundleHistory->bundleDailyTimeoutTimeStamp_ > diff --git a/test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn b/test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn index 9ee599a6c215f058849b038b2993ed3b799b1770..45aaa5019a8e1a11d6609bf3dc7d01ac13628942 100644 --- a/test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn +++ b/test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn @@ -54,9 +54,9 @@ ohos_fuzztest("BundleActiveOnRemoteRequestFuzzTest") { "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "native_appdatamgr:native_rdb", "permission_standard:libpermissionsdk_standard", "power_manager_native:powermgr_client", + "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "startup_l2:syspara", diff --git a/test/fuzztest/bundleactiveonremoterequest_fuzzer/bundleactiveonremoterequest_fuzzer.cpp b/test/fuzztest/bundleactiveonremoterequest_fuzzer/bundleactiveonremoterequest_fuzzer.cpp index d2b6394ad5e28bec7bc7320504a9616106fe6151..e97c7e106f6d97042051d4ff07ba3d92d3e17086 100644 --- a/test/fuzztest/bundleactiveonremoterequest_fuzzer/bundleactiveonremoterequest_fuzzer.cpp +++ b/test/fuzztest/bundleactiveonremoterequest_fuzzer/bundleactiveonremoterequest_fuzzer.cpp @@ -26,24 +26,26 @@ namespace OHOS { namespace DeviceUsageStats { constexpr int32_t MIN_LEN = 4; constexpr int32_t MAX_CODE_TEST = 15; // current max code is 9 + static bool isInited = false; - void DoInit() + bool DoInit() { auto instance = DelayedSingleton::GetInstance(); if (!instance->runner_) { instance->runner_ = AppExecFwk::EventRunner::Create("device_usage_stats_init_handler"); } if (!instance->runner_) { - return; + return false; } if (!instance->handler_) { instance->handler_ = std::make_shared(instance->runner_); } if (!instance->handler_) { - return; + return false; } instance->InitNecessaryState(); + return true; } int32_t OnRemoteRequest(uint32_t code, MessageParcel& data) @@ -75,9 +77,12 @@ namespace DeviceUsageStats { dataMessageParcel.WriteBuffer(data + sizeof(uint32_t), size); dataMessageParcel.RewindRead(0); - DoInit(); - OnRemoteRequest(code, dataMessageParcel); - DelayedSingleton::GetInstance()->OnStop(); + if (!isInited) { + isInited = DoInit(); + } + if (isInited) { + OnRemoteRequest(code, dataMessageParcel); + } } } // namespace DeviceUsageStats } // namespace OHOS