System service control method, electronic equipment and readable storage medium
By introducing system service management module and reference counting mechanism into electronic devices, system services can be actively stopped, solving the problem of excessive resource occupancy of system services and improving the performance and resource utilization of electronic devices.
Patent Information
- Application Number
- CN202311103510.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-29
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2043-08-29
AI Technical Summary
System services in existing electronic devices occupy a large amount of resources, resulting in stuttering of front-end applications and lack of effective control methods to reduce resource utilization.
By creating nodes corresponding to the system service in the system service management module and establishing a mapping relationship with the service requesting end, the system service can actively request to stop running and release resources. In the specific implementation, the system service sends a stop operation request to the system service management module, and the management module updates the reference count and stops the system service when the count is less than the threshold.
It realizes that the system service will be actively stopped from operating without affecting the service requesting tasks, reduce resource usage, and increase the available resources of electronic devices.
Smart Images

Figure CN119536966A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of system services, and in particular to a system service control method, an electronic device, and a readable storage medium. Background Art
[0002] As the functions of electronic devices continue to increase, the number of system services in electronic devices continues to increase, and system services can provide users with a variety of services. Currently, system services in electronic devices can be resident services. These resident services will occupy a large amount of resources of the electronic device and even cause the application running in the foreground to freeze.
[0003] Currently, there is an urgent need for a method to control the operation of system services and reduce the occupation of electronic equipment resources by system services. Summary of the invention
[0004] The embodiments of the present application provide a method for controlling a system service, an electronic device, and a readable storage medium. The system service can actively request to stop running, release the resources occupied by the system service, and reduce the occupation of electronic device resources by the system service.
[0005] In the first aspect, an embodiment of the present application provides a method for controlling a system service. The execution subject of the method may be an electronic device or a chip in the electronic device. The following description is made by taking an electronic device as an example. The electronic device includes: a system service, a system service management module, and a service request end. The system service management module includes: a first node corresponding to the system service, and a second node corresponding to the service request end, and the first node corresponds to the second node.
[0006] In some embodiments, the service requesting end may be an application in the electronic device.
[0007] It should be understood that in the process of the service request end sending a request to the system service to use the system service, the system service management module can create a first node corresponding to the system service and a second node corresponding to the service request end in the system service management module, and establish a mapping relationship between the first node and the second node, that is, the first node corresponds to the second node. The correspondence between the first node and the second node can indicate that the service request end corresponding to the second node requests the system service corresponding to the first node.
[0008] The electronic device may run a service process, the system service may run in the service process, and at least one system service may run in the service process. In some embodiments, at least two system services may run in the service process, and the scenario is: multiple system services run in the same service process. Whether it is a scenario where multiple system services run in the same service process, or a scenario where one system service runs in one service process, in the embodiments of the present application, the system service may actively request to stop running.
[0009] In the method, the system service may send a stop operation request to the system service management module. In response to the stop operation request, the system service management module determines the first node corresponding to the system service, and the second node corresponding to the first node. The system service management module may delete the second node, and the system service management module may update the reference count of the first node according to the number of deleted second nodes. Because the first node corresponds to the system service, the system service can update the reference count of the system service according to the reference count of the first node, and stop running when the reference count of the system service is less than the count threshold.
[0010] Among them, each time a service request end requests to use (or reference) the system service, the reference count of the system service can be increased by 1. Similarly, the system service management module deletes the second node, indicating that the number of service request ends requesting to use the system service is reduced. Therefore, the system service management module can update the reference count of the first node according to the number of deleted second nodes, and the system service can also update the reference count of the system service. When the reference count of the system service is less than the counting threshold, it indicates that the service request end has ended the reference to the system service, and the system service can stop running. Exemplarily, for example, the counting threshold can be 1.
[0011] In the embodiment of the present application, the system service can actively request to stop running, and the system service management module can release the system service. In the embodiment of the present application, when multiple system services (i.e., system services) or one system service are running in a service process, and when the service process is not stopped, any of the system services can actively stop running, which can reduce the occupation of electronic device resources by the system service and increase the available resources of the electronic device.
[0012] In a possible implementation, when all service requesting ends terminate the reference to the system service, the system service may send a stop operation request to the system service management module. When all service requesting ends terminate the reference to the system service, it indicates that no service requesting end currently references the system service provided by the system service, so the system service may request to stop running, which will not affect the tasks performed by the service requesting end and avoid task abnormalities of the service requesting end. Exemplarily, there are multiple service requesting ends that reference the system service, and when the multiple service requesting ends terminate the reference to the system service, the system service may send a stop operation request to the system service management module.
[0013] In a possible implementation, the system service can send a stop operation request to the system service management module when the system service determines not to perform the task according to the characteristics of the task it performs. When the system service does not perform the task, that is, no service request end currently uses the system service provided by the system service, so the system service can request to stop running, and can also avoid task abnormality of the service request end.
[0014] Exemplarily, the system service is an upgrade system service. If the upgrade system service completes the upgrade task, the upgrade system service determines that the upgrade task will not be performed in a short time, so the upgrade system service can request to stop running. The upgrade task may include, but is not limited to, system version upgrade, system application version upgrade, etc.
[0015] Exemplarily, the system service is a Bluetooth system service. When the Bluetooth system service determines that the Bluetooth switch of the electronic device is turned off, or the electronic device has not established a Bluetooth connection with other electronic devices, the Bluetooth system service determines that the task is not to be performed, so the Bluetooth system service can request to stop running. For example, the user can operate the Bluetooth switch or Bluetooth control of the electronic device to turn off the Bluetooth switch of the electronic device, enabling the electronic device to turn off the Bluetooth communication function.
[0016] Exemplarily, the system service is a Wi-Fi system service. When the Wi-Fi system service determines that the Wi-Fi switch of the electronic device is turned off, or the electronic device has not established a Wi-Fi connection with other electronic devices, the Wi-Fi system service determines that the task is not to be performed, so the Wi-Fi system service can request to stop running. For example, the user can operate the Wi-Fi switch or Wi-Fi control of the electronic device to turn off the Wi-Fi switch of the electronic device, enabling the electronic device to turn off the Wi-Fi function.
[0017] Exemplarily, the system service is a system service for providing distributed services, and when the system service determines that the communication switch of the electronic device is turned off, or the electronic device has not established a communication connection with other electronic devices, the system service determines not to perform the task. Exemplarily, the distributed service may include any of the following: a distributed camera, a distributed clipboard, a distributed gallery, and a distributed drawing board. Among them, for example, the user can operate the communication switch of the electronic device to turn off the communication switch. The communication switch may include but is not limited to a Wi-Fi switch, a Bluetooth switch, a mobile cellular network switch, etc., to enable the electronic device to turn off functions with other electronic devices.
[0018] In some embodiments, taking a distributed camera as an example, an electronic device may include a distributed camera application. When the distributed camera application is running, it may call a distributed camera system service to implement the functions of the distributed camera application.
[0019] It should be understood that different types of system services have different conditions for determining not to execute a task. In some embodiments, the trigger conditions for each system service to determine not to execute a task can be pre-set. The system service can detect whether to execute the task based on its own trigger conditions. When the system service determines not to execute the task, the system service can send a stop request to the Binder driver.
[0020] In this implementation, the system service can actively request to stop running when it determines that the service request end has ended the reference to the system service, or when the system service determines not to perform the task based on its own task characteristics. This does not affect the normal execution of the system service's tasks and can also increase the available resources of the electronic device.
[0021] In a possible implementation, when the electronic device uses inter-process communication (IPC) technology to implement cross-process communication, the system service management module includes: Binder driver.
[0022] The system service may send the stop request to the Binder driver. The Binder driver determines the first node corresponding to the system service, and determines the second node corresponding to the first node according to the association relationship between the first node and the second node. Exemplarily, the Binder driver may store the association relationship between the first node and the second node in a data structure such as a red-black tree, a map linked list, or an array.
[0023] In some embodiments, when the Binder driver stores the association relationship between the first node and the second node in a red-black tree, the red-black tree may store information about the first node, and the information about the first node may include the second node corresponding to the first node. The first node corresponds to the second node, which can be understood as the system service corresponding to the second node referencing the system service corresponding to the first node.
[0024] The Binder driver can delete the second node, and the Binder driver updates the reference count of the first node according to the number of the second nodes deleted. In an embodiment of the present application, exemplarily, the Binder driver reduces the reference count of the first node according to the number of the second nodes deleted. It should be understood that in the Binder driver, the first node corresponds to the system service. The reference count of the first node can characterize the reference count of the system service, that is, the number of service request terminals that reference (or use) the system service can be characterized.
[0025] After the Binder driver updates the reference count of the first node, a reference count update indication may be sent to the system service, where the reference count update indication is used to indicate the amount by which the reference count of the system service is reduced. In response to the reference count update indication, the system service updates the reference count of the system service. When the reference count of the system service is less than the count threshold, the system service stops running and calls a stop function to release the resources occupied by the system service.
[0026] In some embodiments, the counting threshold may be 1. In an embodiment of the present application, when the reference count of the system service is 0, the system service stops running and calls a stop function to release the resources occupied by the system service.
[0027] In some embodiments, the system service management module can release the system service, which can be understood as: the system service management module can release the resources occupied by the system service. Resources may include but are not limited to: memory resources, central processing unit CPU resources, network resources,
[0028] In a possible implementation, after the Binder driver updates the reference count of the first node according to the number of deleted second nodes, when the reference count of the first node is less than the count threshold, the Binder driver may delete the first node.
[0029] In some embodiments, the counting threshold may be 1. In an embodiment of the present application, after the Binder driver updates the reference count of the first node according to the number of deleted second nodes, when the reference count of the first node is 0, the Binder driver may delete the first node.
[0030] In a possible implementation, the Binder driver may determine the first node corresponding to the system service and the second node corresponding to the first node in response to a request from the system service to stop running. After the Binder driver determines the second node corresponding to the first node, the Binder driver may send a notification message to the service request end, and the notification message is used to indicate that the system service request stops running. The service request end may release the second node. In some embodiments, the service request end may call a release function to release the resources occupied by the second node.
[0031] In this implementation, the Binder driver can synchronize the system service request to the service request end to stop running, so that the service request end can perceive that the system service has stopped running, and the service request end can perform corresponding operations to avoid task abnormalities of the service request end.
[0032] In a possible implementation, the Binder driver may not synchronize the system service request to the service request end to stop running, so that the service request end may not be aware of the system service stopping running. This implementation method can be applied to the following scenarios to avoid task exceptions on the service request end:
[0033] First, the service request end is configured to reacquire the handle of the system service each time the system service is used. In this way, even if the system service stops running, the next time the service request end uses the system service, the handle of the system service will be reacquired, and the service request end will use the system service to execute the task, which can ensure the smooth execution of the task.
[0034] Secondly, the service request end may register a monitoring service in the system capability manager SAMgr in advance to monitor the system service stopping operation. Exemplarily, the service request end registers a monitoring service with the SAMgr, and the monitoring service is used to monitor the system service stopping operation. After the SAMgr releases the system service, the SAMgr sends a notification message to the service request end that the system service stops operating.
[0035] In this way, although the Binder driver did not notify the service requester using the system service when the system service actively requested to stop running, the service requester can use SAMgr to determine that the system service has stopped running, enabling the service requester to re-acquire the handle the next time the system service is used. Therefore, even if the Binder driver does not notify the service requester using the system service, it will not affect the execution of the service requester's tasks.
[0036] In some embodiments, the Binder driver may determine the first node corresponding to the service provider and the second node corresponding to the first node in response to a request from the service provider to stop running. After the Binder driver determines the second node corresponding to the first node, the Binder driver may send a notification message to the SAMgr, and the notification message is used to indicate that the service provider requests to stop running. The SAMgr may release the second node. In some embodiments, the SAMgr may call a release function to release the resources occupied by the second node.
[0037] In one possible implementation, a first interface is deployed in the electronic device, and the system service calls the first interface to send the stop operation request to the Binder driver. In one possible implementation, a second interface is deployed in the electronic device, and the Binder driver instructs the second node to call the second interface and send a notification message to the service request end.
[0038] In some embodiments, the first interface and the second interface may be deployed at a system service layer of the electronic device, or deployed between a user space and a kernel space.
[0039] In a second aspect, an embodiment of the present application provides an electronic device, which may include: a processor and a memory. The memory is used to store computer executable program code, and the program code includes instructions; when the processor executes the instructions, the instructions cause the electronic device to execute the method in the first aspect.
[0040] In a third aspect, an embodiment of the present application provides an electronic device, which may include a unit, a module or a circuit for executing the method provided in the first aspect above.
[0041] In a fourth aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method in the first aspect.
[0042] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is run on a computer, the computer executes the method in the first aspect above.
[0043] In a sixth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the processor can execute the method in the above-mentioned first aspect using the communication interface.
[0044] The beneficial effects of the possible implementation methods of the second to sixth aspects mentioned above can be referred to the beneficial effects brought about by the first aspect mentioned above, and will not be elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 A schematic diagram of cross-process communication;
[0046] Figure 2 A flowchart of a method for controlling a system service according to an embodiment of the present application;
[0047] Figure 3 A flowchart of a method for controlling system services of another embodiment provided in an embodiment of the present application;
[0048] Figure 4 A flowchart of a method for controlling system services of another embodiment provided in an embodiment of the present application;
[0049] Figure 5 A flowchart of a method for controlling system services of another embodiment provided in an embodiment of the present application;
[0050] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] For ease of understanding, the following first introduces the relevant terms and concepts involved in the embodiments of the present application:
[0052] System capabilities (Sa): can be understood as system programs that provide specific functions and services. Exemplarily, system capabilities may include: system capabilities for monitoring the use of system resources, system capabilities for providing network services, system capabilities for managing files, and system capabilities for providing security protection.
[0053] Exemplarily, the usage of system resources may be, for example, the usage of a central processing unit (CPU), the usage of memory, the usage of disk space, etc. System services for providing network services may be, for example, Bluetooth services, Wi-Fi services, etc. Management files may be, for example, backup files, compressed files, encrypted files, etc. Security protection may include, for example, antivirus, firewall, and intrusion detection, etc. The embodiments of the present application do not limit system services.
[0054] In some embodiments, various types of system services can be deployed in electronic devices. Exemplarily, taking Android as an example, the Android system service provides a Java interface and a native interface for applications (APP) in electronic devices to call system services. Based on the implementation language of the system service, the system service can be divided into Java system services and native system services. The control method of the system service provided in the embodiment of the present application can be applied to native system services, Java system services, and other types of system services. In some embodiments, the local interface can be called a native interface.
[0055] Resident: Currently, the system service can be a resident service, which can be understood as the system service always running in the memory during the operation of the electronic device, even if the system service has completed the task, the system service still runs in the memory. In some embodiments, the system service can run in the background.
[0056] In some embodiments, some system services may not be resident services, and these system services can run in memory when needed. For example, for a distributed camera service, when an electronic device is networked with another electronic device, the electronic device runs the distributed camera service, and then the distributed camera service runs in memory. It should be understood that whether the system service is a resident service or not, it can be applied to the control method of the system service provided in the embodiment of the present application.
[0057] Process: is the basic unit of dynamic execution of the operating system, and system services can run in a process. In some embodiments, the process running the system service can be called a service process, and the following embodiments are described by taking "process" as an example.
[0058] In some embodiments, at least one system service can be run in a process. For example, taking Android as an example, a native system service can be run in a native daemon process. For example, system services such as media player service mediaplayerservice, camera service cameraservice, and audio service audioflinger can be run in a local daemon process.
[0059] Handle: A special smart pointer. For example, when an APP wants to reference a memory block or object managed by another system (such as a database or operating system), it needs to obtain the handle of the memory block or object. In some embodiments, the APP's reference to a memory block or object managed by another system can be understood as the APP's use of a memory block or object managed by another system.
[0060] The electronic device in the embodiment of the present application is a device deployed with system services, and the electronic device can be called user equipment (UE), terminal, etc. For example, the electronic device can be a mobile phone, a tablet, a personal digital assistant (PDA), a handheld device with wireless communication function, a computing device, a vehicle-mounted device or a wearable device, a virtual reality (VR) terminal device, an augmented reality (AR) terminal device, a wireless terminal in industrial control, a wireless terminal in a smart home, etc. The form of the electronic device is not specifically limited in the embodiment of the present application.
[0061] As the functions of electronic devices continue to increase, the number of system services in electronic devices continues to increase. Currently, a large number of system services run in the background, which will occupy a large amount of resources of electronic devices. Even the background process where the system service is located will seize the resources of the application process running in the foreground, causing the application running in the foreground to freeze. Among them, the resources of electronic devices may include but are not limited to: memory resources, CPU resources, network resources, input and output (IO) resources, etc.
[0062] Currently, there is no mechanism in electronic devices for system services to actively stop running when the system services complete their tasks.
[0063] In some embodiments, from the perspective of the Android operating system, a control mechanism for Java system services is designed. For example, an APP in an electronic device can bind a Java system service by calling a bindService function, indicating that the APP can use the Java system service, and the APP can unbind the Java system service by calling an unbindService function, indicating that the APP stops using the Java system service. In some embodiments, using a system service can also be referred to as referencing a system service or calling a system service.
[0064] The activity manager service (AMS) can be used to manage Java system services. When an APP calls the bindService function to bind a Java system service, AMS can determine that there is an APP that references the Java system service and can increase the reference count of the Java system service by 1. When another APP calls the bindService function to bind the Java system service, AMS can increase the reference count of the Java system service by 1. When an APP calls the unbindService function to unbind the Java system service, AMS can reduce the reference count of the Java system service by 1. In this way, AMS can update the reference count of the Java system service based on the binding and unbinding operations of the APP.
[0065] When the reference count of a Java system service is 0, AMS can adjust the adj value of the process where the Java system service is located. The adj value of a process can represent the priority of the process. Exemplarily, when the reference count of the Java system service is 0, AMS can increase the adj value of the process where the Java system service is located to lower the priority of the process. In this example, when the memory of the electronic device is less than the memory threshold, AMS can kill the low-priority process.
[0066] As in the above example, if the APP always holds the handle of the Java system service, the reference count of the Java system service is not 0, and AMS cannot handle the process where the Java system service is located and the Java system service. In addition, AMS manages the Java system service by killing the process where the Java system service is located. When multiple Java system services are running in the process, AMS cannot control a Java system service to stop running alone.
[0067] In some embodiments, the life cycle of a system service is related to the process in which the system service is located. When the process in which the system service is located dies, the system service running in the process can stop running, and the electronic device can release the resources occupied by these system services. The process in which the system service is located can be understood as the process in which the system service is running.
[0068] Exemplarily, the three system services of media playback service, camera service, and audio service run in one process, which can be a local daemon process. At present, when any of the system services of media playback service, camera service, and audio service completes its task, the system service will not stop running, and the system service will still run in the memory, occupying the resources of the electronic device. In some embodiments, when the local daemon process is destroyed due to an operation error, or the local daemon process is forcibly killed, the life cycle of the three system services of media playback service, camera service, and audio service ends, and the three system services can stop running.
[0069] In some embodiments, a process stop condition can also be preset, for example, the condition can be that a preset property of the electronic device reaches a set value. The electronic device can start a property monitoring mechanism, and when the process meets the stop condition, the electronic device can stop the process, the system services running in the process can stop running, and the electronic device can release the resources occupied by these system services.
[0070] In the above system service control method, when multiple system services are running in one process, the system services depend on the process to die or stop. When the process dies or stops, the system services in the process stop running. The electronic device cannot control the operation of a system service alone.
[0071] In order to facilitate the electronic device to control the operation of each system service separately, in some embodiments, a solution of "one system service running in one process" can be designed. In this way, when the system service completes its task, the electronic device can kill the process where the system service is located, and the system service can stop running. However, there are many system services in the electronic device, and one system service running in one process will result in an increase in the number of processes started simultaneously by the electronic device, resulting in high power consumption.
[0072] In response to the above problems, each embodiment of the present application provides a method for controlling system services. When at least one system service is running in a process, any system service in the process can be controlled to stop running without the process dying or stopping, thereby releasing the resources occupied by the system service. On the one hand, it is possible to achieve control of a system service alone, and on the other hand, it is possible to reduce the occupation of resources of the electronic device by the system service, thereby improving the operating speed of the system of the electronic device. It should be understood that in the embodiments of the present application, "Sa" is used as the English abbreviation of the system service for explanation.
[0073] In order to better understand the control method of the system service provided by this application, the principle of cross-process communication is briefly introduced first:
[0074] Because each process has its own independent resources, other processes cannot access the resources of different processes at will, so different processes cannot communicate directly, which gives rise to cross-process communication technology. At present, both interprocess communication (IPC) technology and remote procedure call (RPC) technology can be used to achieve cross-process communication. The difference is that IPC technology uses Binder driver and can be used for cross-process communication within the device, while RPC technology uses soft bus driver and can be used for cross-process communication across devices.
[0075] In some embodiments, the electronic device may use IPC technology, RPC technology or other communication technologies to implement cross-process communication within the device. The following embodiments are described using an electronic device using IPC technology to implement cross-process communication within the device as an example.
[0076] Figure 1 This is a schematic diagram of cross-process communication. Figure 1 In some embodiments, the electronic device may include at least one service requester and at least one service provider. Figure 1 A service request end and a service provider end are used as examples for explanation.
[0077] In some embodiments, when the electronic device uses IPC technology, the driver in the electronic device may be a Binder driver. When the electronic device uses RPC technology, the driver in the electronic device may be a soft bus. Figure 1 The driver is a Binder driver as an example.
[0078] In some embodiments, the service provider can be regarded as a Binder service process, and the service requester can be regarded as a Binder client process. The Binder service process is responsible for processing requests from the Binder client process, and the Binder client process can call the service running in the Binder service process through the interface provided by the Binder driver.
[0079] At least one system service can be run in the Binder service process. In other words, the service provider can provide at least one system service. For example, the three system services, media playback service, camera service, and audio service, run in one process, which can be a local daemon process. The local daemon process can be regarded as the service provider, and the media playback service, camera service, and audio service can be regarded as system services provided by the service provider.
[0080] The service request end may request to call a system service. For example, the service request end may be an APP in an electronic device. The APP may include but is not limited to a third-party application and a system application.
[0081] In some embodiments, the service request end, the service provider end, and the SAMgr may be located in the user space of the electronic device, and the Binder driver may be located in the kernel space of the electronic device.
[0082] In some embodiments, reference Figure 1 , the process of the service requester using the system service provided by the service requester may include:
[0083] Step 1. Register.
[0084] System services can be registered in SAMgr first. In some embodiments, system services can be registered in SAMgr by calling addSystemAbility function after the process (such as Binder service process) where the system service is located is started.
[0085] SAMgr is responsible for managing these system services and providing relevant interfaces to the service requester.
[0086] Step 2: Request.
[0087] If the service requester wants to use a system service in the service provider, it can send a request to the Binder driver.
[0088] The Binder driver responds to the request from the service requester and can communicate with the service provider requested by the service requester.
[0089] In step 2, the Binder driver responds to the request from the service request end, and the Binder driver can send the request to the system service running in the service provider end. Exemplarily, for example, the request can request the CPU usage and the memory usage. Correspondingly, the system service can be a system service for providing a system resource usage monitoring service.
[0090] The system service can process the received request and execute the task. For example, a system service for monitoring the usage of system resources is provided, and in response to a request from a Binder driver, the CPU usage and memory usage can be obtained.
[0091] Step 3: Feedback the task completion results.
[0092] After the system service completes the task, the service provider can return the task completion result to the service requester through the Binder driver. For example, the task completion result may include: CPU usage and memory usage.
[0093] It should be noted that Figure 1 The dotted lines in the figure represent the interaction between the service request end, the service provider end, and the SAMgr. In fact, the interaction between the service request end, the service provider end, and the SAMgr is based on the Binder driver for communication.
[0094] In some embodiments, an interface can be set, which can be, for example, an ioctl interface. The service requester, service provider, and SAMgr can call the ioctl interface to communicate with the Binder driver, thereby realizing interaction between the service requester, service provider, and SAMgr.
[0095] The embodiment of the present application does not elaborate on the process of the service request end using the system service provided by the service request end, and the principle of cross-process communication. For details, please refer to the description of the current cross-process communication principle.
[0096] In some embodiments, inter-process communication interfaces may be deployed on the Binder driver, and the service request end may implement communication with the service provider end by calling these interfaces.
[0097] The following describes the data structure in the Binder driver:
[0098] In some embodiments, the Binder driver may include a Binder entity object and a Binder reference object.
[0099] Binder entity object: Each system service corresponds to a Binder entity object in the Binder driver, and the Binder entity object can be called a Binder_node. In other words, the Binder driver includes a Binder entity object corresponding to each system service. In some embodiments, the Binder entity object can be called a first node.
[0100] Reference Figure 1 , Figure 1 In the example, three system services are run in a Binder service process. Accordingly, each system service corresponds to a Binder entity object, and the Binder service process (service provider) can correspond to three Binder entity objects. In the Binder driver, three Binder entity objects corresponding to the Binder service process can be included.
[0101] Binder reference object: Each service request end corresponds to a Binder reference object in the Binder driver. The Binder reference object can be called Binder_ref, where ref is the abbreviation of reference. In some embodiments, the Binder reference object can be called a second node.
[0102] In some embodiments, the Binder driver can create a Binder entity object corresponding to each system service. In some embodiments, when a service requester requests to use a certain system service, the Binder driver can create a Binder reference object for the service requester, and correspond the Binder reference object of the service requester to the Binder entity object of the system service it uses. Exemplarily, the Binder driver can store the correspondence between the Binder reference object of the service requester and the Binder entity object of the system service it uses.
[0103] Reference Figure 1 , taking an APP as an example, the Binder driver may include the Binder reference object corresponding to the APP. Taking the APP referencing a system service in the Binder service process as an example, in the Binder driver, the Binder entity object of the system service may correspond to the Binder reference object of the APP. Exemplary, Figure 1 The Binder entity object and the Binder reference object are connected in the APP, and the Binder entity object representing the system service can correspond to the Binder reference object of the APP.
[0104] In some embodiments, a Binder reference object may correspond to at least one Binder entity object. Exemplarily, an APP may use at least one system service, and the Binder reference object of the APP in the Binder driver may correspond to the Binder entity object of the at least one system service in the Binder driver. For example, when a navigation APP is running, it may use system service 1 for providing positioning and system service 2 for playing audio. For example, system service 1 corresponds to Binder entity object 1, system service 2 corresponds to Binder entity object 2, and a navigation APP corresponds to Binder reference object 1. In the Binder driver, the Binder reference object 1 may correspond to Binder entity object 1 and Binder entity object 2.
[0105] In some embodiments, a Binder entity object may correspond to at least one Binder reference object. Exemplarily, a system service may be used by multiple apps at the same time, and the Binder entity object of the system service in the Binder driver may correspond to the Binder reference objects of the multiple apps in the Binder driver. For example, both navigation apps and video playback apps use system service 1 for providing positioning, system service 1 corresponds to Binder entity object 1, navigation apps correspond to Binder reference object 1, and video playback apps correspond to Binder reference object 2. Then, in the Binder driver, Binder entity object 1 may correspond to Binder reference object 1 and Binder reference object 2.
[0106] The following describes the control method of the system service provided by the embodiment of the present application in conjunction with specific embodiments. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0107] Figure 2 A flowchart of a method for controlling system services provided in an embodiment of the present application. Figure 2 The control method of the system service provided in the embodiment of the present application may include:
[0108] S201, the system service sends a stop request to the Binder driver.
[0109] In some embodiments, a first interface may be deployed in an electronic device, and a system service may call the first interface to send a stop operation request to a Binder driver. Exemplarily, the first interface may be a function interface, for example, a system service may call a ReleaseSa function to send a stop operation request to a Binder driver through the first interface. In some embodiments, the first interface may be deployed in a system service layer of an electronic device. In some embodiments, the first interface may be deployed between a user space and a kernel space of an electronic device. In some embodiments, the first interface may be deployed on a Binder driver.
[0110] In some embodiments, when the service requesting ends all end the reference to the system service, the system service may send a stop request to the Binder driver.
[0111] When the service request end references the system service, the service request end can send a request to the system service (or the service provider to which the system service belongs) through the Binder driver. Figure 1 When the service request end ends the reference to the system service, the system service can send a stop request to the Binder driver.
[0112] In some embodiments, the service request end can send a request to the system service through the Binder driver. In this example, because the service request end references the system service, the system service can perform the task requested by the first service request end. When the system service completes the task, if the service request end ends the reference to the system service, the system service can send a stop operation request to the Binder driver.
[0113] In some embodiments, in some embodiments, the service request end ends the reference to the system service, which can be understood as no service request end references the system service. When the system service completes the task, if there is no service request end using the system service within the preset time, the system service can send a stop operation request to the Binder driver. Among them, the preset time can give the system service a buffer for a period of time, so as to avoid the problem of frequent switching between stopping and starting the system service when there is another service request end requesting to use the system service in a short period of time.
[0114] In some embodiments, SAMgr can manage system services. When a service requester requests to use a system service, SAMgr can count the number of references to the system service to obtain a reference count of the system service. For each additional service requester request to use a system service, SAMgr can increase the reference count of the system service by 1. Whenever a service requester stops using a system service, SAMgr can reduce the reference count of the system service by 1.
[0115] In an embodiment of the present application, the system service may obtain a reference count of the system service stored in the SAMgr. When the reference count of the system service is 0, the system service may send a stop request to the Binder driver.
[0116] In some embodiments, the system service can manage its own reference count. For each additional service request end requesting to use the system service, the system service can increase the reference count of the system service by 1. Whenever a service request end stops using the system service, the system service can decrease the reference count of the system service by 1.
[0117] In the embodiment of the present application, the system service can determine its own reference count. When the reference count of the system service is 0, the system service can send a stop operation request to the Binder driver.
[0118] In some embodiments, for example, the service request end does not actually need to request the system service to perform a task, but because of application startup settings and other reasons, once the service request end is started, the service request end will obtain the handle of the system service and send a request to the system service. In these examples, the service request end does not actually use the system service, but there may be a situation where the service request end requests to use the system service. For this type of situation, if the system service does not perform the task, it will not affect the normal operation of the service request end. If the system service is still running in the memory, it will also occupy the resources of the electronic device.
[0119] Here is an example of this scenario: For example, when an audio app is started, it will send a request to the media player service through the Binder driver to request to use the system service. But in fact, when the audio app plays audio, it will actually use the media player service to play audio. Therefore, when the audio app starts, it holds the handle of the media player service, which will make the media player service think that there is always a service request end using the media player service. The media player service will always run in memory, occupying system resources.
[0120] Therefore, in order to solve this problem, in some embodiments, the system service can send a stop operation request to the Binder driver when it is determined not to execute the task based on its own task characteristics.
[0121] Exemplarily, the system service is, for example, a system service for providing version upgrades. In some embodiments, the system service for providing version upgrades may be referred to as an upgrade system service. After completing the version upgrade task, the upgrade system service may determine that there is no need to perform the version upgrade task for a period of time, and the upgrade system service may send a stop operation request to the Binder driver. It should be understood that version upgrades may include but are not limited to system version upgrades, system APP version upgrades, etc. In some embodiments, system version upgrades may also be referred to as whole machine version upgrades.
[0122] Exemplarily, the system service is, for example, a system service for providing Bluetooth communication. In some embodiments, the system service for providing Bluetooth communication may be referred to as a Bluetooth system service. For example, when the Bluetooth system service determines that the Bluetooth switch of the electronic device is turned off, the Bluetooth system service determines that there is no need to perform the Bluetooth communication task, so the Bluetooth system service may send a stop operation request to the Binder driver. Among them, the user may turn off the Bluetooth switch of the electronic device, for example, the user may include a Bluetooth control or a Bluetooth switch in a drop-down menu on the desktop of the electronic device. Taking the Bluetooth switch as an example, the user may operate the Bluetooth switch to turn off the Bluetooth switch of the electronic device, and accordingly, the electronic device may turn off the Bluetooth communication function. In this example, for example, the service request end holds the handle of the system service at startup, but the system service determines that the user has turned off the Bluetooth function of the electronic device based on its own task characteristics, and in fact no service request end will use the Bluetooth system service, so the system service may send a stop operation request to the Binder driver.
[0123] For example, for Bluetooth system services, although the Bluetooth switch of an electronic device is turned on, the electronic device has no Bluetooth connection with other electronic devices. In this case, no service requester will actually use the Bluetooth system service, so the Bluetooth system service can send a stop request to the Binder driver.
[0124] Exemplarily, the system service is, for example, a system service for providing Wi-Fi communication. In some embodiments, the system service for providing Wi-Fi communication may be referred to as a Wi-Fi system service. For example, when the Bluetooth system service determines that the Wi-Fi switch of the electronic device is turned off, the Wi-Fi system service determines that there is no need to perform the Wi-Fi communication task, so the Wi-Fi system service may send a stop operation request to the Binder driver. Among them, the way in which the user turns off the Wi-Fi switch of the electronic device can refer to the relevant description of the Bluetooth switch. In this example, for example, the service request end holds the handle of the system service at startup, but the system service determines that the Wi-Fi switch of the electronic device is turned off based on its own task characteristics. In fact, no service request end will use the Wi-Fi system service, so the system service can send a stop operation request to the Binder driver.
[0125] Similarly, for Wi-Fi system services, for example, although the Wi-Fi switch of an electronic device is on, the electronic device has no Wi-Fi connection with other electronic devices. In fact, no service requester will use the Wi-Fi system service, so the Wi-Fi system service can send a stop request to the Binder driver.
[0126] Exemplarily, the system service is, for example, a system service for providing distributed services, and the distributed services may include, but are not limited to: a distributed camera, a distributed clipboard, a distributed gallery, a distributed drawing board, etc. In some embodiments, taking a distributed camera as an example, for example, an electronic device may include a distributed camera application, and when the distributed camera application is running, the distributed camera system service may be called to implement the functions of the distributed camera application.
[0127] Because distributed services require multiple electronic devices to be networked to be implemented, the networking methods may include but are not limited to Wi-Fi networking, Bluetooth networking, etc. In this example, for example, the communication switch of the electronic device has been turned off, the electronic device cannot connect to other electronic devices, and the electronic device determines that it does not need to perform tasks related to distributed services. The system service for providing distributed services can send a stop request to the Binder driver. Exemplarily, the communication switch may include but is not limited to: a Bluetooth switch, a Wi-Fi switch, and a mobile cellular network switch, etc. The method of turning off the communication switch can refer to the relevant description of the Bluetooth switch.
[0128] In addition, for example, although the user turns on the communication switch of the electronic device, the electronic device is not actually connected to other electronic devices for communication and does not actually perform tasks related to distributed services. Therefore, the system service for providing distributed services can send a stop request to the Binder driver.
[0129] In some embodiments, the trigger conditions for each system service to determine not to perform a task can be pre-set. The system service can detect whether to perform the task based on its own trigger conditions. When the system service determines not to perform the task, the system service can send a stop operation request to the Binder driver. Exemplarily, the trigger condition for the upgrade system service to determine not to perform a task can be: completing the upgrade task. For example, the trigger condition for the Bluetooth system service to determine not to perform a task can be: the Bluetooth switch of the electronic device is turned off, or the electronic device has not established a Bluetooth connection with other electronic devices. For example, the trigger condition for the Wi-Fi system service to determine not to perform a task can be: the Wi-Fi switch of the electronic device is turned off, or the electronic device has not established a Wi-Fi connection with other electronic devices.
[0130] S202: The Binder driver determines a first node corresponding to the system service and a second node corresponding to the first node.
[0131] In some embodiments, the Binder driver may store a first node corresponding to the system service, such as a Binder entity object. The Binder driver may also store a second node corresponding to the first node. In response to a stop request from the system service, the Binder driver may determine the first node corresponding to the system service and the second node corresponding to the first node in the Binder driver.
[0132] In some embodiments, the Binder driver may store an association relationship between a first node and a second node, and the association relationship between the first node and the second node is used to indicate the second node corresponding to the first node. In some embodiments, the Binder driver may store the association relationship between the first node and the second node in a data structure such as a red-black tree, a mapping list, an array, etc.
[0133] In some embodiments, when the Binder driver stores the association relationship between the first node and the second node in the red-black tree, the red-black tree may store information of the first node corresponding to the system service.
[0134] In some embodiments, the information of the first node may include: information of the second node corresponding to the first node, and the information of the second node may include the identifier of the second node and the creation time of the second node, etc., which is not limited in this embodiment of the present application.
[0135] In some embodiments, the information of the first node may include: information of the second node corresponding to the first node, and reference count information of the first node. Among them, the reference count information of the first node may include the reference count of the first node, and the reference count of the first node may be the same as the reference count of the system service. For example, for each additional second node corresponding to the first node, the Binder driver may increase the reference count of the first node by 1. Whenever a service request end releases the second node corresponding to the first node, the Binder driver may reduce the reference count of the first node by 1.
[0136] Among them, the Binder driver can determine the second node corresponding to the first node according to the information of the first node in the red-black tree.
[0137] S203: The Binder driver deletes the second node.
[0138] Exemplarily, Binder entity object 1 may correspond to Binder reference object 1 and Binder reference object 2, Binder entity object 1 may serve as a first node, Binder reference object 1 and Binder reference object 2 may both serve as second nodes, and the Binder driver may delete Binder reference object 1 and Binder reference object 2 corresponding to Binder entity object 1 in response to receiving a stop request from the system service corresponding to Binder entity object 1.
[0139] S204: The Binder driver updates the reference count of the first node, and when the reference count of the first node is 0, the Binder driver deletes the first node.
[0140] Because each additional second node corresponds to the first node, the Binder driver can add 1 to the reference count of the first node. After the Binder driver deletes the second node, the Binder driver can update the reference count of the first node based on the number of deleted second nodes. Exemplarily, when the Binder driver deletes a second node, the Binder driver can reduce the reference count of the first node by 1. When the Binder driver deletes two second nodes, the Binder driver can reduce the reference count of the first node by 2.
[0141] When the reference count of the first node is 0, it indicates that no service request end is currently using the system service, and the Binder driver may delete the first node corresponding to the system service.
[0142] S205, the Binder driver sends a reference count update indication to the system service, where the reference count change indication is used to indicate updating the reference count of the system service.
[0143] In some embodiments, after the Binder driver updates the reference count of the first node, it may send a reference count update indication to the system service, wherein the reference count change indication is used to indicate the update of the reference count of the system service.
[0144] In some embodiments, the reference count change indication may include an indication of a number of reference count reductions or increases of the system service. Exemplarily, the Binder driver reduces the reference count of the first node by 1, and the reference count change indication may include an indication of a number of reference count reductions of the system service as 1, that is, the reference count change indication is used to instruct the system service to reduce the reference count of the system service by 1.
[0145] In some embodiments, when the SAMgr manages the reference count of the system service, after the Binder driver updates the reference count of the first node, it can send a reference count update indication to the SAMgr to instruct the SAMgr to update the reference count of the system service.
[0146] S206: The system service updates the reference count of the system service in response to the reference count change indication, and when the reference count of the system service is 0, the system service stops running.
[0147] The system service may update the reference count of the system service according to the reference count change indication. Exemplarily, the reference count change indication may include indicating that the reference count of the system service is reduced by 1, and the system service may reduce the reference count of the system service by 1 according to the reference count change indication.
[0148] When the reference count of the system service is 0, it indicates that the service request end has ended the reference to the system service, and the system service can stop running. In some embodiments, the system service stops running, which can be understood as: the system service stops running, and triggers the system service recycling, releasing the resources occupied by the system service. In some embodiments, the system service stops running, which can be understood as: the system service exits or is uninstalled from the process.
[0149] In some embodiments, when the reference count of the system service is 0, the system service can call a stop function to trigger the system service recycling to release the resources occupied by the system service. In some embodiments, the stop function can be, for example, an OnReleaseObject function.
[0150] In some embodiments, when SAMgr manages the reference count of the system service, the reference count of the system service can be updated by SAMgr, and when the reference count of the system service is 0, SAMgr can call the OnReleaseObject function to trigger system service recycling to release the resources occupied by the system service.
[0151] In an embodiment of the present application, when the system service determines that the service request end has ended the reference to the system service, or when the system service determines not to perform the task based on its own task characteristics, the system service can actively initiate a stop request to the Binder driver, and the Binder driver can update the reference count of the first node corresponding to the system service, and trigger the system service to update its own reference count. When the reference count of the system service is 0, the system service can stop running and trigger the release of the resources occupied by the system service. In an embodiment of the present application, when multiple system services are running in a process, and if the process is not stopped, when any of the system services completes the task or does not perform the task, the system service can actively stop running. On the one hand, it can not affect the execution of tasks by other system services, and on the other hand, the electronic device can release the resources occupied by the system service and increase the available resources of the electronic device.
[0152] In some embodiments, when a system service actively stops running, the Binder driver can also notify the service request end that uses the system service, so that the service request end can perceive that the system service has stopped running, and then the service request end can perform corresponding operations to avoid task abnormalities of the service request end.
[0153] In this embodiment, refer to Figure 3 The control method of the system service provided in the embodiment of the present application may include:
[0154] S301, the system service sends a stop request to the Binder driver.
[0155] S302, the Binder driver determines a first node corresponding to the system service, and a second node corresponding to the first node.
[0156] S301 - S302 may refer to the description of S201 - S202 .
[0157] S303, the Binder driver sends a notification message to the service request end corresponding to the second node, where the notification message is used to instruct the system service request to stop running.
[0158] In some embodiments, a second interface can be deployed in an electronic device, and a Binder driver can call the second interface to send a notification message to a service request end corresponding to the second node. Exemplarily, the second interface can be a function interface, for example, the Binder driver can instruct the second node to call back the OnSaRelease function to enable the Binder driver to send a notification message to the service request end corresponding to the second node through the second interface. The deployment method of the second interface can refer to the relevant description of the first interface.
[0159] Notification messages are used to indicate that a system service requests to stop running, and can also be used to indicate that a system service is about to stop running.
[0160] S304: The service requesting end releases the second node.
[0161] In some embodiments, the service requester may call the ReleaseHandle function to release the second node.
[0162] In some embodiments, the service request end releasing the second node can be understood as: the service request end releasing the handle of the system service, or the service request end marking the system service as invalid, and the service request end can release the resources occupied by the second node.
[0163] In some embodiments, for example, a system service can be used to provide multiple sub-services, and the sub-services may include: monitoring CPU usage, memory usage, and disk space usage. Among them, monitoring CPU usage can be called a first sub-service, monitoring memory usage can be called a second sub-service, and monitoring disk space usage can be called a third sub-service. The service request end requests to use the first sub-service provided by the system service. In this example, the service request end releasing the second node can be understood as: the service request end releasing the resources occupied by the first sub-service. Similarly, in the above S206, releasing the resources occupied by the system service can be understood as: releasing the resources occupied by the first sub-service, the resources occupied by the second sub-service, and the resources occupied by the third sub-service.
[0164] S305: The Binder driver deletes the second node.
[0165] S306: The Binder driver updates the reference count of the first node, and when the reference count of the first node is 0, the Binder driver deletes the first node.
[0166] S307, the Binder driver sends a reference count update indication to the system service, where the reference count change indication is used to indicate an update of the reference count of the system service.
[0167] S308: The system service updates the reference count of the system service in response to the reference count change indication, and when the reference count of the system service is 0, the system service stops running.
[0168] S305-S308 may refer to the description in S203-S206.
[0169] In some embodiments, when a service requester perceives that a system service has stopped running, different service requesters perform different operations.
[0170] For example, the system service may provide a first sub-service, a second sub-service, and a third sub-service. The service requester requests to use the first sub-service provided by the system service. When the system service requests to stop running, the Binder driver may notify the service requester. In this way, the service requester can determine that the system service has stopped running. The service requester can reacquire the handle of the system service the next time it requests to use the first sub-service to ensure the use of the first sub-service, so as to ensure the normal execution of the task of the service requester.
[0171] Exemplarily, for example, when the system service is a Bluetooth system service, when the Bluetooth system service requests to stop running, the Binder driver can notify the service request end using the Bluetooth system service. In this way, the service request end can determine that the Bluetooth system service has stopped running, and the service request end can trigger the display screen to not display the Bluetooth logo in the status bar of the electronic device. Similarly, for example, the system service can be a Wi-Fi system service. When the Wi-Fi system service requests to stop running, the Binder driver can notify the service request end using the Wi-Fi system service. In this way, the service request end can determine that the Wi-Fi system service has stopped running, and the service request end can trigger the display screen to not display the Wi-Fi logo in the status bar of the electronic device.
[0172] In some embodiments, based on the structure of the electronic device provided by the embodiments of the present application (such as Figure 1 shown), combined Figure 4 The present invention introduces a control method for system services provided by an embodiment of the present application. Figure 4 A flowchart of a method for controlling system services of another embodiment provided in an embodiment of the present application.
[0173] Reference Figure 4 The control method of the system service provided in the embodiment of the present application may include:
[0174] S401. The system service calls the ReleaseSa function to send a stop request to the Binder driver.
[0175] S402: The Binder driver determines the first node corresponding to the system service.
[0176] S403. The Binder driver determines the second node corresponding to the first node according to the red-black tree.
[0177] S404. The Binder driver instructs the second node to call back the OnSaRelease function to send a notification message to the service requester.
[0178] S405: The service request end calls the ReleaseHandle function to release the second node.
[0179] S406: The Binder driver deletes the second node.
[0180] S407: The Binder driver updates the reference count of the first node, and when the reference count of the first node is 0, deletes the first node.
[0181] S408. The Binder driver sends a reference count update indication to the system service.
[0182] S409: The system service updates the reference count of the system service, and when the reference count of the system service is 0, the system service calls the OnReleaseObject function and stops running.
[0183] Among them, S401-S409 can refer to the description in S301-S308.
[0184] It should be understood that Figure 4 Other first nodes corresponding to the service provider are not shown, and only the first node corresponding to one of the system services provided by the service provider is shown.
[0185] In an embodiment of the present application, when a system service actively requests to stop running, the Binder driver can notify the service request end using the system service so that the service request end can perceive that the system service has stopped running, so that the service request end can perform corresponding operations to avoid task abnormalities of the service request end.
[0186] In some embodiments, in the following scenario, when a system service actively requests to stop running, even if the Binder driver does not notify the service request end using the system service, it will not affect the execution of the task of the service request end.
[0187] For example, scenario 1:
[0188] In some embodiments, each time the service request end uses the system service provided by the system service, the service request end can be configured to reacquire the handle of the system service. It should be understood that after the system service stops running, the handle that the service request end has acquired becomes invalid. When the service request end uses the system service provided by the system service, because the handle that the service request end has acquired becomes invalid, the service request end cannot continue to use the system service to perform tasks, resulting in task abnormalities. However, each time the service request end uses the system service provided by the system service, if the service request end is configured to reacquire the handle of the system service, then even if the system service stops running, the next time the service request end uses the system service, the handle of the system service will be reacquired, and the service request end will use the system service to perform tasks, which can ensure the smooth execution of tasks.
[0189] Exemplary scenario 2:
[0190] In some embodiments, the service request end may pre-register a monitoring service in SAMgr, and the monitoring service is used to monitor whether the system service stops running. After the service request end registers the monitoring service in SAMgr, when the system service stops running, SAMgr may send a notification message of the system service stopping running to the service request end. In this way, the service request end may also determine that the system service stops running.
[0191] In some embodiments, the service request end may register the monitoring service in SAMgr after installation, or the service request end may register the monitoring service in SAMgr when it is first started, and the embodiments of the present application are not limited to this.
[0192] In the above two scenarios, although the Binder driver did not notify the service requester using the system service when the system service actively requested to stop running, the service requester can re-acquire the handle the next time the system service is used, or use SAMgr to determine that the system service has stopped running, and re-acquire the handle the next time the system service is used. Therefore, even if the Binder driver does not notify the service requester using the system service, it does not affect the execution of the service requester's tasks.
[0193] In one embodiment, in the above two scenarios, because the Binder driver does not notify the service request end using the system service, the SAMgr can release the second node to release the resources occupied by the second node.
[0194] In an embodiment of the present application, each time the service request end uses the system service provided by the system service, if the service request end is configured to re-acquire the handle of the system service, or the service request end can pre-register the listening service in SAMgr, when the system service stops running, the Binder driver may not notify the service request end that uses the system service, because the system service can re-acquire the handle the next time the system service is used, or use SAMgr to determine that the system service stops running so as to re-acquire the handle the next time the system service is used, thereby not affecting the execution of the task of the service request end.
[0195] In some embodiments, the above Figures 2 to 4 The embodiments in the embodiment can be applicable to native system services, Java system services, and other system services. In some embodiments, the electronic device can include a system service management module. For example, when the electronic device can use IPC technology, the system service management module can be a Binder driver.
[0196] In some embodiments, the control method of the system service provided in the embodiments of the present application can also be applied to other system architectures, such as in the RPC communication system structure, the electronic device can include a system service management module, and the system service management module can be a soft bus. In some embodiments, when the system service is a Java system service, the system service management module can be an AMS.
[0197] It should be understood that when the system service is other types of system services, the system service management module may be other modules in the electronic device, and the embodiments of the present application do not exhaustively list the system service management modules.
[0198] Reference Figure 5 The control method of the system service provided in the embodiment of the present application may include:
[0199] S501, the system service sends a stop operation request to the system service management module.
[0200] S501 may refer to the description in S201.
[0201] S502: In response to a stop request, the system service management module determines a first node corresponding to the system service and a second node corresponding to the first node.
[0202] In some embodiments, a red-black tree may be stored in the system service management module, and the system service management module may determine the second node corresponding to the first node based on the red-black tree, and reference may be made to the relevant description of the Binder driver in S202.
[0203] S503: The system service management module deletes the second node.
[0204] S503 may refer to the description in S203.
[0205] S504: The system service management module updates the reference count of the first node according to the number of deleted second nodes.
[0206] S505: The system service updates the reference count of the system service according to the reference count of the first node, and stops running when the reference count of the system service is less than the count threshold.
[0207] In some embodiments, S504 may refer to the description in S204 - S206 .
[0208] Exemplarily, when the system service management module deletes a second node, the system service management module may reduce the reference count of the first node by 1. Since the first node corresponds to the system service, the system service may also reduce the reference count of the system service by 1 according to the update of the reference count of the first node. When the system service management module deletes two second nodes, the system service management module may reduce the reference count of the first node by 2. Accordingly, the system service may also reduce the reference count of the system service by 2 according to the update of the reference count of the first node.
[0209] The system service corresponds to the first node, and the reference count of the system service may be equal to the reference count of the first node. Exemplarily, when the system service management module deletes a second node, the system service management module may reduce the reference count of the first node by 1, because the first node corresponds to the system service, and thus the system service may update the reference count of the system service according to the reference count of the first node. For example, when the reference count of the first node is reduced from 2 to 1, the system service may reduce the reference count of the system service from 2 to 1.
[0210] In the embodiment of the present application, when the reference count of the reference count of the system service is less than the count threshold, the system service can stop running. For example, the count threshold can be 1, and when the reference count of the system service is 0, the system service stops running, and the description in S206 can be referred to.
[0211] The control method of the system service provided in the embodiment of the present application has the same technical principles and technical effects as the above-mentioned embodiment, and can refer to the description in the above-mentioned embodiment.
[0212] It should be noted that the data involved in this application (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0213] In one embodiment, the present application also provides an electronic device, referring to Figure 6 , the electronic device may include: a processor 601 (such as a CPU), and a memory 602. The memory 602 may include a high-speed random access memory (RAM), and may also include a non-volatile memory (NVM), such as at least one disk memory. The memory 602 may store various instructions for completing various processing functions and implementing the method steps of the present application.
[0214] Optionally, the electronic device involved in the present application may further include: a power supply 603, a communication bus 604 and a communication port 605. The above-mentioned communication port 605 is used to realize the connection and communication between the electronic device and other peripherals. In the embodiment of the present application, the memory 602 is used to store computer executable program code, and the program code includes instructions; when the processor 601 executes the instruction, the instruction causes the processor 601 of the electronic device to perform the action in the above-mentioned method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0215] It should be noted that the modules or components described in the above embodiments may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASICs), or one or more digital signal processors (DSPs), or one or more field programmable gate arrays (FPGAs). For another example, when a module above is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processors that can call program codes, such as a controller. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0216] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loading and executing computer program instructions on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, a data center, etc. that contains one or more available media integrated. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0217] The term "plurality" in this article refers to two or more than two. The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the previous and next associated objects are in an "or" relationship; in the formula, the character " / " indicates that the previous and next associated objects are in a "division" relationship. In addition, it should be understood that in the description of this application, words such as "first" and "second" are only used for the purpose of distinguishing descriptions, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.
[0218] It should be understood that the various numerical numbers involved in the embodiments of the present application are only used for the convenience of description and are not used to limit the scope of the embodiments of the present application.
[0219] It can be understood that in the embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
Claims
1. A system service control method, applied to electronic equipment, characterized in that: The method comprises: The system service management module receives a stop operation request from the system service; In response to the stop operation request, the system service management module determines a first node corresponding to the system service and a second node corresponding to the first node; The system service management module deletes the second node; The system service management module updates the reference count of the first node according to the number of the deleted second nodes; The system service updates a reference count of the system service according to the reference count of the first node, and stops running when the reference count of the system service is less than a count threshold.
2. The method according to claim 1, characterized in that The method further comprises: A service process is run, wherein at least one system service is run in the service process.
3. The method according to claim 1 or 2, characterized in that: The system service sends a stop operation request to the system service management module, including: When the service requesting ends all end the reference to the system service, the system service sends a stop operation request to the system service management module; or, When the system service determines not to execute the task, the system service sends a stop operation request to the system service management module.
4. The method according to claim 3, characterized in that The system service determines not to perform tasks, including: The system service is an upgrade system service, and when the upgrade system service completes the upgrade task, the upgrade system service determines not to execute the task; or, The system service is a Bluetooth system service. When the Bluetooth system service determines that the Bluetooth switch of the electronic device is turned off, or the electronic device has not established a Bluetooth connection with other devices, the Bluetooth system service determines not to execute the task; or, The system service is a Wi-Fi system service. When the Wi-Fi system service determines that the Wi-Fi switch of the electronic device is turned off, or the electronic device has not established a Wi-Fi connection with other electronic devices, the Wi-Fi system service determines not to perform the task; or, When the system service is a system service for providing distributed services, when the system service determines that the communication switch of the electronic device is turned off, or the electronic device has not established a communication connection with other electronic devices, the system service determines not to execute the task.
5. The method according to any one of claims 1 to 4, characterized in that The system service management module includes: Binder driver; The system service management module determines the first node corresponding to the system service and the second node corresponding to the first node, including: The Binder driver determines the first node corresponding to the system service, and determines the second node corresponding to the first node according to the association relationship between the first node and the second node; After updating the reference count of the first node, the method further includes: The Binder driver sends a reference count update indication to the system service, where the reference count update indication is used to indicate the amount by which the reference count of the system service is reduced; The system service updates a reference count of the system service according to the reference count of the first node, and stops running when the reference count of the system service is less than a count threshold, including: In response to the reference count update indication, the system service updates a reference count of the system service; When the reference count of the system service is less than the count threshold, the system service calls a stop function to release the resources occupied by the system service.
6. The method according to claim 5, characterized in that The counting threshold is 1.
7. The method according to claim 5 or 6, characterized in that: After the reference count of the first node is updated, the method further includes: When the reference count of the first node is 0, the Binder driver deletes the first node.
8. The method according to any one of claims 1 to 7, characterized in that The service request end is configured to reacquire the handle of the system service each time the system service is referenced.
9. The method according to claim 8, characterized in that The electronic device comprises: a system capability manager, and the method further comprises: The service request end registers a monitoring service with the system capability manager, and the monitoring service is used to monitor the system service stopping running; When the system service stops running, the system capability manager sends a notification message of the system service stopping running to the service request end.
10. The method according to any one of claims 5 to 7, characterized in that: After determining the second node corresponding to the first node, the method further includes: The Binder driver sends a notification message to the service request end, where the notification message is used to instruct the system service request to stop running; The service requesting end releases the second node.
11. The method according to any one of claims 5 to 7, characterized in that: The electronic device is provided with a first interface, and the method further comprises: The system service calls the first interface and sends the stop operation request to the Binder driver.
12. The method according to claim 10, characterized in that The electronic device is provided with a second interface, and the Binder driver sends a notification message to the service request end, including: The Binder driver instructs the second node to call the second interface and send the notification message to the service request end.
13. An electronic device, characterized in that: include: Processor and memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program or instruction, and when the computer program or instruction is executed, the method according to any one of claims 1 to 12 is implemented.
Citation Information
Patent Citations
Service management method, service management device and service management terminal
CN103294166A
Application service control method and device, storage medium and mobile terminal
CN107885588A
User equipment service management
CN109417760A
Intelligent terminal, operation control method and system thereof, electronic equipment and storage medium
CN113961265A
Visual administrator for specifying service references to support a service
US20050216860A1
Cited By
System service control method, electronic device, and readable storage medium
EP4722911A1
System service control method, electronic device, and readable storage medium
WO2025044575A1