OpenHarmony的公共事件

OpenHarmony的公共事件

公共事件简介

CES(Common Event Service,公共事件服务)为应用程序提供订阅、发布、退订公共事件的能力。

公共事件分类

公共事件从系统角度可分为:系统公共事件和自定义公共事件。

  • 系统公共事件:CES内部定义的公共事件,当前仅支持系统应用和系统服务发布,例如HAP安装、更新、卸载等公共事件。目前支持的系统公共事件请参见系统公共事件列表。
  • 自定义公共事件:应用定义的公共事件,可用于实现跨进程的事件通信能力。
    公共事件按发送方式可分为:无序公共事件、有序公共事件和粘性公共事件。
  • 无序公共事件:CES在转发公共事件时,不考虑订阅者是否接收到该事件,也不保证订阅者接收到该事件的顺序与其订阅顺序一致。
  • 有序公共事件:CES在转发公共事件时,根据订阅者设置的优先级等级,优先将公共事件发送给优先级较高的订阅者,等待其成功接收该公共事件之后再将事件发送给优先级较低的订阅者。如果有多个订阅者具有相同的优先级,则他们将随机接收到公共事件。
  • 粘性公共事件:能够让订阅者收到在订阅前已经发送的公共事件就是粘性公共事件。普通的公共事件只能在订阅后发送才能收到,而粘性公共事件的特殊性就是可以先发送后订阅,同时也支持先订阅后发送。发送粘性事件必须是系统应用或系统服务,粘性事件发送后会一直存在系统中,且发送者需要申请ohos.permission.COMMONEVENT_STICKY权限,配置方式请参见声明权限。

运作机制

每个应用都可以按需订阅公共事件,订阅成功,当公共事件发布时,系统会将其发送给对应的应用。这些公共事件可能来自系统、其他应用和应用自身。
图1 公共事件示意图
图1 公共事件示意图

安全注意事项

  • 公共事件发布方:如果不加限制,任何应用都可以订阅公共事件并读取相关信息,应避免在公共事件中携带敏感信息。采用以下方式,可以限制公共事件接收方的范围。
    • 通过CommonEventPublishData中的subscriberPermissions参数指定订阅者所需权限。
    • 通过CommonEventPublishData中的bundleName参数指定订阅者的包名。
  • 公共事件订阅方:订阅自定义公共事件后,任意应用都可以向订阅者发送潜在的恶意公共事件。采用以下方式,可以限制公共事件发布方的范围。
    • 通过CommonEventSubscribeInfo中的publisherPermission参数指定发布者所需权限。
    • 通过CommonEventSubscribeInfo中的publisherBundleName参数参数指定发布者的包名。
  • 自定义公共事件名称应确保全局唯一,否则可能与其他公共事件冲突。

常用的公共事件

公共事件类型定义在ohos.commonEventManager模块的Support枚举中。

事件名称功能描述
COMMON_EVENT_POWER_CONNECTED设备连接到外部电源的公共事件的动作
COMMON_EVENT_POWER_DISCONNECTED设备与外部电源断开的公共事件的动作
COMMON_EVENT_CHARGING表示系统开始为电池充电的公共事件的动作
COMMON_EVENT_DISCHARGING表示系统停止为电池充电的公共事件的动作
COMMON_EVENT_SHUTDOWN表示设备正在关闭并将继续最终关闭的公共事件的操作
COMMON_EVENT_SCREEN_ON表示由电源服务发起的设备亮屏完成的普通事件的动作
COMMON_EVENT_SCREEN_OFF表示由电源服务发起的设备灭屏完成的普通事件的动作
COMMON_EVENT_WIFI_POWER_STATEWi-Fi开关状态变化
COMMON_EVENT_SCREEN_LOCKED表示屏幕锁定的公共事件
COMMON_EVENT_SCREEN_UNLOCKED表示屏幕解锁的公共事件
COMMON_EVENT_BATTERY_CHANGED表示电池充电状态、电平和其他信息发生变化的公共事件的动作
COMMON_EVENT_USB_DEVICE_ATTACHED当用户设备作为USB主机时,提示USB设备已挂载
COMMON_EVENT_USB_DEVICE_DETACHED当用户设备作为USB主机时,提示USB设备被卸载
其中上面的屏幕亮屏和灭屏,屏幕锁屏和解锁,接电源适配器和拔掉电源适配器、开启wifi和断开wifi、插入USB设备/拔掉USB设备等。其中对于手机、平板、PC来说,上面的几个事件都比较常用,尤其在设备后台灭屏降功耗的时候比较有用。COMMON_EVENT_POWER_CONNECTED/COMMON_EVENT_POWER_DISCONNECTED这两个事件对于手机和平板来说就是接电源和拔掉电源,在PC中就是AC和DC了。

资源调度服务中的事件转换

resource_schedule_service开源仓地址:https://gitee.com/openharmony/resourceschedule_resource_schedule_service
在资源调度子系统中,提供系统事件的感知以及分发,例如应用启动、退出、亮灭屏等。如果需要获取系统事件,并且进行相关资源调度,那么可以选择以插件形式加入资源调度服务中。

作为资源调度子系统的子模块,智能分组模块通过系统内应用前后台切换、用户焦点输入、后台任务的执行状态,决策进程的分组调度策略,并支持通过配置将调度策略映射到不同的CGROUP分组,为系统的性能、功耗均衡调度提供决策依据。同时该模块向资源调度框架转发应用状态、焦点状态、后台任务状态等系统事件,供插件订阅。

resource_schedule_service是接收事件,决策调度策略和执行调度机制的引擎,其架构图示如下:
资源调度服务架构图
其中包括以下几个重要组成部分: 1、事件管理器,包含了使用对外接口直接感知系统事件,以及使用监听形式感知系统事件功能。 2、应用智能分组,该组件接收应用生命周期变更的事件,决策应用的分组优先级,是全局资源调度的根本依据。 3、插件管理器,负责产品对应资源调度插件的加载,接收系统和应用的事件,并根据插件的订阅情况将事件分发给插件。 4、SOC统一调频服务,该服务主要是从SOC统一调频插件中接收调频事件,进行相关的调频仲裁,最终使用内核接口设置CPU频率策略。

resource_schedule_service主要通过插件的形式进行扩展和实现系统全局资源的调度功能,插件以动态链接的形式运行,不同产品可以选择不同的插件进行加载。目前已知的插件有智能感知调度插件、设备状态管理插件、SOC统一调频插件。其中SOC统一调频插件的服务包含在resource_schedule_service中,而另外两个插件的服务包含在其它仓内,最终都是根据系统事件设置调度策略到内核中进行实施。

1:插件Check_List

更新2022年2月18日14:35:24

插件名插件功能简介插件订阅事件进程基线内存(KB)插件内存基线(KB)插件的事件执行效率插件新增线程插件关联进程插件需要的权限插件负责人
soc_perfcpu提频RES_TYPE_APP_STATE_CHANGE; RES_TYPE_WINDOW_FOCUS; RES_TYPE_CLICK_RECOGNIZE;RES_TYPE_PUSH_PAGE; RES_TYPE_SLIDE_RECOGNIZE;常驻:5918 动态:5922常驻:88 动态:88socperf_serviceHaoyangT
frame_aware_sched智能感知调度RES_TYPE_WINDOW_FOCUS; RES_TYPE_PROCESS_STATE_CHANGE; RES_TYPE_APP_STATE_CHANGE常驻:4537常驻:109暂无rongkunshi
component_sched外设调度RES_TYPE_SCREEN_STATUS;RES_TYPE_APP_STATE_CHANGE;RES_TYPE_ABILITY_STATE_CHANGE;RES_TYPE_EXTENSION_STATE_CHANGE;RES_TYPE_PROCESS_STATE_CHANGE;RES_TYPE_WINDOW_FOCUS; RES_TYPE_DEVICE_STILL_STATE_CHANGE;常驻:常驻: 动态:暂无linyunxuan
事件Check_List

更新2022年6月01日14:35:24

