Key event processing method, device, storage medium and terminal
By using the unified input management interface in the Android system for key interception processing, the problems of complex and redundant key event processing logic in the prior art are solved, and the system performance and efficiency are improved.
Patent Information
- Application Number
- CN202210041430.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-14
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2042-01-14
AI Technical Summary
The key event processing logic in the existing Android system is complex and redundant, and there is a lack of effective key distribution and notification methods, resulting in system performance loss and inefficiency.
By detecting key events in the terminal system kernel, calling the window manager to obtain the application's interception data, and using the unified input management interface to perform key interception processing, reducing system load and avoiding resource consumption.
It simplifies the key processing logic, reduces system load and resource consumption, improves terminal performance, and avoids delays and data drop problems caused by broadcasting and service methods.
Smart Images

Figure CN114489354B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a key event processing method, device, storage medium and terminal. Background Art
[0002] Android-based terminals, such as smart TVs, provide panel buttons and remote controls for user convenience. In particular, the remote control has rich button functions, which can quickly and conveniently operate the smart TV, greatly facilitating users and improving the interactive experience with the terminal. However, the rich button functions also make the button processing logic of the button events in the terminal increasingly complex, especially the button interception processing logic.
[0003] Since there was no reasonable design scheme in the early stage of the development of the key processing logic of key events, a piece of code was added when a new requirement came in the later projects. Over time, the key processing logic in the Android system is relatively complex and redundant. At the same time, since there is no effective way to distribute / notify keys to applications in the current key interception processing logic, in scenarios where applications have key processing requirements, cross-process communication (application process and system process) is mostly achieved in the form of broadcast or service. For example, when an application needs to be notified, a corresponding notification is sent to the application using a broadcast or service. However, the broadcast or service method is very likely to cause delays, and it is easy to cause the corresponding data packets to be discarded, resulting in low efficiency, and it is easy to cause system performance loss, affecting the performance of the Android system. Summary of the invention
[0004] The embodiments of the present application provide a key event processing method, device, storage medium and terminal, which can uniformly set the interception data of applications, uniformly process the key events of applications, and significantly reduce the load of the Android system to avoid excessive consumption of resources of the Android system.
[0005] The present application embodiment provides a key event processing method, which is applied to a terminal, and the terminal is installed with at least one application. The key event processing method includes:
[0006] When the kernel of the terminal system detects a key event, determining a target key corresponding to the key event, and calling a window manager of the system;
[0007] Obtaining interception data of the application saved in the window manager, the interception data including a key combination of the application to be intercepted and a callback function corresponding to the application, the interception data is set in advance by the application through a newly added unified input management interface and sent to the window manager for storage;
[0008] According to the target key, the key combination to be intercepted of the application and the callback function, a key interception process is performed on the target key corresponding to the key event.
[0009] The embodiment of the present application further provides a key event processing device, which is applied to a terminal, and the terminal is installed with at least one application program, and the key event processing device includes:
[0010] A detection and determination module, used for determining a target key corresponding to a key event when a kernel of a terminal system detects a key event, and calling a window manager of the system;
[0011] A data acquisition module, used to acquire interception data of an application program saved in the window manager, wherein the interception data includes a key combination of an application program to be intercepted and a callback function corresponding to the application program, wherein the interception data is set in advance by the application program through a newly added unified input management interface and sent to the window manager for storage;
[0012] The interception processing module is used to perform key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the application and the callback function.
[0013] An embodiment of the present application further provides a computer-readable storage medium, wherein a plurality of instructions are stored in the computer-readable storage medium, and wherein the instructions are suitable for being loaded by a processor to execute any of the above-mentioned key event processing methods.
[0014] An embodiment of the present application further provides a terminal, including a processor and a memory, wherein the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used to perform the steps in any of the above-mentioned key event processing methods.
[0015] The key event processing method, device, storage medium and terminal provided by the present application realize the mutual communication between the application process and the system process through the newly added unified input management interface, and the application is provided with interception data through the unified input management interface. The interception data of the application can be uniformly set and uniformly managed, such as uniformly saving the interception data in the window manager, which avoids the confusion and redundancy of the key processing logic in the system on the one hand, and on the other hand, when the key event is processed, the interception data is directly read from the window manager, without the need for the system to read and write multiple attributes, which greatly reduces the system load and resource consumption. Moreover, the interception data of the application includes the key combination to be intercepted, which can be used for the application to set multiple keys to be intercepted, and there is no need to add a separate code for the newly added key to be intercepted, thereby avoiding excessive redundancy in the key processing logic. In addition, the interception data of the application also includes the callback function of the application, which is set by the application. In this way, the application can be notified to perform corresponding processing by callback, and the use of broadcast, service and other methods to notify the application is avoided, thereby reducing the system load and resource consumption, and improving the performance of the terminal system. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The technical solution and other beneficial effects of the present application will be made apparent by describing in detail the specific implementation methods of the present application in conjunction with the accompanying drawings.
[0017] Figure 1 This is a partial schematic diagram related to key interception processing in the terminal provided in an embodiment of the present application.
[0018] Figure 2 This is an example flowchart of the key event processing method provided in an embodiment of the present application.
[0019] Figure 3 A schematic diagram of a sub-process of a key event processing method provided in an embodiment of the present application.
[0020] Figure 4 Another flowchart of the key event processing method provided in an embodiment of the present application.
[0021] Figure 5 A schematic diagram of registering and unregistering a callback function provided in an embodiment of the present application.
[0022] Figure 6 A schematic diagram of the structure of a key event processing device provided in an embodiment of the present application.
[0023] Figure 7 A schematic diagram of the structure of a terminal provided in an embodiment of the present application.
[0024] Figure 8Another schematic diagram of the structure of the terminal provided in the embodiment of the present application. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0026] The embodiments of the present application provide a key event processing method, device, storage medium and terminal. Any key event processing device provided in the embodiments of the present application can be integrated in a terminal, and the terminal can include a smart phone, a pad, a wearable device, a robot, a smart TV, a smart air conditioner, etc. The system of the terminal can be an Android system or an Apple system or other systems, and the terminal includes at least one application. The terminal can provide a panel button or a remote control to control it.
[0027] The following description will be given by taking the Android system as an example.
[0028] Since a panel button or a remote controller is required to control the terminal, key event processing of the terminal is very important. The key processing logic in the embodiment of the present application includes key interception processing logic.
[0029] In the process of keystroke interception and processing of keystroke events in existing terminals, after long-term observation, summary and analysis, the following unreasonable aspects exist:
[0030] Complex logic and redundant code: Since there was no reasonable solution design in the early stage of development, in the later projects, when new requirements came up (key interception and processing logic for new key events needed to be added), a piece of code was added. Over time, the key processing logic in the Android system became more complex and redundant.
[0031] Business intrusion, poor independence: Due to historical reasons, many of the logics processed by the application have also been forcibly added to the key processing logic of the Android system, resulting in the Android system's key processing logic containing a large amount of business code. For example, when clicking the up key to launch an application, the current method is to write the function of launching the application in the Android system framework and launch the application through the Android system. In this way, the code of the business processing logic of launching the application is added to the key processing logic of the Android system, and the functions of the Android system and the application are mixed together.
[0032] Time-consuming operations and performance loss: Since there is no unified performance specification requirement, in the key interception processing flow, for each key event processing, the Android system will obtain which key events the application needs to respond to through multiple attribute read and write operations, so as to determine the application associated with the corresponding key in the key event. For example, the Android system does not know which keys of the application have key interception settings, so it needs to read some related attributes of the application multiple times, and also involves write operations. Moreover, since it is currently impossible to perceive the status of the application, it is necessary to frequently query whether the key-associated application is still an active application. For example, an application sets the interception processing of the up, down, left, and right keys, but it is currently unknown whether the application is running on the front end of the terminal, so it is necessary to frequently query whether the application is still an active application. In this way, multiple attribute read and write operations and frequent queries of active applications will significantly increase the time consumption of key processing and affect the performance of the Android system.
[0033] No channel, rely more on broadcast: Since there is no effective way to distribute keys to applications in the current key interception processing logic (or it can be understood that there is no effective way for applications to connect and communicate with the Android system), in scenarios where applications have key processing requirements, broadcast or service is often used to achieve cross-process communication (application process and Android system process). For example, when an application needs to be notified, a corresponding notification is sent to the application using broadcast or service. However, broadcast or service methods are very likely to cause delays and easily cause the corresponding data packets to be discarded, resulting in low efficiency and easy to cause system performance loss.
[0034] Based on the above-mentioned deficiencies, the embodiment of the present application reconstructs the existing key interception processing function and proposes a new key event processing method, device, storage medium and terminal, which aims to strip non-system-level business codes, improve key processing efficiency, reduce performance loss caused by the system, and improve scalability and maintainability.
[0035] like Figure 1 As shown, it is a partial schematic diagram related to key interception processing in the terminal provided in the embodiment of the present application. In the terminal, the kernel (Kernel) of the Android system, the system framework of the Android system and at least one application, such as application 1, application 2, etc. The kernel of the Android system can be used to detect key events, such as key events triggered by various input devices, such as event0, event1, etc.
[0036] Among them, the system framework of the Android system includes a software development kit (Software Development Kit, SDK), a window management service (WindowManagerService) and a window manager (PhoneWindowManager).
[0037] A new input management interface, InputManager, is added to the software development kit. The new input management interface realizes the mutual communication between the application process and the Android system process, provides a channel for the application process to access the window management service in the system framework, and the interception data of the application can be set through the input management interface. In this embodiment, the window management service is only a channel that forwards the interception data set from the application to the window manager. It should be noted that in the existing key interception processing flow, the application cannot access the window management service.
[0038] The window manager stores interception data set by the application through the input management interface. The interception data includes identification information of the application, a key combination (keyMap) to be intercepted by the application, and a callback function (keyEventListener) corresponding to the application. The identification information may be the package name (pkgName) of the application or other identification information, and the key combination to be intercepted by the application includes at least one key and a key processing type corresponding to at least one key, and each key corresponds to a key processing type.
[0039] The callback function of the application includes a status detection function of the application process. The status detection function is used to realize the perception of the status of the application. The status detection function is provided by the Android system. The Android system will inform the window manager of the status of the application, which solves the problem that the existing solution cannot perceive the status of the application. In addition, the callback function of the application can also add the business processing logic that the application needs to handle according to actual needs. It should be noted that since the callback function can also include the business processing logic that the application needs to handle, the business processing logic corresponding to the application does not need to be mixed in the system framework of the Android system, which separates the Android system and the business processing logic, isolates the system and the application from the functions, and strips off the non-system-level business processing logic, realizing the decoupling of the business processing logic of the Android system and the application.
[0040] based on Figure 1 The schematic diagram shown in FIG. 1 is a schematic diagram showing a key event processing method, device, storage medium and terminal.
[0041] See also Figure 1 , Figure 21 is a flow chart of a key event processing method provided in an embodiment of the present application. The key event processing method is applied in a terminal and includes the following steps.
[0042] 101. When the kernel of the terminal system detects a key event, the target key corresponding to the key event is determined, and the window manager of the system is called.
[0043] When the panel button on the terminal is triggered, such as by clicking / touching / voice, for example, when the voice command "start application A" is received, the button corresponding to the start application A is triggered; or when the remote control is triggered to trigger the button on the terminal, the Android system kernel will detect the button event corresponding to the button. After the button event is detected, the target button corresponding to the button event is determined. For example, the confirmation button, up button, down button, left button, right button, etc.
[0044] After the Android system kernel detects the key event, it calls the window manager in the Android framework and uses the window manager for further processing.
[0045] 102. Obtain interception data of the application stored in the window manager, wherein the interception data includes a key combination to be intercepted by the application and a callback function corresponding to the application. The interception data is set in advance by the application through a newly added unified input management interface and sent to the window manager for storage.
[0046] The window manager stores interception data of at least one application. The interception data of each application includes identification information of the application, the key combination to be intercepted of the application, and the callback function corresponding to the application. The key combination of the application includes at least one key to be intercepted and a key processing type corresponding to at least one key. It should be noted that the key processing type here is determined during the key interception process based on long-term observation, summary, refinement and classification of the application's needs for key interception. The existing solution does not determine the type of interception processing for the key event in the key interception process, and does not classify the intercepted key processing type.
[0047] In this embodiment, the key processing types include the following four categories. It should be noted that in other embodiments, the management processing types may also include more or fewer types.
[0048] Application notification type (first type): In certain scenarios, some designated buttons follow the original system processing flow (or original system processing logic) of the Android system, and the application needs to be notified of the button event. For example, in the terminal's smart speaker mode, the volume + / volume- button, mute button, etc., follow the original system flow to adjust the volume, and the application needs to be notified to handle it, and the application will decide the response logic, such as lighting up the screen, etc. For example, when the volume + button event is triggered, in addition to increasing the volume, the application needs to be notified to light up the screen, etc.
[0049] Application consumption type (second type): In a specific scenario, some of the specified keys need to be consumed by the specified application, and the original system processing flow corresponding to the keys is no longer used. For example, in the smart speaker mode of the terminal, the speaker key or the power key needs to be responded to by the smart speaker application, and the original system key processing flow of the corresponding keys can no longer be used.
[0050] Only allow type (third type): This type is suitable for situations where there are many keys to be intercepted. In a specific scenario, only the specified keys are released, and other keys are directly intercepted by the system; because there are many keys to be intercepted, it is not suitable for enumeration settings, so only allow represents this scenario for easy setting. For example, in EAS mode, only the power key is responded to, and all other keys are intercepted.
[0051] Only interception type (fourth type): This type is suitable for situations where there are fewer buttons to be intercepted. In specific scenarios, only the specified buttons are intercepted, and other buttons follow the original system processing flow. For example, in P mode, the power button of the remote control is intercepted, and standby cannot be enabled, while other buttons can respond normally.
[0052] Among them, the third type and the fourth type are complementary.
[0053] By classifying the key interception types, different processing can be performed on different key interception types to facilitate unified control of all key events.
[0054] In one embodiment, the callback function corresponding to the application includes a state detection function of the application process corresponding to the application. The state detection function is used to realize the perception of the state of the application. The state detection function is provided by the Android system. The Android system will inform the window manager of the state of the application, which solves the problem of frequently querying the current activity (topactivity) application in the existing solution, that is, it solves the problem that the state of the application cannot be perceived in the existing solution, realizes the monitoring of the process state of the application, reduces the load and resource consumption of the Android system, and also reduces the time consumption of the key processing logic.
[0055] In one embodiment, the callback function may also include the business processing logic that the application needs to process. Therefore, the business processing logic corresponding to the application does not need to be mixed in the system framework of the Android system. The Android system and the business processing logic are separated, and the Android system and the application are functionally isolated. The non-system-level business processing logic is stripped off, and the business processing logic of the Android system and the application is decoupled, thereby improving the security of the Android system. The business processing logic of the application is processed by callback. Compared with the notification methods such as broadcasts and services in existing solutions, this can reduce the load and resource consumption of the Android system and improve the performance of the Android system. In addition, the callback method provides the application with the freedom to process intercepted keys.
[0056] That is, the callback function provides the application with the ability to freely process the keys of interest, and at the same time provides the application with monitoring functions, such as monitoring the process status of the application process, and also realizes the decoupling of the business processing logic of the Android system and the application. In addition, the callback is also used to notify the application to handle the key events that the application is interested in, providing a cross-process (cross-application process and system process) event notification channel.
[0057] The interception data of the above-mentioned application is set by the application in advance through the newly added input management interface, and sent to the window manager for storage. Among them, the application calls the input management interface to set the interception data of the application, and sends it to the window manager through the window management service, and the window manager saves the interception data corresponding to the application. The interception data corresponding to the application is saved in the window manager. Each time a key event is processed, it is only necessary to obtain the interception data from the window manager, especially to obtain the key combination to be intercepted of the application. There is no need for the Android system to read the properties of the application multiple times and perform multiple write operations to obtain which key events the application needs to respond to, which greatly reduces the load and resource consumption of the Android system. Moreover, through the unified input management interface for the application to set the interception data, the interception data of the application can be uniformly set and managed, avoiding the confusion and redundancy of the key processing logic in the Android system.
[0058] 103. Perform key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the application program and the callback function.
[0059] Among them, the key interception processing for the target key corresponding to the key event can be executed in the process of adding the key to the queue (handleKeyBoforeQueueing). When a key event occurs, it will enter handleKeyBoforeQueueing.
[0060] In one embodiment, the callback function includes a status detection function of an application process corresponding to the application, and the status detection function is used to detect the process status of the application process. The above step 103 includes: detecting whether there is an application that has set up key interception; if there is an application that has set up key interception, determining the target application according to the process status of the application; performing key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the target application and the callback function of the target application; if no application has set up key interception, continuing the original system processing flow of the target key.
[0061] Among them, it is detected whether an application has set up key interception. Specifically, it can be detected whether the window manager stores the interception data of the application to determine whether an application has set up key interception. This can be understood as a switch. When the application sets up key interception, the key interception processing function of the key event is turned on. Otherwise, there is no need to perform key interception processing, and the key interception processing function of the key event is turned off.
[0062] The process status of the application includes active status, exit status, abnormal exit status, etc. If there is an application that sets key interception, the application currently in the active state can be obtained, that is, the application currently displayed on the front end of the terminal, and the application currently in the active state is determined as the target application. It can be understood that the target application is generally one.
[0063] After the target application is determined, the target key corresponding to the key event is intercepted according to the target key, the key combination to be intercepted of the target application and the callback function of the target application.
[0064] In one embodiment, the callback function also includes the business processing logic of the application. The above step of performing key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the target application and the callback function of the target application specifically includes: obtaining the key processing type of each key in the key combination to be intercepted of the target application; performing key interception processing on the target key corresponding to the key event according to the target key, the key combination and the corresponding key processing type and the business processing logic of the target application. The key processing type has been described above and will not be repeated here.
[0065] In one embodiment, the step of intercepting the target key corresponding to the key event according to the target key, key combination and corresponding key processing type, and the business processing logic of the target application includes: when the key processing type includes an application notification type, and the key of the application notification type matches the target key, the target application is notified through the target application callback function to process the business processing logic, and the target key continues the original system processing flow; when the key processing type does not include the application notification type but includes the application consumption type, and the key of the application consumption type matches the target key, the target application is notified through the target application callback function to process the business processing logic and intercept the target key; when the key processing type does not include the application notification type and When the application consumption type includes the third type, if the third type of button matches the target button, the target button is released and the target button continues the original system processing flow. If the third type of button does not match the target button, the button that does not match the target button in the button combination of the target application is intercepted; when the button processing type does not include the application notification type and the application consumption type, but includes the fourth type, if the fourth type of button matches the target button, the target button is intercepted. If the fourth type of button does not match the target button, the button that does not match the target button in the button combination of the target application continues the original system processing flow; when the button processing type does not include the application notification type, the application consumption type, the third type and the fourth type, the target button continues the original system processing flow.
[0066] Among them, since a target application has only one callback function, the key that matches the target key in the key combination to be intercepted of the target application is determined, and the key is passed into the callback function as a parameter, and the target application is notified through the callback function to process the business processing logic.
[0067] It should be noted that when the key processing type is the application notification type and the application consumption type, the callback method corresponding to the callback function is used to notify the application to process the business processing logic. In this way, the application is notified to process through the callback method, and the business processing logic of the application does not need to be written into the Android system, thereby avoiding the use of services, broadcasts, etc. to process and the loss of Android system performance, thereby realizing the decoupling of the Android system and the application. At the same time, the callback function is used to provide the application with the ability to freely process the keys of interest (keys to be intercepted), which can be understood as the business processing logic of the keys to be intercepted can be set according to the specific application scenario of the specific application.
[0068] In one embodiment, if Figure 3As shown, the above-mentioned step of performing key interception processing on the target key corresponding to the key event according to the target key, key combination and corresponding key processing type, and the business processing logic of the target application includes the following steps.
[0069] 201, a key event occurs and enters handleKeyBforeQueueing.
[0070] 202, detecting whether there is an application program that has set up key interception in the current state.
[0071] This can be understood as a switch. If an application has set up key interception, step 203 is executed; if no application has set up key interception, no special processing is performed and the original system processing flow continues, as shown in step 215.
[0072] 203, determine the target application program. The target application program is determined according to the process status of the application program.
[0073] 204 , determining whether the key processing type is an application notification type.
[0074] Determine whether the key processing type in the key combination to be intercepted of the target application includes an application notification type. If yes, execute step 205; if not, execute step 207.
[0075] 205 , determining whether the key of the application notification type matches the target key.
[0076] If they match, step 206 is executed; if they do not match, step 207 is executed.
[0077] 206, notifying the target application program through the callback function to process the business processing logic, while the target button continues the original system processing flow.
[0078] like Figure 1 and Figure 3 The target application is notified to process the business processing logic through callback (keyEventListener), for example, the target application is notified to light up the screen through callback; at the same time, the original system processing flow of the target key is not interfered with, that is, the target key continues the original system processing flow.
[0079] 207, determining whether the key processing type is an application consumption type.
[0080] Determine whether the key processing type in the key combination to be intercepted of the target application includes an application consumption type. If yes, execute step 208; if not, execute step 211.
[0081] 208 , determining whether the key of the application consumption type matches the target key.
[0082] If they match, then execute step 209 ; if they do not match, then execute step 210 .
[0083] 209, notifying the application program to process the business processing logic through the callback function.
[0084] It should be noted that the business processing logics corresponding to step 206 and step 209 are different.
[0085] 210, intercepting the target key. The target key is intercepted to terminate the original system processing flow of the target key.
[0086] 211, determine whether the key processing type is the only allowed type.
[0087] Determine whether the key processing type in the key combination to be intercepted of the target application includes the only allowed type. If yes, execute step 212; if not, execute step 213.
[0088] 212, determine whether the key of the only allowed type matches the target key.
[0089] If there is a match, the target key is released and the processing flow of the target key is not interfered with. The target key continues the original system processing flow, as shown in step 215; if there is no match, step 210 is executed to intercept the keys in the key combination of the target application that do not match the target key.
[0090] 213, determine whether the key processing type is the interception only type.
[0091] It is determined whether the key processing type in the key combination to be intercepted of the target application includes the interception-only type. If yes, step 214 is executed; if not, step 215 is executed.
[0092] 214, determine whether the key of the interception type only matches the target key.
[0093] If there is a match, then step 210 is executed to intercept the target key and terminate the original system processing flow of the target key. If there is no match, then step 215 is executed to not interfere with the original system processing flow of the target key.
[0094] 215, continue the original system processing flow.
[0095] This embodiment is an implementation of the logic of key interception processing of key events.
[0096] In one embodiment, the key event processing method further includes: the application sets the interception data corresponding to the application through the input management interface. In one embodiment, the application sets the interception data corresponding to the application through the input management interface, specifically as follows Figure 4 Steps 301 to 303 in .
[0097] For details, please see Figure 4 , is another flow chart of the key event processing method provided in the embodiment of the present application. The key event processing method includes the following steps.
[0098] 301, when the application needs to set key interception, the application calls a newly added input management interface, sets the key combination to be intercepted of the application through the input management interface, and determines the key processing type of each key in the key combination.
[0099] The application can set key interception at an appropriate time, for example, when the application process of the application is started or the application enters a certain scene, key interception can be set. When setting key interception, the newly added input management interface is called by the application, and the key combination to be intercepted by the application is set through the input management interface, wherein the key combination includes at least one key to be intercepted, and the key processing type of each key in the key combination is determined. Specifically, the key processing type can refer to the description above. The key processing type of each key in the key combination can be represented by a type identifier, for example, the first type is represented by 1, the second type is represented by 2, the fourth type is represented by 4, etc. It is also possible to directly use text or other characters or other numbers to represent the corresponding key processing type.
[0100] 302, registering the callback function of the application through the input management interface.
[0101] The callback function includes a state detection function of the application process corresponding to the application, and the state detection function is used to detect the process state of the application process. In one embodiment, the callback function also includes the business processing logic of the application.
[0102] The callback function of the application is registered by calling the registered function through the input management interface, such as registerListener. The input parameters of the callback function include keys. In the application, when the callback function needs to be called, the corresponding specific key is passed to the callback function to notify the application to execute the business processing logic in the callback function.
[0103] like Figure 5As shown, when application 1 enters a scene or starts an application process, it calls registerListener to register a callback function. The callback function includes a state detection function of the application process corresponding to the application and the business processing logic of the application. The state detection function is used to detect the process state of the application process.
[0104] 303, sending the identification information of the application, the key combination to be intercepted by the application and the corresponding key processing type, and the callback function to the window manager, and saving them in the window manager, wherein the identification information of the application, the key combination to be intercepted by the application and the corresponding key processing type, and the callback function are used as the interception data of the application.
[0105] The identification information of the application, the key combination to be intercepted by the application and the corresponding key processing type, and the callback function are used as the interception data of the application, and are sent to the window manager through the window management service to be saved in the window manager.
[0106] like Figure 5 As shown, after registering the callback function through registerListener, add the corresponding keyEventListener function.
[0107] The application registers a callback function with the system framework. When a specified key event occurs, the application is notified through the callback function to process the business processing logic.
[0108] 304, when the Android system kernel detects a key event, a target key corresponding to the key event is determined, and a window manager of the Android system is called.
[0109] 305, obtaining interception data of the application program stored in the window manager.
[0110] 306 , performing key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the application program, and the callback function.
[0111] Among them, please refer to the description of the corresponding steps in the above text for steps 304 to 306, which will not be repeated here.
[0112] In one embodiment, the key event processing method further includes the following steps.
[0113] 307, when the application needs to release the key interception, the application calls the newly added input management interface, releases the registration of the corresponding callback function through the input management interface, and deletes the saved interception data of the application.
[0114] The application can cancel the key interception setting at an appropriate time, for example, when the application process of the application exits or the application exits a certain scene, the key interception setting can be canceled.
[0115] In one embodiment, when canceling the key interception setting, specifically includes: the application calls the newly added input management interface, unregisters the corresponding callback function through the input management interface, for example, the callback function can be unregistered through unregisterListener, and the interception data of the application saved in the window manager is deleted. Figure 5 As shown, after the callback function is unregistered through unregisterListener, the corresponding keyEventListener function is removed.
[0116] The application unregisters the callback function from the system framework, and the Android system stops distributing key events to the application.
[0117] In the above embodiments, the application program normally executes the corresponding embodiments. Correspondingly, the setting of key interception and the setting of canceling key interception are implemented by the application program calling the input management interface.
[0118] However, during the execution process, there may be abnormal situations, for example, the application crashes abnormally, resulting in failure to release the key interception in time or failure to cancel the key interception setting in time. Correspondingly, the key event processing method also includes: when the state monitoring function of the application detects that the corresponding process state is an abnormal exit state, the Android system cancels the registration of the callback function of the application and deletes the saved interception data of the application. It should be noted that in this embodiment, the system framework actively cancels the key interception function set by the application, cancels the registered callback function, and deletes the interception data of the application. In this way, it is avoided that the interception data and other information that are not deleted due to the abnormal exit of the application occupy system resources, while ensuring the normal operation of the key interception function.
[0119] In the above embodiment, the application can freely set the interception data of key interception according to its own business needs, and the interception data includes the key combination to be intercepted and the callback function of the application. The callback function can completely decouple the functions of the Android system and the application; the communication between the application process and the system process through the callback method can improve efficiency compared with the previous broadcast notification method; and because of the reduction of frequent attribute reading, topactivity query, etc., the system load can be greatly reduced, the excessive consumption of system resources can be avoided, the system fluency can be improved, the user experience can be improved, and the scalability and maintainability of the Android system can also be improved.
[0120] According to the method described in the above embodiment, this embodiment will be further described from the perspective of a key event processing device. The key event processing device can be implemented as an independent entity or integrated in a terminal.
[0121] See also Figure 6 , Figure 6 The key event processing device provided in the embodiment of the present application is specifically described, which is applied in a terminal, and the terminal includes at least one application. The key event processing device may include: a detection and determination module 401, a data acquisition module 402 and an interception processing module 403.
[0122] The detection and determination module 401 is used to determine the target key corresponding to the key event when the kernel of the terminal system detects a key event, and call the window manager of the system.
[0123] The data acquisition module 402 is used to obtain the interception data of the application saved in the window manager, and the interception data includes the key combination to be intercepted of the application and the callback function corresponding to the application. The interception data is set in advance by the application through the newly added unified input management interface and sent to the window manager for storage.
[0124] The interception processing module 403 is used to perform key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the application and the callback function.
[0125] In one embodiment, the callback function includes a status detection function of an application process corresponding to the application, and the status detection function is used to detect the process status of the application process. Correspondingly, the interception processing module 403 is specifically used to determine the target application according to the process status of the application; according to the target key, the key combination to be intercepted of the target application and the callback function of the target application, the target key corresponding to the key event is subjected to key interception processing.
[0126] In one embodiment, the callback function also includes the business processing logic of the application. Correspondingly, the interception processing module 403, when executing the key interception processing for the target key corresponding to the key event according to the target key, the key combination to be intercepted of the target application and the callback function of the target application, specifically executes: obtaining the key processing type of each key in the key combination to be intercepted of the target application; performing key interception processing on the target key corresponding to the key event according to the target key, the key combination and the corresponding key processing type, and the business processing logic of the target application.
[0127] In one embodiment, when the interception processing module 403 executes the step of performing key interception processing on the target key corresponding to the key event according to the target key, the key combination and the corresponding key processing type, and the business processing logic of the target application, the following is specifically performed: when the key processing type includes an application notification type, and the key of the application notification type matches the target key, the target application is notified through the target application callback function to perform the business processing logic, and the target key continues the original system processing flow; when the key processing type does not include an application notification type but includes an application consumption type, and the key of the application consumption type matches the target key, the target application is notified through the target application callback function to perform the business processing logic. the processing of the processing logic and intercepting the target key; when the key processing type does not include the application notification type and the application consumption type, but includes the third type, if the key of the third type matches the target key, the target key is released, and the target key continues the original system processing flow; if the key of the third type does not match the target key, the keys in the key combination of the target application that do not match the target key are intercepted; when the key processing type does not include the application notification type and the application consumption type, but includes the fourth type, if the key of the fourth type matches the target key, the target key is intercepted; if the key of the fourth type does not match the target key, the keys in the key combination of the target application that do not match the target key continue the original system processing flow.
[0128] In one embodiment, if Figure 6 As shown, the key event processing device also includes a setting module 404. The setting module 404 is used to call a newly added input management interface through the application when the application needs to set key interception, set the key combination to be intercepted of the application through the input management interface, and determine the key processing type of each key in the key combination; register the callback function of the application through the input management interface; send the identification information of the application, the key combination to be intercepted by the application and the corresponding key processing type, and the callback function to the window manager, and save them in the window manager, wherein the identification information of the application, the key combination to be intercepted by the application and the corresponding key processing type, and the callback function are used as the interception data of the application.
[0129] In one embodiment, if Figure 6As shown, the key event processing device also includes a release setting module 405. The release setting module 405 is used for when the application needs to release the key interception, the application calls the newly added input management interface, cancels the registration of the corresponding callback function through the input management interface, and deletes the saved interception data of the application.
[0130] In one embodiment, the release setting module 405 is also used to unregister the callback function of the application through the terminal system and delete the saved interception data of the application when the status detection function of the application detects that the corresponding process status is an abnormal exit state.
[0131] During specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above modules can refer to the previous method embodiments. The specific beneficial effects that can be achieved can also refer to the beneficial effects in the previous method embodiments, which will not be repeated here.
[0132] In addition, the present application embodiment also provides a terminal, such as Figure 7 As shown, the terminal 500 includes a processor 501 and a memory 502. At least one application is installed in the terminal. The processor 501 is electrically connected to the memory 502.
[0133] Processor 501 is the control center of terminal 500, and uses various interfaces and lines to connect various parts of the entire terminal. It executes various functions of the terminal and processes data by running or loading applications stored in memory 502 and calling data stored in memory 502, thereby monitoring the terminal as a whole.
[0134] In this embodiment, the processor 501 in the terminal 500 loads instructions corresponding to the processes of one or more applications into the memory 502 according to the following steps, and the processor 501 runs the application stored in the memory 502, thereby realizing various functions, such as:
[0135] When the kernel of the terminal system detects a key event, the target key corresponding to the key event is determined, and the system's window manager is called; interception data of the application stored in the window manager is obtained, the interception data includes the key combination of the application to be intercepted and the callback function corresponding to the application, the interception data is set by the application in advance through a newly added unified input management interface, and is sent to the window manager for storage; according to the target key, the key combination of the application to be intercepted and the callback function, the target key corresponding to the key event is subjected to key interception processing.
[0136] The terminal can implement the steps in any embodiment of the key event processing method provided in the embodiments of the present application, and therefore can achieve the beneficial effects that can be achieved by any key event processing method provided in the embodiments of the present invention. Please refer to the previous embodiments for details and will not be repeated here.
[0137] Figure 8 The specific structural block diagram of the terminal provided by the embodiment of the present invention is shown, and the terminal can be used to implement the key event processing method provided in the above embodiment. The terminal includes the following modules / units.
[0138] The RF circuit 610 is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, and thus communicate with a communication network or other devices. The RF circuit 610 may include various existing circuit elements for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity module (SIM) cards, memories, etc. The RF circuit 610 can communicate with various networks such as the Internet, corporate intranets, wireless networks, or communicate with other devices through wireless networks. The above-mentioned wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. The above-mentioned wireless networks can use various communication standards, protocols and technologies, including but not limited to Global System for Mobile Communication (GSM), Enhanced Data GSM Environment (EDGE), Wideband Code Division Multiple Access (WCDMA), Code Division Multiple Access (CDMA), Time Division Multiple Access (TDMA), Wireless Fidelity (Wi-Fi) (such as Institute of Electrical and Electronics Engineers standards IEEE802.11a, IEEE 802.11b, IEEE802.11g and / or IEEE 802.11n), Voice over Internet Protocol (VoIP), Worldwide Interoperability for Microwave Access (Wi-Max), other protocols for email, instant messaging and short messages, and any other suitable communication protocols, even those that have not yet been developed.
[0139] The memory 620 can be used to store software programs (computer programs) and modules, such as the corresponding program instructions / modules in the above embodiments. The processor 680 executes various functional applications and data processing by running the software programs and modules stored in the memory 620. The memory 620 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 620 may further include a memory remotely arranged relative to the processor 680, and these remote memories may be connected to the terminal 600 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0140] The input unit 630 can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control. Specifically, the input unit 630 may include a touch-sensitive surface 631 and other input devices 632. The touch-sensitive surface 631, also known as a touch display screen (touch screen) or a touchpad, can collect user touch operations on or near it (such as operations performed by users using fingers, styluses, or any other suitable objects or accessories on or near the touch-sensitive surface 631), and drive corresponding connection devices according to a pre-set program. Optionally, the touch-sensitive surface 631 may include a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into touch point coordinates, and then sends it to the processor 680, and can receive and execute commands sent by the processor 680. In addition, the touch-sensitive surface 631 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch-sensitive surface 631, the input unit 630 may further include other input devices 632. Specifically, the other input devices 632 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, and the like.
[0141] The display unit 640 can be used to display information input by the user or information provided to the user and various graphical user interfaces of the terminal 600, which can be composed of graphics, text, icons, videos and any combination thereof. The display unit 640 may include a display panel 641, and optionally, the display panel 641 may be configured in the form of LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode), etc. Further, the touch-sensitive surface 631 may cover the display panel 641, and when the touch-sensitive surface 631 detects a touch operation on or near it, it is transmitted to the processor 680 to determine the type of the touch event, and then the processor 680 provides corresponding visual output on the display panel 641 according to the type of the touch event. Although in the figure, the touch-sensitive surface 631 and the display panel 641 are implemented as two independent components to implement input and output functions, it can be understood that the touch-sensitive surface 631 is integrated with the display panel 641 to implement input and output functions.
[0142] The terminal 600 may also include at least one sensor 650, such as a light sensor, a direction sensor, a proximity sensor, and other sensors. As a type of motion sensor, the gravity acceleration sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that recognize the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc. As for other sensors that can be configured in the terminal 600, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be described in detail here.
[0143] The audio circuit 660, the speaker 661, and the microphone 662 can provide an audio interface between the user and the terminal 600. The audio circuit 660 can transmit the received audio data to the speaker 661 after converting the received audio data into an electrical signal, which is converted into a sound signal for output by the speaker 661; on the other hand, the microphone 662 converts the collected sound signal into an electrical signal, which is received by the audio circuit 660 and converted into audio data, and then the audio data is processed by the output processor 680 and sent to, for example, another terminal through the RF circuit 610, or the audio data is output to the memory 620 for further processing. The audio circuit 660 may also include an earplug jack to provide communication between an external headset and the terminal 600.
[0144] The terminal 600 can help users receive requests, send information, etc. through a transmission module 670 (such as a Wi-Fi module), which provides users with wireless broadband Internet access. Although the transmission module 670 is shown in the figure, it is understandable that it is not a necessary component of the terminal 600 and can be omitted as needed without changing the essence of the invention.
[0145] The processor 680 is the control center of the terminal 600. It uses various interfaces and lines to connect various parts of the entire mobile phone. It executes various functions of the terminal 600 and processes data by running or executing software programs (computer programs) and / or modules stored in the memory 620, and calling data stored in the memory 620, so as to monitor the terminal as a whole. Optionally, the processor 680 may include one or more processing cores; in some embodiments, the processor 680 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It can be understood that the above-mentioned modem processor may not be integrated into the processor 680.
[0146] The terminal 600 also includes a power supply 690 (such as a battery) for supplying power to various components. In some embodiments, the power supply can be logically connected to the processor 680 through a power management system, so that the power management system can manage charging, discharging, and power consumption management. The power supply 690 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0147] Although not shown, the terminal 600 also includes a camera (such as a front camera, a rear camera), a Bluetooth module, etc., which will not be described in detail here. Specifically in this embodiment, the display unit of the terminal is a touch screen display, and the terminal also includes a memory, and one or more programs (computer programs), wherein one or more programs are stored in the memory and are configured to be executed by one or more processors. One or more programs include instructions for performing the following operations:
[0148] When the kernel of the terminal system detects a key event, the target key corresponding to the key event is determined, and the system's window manager is called; interception data of the application stored in the window manager is obtained, the interception data includes the key combination of the application to be intercepted and the callback function corresponding to the application, the interception data is set by the application in advance through a newly added unified input management interface, and is sent to the window manager for storage; according to the target key, the key combination of the application to be intercepted and the callback function, the target key corresponding to the key event is subjected to key interception processing.
[0149] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above modules can be found in the previous method embodiments, which will not be repeated here.
[0150] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be completed by instructions (computer programs) or by controlling related hardware through instructions, and the instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. To this end, an embodiment of the present invention provides a storage medium in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps of any embodiment of the key event processing method provided in the embodiment of the present invention.
[0151] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0152] Since the instructions stored in the storage medium can execute the steps in any embodiment of the key event processing method provided in the embodiments of the present invention, the beneficial effects that can be achieved by any key event processing method provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0153] The above is a detailed introduction to a key event processing method, device, storage medium and terminal provided in an embodiment of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A key event processing method, characterized in that: Applied in a terminal, wherein at least one application is installed in the terminal, including: When the kernel of the terminal system detects a key event, determining a target key corresponding to the key event, and calling a window manager of the system; Obtaining interception data of the application saved in the window manager, the interception data including a key combination of the application to be intercepted and a callback function corresponding to the application, the interception data is set in advance by the application through a newly added unified input management interface and sent to the window manager for storage; According to the target key, the key combination to be intercepted of the application and the callback function, a key interception process is performed on the target key corresponding to the key event.
2. The key event processing method according to claim 1, characterized in that: The callback function includes a state detection function of an application process corresponding to the application, and the state detection function is used to detect the process state of the application process. The step of performing key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the application and the callback function includes: Determining a target application according to a process state of the application; According to the target key, the key combination to be intercepted of the target application and the callback function of the target application, a key interception process is performed on the target key corresponding to the key event.
3. The key event processing method according to claim 2, characterized in that: The callback function also includes the business processing logic of the application. The step of performing key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the target application and the callback function of the target application includes: Obtaining the key processing type of each key in the key combination to be intercepted of the target application; According to the target key, the key combination and the corresponding key processing type, and the business processing logic of the target application, key interception processing is performed on the target key corresponding to the key event.
4. The key event processing method according to claim 3, characterized in that: The step of performing key interception processing on the target key corresponding to the key event according to the target key, the key combination and the corresponding key processing type, and the business processing logic of the target application comprises: When the key processing type includes an application notification type, and the key of the application notification type matches the target key, the target application is notified through the target application callback function to process the business processing logic, and the target key continues the original system processing flow; When the key processing type does not include the application notification type but includes the application consumption type, and the key of the application consumption type matches the target key, the target application is notified through the target application callback function to process the business processing logic and the target key is intercepted; When the key processing type does not include the application notification type and the application consumption type but includes the third type, if the key of the third type matches the target key, the target key is released and the target key continues the original system processing flow; if the key of the third type does not match the target key, the key in the key combination of the target application that does not match the target key is intercepted; When the key processing type does not include the application notification type and the application consumption type, but includes the fourth type, if the key of the fourth type matches the target key, the target key is intercepted; if the key of the fourth type does not match the target key, the key in the key combination of the target application that does not match the target key continues the original system processing flow.
5. The key event processing method according to claim 1, characterized in that: Also includes: When the application needs to set key interception, the newly added input management interface is called by the application, the key combination to be intercepted of the application is set through the input management interface, and the key processing type of each key in the key combination is determined; Registering a callback function of the application program through the input management interface; The identification information of the application, the key combination to be intercepted by the application and the corresponding key processing type, and the callback function are sent to the window manager and saved in the window manager, wherein the identification information of the application, the key combination to be intercepted by the application and the corresponding key processing type, and the callback function are used as interception data of the application.
6. The key event processing method according to claim 1, characterized in that: Also includes: When the application needs to release the key interception, the application calls the newly added input management interface, releases the registration of the corresponding callback function through the input management interface, and deletes the saved interception data of the application.
7. The key event processing method according to claim 1, characterized in that: The callback function includes a state detection function of an application process corresponding to the application, and the state detection function is used to detect the process state of the application process. The key event processing method also includes: When the state detection function of the application detects that the corresponding process state is an abnormal exit state, the registration of the callback function of the application is released through the terminal system, and the saved interception data of the application is deleted.
8. A key event processing device, characterized in that: Applied in a terminal, wherein at least one application is installed in the terminal, the key event processing device comprises: A detection and determination module, used for determining a target key corresponding to a key event when a kernel of a terminal system detects a key event, and calling a window manager of the system; A data acquisition module, used to acquire interception data of the application program saved in the window manager, wherein the interception data includes a key combination of the application program to be intercepted and a callback function corresponding to the application program, wherein the interception data is set in advance by the application program through a newly added unified input management interface and sent to the window manager for storage; The interception processing module is used to perform key interception processing on the target key corresponding to the key event according to the target key, the key combination to be intercepted of the application and the callback function.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the key event processing method according to any one of claims 1 to 7.
10. A terminal, characterized in that: It comprises a processor and a memory, the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used to execute the steps in the key event processing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Monitoring module, intelligent television system and television
CN102404633A
Method and system for rapidly switching main interfaces in Android system
CN103677587A
Control method and system for key event of mobile terminal
CN106201548A
Touch event processing method, apparatus and terminal device
CN106462351A
Panel key response method, television equipment and computer readable storage medium
CN108153600A