事件type事件用途事件value事件payload格式事件打点延时:订阅事件插件
RES_TYPE_SCREEN_STATUS屏幕状态0:屏幕暗 1:屏幕亮无需payload
RES_TYPE_APP_STATE_CHANGEAPP状态改变事件value : app state{“pid”=?,“uid”=?,“bundleName”=“?”}<10mssoc_perf; frame_aware
RES_TYPE_ABILITY_STATE_CHANGEABILITY状态改变事件value : ability state{“pid”=?,“uid”=?,“bundleName”=“?”}
RES_TYPE_EXTENSION_STATE_CHANGEEXTENSION状态改变事件value :extension state{“pid”=?,“uid”=?,“bundleName”=“?”}
RES_TYPE_PROCESS_STATE_CHANGE进程状态事件0:创建 1:销毁{“pid”=?,“uid”=?,“bundleName”=“?”}<10msframe_aware
RES_TYPE_WINDOW_FOCUS窗口聚焦事件0:聚焦1:不聚焦{“pid”=?,“uid”=?,“bundleName”=“?”, “windowId”=?,“windowType”=?,displayId=?}<10mssoc_perf ; frame_aware
RES_TYPE_TRANSIENT_TASK瞬态任务事件0:开始 1:结束{“pid”=?,“uid”=?,“bundleName”=“?”}
RES_TYPE_CONTINUOUS_TASK长时任务事件0:开始 1:结束{“pid”=?,“uid”=?,“abilityName”=“?”}
RES_TYPE_CGROUP_ADJUSTERcgroup改变事件0: 进程组分组变化 1: 线程分组变化{“pid”=?,“uid”=?,“name”=“?”,“oldGroup”=?, “newGroup”=?}
RES_TYPE_CLICK_RECOGNIZEace手势点击识别器<10mssoc_perf
RES_TYPE_PUSH_PAGEace pipeline_context.cpp::PushPage()<10mssoc_perf
RES_TYPE_SLIDE_RECOGNIZEace slide event recognize1: list fling on; 0: list fling off; 3: slide normal begin, 4: slide normal end<10mssoc_perf
RES_TYPE_WINDOW_VISIBILITY_CHANGE窗口可见性状态变化事件1: 可见, 0: 不可见--
RES_TYPE_REPORT_MMI_PROCESS上报mmi_service线程IDmmi_service线程号{“uid”=?, “pid”=?}--
RES_TYPE_REPORT_RENDER_THREAD上报应用的RSRender线程IDRSRenderThread线程号{“uid”=?, “pid”=?}--
RES_TYPE_APP_INSTALL_UNINSTALL应用安装和卸载事件value 0: 卸载, 1: 安装{“uid”=?,“bundleName”="?}--
RES_TYPE_WIFI_CONNECT_STATE_CHANGEwifi连接状态事件1:空闲, 2:连接中, 3:已连接, 4:断开中, 5:已断开无需payload--
RES_TYPE_USER_SWITCH用户切换事件value: 切换到的目标用户id无需payload--
RES_TYPE_USER_REMOVE用户删除事件value: 删除的用户id无需payload--
RES_TYPE_SCREEN_LOCK锁屏和解锁事件0:解锁 1:锁屏无需payload--
RES_TYPE_CALL_STATE_UPDATE电话状态改变事件value:电话状态无需payload--
RES_TYPE_AUDIO_RENDER_STATE_CHANGE音频流状态改变事件value:音频流状态{“uid”=?,“sessionId”=?}--
RES_TYPE_AUDIO_RING_MODE_CHANGE声音模式改变事件0:响铃模式 1:静音模式无需payload--
RES_TYPE_AUDIO_VOLUME_KEY_CHANGE音量改变事件value:音量大小{“volumeType”=?}--
RES_TYPE_POP_PAGEace pipeline_context.cpp::PopPage();{“pid”=?,“uid”=?,“bundleName”=“?”,“abilityName”=“?”, “pageUrl”=“?”}--
RES_TYPE_WEB_GESTUREweb手势事件--
RES_TYPE_SHOW_REMOTE_ANIMATION动画开始事件0:动画开始 1:动画结束{“srcPid”=?}--
RES_TYPE_DEVICE_STILL_STATE_CHANGE当前设备运动状态和静止状态转变事件-1: 无效值,0: 转变为运动状态,1:转变为静止状态--
RES_TYPE_RESIZE_WINDOW窗口缩放事件0: 窗口缩放开始,1:窗口缩放结束--
RES_TYPE_MOVE_WINDOW窗口拖拽事件0: 窗口拖拽开始,1:窗口拖拽结束--
RES_TYPE_LOAD_PAGE页面加载事件0: 页面加载开始,1:页面加载结束--
RES_TYPE_DRAG_STATUS_BAR状态栏下拉事件0:状态栏下拉开始, 1:状态栏下拉结束--
RES_TYPE_REPORT_SCENE_BOARD报告sceneBoard进程信息进程PID{“uid”=?, “mainTid”=?, “bundleName”=?}--
RES_TYPE_REPORT_KEY_THREAD报告关键线程0:新增,1:删除{“uid”=?, “pid”=?, “tid”=?, “role”=?}--
RES_TYPE_REPORT_WINDOW_STATE报告窗口状态0:新增,1:删除{“uid”=?, “pid”=?, “windowId”=?, “serialNum”=?, “state”=0 active 1 inactive}--
RES_TYPE_REPORT_SCENE_SCHED报告场景状态0:场景进入,1:场景退出{“uid”=?, “sceneId”=?,}--

通过查看https://gitee.com/openharmony/resourceschedule_resource_schedule_service中的源代码,我们可以看到event_controller.cpp中的void EventController::SystemAbilityStatusChangeListener::OnAddSystemAbility( int32_t systemAbilityId, const std::string& deviceId)接口中,添加了需要监听的公共事件,代码如下:

void EventController::SystemAbilityStatusChangeListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
{RESSCHED_LOGI("common event service is added");MatchingSkills matchingSkills;matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_INSTALLATION_STARTED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REPLACED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_ON);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_OFF);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_REMOVED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIME_CHANGED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_NITZ_TIME_CHANGED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_NITZ_TIMEZONE_CHANGED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CHARGING);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_DISCHARGING);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_P2P_STATE_CHANGED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED);matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);matchingSkills.AddEvent(DATA_SHARE_READY);CommonEventSubscribeInfo subscriberInfo(matchingSkills);subscriber_ = std::make_shared<EventController>(subscriberInfo);SubscribeCommonEvent(subscriber_);SubscribeLockScreenCommonEvent();
}void EventController::SystemAbilityStatusChangeListener::SubscribeLockScreenCommonEvent()
{MatchingSkills lockScreenSkills;lockScreenSkills.AddEvent("common.event.UNLOCK_SCREEN");lockScreenSkills.AddEvent("common.event.LOCK_SCREEN");CommonEventSubscribeInfo subscriberInfo(lockScreenSkills);subscriberInfo.SetPublisherBundleName(SCENE_BOARD_NAME);lockScreenSubscriber_ = std::make_shared<EventController>(subscriberInfo);SubscribeCommonEvent(lockScreenSubscriber_);
}inline void SubscribeCommonEvent(std::shared_ptr<EventController> subscriber)
{if (CommonEventManager::SubscribeCommonEvent(subscriber)) {RESSCHED_LOGI("SubscribeCommonEvent ok");} else {RESSCHED_LOGW("SubscribeCommonEvent fail");HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::RSS, "INIT_FAULT", HiviewDFX::HiSysEvent::EventType::FAULT,"COMPONENT_NAME", "MAIN","ERR_TYPE", "register failure","ERR_MSG", "EventController subscribe common events failed!");}
}

另外,资源调度服务部件是通过`void EventController::OnReceiveEvent(const EventFwk::CommonEventData &data)'这个函数接口中转换公共事件到自定义枚举事件的,代码如下:

void EventController::OnReceiveEvent(const EventFwk::CommonEventData &data)
{Want want = data.GetWant();std::string action = want.GetAction();RESSCHED_LOGI("Recieved common event:%{public}s", action.c_str());nlohmann::json payload = nlohmann::json::object();if (HandlePkgCommonEvent(action, want, payload)) {return;}if (action == CommonEventSupport::COMMON_EVENT_SCREEN_ON) {ReportDataInProcess(ResType::RES_TYPE_SCREEN_STATUS, ResType::ScreenStatus::SCREEN_ON, payload);return;}if (action == CommonEventSupport::COMMON_EVENT_SCREEN_OFF) {ReportDataInProcess(ResType::RES_TYPE_SCREEN_STATUS, ResType::ScreenStatus::SCREEN_OFF, payload);return;}if (action == CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE) {int32_t code = data.GetCode();HandleConnectivityChange(want, code, payload);return;}if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {int32_t userId = data.GetCode();ReportDataInProcess(ResType::RES_TYPE_USER_SWITCH, static_cast<int64_t>(userId), payload);return;}if (action == CommonEventSupport::COMMON_EVENT_USER_REMOVED) {int32_t userId = data.GetCode();ReportDataInProcess(ResType::RES_TYPE_USER_REMOVE, static_cast<int64_t>(userId), payload);return;}if (action == "common.event.UNLOCK_SCREEN") {ReportDataInProcess(ResType::RES_TYPE_SCREEN_LOCK, ResType::ScreenLockStatus::SCREEN_UNLOCK, payload);return;}if (action == "common.event.LOCK_SCREEN") {ReportDataInProcess(ResType::RES_TYPE_SCREEN_LOCK, ResType::ScreenLockStatus::SCREEN_LOCK, payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED) {payload["state"] = want.GetIntParam("state", -1);ReportDataInProcess(ResType::RES_TYPE_CALL_STATE_CHANGED, static_cast<int64_t>(data.GetCode()), payload);return;}if (action == DATA_SHARE_READY) {DataShareIsReady();return;}handleEvent(data.GetCode(), action, payload);
}void EventController::handleEvent(int32_t userId, const std::string &action, nlohmann::json &payload)
{if (action == CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED) {ReportDataInProcess(ResType::RES_TYPE_TIMEZONE_CHANGED, ResType::RES_TYPE_TIMEZONE_CHANGED, payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED) {ReportDataInProcess(ResType::RES_TYPE_TIME_CHANGED, static_cast<int64_t>(userId), payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_NITZ_TIME_CHANGED) {ReportDataInProcess(ResType::RES_TYPE_NITZ_TIME_CHANGED, static_cast<int64_t>(userId), payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_NITZ_TIMEZONE_CHANGED) {ReportDataInProcess(ResType::RES_TYPE_NITZ_TIMEZONE_CHANGED, static_cast<int64_t>(userId), payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING) {ReportDataInProcess(ResType::RES_TYPE_CHARGING_DISCHARGING, ResType::ChargeStatus::EVENT_CHARGING, payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING) {ReportDataInProcess(ResType::RES_TYPE_CHARGING_DISCHARGING, ResType::ChargeStatus::EVENT_DISCHARGING, payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED) {ReportDataInProcess(ResType::RES_TYPE_USB_DEVICE, ResType::UsbDeviceStatus::USB_DEVICE_ATTACHED, payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED) {ReportDataInProcess(ResType::RES_TYPE_USB_DEVICE, ResType::UsbDeviceStatus::USB_DEVICE_DETACHED, payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_WIFI_P2P_STATE_CHANGED) {ReportDataInProcess(ResType::RES_TYPE_WIFI_P2P_STATE_CHANGED, static_cast<int64_t>(userId), payload);return;}if (action == EventFwk::CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED) {ReportDataInProcess(ResType::RES_TYPE_POWER_MODE_CHANGED, static_cast<int64_t>(userId), payload);return;}handleOtherEvent(userId, action, payload);
}void EventController::handleOtherEvent(int32_t userId, const std::string &action, nlohmann::json &payload)
{if (action == EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED) {RESSCHED_LOGI("report boot completed");ReportDataInProcess(ResType::RES_TYPE_BOOT_COMPLETED,ResType::BootCompletedStatus::START_BOOT_COMPLETED, payload);return;}
}

其中资源调度服务内部事件枚举定义如下:

namespace OHOS {
namespace ResourceSchedule {
namespace ResType {
enum : uint32_t {// first resTypeRES_TYPE_FIRST = 0,// screen status, value 0 means screen off, value 1 means screen on, else are invalid.RES_TYPE_SCREEN_STATUS = RES_TYPE_FIRST,// app state change event; value means app state; payload:pid,uid,bundleNameRES_TYPE_APP_STATE_CHANGE = 1,// ability state change event; value means ability state; payload:pid,uid,bundleNameRES_TYPE_ABILITY_STATE_CHANGE = 2,// extension state change event; value means extension state; payload:pid,uid,bundleNameRES_TYPE_EXTENSION_STATE_CHANGE = 3,// process state event; value 0:created, 1:died; payload:pid,uid,bundleNameRES_TYPE_PROCESS_STATE_CHANGE = 4,// window focused event; value 0:focused, 1:unfocused; payload:pid,uid,bundleName,windowId,windowType,displayIdRES_TYPE_WINDOW_FOCUS = 5,// transient task event; value 0:start, 1:finish; payload:pid,uid,bundleNameRES_TYPE_TRANSIENT_TASK = 6,// continuous task event; value 0:start, 1:finish; payload:pid,uid,abilityNameRES_TYPE_CONTINUOUS_TASK = 7,/* cgroup change event;* value 0:set thread group sched; 1:set thread sched* payload: pid,uid,name,oldGroup,newGroup*/RES_TYPE_CGROUP_ADJUSTER = 8,// ace gestures click_recognizer; value 1 touch event, value 2 click eventRES_TYPE_CLICK_RECOGNIZE = 9,// ace pipeline_context.cpp::PushPage(); value 0: push_page_start, 1: push_page_completeRES_TYPE_PUSH_PAGE = 10,// ace slide event recognize; value 1: list fling on; 0: list fling off; 3: slide normal begin, 4: slide normal end.RES_TYPE_SLIDE_RECOGNIZE = 11,// window visibility change, value 1: isVisible, 0: not isVisible, payload:pid,uid,windowId,windowTypeRES_TYPE_WINDOW_VISIBILITY_CHANGE = 12,// report mmi_service service; value mmi_service tid; payload:uid,pidRES_TYPE_REPORT_MMI_PROCESS = 13,// report render thread; value render tid; payload:uid,pidRES_TYPE_REPORT_RENDER_THREAD = 14,// app install and uninstall event; value 0: uninstall, 1: install; payload:uid,bundleNameRES_TYPE_APP_INSTALL_UNINSTALL = 15,// net connect state; value 0:unknow, 1:idle, 2:connecting, 3:connected, 4:disconnecting, 5:disconnectedRES_TYPE_WIFI_CONNECT_STATE_CHANGE = 16,// user switch, value means the userId which switch to.RES_TYPE_USER_SWITCH = 17,// user remove, value means the userId which is removed.RES_TYPE_USER_REMOVE = 18,// screen unlock, value 0 means unlock, value 1 means locked.RES_TYPE_SCREEN_LOCK = 19,// bluetooth a2dp connect state, value 1: connected, 3: disconnected.RES_TYPE_BLUETOOTH_A2DP_CONNECT_STATE_CHANGE = 20,// network latency request, value 0: low latency, 1: normal latency, payload: identityRES_TYPE_NETWORK_LATENCY_REQUEST = 21,// call state update; value 0 : active, value 1 : holding, value 2 : dialing, value 3 : alerting,// value 4 : incoming, value 5 : waiting, value 6 : disconnected, value 7 : disconnecting, value 8 : idleRES_TYPE_CALL_STATE_UPDATE = 22,// Other process modify the thread Qos, value for client name id, payload: tid : qos , clientpid, pidRES_TYPE_THREAD_QOS_CHANGE = 23,// audio render state change; value -1 : RENDERER_INVALID, value 0 : RENDERER_NEW, value 1 : RENDERER_PREPARED,// value 2 : RENDERER_RUNNING, value 3 : RENDERER_STOPPED, value 4 : RENDERER_RELEASED, value 5 : RENDERER_PAUSED// payload:uid,sessionIdRES_TYPE_AUDIO_RENDER_STATE_CHANGE = 24,// audio ring mode change; value 0 : RINGER_MODE_NORMAL, value 1 : RINGER_MODE_SILENT// value 2 : RINGER_MODE_VIBRATERES_TYPE_AUDIO_RING_MODE_CHANGE = 25,RES_TYPE_AUDIO_VOLUME_KEY_CHANGE = 26,// app_ability_start_event : a very early app startup stub, when the app process has not been pulled up.// stub position : ability_runtime ability_manager_service.cpp::StartAbilityInner().// specifically : ability type is PAGE and ability launchMode is not SPECIFIED.RES_TYPE_APP_ABILITY_START = 27,// ace pipeline_context.cpp::PopPage(); value means nothingRES_TYPE_POP_PAGE = 28,// ace web gesture event recognize; value means nothingRES_TYPE_WEB_GESTURE = 29,// info from msdp, means device still state change(enter or exit)RES_TYPE_DEVICE_STILL_STATE_CHANGE = 30,// window resize event; value 0: resize window , value 1: stop resizing window.RES_TYPE_RESIZE_WINDOW = 31,// window move event; value 0: move window, value 1: stop moving window.RES_TYPE_MOVE_WINDOW = 32,// animation transition event; value 0: animation begin, value 1: animation end.RES_TYPE_SHOW_REMOTE_ANIMATION = 33,// load page; value 0: load page begin, value 1: load page end.RES_TYPE_LOAD_PAGE = 34,// report camera state, value 0: camera connect; value 1: camera disconnectRES_TYPE_REPORT_CAMERA_STATE = 35,// report runningLock state, value 0: runningLock disable; value 1: runningLock enable;// value 2: runningLock is proxied; value 3: runningLock is not proxiedRES_TYPE_RUNNINGLOCK_STATE = 36,// drag status bar event; value 0: start drag, value 1: stop drag.RES_TYPE_DRAG_STATUS_BAR = 37,// report SceneBoard service, value pid; payload:uid, main_tid, bundleNameRES_TYPE_REPORT_SCENE_BOARD = 38,// report key thread for render, value 0 add key Thread, 1 remove key thread, payload: uid, pid, tid, roleRES_TYPE_REPORT_KEY_THREAD = 39,// report window state, value 0 add 1 remove, payload: uid, pid, windowId, serialNum state: 0 active 1 inactiveRES_TYPE_REPORT_WINDOW_STATE = 40,// report scene sched, value 0 scene on 1 scene off, payload: uid, sceneIdRES_TYPE_REPORT_SCENE_SCHED = 41,// web gesture move event; value 0: web gesture move start, value 1: web gesture move end.RES_TYPE_WEB_GESTURE_MOVE = 42,// web slide normal event; value 0: web slide normal start, value 1: web slide normal end.RES_TYPE_WEB_SLIDE_NORMAL = 43,// load url event; value means nothing.RES_TYPE_LOAD_URL = 44,// mousewheel event; value means nothing.RES_TYPE_MOUSEWHEEL = 45,// report webview audio status, value 0 start 1 stop, payload: uid, pid, tidRES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE = 46,// report entering the multimodalinput state, value means subscribed multimodalinput state.RES_TYPE_MMI_INPUT_STATE = 47,// report anco load protect file configRES_TYPE_ANCO_CUST = 48,// report time zone changedRES_TYPE_TIMEZONE_CHANGED = 50,// report connection statusRES_TYPE_CONNECTION_OBSERVER = 51,// report av session create eventRES_TYPE_AV_SESSION_ON_SESSION_CREATE = 52,// report av session release eventRES_TYPE_AV_SESSION_ON_SESSION_RELEASE = 53,// report av session change eventRES_TYPE_AV_SESSION_ON_TOP_SESSION_CHANGE = 54,// report OnAppStateChanged eventRES_TYPE_ON_APP_STATE_CHANGED = 55,// report efficiency resources eventRES_TYPE_EFFICIENCY_RESOURCES_STATE_CHANGED = 56,// report av_codec state, value 0:codec start info, value 1:codec stop info.RES_TYPE_AV_CODEC_STATE = 57,// 58-64 value do not changeRES_TYPE_NITZ_TIME_CHANGED = 58,RES_TYPE_TIME_CHANGED = 59,RES_TYPE_NITZ_TIMEZONE_CHANGED = 60,RES_TYPE_CHARGING_DISCHARGING = 61,RES_TYPE_USB_DEVICE = 62,RES_TYPE_CALL_STATE_CHANGED = 63,RES_TYPE_WIFI_P2P_STATE_CHANGED = 64,// last resType//report app associated start to performance radarRES_TYPE_APP_ASSOCIATED_START = 65,//report thermal state eventRES_TYPE_THERMAL_STATE = 66,// socperf event beginRES_TYPE_SOCPERF_CUST_EVENT_BEGIN = 67,// socperf event endRES_TYPE_SOCPERF_CUST_EVENT_END = 68,// window drawing content change eventRES_TYPE_WINDOW_DRAWING_CONTENT_CHANGE = 69,// report vediuo capture start or stopRES_TYPE_REPORT_SCREEN_CAPTURE = 70,// report long frame, value 0 scene on 1 scene off.RES_TYPE_LONG_FRAME = 71,// report key perf scene, value 0 enter scene 1 exit scene.RES_TYPE_KEY_PERF_SCENE = 72,// report super launcher stateRES_TYPE_SUPER_LAUNCHER = 73,// report cast screen stateRES_TYPE_CAST_SCREEN = 74,// report screen collabroation stateRES_TYPR_SCREEN_COLLABROATION = 75,// report sa control app event, eg: start app or stop appRES_TYPE_SA_CONTROL_APP_EVENT = 76,// report CPU load of the entire machine,payload:cpuPercentRES_TYPE_SYSTEM_CPU_LOAD = 77,// report download or upload scene,value 0 enter scene 1 exit scene.RES_TYPE_UPLOAD_DOWNLOAD = 78,// report main screen split,value 0 enter scene 1 exit scene.RES_TYPE_SPLIT_SCREEN = 79,// report main screen floating window,value 0 enter scene 1 exit scene.RES_TYPE_FLOATING_WINDOW = 80,// report event distribute tid, value tid, payload uid, pid.RES_TYPE_REPORT_DISTRIBUTE_TID = 81,// report frame rateRES_TYPE_FRAME_RATE_REPORT = 82,// report web screen capture, value 0 start, value 1 stopRES_TYPE_WEBVIEW_SCREEN_CAPTURE = 83,// report video state. value 0 start playing, value 1 stop playingRES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE = 84,// report location status. value 0 app status, value 1 switch statusRES_TYPE_LOCATION_STATUS_CHANGE = 85,// report silent playbackRES_TYPE_AUDIO_SILENT_PLAYBACK = 86,// report display mode event, value status, payload mode.RES_TYPE_DEVICE_MODE_STATUS = 88,// report distribute component changeRES_TYPE_REPORT_DISTRIBUTE_COMPONENT_CHANGE = 89,// report web drag resizeRES_TYPE_WEB_DRAG_RESIZE = 90,// report formCard create start/endRES_TYPE_FORM_STATE_CHANGE_EVENT = 91,// report power mode changedRES_TYPE_POWER_MODE_CHANGED = 92,// report thermal scenario changedRES_TYPE_THERMAL_SCENARIO_REPORT = 93,// report boot completedRES_TYPE_BOOT_COMPLETED = 94,// report continuous application startupRES_TYPE_CONTINUOUS_STARTUP = 95,// report account activatingRES_TYPE_ACCOUNT_ACTIVATING = 96,// report silent playback in rendererRES_TYPE_AUDIO_RENDERER_SILENT_PLAYBACK = 97,// report continuous application installRES_TYPE_CONTINUOUS_INSTALL = 98,// report system updatedRES_TYPE_FIRST_BOOT_AFTER_SYSTEM_UPGRADE = 99,// report background perceivable sceneRES_TYPE_BACKGROUND_PERCEIVABLE_SCENE = 100,// user interaction sceneRES_TYPE_USER_INTERACTION_SCENE = 101,// report game sched, value 0 start, value 1 stopRES_TYPE_REPORT_GAME_SCHED = 102,// report send frame eventRES_TYPE_SEND_FRAME_EVENT = 103,// report app cold start only perf, value 0 start, value 1 stopRES_TYPE_ONLY_PERF_APP_COLD_START = 104,// report scene rotation, value 0 start, value 1 stopRES_TYPE_SCENE_ROTATION = 105,// report event vsync tid, value tid, payload pid, tid, uid.RES_TYPE_REPORT_VSYNC_TID = 106,// report cloud config updateRES_TYPE_CLOUD_CONFIG_UPDATE = 107,// system ability status changeRES_TYPE_SYSTEM_ABILITY_STATUS_CHANGE = 108,// mmi status changeRES_TYPE_MMI_STATUS_CHANGE = 109,// report media output device changeRES_TYPE_OUTPUT_DEVICE_CHANGE = 110,// report device idleRES_TYPE_DEVICE_IDLE = 111,// report media output device changeRES_TYPE_BT_SERVICE_EVENT = 112,// report to hisi, let bmm_report begin changeRES_TYPE_BMM_MONITER_CHANGE_EVENT = 113,// app frame drop eventRES_TYPE_APP_FRAME_DROP = 114,// report rss cloud config updateRES_TYPE_RSS_CLOUD_CONFIG_UPDATE = 115,// report game infoRES_TYPE_GAME_INFO_NOTIFY = 116,// report power key downRES_TYPE_MMI_INPUT_POWER_KEY = 117,// report application stoppedRES_TYPE_APP_STOPPED = 118,// last async resTypeASYNC_RES_TYPE_LAST,// first sync resTypeSYNC_RES_TYPE_FIRST = ASYNC_RES_TYPE_LAST,// thaw one applicationSYNC_RES_TYPE_THAW_ONE_APP,// get all suspend stateSYNC_RES_TYPE_GET_ALL_SUSPEND_STATE,// get thermal dataSYNC_RES_TYPE_GET_THERMAL_DATA,// check shoul force kill process,SYNC_RES_TYPE_SHOULD_FORCE_KILL_PROCESS,// report to request mutex statusSYNC_RES_TYPE_REQUEST_MUTEX_STATUS = 500,// report to check mutex before startSYNC_RES_TYPE_CHECK_MUTEX_BEFORE_START = 501,// last sync resTypeSYNC_RES_TYPE_LAST,// last resTypeRES_TYPE_LAST = SYNC_RES_TYPE_LAST,
};
} // namespace ResType
} // namespace ResourceSchedule
} // namespace OHOS

接着在调频插件socperf_plugin、待机插件device_standby_plugin、分组策略插件cgroup_sched_plugin中添加对资源调度内部事件的订阅和监听回调处理。
以上三个插件都分别实现了如下三个接口:

接口名接口描述
function OnPluginInit(std::string& libName): bool;插件初始化
function OnPluginDisable(): void;插件退出
function OnDispatchResource(const std::shared_ptr<ResData>& data):void;获取分发的事件

插件初始化的时候,指定需要注册监听的事件。在这些事件发生的时候,框架会依次分发给各个插件, 此时插件需要快速处理消息接收进行资源调度(需要有耗时任务则需另起线程处理),处理完成后返回。
插件事件处理约束

  • 1、插件可以用C/C++实现。
  • 2、插件的事件处理,必须快速完成,超过1ms会打印相关告警,超过10ms,框架认为插件异常而进行插件退出操作。

以待机插件device_standby_plugin为例,其代码实现路径为:device_standby_plugin.cpp

在init()函数中订阅相关事件,具体代码如下:

// 插件初始化
extern "C" bool OnPluginInit(std::string& libName)
{if (libName != LIB_NAME) {STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginInit lib name is not match");return false;}DeviceStandbyPlugin::GetInstance().Init();STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginInit success.");return true;
}void DeviceStandbyPlugin::Init()
{resTypes_.insert(RES_TYPE_APP_INSTALL_UNINSTALL);resTypes_.insert(RES_TYPE_SCREEN_STATUS);resTypes_.insert(RES_TYPE_TIME_CHANGED);resTypes_.insert(RES_TYPE_NITZ_TIME_CHANGED);resTypes_.insert(RES_TYPE_TIMEZONE_CHANGED);resTypes_.insert(RES_TYPE_NITZ_TIMEZONE_CHANGED);resTypes_.insert(RES_TYPE_CHARGING_DISCHARGING);resTypes_.insert(RES_TYPE_USB_DEVICE);resTypes_.insert(RES_TYPE_CALL_STATE_CHANGED);resTypes_.insert(RES_TYPE_WIFI_P2P_STATE_CHANGED);resTypes_.insert(RES_TYPE_EFFICIENCY_RESOURCES_STATE_CHANGED);resTypes_.insert(RES_TYPE_POWER_MODE_CHANGED);resTypes_.insert(RES_TYPE_CLICK_RECOGNIZE);resTypes_.insert(RES_TYPE_MMI_INPUT_POWER_KEY);for (auto resType : resTypes_) {PluginMgr::GetInstance().SubscribeResource(LIB_NAME, resType);}STANDBYSERVICE_LOGI("DevicesStandbyPlugin::Init success");
}

待机插件事件分发处理,相关代码如下:

// 获取分发的事件
extern "C" void OnDispatchResource(const std::shared_ptr<ResData>& data)
{DeviceStandbyPlugin::GetInstance().DispatchResource(data);STANDBYSERVICE_LOGD("DeviceStandbyPlugin::OnDispatchResource success.");
}

待机插件退出,相关代码如下:

// 插件退出
extern "C" void OnPluginDisable()
{DeviceStandbyPlugin::GetInstance().Disable();STANDBYSERVICE_LOGI("DeviceStandbyPlugin::OnPluginDisable success.");
}void DeviceStandbyPlugin::Disable()
{for (auto resType : resTypes_) {PluginMgr::GetInstance().UnSubscribeResource(LIB_NAME, resType);}resTypes_.clear();STANDBYSERVICE_LOGI("DevicesStandbyPlugin::Disable success");
}

在待机部件device_standby中使用事件

待机部件device_standby仓的源代码地址为:https://gitee.com/openharmony/resourceschedule_device_standby
设备待机部件为提高设备续航,降低设备功耗,在设备进入待机空闲状态时,系统会限制后台应用使用资源。开发者可以根据自身情况,为自己的应用申请纳入待机资源管控,或者暂时不被待机资源管控。
图 1 设备待机部件整体架构图
图 1 设备待机部件整体架构图
那么我们以亮屏和灭屏事件为例,看一下设备待机部件device_standby是如何使用资源调度部件resource_schedule_service中定义的事件的?

我们使用git clone https://gitee.com/openharmony/resourceschedule_device_standby.git命令下载好设备待机部件仓的源代码后,使用VScode打开源代码,搜索RES_TYPE_SCREEN_STATUS这个亮屏状态关键字,如下图所示:
搜索亮屏状态
可以看到utils\common\include\res_type.h中保持了一份资源调度模块的事件枚举
的子集,代码如下所示:

namespace OHOS {
namespace DevStandbyMgr {
namespace ResType {
enum : uint32_t {// first resTypeRES_TYPE_FIRST = 0,// screen status, value 0 means screen off, value 1 means screen on, else are invalid.RES_TYPE_SCREEN_STATUS = RES_TYPE_FIRST,// app state change event; value means app state; payload:pid,uid,bundleNameRES_TYPE_APP_STATE_CHANGE = 1,// ability state change event; value means ability state; payload:pid,uid,bundleNameRES_TYPE_ABILITY_STATE_CHANGE = 2,// extension state change event; value means extension state; payload:pid,uid,bundleNameRES_TYPE_EXTENSION_STATE_CHANGE = 3,// process state event; value 0:created, 1:died; payload:pid,uid,bundleNameRES_TYPE_PROCESS_STATE_CHANGE = 4,// window focused event; value 0:focused, 1:unfocused; payload:pid,uid,bundleName,windowId,windowType,displayIdRES_TYPE_WINDOW_FOCUS = 5,// transient task event; value 0:start, 1:finish; payload:pid,uid,bundleNameRES_TYPE_TRANSIENT_TASK = 6,// continuous task event; value 0:start, 1:finish; payload:pid,uid,abilityNameRES_TYPE_CONTINUOUS_TASK = 7,/* cgroup change event;* value 0:set thread group sched; 1:set thread sched* payload: pid,uid,name,oldGroup,newGroup*/RES_TYPE_CGROUP_ADJUSTER = 8,// ace gestures click_recognizer; value 1 touch event, value 2 click eventRES_TYPE_CLICK_RECOGNIZE = 9,// ace pipeline_context.cpp::PushPage(); value 0: push_page_start, 1: push_page_completeRES_TYPE_PUSH_PAGE = 10,// ace slide event recognize; value 1: list fling on; 0: list fling off; 3: slide normal begin, 4: slide normal end.RES_TYPE_SLIDE_RECOGNIZE = 11,// window visibility change, value 1: isVisible, 0: not isVisible, payload:pid,uid,windowId,windowTypeRES_TYPE_WINDOW_VISIBILITY_CHANGE = 12,// report mmi_service service; value mmi_service tid; payload:uid,pidRES_TYPE_REPORT_MMI_PROCESS = 13,// report render thread; value render tid; payload:uid,pidRES_TYPE_REPORT_RENDER_THREAD = 14,// app install and uninstall event; value 0: uninstall, 1: install; payload:uid,bundleNameRES_TYPE_APP_INSTALL_UNINSTALL = 15,// net connect state; value 0:unknow, 1:idle, 2:connecting, 3:connected, 4:disconnecting, 5:disconnectedRES_TYPE_WIFI_CONNECT_STATE_CHANGE = 16,// user switch, value means the userId which switch to.RES_TYPE_USER_SWITCH = 17,// user remove, value means the userId which is removed.RES_TYPE_USER_REMOVE = 18,// screen unlock, value 0 means unlock, value 1 means locked.RES_TYPE_SCREEN_LOCK = 19,// bluetooth a2dp connect state, value 1: connected, 3: disconnected.RES_TYPE_BLUETOOTH_A2DP_CONNECT_STATE_CHANGE = 20,// network latency request, value 0: low latency, 1: normal latency, payload: identityRES_TYPE_NETWORK_LATENCY_REQUEST = 21,// call state update; value 0 : active, value 1 : holding, value 2 : dialing, value 3 : alerting,// value 4 : incoming, value 5 : waiting, value 6 : disconnected, value 7 : disconnecting, value 8 : idleRES_TYPE_CALL_STATE_UPDATE = 22,// Other process modify the thread Qos, value for client name id, payload: tid : qos , clientpid, pidRES_TYPE_THREAD_QOS_CHANGE = 23,// audio render state change; value -1 : RENDERER_INVALID, value 0 : RENDERER_NEW, value 1 : RENDERER_PREPARED,// value 2 : RENDERER_RUNNING, value 3 : RENDERER_STOPPED, value 4 : RENDERER_RELEASED, value 5 : RENDERER_PAUSED// payload:uid,sessionIdRES_TYPE_AUDIO_RENDER_STATE_CHANGE = 24,// audio ring mode change; value 0 : RINGER_MODE_NORMAL, value 1 : RINGER_MODE_SILENT// value 2 : RINGER_MODE_VIBRATERES_TYPE_AUDIO_RING_MODE_CHANGE = 25,RES_TYPE_AUDIO_VOLUME_KEY_CHANGE = 26,// app_ability_start_event : a very early app startup stub, when the app process has not been pulled up.// stub position : ability_runtime ability_manager_service.cpp::StartAbilityInner().// specifically : ability type is PAGE and ability launchMode is not SPECIFIED.RES_TYPE_APP_ABILITY_START = 27,// ace pipeline_context.cpp::PopPage(); value means nothingRES_TYPE_POP_PAGE = 28,// ace web gesture event recognize; value means nothingRES_TYPE_WEB_GESTURE = 29,// info from msdp, means device still state change(enter or exit)RES_TYPE_DEVICE_STILL_STATE_CHANGE = 30,// window resize event; value 0: resize window , value 1: stop resizing window.RES_TYPE_RESIZE_WINDOW = 31,// window move event; value 0: move window, value 1: stop moving window.RES_TYPE_MOVE_WINDOW = 32,// animation transition event; value 0: animation begin, value 1: animation end.RES_TYPE_SHOW_REMOTE_ANIMATION = 33,// load page; value 0: load page begin, value 1: load page end.RES_TYPE_LOAD_PAGE = 34,// report camera state, value 0: camera connect; value 1: camera disconnectRES_TYPE_REPORT_CAMERA_STATE = 35,// value 2: runningLock is proxied; value 3: runningLock is not proxiedRES_TYPE_RUNNINGLOCK_STATE = 36,// drag status bar event; value 0: start drag, value 1: stop drag.RES_TYPE_DRAG_STATUS_BAR = 37,// report SceneBoard service, value pid; payload:uid, main_tid, bundleNameRES_TYPE_REPORT_SCENE_BOARD = 38,// report key thread for render, value 0 add key Thread, 1 remove key thread, payload: uid, pid, tid, roleRES_TYPE_REPORT_KEY_THREAD = 39,// report window state, value 0 add 1 remove, payload: uid, pid, windowId, serialNum state: 0 active 1 inactiveRES_TYPE_REPORT_WINDOW_STATE = 40,// report scene sched, value 0 scene on 1 scene off, payload: uid, sceneIdRES_TYPE_REPORT_SCENE_SCHED = 41,// web gesture move event; value 0: web gesture move start, value 1: web gesture move end.RES_TYPE_WEB_GESTURE_MOVE = 42,// web slide normal event; value 0: web slide normal start, value 1: web slide normal end.RES_TYPE_WEB_SLIDE_NORMAL = 43,// load url event; value means nothing.RES_TYPE_LOAD_URL = 44,// mousewheel event; value means nothing.RES_TYPE_MOUSEWHEEL = 45,// report webview audio status, value 0 start 1 stop, payload: uid, pid, tidRES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE = 46,// report entering the multimodalinput state, value means subscribed multimodalinput state.RES_TYPE_MMI_INPUT_STATE = 47,// report anco load protect file configRES_TYPE_ANCO_CUST = 48,// report anco app is frontRES_TYPE_ANCO_APP_FRONT = 49,// report time zone changedRES_TYPE_TIMEZONE_CHANGED = 50,// report connection statusRES_TYPE_CONNECTION_OBSERVER = 51,// report av session create eventRES_TYPE_AV_SESSION_ON_SESSION_CREATE = 52,// report av session release eventRES_TYPE_AV_SESSION_ON_SESSION_RELEASE = 53,// report av session change eventRES_TYPE_AV_SESSION_ON_TOP_SESSION_CHANGE = 54,// report OnAppStateChanged eventRES_TYPE_ON_APP_STATE_CHANGED = 55,// report efficiency resources eventRES_TYPE_EFFICIENCY_RESOURCES_STATE_CHANGED = 56,// report av_codec state, value 0:codec start info, value 1:codec stop info.RES_TYPE_AV_CODEC_STATE = 57,RES_TYPE_NITZ_TIME_CHANGED = 58,RES_TYPE_TIME_CHANGED = 59,RES_TYPE_NITZ_TIMEZONE_CHANGED = 60,RES_TYPE_CHARGING_DISCHARGING = 61,RES_TYPE_USB_DEVICE = 62,RES_TYPE_CALL_STATE_CHANGED = 63,RES_TYPE_WIFI_P2P_STATE_CHANGED = 64,// report power mode changedRES_TYPE_POWER_MODE_CHANGED = 92,// report power key downRES_TYPE_MMI_INPUT_POWER_KEY = 117,// last resTypeRES_TYPE_LAST,
};inline const std::map<uint32_t, std::string> resTypeToStr = {{ RES_TYPE_SCREEN_STATUS, "SCREEN_STATUS" },{ RES_TYPE_APP_STATE_CHANGE, "APP_STATE_CHANGE" },{ RES_TYPE_ABILITY_STATE_CHANGE, "ABILITY_STATE_CHANGE" },{ RES_TYPE_EXTENSION_STATE_CHANGE, "EXTENSION_STATE_CHANGE" },{ RES_TYPE_PROCESS_STATE_CHANGE, "PROCESS_STATE_CHANGE" },{ RES_TYPE_WINDOW_FOCUS, "WINDOW_FOCUS" },{ RES_TYPE_TRANSIENT_TASK, "TRANSIENT_TASK" },{ RES_TYPE_CONTINUOUS_TASK, "CONTINUOUS_TASK" },{ RES_TYPE_CGROUP_ADJUSTER, "CGROUP_ADJUSTER" },{ RES_TYPE_CLICK_RECOGNIZE, "CLICK_RECOGNIZE" },{ RES_TYPE_PUSH_PAGE, "PUSH_PAGE" },{ RES_TYPE_SLIDE_RECOGNIZE, "SLIDE_RECOGNIZE" },{ RES_TYPE_WINDOW_VISIBILITY_CHANGE, "WINDOW_VISIBILITY_CHANGE" },{ RES_TYPE_REPORT_MMI_PROCESS, "REPORT_MMI_PROCESS" },{ RES_TYPE_REPORT_RENDER_THREAD, "REPORT_RENDER_THREAD" },{ RES_TYPE_APP_INSTALL_UNINSTALL, "APP_INSTALL_UNINSTALL" },{ RES_TYPE_WIFI_CONNECT_STATE_CHANGE, "WIFI_CONNECT_STATE_CHANGE" },{ RES_TYPE_USER_SWITCH, "USER_SWITCH" },{ RES_TYPE_USER_REMOVE, "USER_REMOVE" },{ RES_TYPE_SCREEN_LOCK, "SCREEN_LOCK" },{ RES_TYPE_BLUETOOTH_A2DP_CONNECT_STATE_CHANGE, "BLUETOOTH_A2DP_CONNECT_STATE_CHANGE" },{ RES_TYPE_NETWORK_LATENCY_REQUEST, "NETWORK_LATENCY_REQUEST" },{ RES_TYPE_CALL_STATE_UPDATE, "CALL_STATE_UPDATE" },{ RES_TYPE_THREAD_QOS_CHANGE, "THREAD_QOS_CHANGE" },{ RES_TYPE_AUDIO_RENDER_STATE_CHANGE, "AUDIO_RENDER_STATE_CHANGE" },{ RES_TYPE_AUDIO_RING_MODE_CHANGE, "AUDIO_RING_MODE_CHANGE" },{ RES_TYPE_AUDIO_VOLUME_KEY_CHANGE, "AUDIO_VOLUME_KEY_CHANGE" },{ RES_TYPE_APP_ABILITY_START, "APP_ABILITY_START" },{ RES_TYPE_POP_PAGE, "POP_PAGE" },{ RES_TYPE_WEB_GESTURE, "WEB_GESTURE" },{ RES_TYPE_DEVICE_STILL_STATE_CHANGE, "DEVICE_STILL_STATE_CHANGE" },{ RES_TYPE_RESIZE_WINDOW, "RES_TYPE_RESIZE_WINDOW" },{ RES_TYPE_MOVE_WINDOW, "RES_TYPE_MOVE_WINDOW" },{ RES_TYPE_SHOW_REMOTE_ANIMATION, "RES_TYPE_SHOW_REMOTE_ANIMATION" },{ RES_TYPE_LOAD_PAGE, "RES_TYPE_LOAD_PAGE" },{ RES_TYPE_REPORT_CAMERA_STATE, "RES_TYPE_REPORT_CAMERA_STATE" },{ RES_TYPE_RUNNINGLOCK_STATE, "RES_TYPE_RUNNINGLOCK_STATE" },{ RES_TYPE_DRAG_STATUS_BAR, "RES_TYPE_DRAG_STATUS_BAR" },{ RES_TYPE_REPORT_SCENE_BOARD, "RES_TYPE_REPORT_SCENE_BOARD" },{ RES_TYPE_REPORT_KEY_THREAD, "RES_TYPE_REPORT_KEY_THREAD" },{ RES_TYPE_REPORT_WINDOW_STATE, "RES_TYPE_REPORT_WINDOW_STATE" },{ RES_TYPE_REPORT_SCENE_SCHED, "RES_TYPE_REPORT_SCENE_SCHED" },{ RES_TYPE_WEB_GESTURE_MOVE, "RES_TYPE_WEB_GESTURE_MOVE" },{ RES_TYPE_WEB_SLIDE_NORMAL, "RES_TYPE_WEB_SLIDE_NORMAL" },{ RES_TYPE_LOAD_URL, "RES_TYPE_LOAD_URL" },{ RES_TYPE_MOUSEWHEEL, "RES_TYPE_MOUSEWHEEL" },{ RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE, "RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE" },{ RES_TYPE_MMI_INPUT_STATE, "RES_TYPE_MMI_INPUT_STATE" },{ RES_TYPE_ANCO_CUST, "RES_TYPE_ANCO_CUST" },{ RES_TYPE_ANCO_APP_FRONT, "RES_TYPE_ANCO_APP_FRONT" },{ RES_TYPE_TIMEZONE_CHANGED, "RES_TYPE_TIMEZONE_CHANGED" },{ RES_TYPE_TIME_CHANGED, "RES_TYPE_TIME_CHANGED" },{ RES_TYPE_NITZ_TIME_CHANGED, "RES_TYPE_NITZ_TIME_CHANGED" },{ RES_TYPE_NITZ_TIMEZONE_CHANGED, "RES_TYPE_NITZ_TIMEZONE_CHANGED" },{ RES_TYPE_CHARGING_DISCHARGING, "RES_TYPE_CHARGING_DISCHARGING" },{ RES_TYPE_USB_DEVICE, "RES_TYPE_USB_DEVICE" },{ RES_TYPE_CALL_STATE_CHANGED, "RES_TYPE_CALL_STATE_CHANGED" },{ RES_TYPE_WIFI_P2P_STATE_CHANGED, "RES_TYPE_WIFI_P2P_STATE_CHANGED" },{ RES_TYPE_CONNECTION_OBSERVER, "RES_TYPE_CONNECTION_OBSERVER" },{ RES_TYPE_AV_SESSION_ON_SESSION_CREATE, "RES_TYPE_AV_SESSION_ON_SESSION_CREATE" },{ RES_TYPE_AV_SESSION_ON_SESSION_RELEASE, "RES_TYPE_AV_SESSION_ON_SESSION_RELEASE" },{ RES_TYPE_AV_SESSION_ON_TOP_SESSION_CHANGE, "RES_TYPE_AV_SESSION_ON_TOP_SESSION_CHANGE" },{ RES_TYPE_ON_APP_STATE_CHANGED, "RES_TYPE_ON_APP_STATE_CHANGED" },{ RES_TYPE_EFFICIENCY_RESOURCES_STATE_CHANGED, "RES_TYPE_EFFICIENCY_RESOURCES_STATE_CHANGED" },{ RES_TYPE_AV_CODEC_STATE, "RES_TYPE_AV_CODEC_STATE" },{ RES_TYPE_POWER_MODE_CHANGED, "RES_TYPE_POWER_MODE_CHANGED" },
};
} // namespace ResType
} // namespace ResourceSchedule
} // namespace OHOS

并且在services\core\src\standby_service_impl.cpp中的 StandbyServiceImpl::HandleCommonEvent接口,实现了对事件的统一处理,代码如下:

ErrCode StandbyServiceImpl::HandleCommonEvent(const uint32_t resType, const int64_t value, const std::string &sceneInfo)
{STANDBYSERVICE_LOGI("HandleCommonEvent resType = %{public}u, value = %{public}lld, sceneInfo = %{public}s",resType, (long long)(value), sceneInfo.c_str());switch (resType) {case ResType::RES_TYPE_SCREEN_STATUS:HandleScreenStateChanged(value);break;case ResType::RES_TYPE_CHARGING_DISCHARGING:HandleChargeStateChanged(value);break;case ResType::RES_TYPE_USB_DEVICE:if (value == 0) {DispatchEvent(StandbyMessage(StandbyMessageType::COMMON_EVENT,EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED));} else {DispatchEvent(StandbyMessage(StandbyMessageType::COMMON_EVENT,EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED));}break;case ResType::RES_TYPE_CALL_STATE_CHANGED:HandleCallStateChanged(sceneInfo);break;case ResType::RES_TYPE_WIFI_P2P_STATE_CHANGED:HandleP2PStateChanged(value);break;case ResType::RES_TYPE_CLICK_RECOGNIZE:HandleScreenClickRecognize(value);break;case ResType::RES_TYPE_MMI_INPUT_POWER_KEY:HandleMmiInputPowerKeyDown(value);break;
#ifdef STANDBY_POWER_MANAGER_ENABLEcase ResType::RES_TYPE_POWER_MODE_CHANGED:HandlePowerModeChanged(static_cast<PowerMgr::PowerMode>(value));break;
#endifcase ResType::RES_TYPE_EFFICIENCY_RESOURCES_STATE_CHANGED:HandleResourcesStateChanged(value, sceneInfo);break;default:AppEventHandler(resType, value, sceneInfo);break;}return ERR_OK;
}void StandbyServiceImpl::HandleScreenStateChanged(const int64_t value)
{if (value == 1) {DispatchEvent(StandbyMessage(StandbyMessageType::COMMON_EVENT,EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON));} else {DispatchEvent(StandbyMessage(StandbyMessageType::COMMON_EVENT,EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF));}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/60786.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【AlphaFold3】开源本地的安装及使用

文章目录 安装安装DockerInstalling Docker on Host启用Rootless Docker 安装 GPU 支持安装 NVIDIA 驱动程序安装 NVIDIA 对 Docker 的支持 获取 AlphaFold 3 源代码获取基因数据库获取模型参数构建将运行 AlphaFold 3 的 Docker 容器 参考 AlphaFold3: https://github.com/goo…

npm list -g --depth=0(用来列出全局安装的所有 npm 软件包而不显示它们的依赖项)

您提供的命令 npm list -g --depth0 是在 Node Package Manager (npm) 的上下文中使用的&#xff0c;用来列出全局安装的所有 npm 软件包而不显示它们的依赖项。 这是它的运作方式&#xff1a; npm list -g --depth0-g: 指定列表应包括全局安装的软件包。--depth0: 限制树形结…

Spring Boot框架:电商系统的技术革新

4 系统设计 网上商城系统的设计方案比如功能框架的设计&#xff0c;比如数据库的设计的好坏也就决定了该系统在开发层面是否高效&#xff0c;以及在系统维护层面是否容易维护和升级&#xff0c;因为在系统实现阶段是需要考虑用户的所有需求&#xff0c;要是在设计阶段没有经过全…

【数据分享】中国对外投资合作发展报告(2013-2023)

数据介绍 绪 论............................................................................................................................. 1 对外投资合作高质量发展迈出新步伐................................................................... 2 第一篇 发…

【深度学习】LSTM、BiLSTM详解

文章目录 1. LSTM简介&#xff1a;2. LSTM结构图&#xff1a;3. 单层LSTM详解4. 双层LSTM详解5. BiLSTM6. Pytorch实现LSTM示例7. nn.LSTM参数详解 1. LSTM简介&#xff1a; LSTM是一种循环神经网络&#xff0c;它可以处理和预测时间序列中间隔和延迟相对较长的重要事件。LSTM通…

【云原生系列--Longhorn的部署】

Longhorn部署手册 1.部署longhorn longhorn架构图&#xff1a; 1.1部署环境要求 kubernetes版本要大于v1.21 每个节点都必须装open-iscsi &#xff0c;Longhorn依赖于 iscsiadm主机为 Kubernetes 提供持久卷。 apt-get install -y open-iscsiRWX 支持要求每个节点都安装 N…

【Hadoop】【hdfs】【大数据技术基础】实验三 HDFS 基础编程实验

实验三&#xff1a; HDFS Java API编程实践 实验题目 HDFS Java API编程实践 实验目的 熟悉HDFS操作常用的Java API。 实验平台 操作系统&#xff1a;Linux Hadoop版本&#xff1a;2.6.0或以上版本 JDK版本&#xff1a;1.6或以上版本 Java IDE&#xff1a;Eclipse 实验…

ssm114基于SSM框架的网上拍卖系统的设计与实现+vue(论文+源码)_kaic

摘 要 随着科学技术的飞速发展&#xff0c;各行各业都在努力与现代先进技术接轨&#xff0c;通过科技手段提高自身的优势&#xff0c;商品拍卖当然也不能排除在外&#xff0c;随着商品拍卖管理的不断成熟&#xff0c;它彻底改变了过去传统的经营管理方式&#xff0c;不仅使商品…

Transformer中的算子:其中Q,K,V就是算子

目录 Transformer中的算子 其中Q,K,V就是算子 一、数学中的算子 二、计算机科学中的算子 三、深度学习中的算子 四、称呼的由来 Transformer中的算子 其中Q,K,V就是算子 “算子”这一称呼源于其在数学、计算机科学以及深度学习等多个领域中的广泛应用和特定功能。以下是…

厦大南洋理工最新开源,一种面向户外场景的特征-几何一致性无监督点云配准方法

导读 本文提出了INTEGER&#xff0c;一种面向户外点云数据的无监督配准方法&#xff0c;通过整合高层上下文和低层几何特征信息来生成更可靠的伪标签。该方法基于教师-学生框架&#xff0c;创新性地引入特征-几何一致性挖掘&#xff08;FGCM&#xff09;模块以提高伪标签的准确…

生产环境中AI调用的优化:AI网关高价值应用实践

随着越来越多的组织将生成式AI引入生产环境&#xff0c;他们面临的挑战已经超出了初步实施的范畴。如果管理不当&#xff0c;扩展性限制、安全漏洞和性能瓶颈可能会阻碍AI应用的推广。实际问题如用户数据的安全性、固定容量限制、成本管理和延迟优化等&#xff0c;需要创新的解…

Redis 概 述 和 安 装

安 装 r e d i s: 1. 下 载 r e dis h t t p s : / / d o w n l o a d . r e d i s . i o / r e l e a s e s / 2. 将 redis 安装包拷贝到 /opt/ 目录 3. 解压 tar -zvxf redis-6.2.1.tar.gz 4. 安装gcc yum install gcc 5. 进入目录 cd redis-6.2.1 6. 编译 make …

SpringBoot 2.2.10 无法执行Test单元测试

很早之前的项目今天clone现在&#xff0c;想执行一个业务订单的检查&#xff0c;该检查的代码放在test单元测试中&#xff0c;启动也是好好的&#xff0c;当点击对应的方法执行Test的时候就报错 tip&#xff1a;已添加spring-boot-test-starter 所以本身就引入了junit5的库 No…

[项目代码] YOLOv5 铁路工人安全帽安全背心识别 [目标检测]

YOLOv5是一种单阶段&#xff08;one-stage&#xff09;检测算法&#xff0c;它将目标检测问题转化为一个回归问题&#xff0c;能够在一次前向传播过程中同时完成目标的分类和定位任务。相较于两阶段检测算法&#xff08;如Faster R-CNN&#xff09;&#xff0c;YOLOv5具有更高的…

SIM Jacker攻击分析

简介&#xff1a; 2019年9月12日&#xff0c;AdaptiveMobile Security公布了一种针对SIM卡ST Browser的远程攻击方式&#xff1a;Simjacker。攻击者使用普通手机发送特殊构造的短信即可远程定位目标&#xff0c;危害较大 。sim卡的使用在手机上的使用非常普遍&#xff0c;所以…

【linux】centos7 换阿里云源

相关文章 【linux】CentOS 的软件源&#xff08;Repository&#xff09;学习-CSDN博客 查看yum配置文件 yum的配置文件通常位于/etc/yum.repos.d/目录下。你可以使用以下命令查看这些文件&#xff1a; ls /etc/yum.repos.d/ # 或者 ll /etc/yum.repos.d/备份当前的yum配置文…

AI 写作(八)实战项目一:自动写作助手(8/10)

一、项目背景与需求分析 &#xff08;一&#xff09;写作需求的多样化 在互联网普及的今天&#xff0c;人们对写作的需求呈现出前所未有的多样化态势。无论是学术论文、新闻报道&#xff0c;还是社交媒体的动态更新、网络小说的创作&#xff0c;都离不开高质量的写作。以学术研…

微信小程序内嵌h5页面(uniapp写的),使用uni.openLocation无法打开页面问题

1.问题 微信小程序内嵌h5页面(uniapp写的),使用uni.openLocation打开地图页面后,点击该页面下方“到这里”按钮,显示无法打开。如下图: 3.解决方案 在内嵌h5中不使用uniapp的api打开地图,而在h5页面事件处理程序中去跳转新的小程序页面,在该新页面去使用微信小程序…

SpringCloud核心组件(五)

文章目录 Gateway一. 概述简介1. Gateway 是什么2. 什么是网关?3.Gateway 和 Nginx 两个网关的区别什么是流量入口&#xff1f; 4.Gateway 能干嘛5.gateway 三大核心概念6.运行方式 二. 入门案例a.创建gateway模块&#xff0c;在pom.xml中引入依赖b.创建启动类GatewayApplicat…

1+X应急响应(网络)系统备份:

系统备份&#xff1a; 系统备份概述&#xff1a; 备份种类&#xff1a; 灾难恢复等级划分&#xff1a; 执行一次备份&#xff1a; 创建备份计划&#xff1a; 恢复备份&#xff1a;