System service control method, electronic device, and readable storage medium

Through the system service management module and Binder driver, system services in electronic devices can be actively stopped, solving the problem of system services occupying resources and improving the available resources and operating speed of the equipment.

WO2025044575A1PCT designated stage expired Publication Date: 2025-03-06HUAWEI TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/105993
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-08-29
Filing Date
2024-07-17
Publication Date
2025-03-06

AI Technical Summary

Technical Problem

System services in existing electronic devices occupy a large amount of resources, resulting in the stuttering of front-end applications and lack of a mechanism for system services to actively stop running.

Method used

Through the system service management module and Binder driver, the system service can actively request to stop running, release resources, and reduce the use of electronic device resources.

Benefits of technology

It realizes that the system services are actively stopped from operating without affecting other tasks, reduce resource usage, and improve the available resources and operation speed of electronic equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024105993_06032025_PF_FP_ABST
    Figure CN2024105993_06032025_PF_FP_ABST
Patent Text Reader

Abstract

The present application provides a system service control method, an electronic device, and a readable storage medium. A system service management module receives an operation stop request from a system service; in response to the operation stop request, the system service management module determines a first node corresponding to the system service and second nodes corresponding to the first node; the system service management module deletes the second nodes; on the basis of the number of the deleted second nodes, the system service management module updates a reference count of the first node; and the system service updates a reference count of the system service, and stops operation when the reference count of the system service is less than a count threshold. In the present application, a system service can actively request to stop operation, thereby reducing the occupation of the system service on resources of an electronic device, and increasing available resources of the electronic device.
Need to check novelty before this filing date? Find Prior Art

Description

System service control method, electronic device and readable storage medium

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on August 29, 2023, with application number 202311103510.7 and application name “System Service Control Method, Electronic Device and Readable Storage Medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the technical field of system services, and in particular to a system service control method, electronic device, and readable storage medium. Background Art

[0003] As electronic devices continue to add functionality, the number of system services within them continues to grow. These services can provide a wide variety of services to users. Currently, these services can be resident services. These resident services can consume significant resources and even cause foreground applications to freeze.

[0004] Currently, there is an urgent need for a method for controlling the operation of system services to reduce the occupation of electronic equipment resources by system services.

[0005] Summary of the Invention

[0006] 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.

[0007] In a 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 uses 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, wherein the first node and the second node correspond to each other.

[0008] In some embodiments, the service requesting end may be an application in the electronic device.

[0009] It should be understood that when a service requesting end sends a request to a system service to use the system service, the system service management module may create a first node corresponding to the system service and a second node corresponding to the service requesting end in the system service management module, and establish a mapping relationship between the first node and the second node, i.e., the first node corresponds to the second node. The correspondence between the first node and the second node may indicate that the service requesting end corresponding to the second node is requesting the system service corresponding to the first node.

[0010] The electronic device can run a service process, the system service can run in the service process, and at least one system service can run in the service process. In some embodiments, at least two system services can run in the service process, and this 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 can actively request to stop running.

[0011] In this method, the system service may send a stop request to the system service management module. In response to the stop 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 update the reference count of the first node based on the number of deleted second nodes. Because the first node corresponds to the system service, the system service may update the reference count of the system service based on the reference count of the first node and stop running when the reference count of the system service is less than a count threshold.

[0012] 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.

[0013] In an embodiment of the present application, a system service can proactively request to stop running, and the system service management module can release the system service. In an embodiment of the present application, when multiple system services (i.e., system services) or one system service are running in a service process, and the service process is not stopped, any of the system services can proactively stop running, which can reduce the occupation of electronic device resources by the system services and increase the available resources of the electronic device.

[0014] In one possible implementation, when all service requesting ends have ended their references to the system service, the system service may send a stop-operation request to the system service management module. When all service requesting ends have ended their references to the system service, it indicates that no service requesting end is currently referencing the system service provided by the system service. Therefore, the system service may request to stop operating, which will not affect the tasks performed by the service requesting end and avoid task anomalies on the service requesting end. For example, there are multiple service requesting ends referencing the system service. When all of the multiple service requesting ends have ended their references to the system service, the system service may send a stop-operation request to the system service management module.

[0015] In one possible implementation, the system service may, based on its own task execution characteristics, send a stop request to the system service management module when the system service determines that it is not performing a task. When the system service is not performing a task, that is, no service requester is currently using the system service provided by the system service, the system service may request to stop running, thereby avoiding task anomalies on the service requester.

[0016] For example, the system service is an upgrade system service. If the upgrade system service completes the upgrade task and determines that it will not perform the upgrade task in a short period of time, the upgrade system service may request to stop running. The upgrade task may include, but is not limited to, a system version upgrade, a system application version upgrade, etc.

[0017] 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 another electronic device, the Bluetooth system service determines that it does not need to perform the task, and thus the Bluetooth system service may request to stop running. For example, a user may operate the Bluetooth switch or Bluetooth control of the electronic device to turn off the Bluetooth switch of the electronic device, thereby enabling the electronic device to disable the Bluetooth communication function.

[0018] 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 it does not need to perform the task, and thus the Wi-Fi system service may request to stop running. For example, a user may operate the Wi-Fi switch or Wi-Fi control of the electronic device to turn off the Wi-Fi switch of the electronic device, thereby enabling the electronic device to turn off the Wi-Fi function.

[0019] Exemplarily, 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 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. For example, a 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 the function of connecting with other electronic devices.

[0020] 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.

[0021] 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.

[0022] 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.

[0023] 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.

[0024] 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 based on 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 using a data structure such as a red-black tree, a map linked list, or an array.

[0025] In some embodiments, when a Binder driver stores the association between a first node and a 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.

[0026] 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, illustratively, 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 represent the reference count of the system service, that is, it can represent the number of service request terminals that reference (or use) the system service.

[0027] After the Binder driver updates the reference count of the first node, it may send 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. 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 a count threshold, the system service stops running and calls a stop function to release resources occupied by the system service.

[0028] 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.

[0029] In some embodiments, the system service management module being able to release the system service can be understood as: the system service management module being able to release resources occupied by the system service. Resources may include but are not limited to: memory resources, central processing unit (CPU) resources, network resources, input and output resources, etc.

[0030] 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.

[0031] 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.

[0032] In one possible implementation, the Binder driver, in response to a request from a system service to stop running, may determine a first node corresponding to the system service and a second node corresponding to the first node. 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, where the notification message is used to indicate that the system service request has stopped running. The service request end may release the second node. In some embodiments, the service request end may call a release function to release resources occupied by the second node.

[0033] 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 perform corresponding operations to avoid task abnormalities on the service request end.

[0034] In one possible implementation, the Binder driver can not synchronize the system service request to the service request end to stop running, so that the service request end can not be aware of the system service stopping running. This implementation method is suitable for the following scenarios to avoid task exceptions on the service request end:

[0035] First, the service requester is configured to reacquire the handle of the system service each time it uses the system service. In this way, even if the system service stops running, the next time the service requester uses the system service, the system service handle will be reacquired and the service requester will use the system service to perform the task, ensuring the smooth execution of the task.

[0036] Secondly, the service request end may pre-register a monitoring service in the system capability manager SAMgr to monitor the cessation of the system service. Exemplarily, the service request end registers a monitoring service with the SAMgr, and the monitoring service is used to monitor the cessation of the system service. After the SAMgr releases the system service, the SAMgr sends a notification message to the service request end indicating that the system service has ceased operation.

[0037] In this way, although the Binder driver does not notify the service request end that uses the system service when the system service actively requests to stop running, the service request end can use SAMgr to determine that the system service has stopped running, enabling the service request end to re-acquire the handle the next time it uses the system service. Therefore, even if the Binder driver does not notify the service request end that uses the system service, it does not affect the execution of the service request end's tasks.

[0038] In some embodiments, the Binder driver, in response to a request from the service provider to stop running, can determine a first node corresponding to the service provider and a second node corresponding to the first node. After the Binder driver determines the second node corresponding to the first node, the Binder driver can send a notification message to the SAMgr, where the notification message is used to indicate that the service provider requests to stop running. The SAMgr can release the second node. In some embodiments, the SAMgr can call a release function to release resources occupied by the second node.

[0039] 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 request to the Binder driver. In another 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 requester.

[0040] 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.

[0041] 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 configured to store computer-executable program code, the program code including instructions; when the processor executes the instructions, the instructions cause the electronic device to perform the method described in the first aspect.

[0042] In a third aspect, an embodiment of the present application provides an electronic device, which may include a unit, module or circuit for executing the method provided in the first aspect above.

[0043] 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 described above.

[0044] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enables the computer to execute the method in the first aspect above.

[0045] 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 first aspect mentioned above using the communication interface.

[0046] 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

[0047] FIG1 is a schematic diagram of cross-process communication;

[0048] FIG2 is a flow chart of a method for controlling system services according to an embodiment of the present application;

[0049] FIG3 is a flow chart of a method for controlling system services according to another embodiment of the present application;

[0050] FIG4 is a flow chart of a method for controlling system services according to another embodiment of the present application;

[0051] FIG5 is a flow chart of a method for controlling system services according to another embodiment of the present application;

[0052] FIG6 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0053] For ease of understanding, the following first introduces the relevant terms and concepts involved in the embodiments of the present application:

[0054] System capabilities (Sa): These are system programs that provide specific functions and services. Examples of system services include monitoring system resource usage, providing network services, managing files, and providing security protection.

[0055] For example, system resource usage may include central processing unit (CPU) usage, memory usage, disk space usage, etc. System services for providing network services may include Bluetooth services, Wi-Fi services, etc. Management files may include backup files, compressed files, encrypted files, etc. Security protection includes antivirus, firewalls, and intrusion detection. The embodiments of this application do not limit system services.

[0056] In some embodiments, various types of system services can be deployed in electronic devices. For example, 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.

[0057] Resident: Currently, system services can be resident services, which can be understood as running in the memory during the operation of the electronic device. Even after the system service has completed its task, the system service still runs in the memory. In some embodiments, the system service can run in the background.

[0058] In some embodiments, some system services may not be resident services; instead, they may run in memory when needed. For example, in the case of a distributed camera service, the electronic device only runs the distributed camera service after it is networked with another electronic device, at which point the distributed camera service runs in memory. It should be understood that regardless of whether a system service is resident, it is applicable to the system service control methods provided in the embodiments of this application.

[0059] Process: is the basic unit of dynamic execution of the operating system. System services can run in a process. In some embodiments, the process running a system service can be called a service process. The following embodiments use "process" as an example for explanation.

[0060] In some embodiments, at least one system service can run in a process. For example, in Android, native system services can run in a native daemon process. For example, system services such as media player service (mediaplayerservice), camera service (cameraservice), and audio service (audioflinger) can run in a native daemon process.

[0061] A handle is a special type of smart pointer. For example, when an app references a memory block or object managed by another system (such as a database or operating system), it obtains the handle to that memory block or object. In some embodiments, "an app referencing a memory block or object managed by another system" can be understood as the app's use of that memory block or object.

[0062] The electronic devices in the embodiments of the present application are devices deployed with system services, and the electronic devices may be referred to as user equipment (UE), terminals, etc. For example, the electronic devices may be mobile phones, tablets, personal digital assistants (PDAs), handheld devices with wireless communication capabilities, computing devices, vehicle-mounted devices, or wearable devices, virtual reality (VR) terminal devices, augmented reality (AR) terminal devices, wireless terminals in industrial control, wireless terminals in smart homes, etc. The embodiments of the present application do not specifically limit the form of the electronic devices.

[0063] As electronic devices continue to expand in functionality, the number of system services within them continues to increase. Currently, numerous system services run in the background, occupying significant amounts of electronic device resources. These background processes can even preempt resources from foreground applications, causing foreground applications to freeze. Electronic device resources can include, but are not limited to, memory resources, CPU resources, network resources, and input / output (IO) resources.

[0064] Currently, there is no mechanism in electronic devices for system services to actively stop running when the system services complete their tasks.

[0065] In some embodiments, a control mechanism for Java system services is designed from the perspective of the Android operating system. For example, an app in an electronic device can bind a Java system service by calling the bindService function, indicating that the app can use the Java system service. The app can unbind the Java system service by calling the unbindService function, indicating that the app has stopped 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.

[0066] 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 referencing 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.

[0067] 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. For example, 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.

[0068] As in the example above, if the app continues to hold a handle to the Java system service, the reference count of the Java system service will not be 0, and AMS cannot handle the process containing the Java system service or the Java system service itself. Furthermore, AMS manages Java system services by killing the process containing the Java system service. If multiple Java system services are running in the same process, AMS cannot stop a single Java system service.

[0069] In some embodiments, the lifecycle of a system service is related to the process in which the system service resides. When the process in which the system service resides dies, the system service running in the process can stop running, and the electronic device can release the resources occupied by the system service. The process in which the system service resides can be understood as the process in which the system service is running.

[0070] For example, the three system services, media player service, camera service, and audio service, run in one process, which can be a local daemon process. Currently, when any of the system services, media player service, camera service, and audio service, completes its task, the system service does not stop running. 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 operating error, or the local daemon process is forcibly killed, the life cycle of the three system services, media player service, camera service, and audio service, ends, and the three system services can stop running.

[0071] In some embodiments, a process stop condition can be pre-set, for example, the condition can be that a preset property of the electronic device reaches a set value. The electronic device can activate a property monitoring mechanism. When a 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.

[0072] In the above method for controlling system services, when multiple system services are running in one process, the system services depend on the process dying or stopping. When the process dies or stops, the system services in the process stop running. The electronic device cannot control the running of one system service alone.

[0073] To facilitate electronic devices to independently control the operation of each system service, some embodiments can design a "one system service running in one process" solution. This allows the electronic device to terminate the process containing the system service upon completion of its task, thus halting the system service. However, electronic devices may have numerous system services, and running each system service in a separate process can increase the number of concurrently running processes and consume more power.

[0074] To address the above issues, various embodiments of the present application provide 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 independent control of a system service, and on the other hand, it is possible to reduce the occupation of electronic device resources by the system service and improve the operating speed of the electronic device system. It should be understood that in the embodiments of the present application, "Sa" is used as the English abbreviation for the system service for explanation.

[0075] To better understand the control method of the system services provided by this application, we first briefly introduce the principle of cross-process communication:

[0076] Because each process has its own independent resources, other processes cannot freely access the resources of a different process. Therefore, direct communication between different processes is impossible, giving rise to cross-process communication technology. Currently, both inter-process communication (IPC) and remote procedure call (RPC) technologies can be used to implement cross-process communication. The difference is that IPC technology uses Binder drivers and can be used for cross-process communication within a device, while RPC technology uses a soft bus driver and can be used for cross-process communication across devices.

[0077] 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.

[0078] Figure 1 is a schematic diagram of cross-process communication. Referring to Figure 1 , an electronic device may include a service requester (client), a service provider (server), a system capability manager (SAMgr), and a driver. In some embodiments, the electronic device may include at least one service requester and at least one service provider. Figure 1 illustrates one service requester and one service provider as examples.

[0079] In some embodiments, when the electronic device uses IPC technology, the driver in the electronic device can be a Binder driver. When the electronic device uses RPC technology, the driver in the electronic device can be a soft bus. FIG1 takes the Binder driver as an example.

[0080] 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. The Binder client process can call the service running in the Binder service process through the interface provided by the Binder driver.

[0081] At least one system service can 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, can run in a single process. This process can be a local daemon process. The local daemon process can be considered the service provider, and the media playback service, camera service, and audio service can be considered the system services provided by the service provider.

[0082] The service requester can request to call a system service. For example, the service requester can be an APP in an electronic device. The APP can include but is not limited to third-party applications and system applications.

[0083] 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.

[0084] In some embodiments, referring to FIG. 1 , the process of a service requester using a system service provided by the service requester may include:

[0085] Step 1. Register.

[0086] System services can first be registered in SAMgr. 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.

[0087] SAMgr is responsible for managing these system services and providing relevant interfaces to the service requester.

[0088] Step 2: Request.

[0089] If the service requester wants to use a system service in the service provider, it can send a request to the Binder driver.

[0090] The Binder driver responds to the request from the service requester and can communicate with the service provider requested by the service requester.

[0091] In step 2, the Binder driver responds to the request from the service requester and can send the request to the system service running on the service provider. For example, the request can request CPU usage and memory usage. Accordingly, the system service can be a system service for monitoring the usage of system resources.

[0092] The system service can process the received request and execute the task. For example, a system service that monitors the usage of system resources can obtain the CPU usage and memory usage in response to a request from a Binder driver.

[0093] Step 3: Feedback the task completion results.

[0094] 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.

[0095] It should be noted that the dotted lines in Figure 1 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 Binder-driven communication.

[0096] 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.

[0097] 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, as well as the principle of cross-process communication. For details, please refer to the description of the current cross-process communication principle.

[0098] In some embodiments, inter-process communication interfaces may be deployed on the Binder driver, and the service requester may communicate with the service provider by calling these interfaces.

[0099] The following describes the data structure in the Binder driver:

[0100] In some embodiments, the Binder driver may include a Binder entity object and a Binder reference object.

[0101] Binder entity object: Each system service corresponds to a Binder entity object in the Binder driver. 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.

[0102] Referring to Figure 1, Figure 1 takes three system services running in a Binder service process as an example for explanation. 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, the three Binder entity objects corresponding to the Binder service process can be included.

[0103] 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 can be the abbreviation of reference. In some embodiments, the Binder reference object can be called a second node.

[0104] 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 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.

[0105] Referring to Figure 1, taking an APP as an example, the Binder driver can 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 can correspond to the Binder reference object of the APP. Exemplarily, in Figure 1, the Binder entity object and the Binder reference object are connected, and the Binder entity object representing the system service can correspond to the Binder reference object of the APP.

[0106] In some embodiments, a Binder reference object can correspond to at least one Binder entity object. For example, an APP can use at least one system service, and the Binder reference object of the APP in the Binder driver can 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 can 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 the navigation APP corresponds to Binder reference object 1. In the Binder driver, the Binder reference object 1 can correspond to Binder entity object 1 and Binder entity object 2.

[0107] In some embodiments, a Binder entity object can correspond to at least one Binder reference object. For example, a system service can be used by multiple APPs at the same time, and the Binder entity object of the system service in the Binder driver can correspond to the Binder reference objects of the multiple APPs in the Binder driver. For example, both the navigation APP and the video playback APP use the system service 1 for providing positioning. The system service 1 corresponds to the Binder entity object 1, the navigation APP corresponds to the Binder reference object 1, and the video playback APP corresponds to the Binder reference object 2. Then, in the Binder driver, the Binder entity object 1 can correspond to the Binder reference object 1 and the Binder reference object 2.

[0108] 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 repeated in some embodiments.

[0109] FIG2 is a flow chart of a method for controlling a system service according to an embodiment of the present application. Referring to FIG2 , the method for controlling a system service according to an embodiment of the present application may include:

[0110] S201: The system service sends a stop request to the Binder driver.

[0111] In some embodiments, a first interface can be deployed in an electronic device, and a system service can call the first interface to send a stop operation request to a Binder driver. Exemplarily, the first interface can be a function interface, for example, a system service can call a ReleaseSa function to send a stop operation request to a Binder driver through the first interface. In some embodiments, the first interface can be deployed in a system service layer of an electronic device. In some embodiments, the first interface can be deployed between a user space and a kernel space of an electronic device. In some embodiments, the first interface can be deployed on a Binder driver.

[0112] In some embodiments, when both service requesting ends reference the system service, the system service may send a stop request to the Binder driver.

[0113] 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, as described in 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.

[0114] In some embodiments, a service requester can send a request to a system service via a Binder driver. In this example, because a service requester references the system service, the system service can perform the task requested by the first service requester. When the system service completes the task, if the service requester ends its reference to the system service, the system service can send a stop request to the Binder driver.

[0115] 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 a preset time, the system service can send a stop operation request to the Binder driver. The preset time can give the system service a buffer period, which can avoid the problem of the system service frequently switching between stopping and starting when there is a service request end requesting to use the system service within a short period of time.

[0116] In some embodiments, the SAMgr can manage system services. When a service requester requests to use a system service, the SAMgr can count the number of times the system service is referenced to obtain a reference count for the system service. Each time a service requester requests to use the system service, the SAMgr can increase the reference count for the system service by 1. Whenever a service requester stops using the system service, the SAMgr can decrease the reference count for the system service by 1.

[0117] 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.

[0118] In some embodiments, the system service may manage its own reference count. Each time a service requester requests to use the system service, the system service may increase the reference count by 1. Whenever a service requester stops using the system service, the system service may decrease the reference count by 1.

[0119] In an embodiment of the present application, the system service may determine its own reference count. When the reference count of the system service is 0, the system service may send a stop request to the Binder driver.

[0120] In some embodiments, for example, the service requester does not actually need to request the system service to perform a task, but due to reasons such as application startup settings, once the service requester is started, the service requester will obtain the handle of the system service and send a request to the system service. In these examples, the service requester does not actually use the system service, but there may be cases where the service requester requests to use the system service. In this type of situation, if the system service does not perform the task, it will not affect the normal operation of the service requester. If the system service is still running in the memory, it will also occupy the resources of the electronic device.

[0121] Here's an example scenario: For example, when an audio app starts, it sends a request to the media player service through the Binder driver to use the system service. However, the audio app actually uses the media player service to play audio. Therefore, the audio app holds a handle to the media player service when it starts, causing the media player service to believe that there is always a service requester using the media player service. As a result, the media player service will continue to run in memory, occupying system resources.

[0122] Therefore, in order to solve this problem, in some embodiments, the system service can send a stop request to the Binder driver when it is determined not to execute a task based on its own task characteristics.

[0123] For example, a system service is a system service for providing version upgrades. In some embodiments, the system service for providing version upgrades can be referred to as an upgrade system service. After completing a version upgrade task, the upgrade system service can determine that there is no need to perform the version upgrade task for a period of time. The upgrade system service can send a stop request to the Binder driver. It should be understood that version upgrades can include but are not limited to system version upgrades, system app version upgrades, etc. In some embodiments, system version upgrades can also be referred to as whole-machine version upgrades.

[0124] 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 can turn off the Bluetooth switch of the electronic device, for example, the user includes a Bluetooth control or a Bluetooth switch in the drop-down menu on the desktop of the electronic device. Taking the Bluetooth switch as an example, the user can operate the Bluetooth switch to turn off the Bluetooth switch of the electronic device, and accordingly, the electronic device can 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. In fact, no service request end will use the Bluetooth system service, so the system service can send a stop operation request to the Binder driver.

[0125] For example, for Bluetooth system services, although the Bluetooth switch of an electronic device is on, the electronic device has no Bluetooth connection with other electronic devices. In this case, no service request end will actually use the Bluetooth system service, so the Bluetooth system service can send a stop request to the Binder driver.

[0126] 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 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 may send a stop request to the Binder driver.

[0127] 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 request end will use the Wi-Fi system service, so the Wi-Fi system service can send a stop request to the Binder driver.

[0128] Exemplarily, the system service is a system service for providing distributed services, which may include, but are not limited to, a distributed camera, a distributed clipboard, a distributed image gallery, and a distributed drawing board. 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 the distributed camera system service to implement the functions of the distributed camera application.

[0129] Because distributed services require multiple electronic devices to be networked to implement, 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 is 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.

[0130] 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 will not actually perform tasks related to distributed services. Therefore, the system service used to provide distributed services can send a stop request to the Binder driver.

[0131] 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. For example, 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.

[0132] S202: The Binder driver determines a first node corresponding to the system service and a second node corresponding to the first node.

[0133] 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, in the Binder driver, the first node corresponding to the system service and the second node corresponding to the first node.

[0134] In some embodiments, a Binder driver may store an association relationship between a first node and a second node, where the association relationship between the first node and the second node indicates 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 using a data structure such as a red-black tree, a map linked list, or an array.

[0135] 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 of the first node corresponding to the system service.

[0136] 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.

[0137] 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. 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, each time a second node is added corresponding to the first node, the Binder driver may add 1 to the reference count of the first node. Whenever a service request end releases the second node corresponding to the first node, the Binder driver may subtract 1 from the reference count of the first node.

[0138] The Binder driver can determine the second node corresponding to the first node based on the information of the first node in the red-black tree.

[0139] S203: The Binder driver deletes the second node.

[0140] Exemplarily, Binder entity object 1 may correspond to Binder reference object 1 and Binder reference object 2, Binder entity object 1 may serve as the first node, Binder reference object 1 and Binder reference object 2 may both serve as the second node, and the Binder driver may delete the Binder reference object 1 and the Binder reference object 2 corresponding to the Binder entity object 1 in response to receiving a stop request from the system service corresponding to the Binder entity object 1.

[0141] 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.

[0142] Because each time a second node is added corresponding to the first node, the Binder driver can add 1 to the reference count of the first node. When 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. For example, 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.

[0143] 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.

[0144] S205 , the Binder driver sends a reference count update indication to the system service. The reference count change indication is used to instruct to update the reference count of the system service.

[0145] 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.

[0146] In some embodiments, the reference count change indication may include an amount by which the reference count of the system service is decreased or increased. For example, the Binder driver decrements the reference count of the first node by 1, and the reference count change indication may include indicating that the reference count of the system service is decreased by 1, that is, the reference count change indication is used to instruct the system service to decrement the reference count of the system service by 1.

[0147] 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.

[0148] 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.

[0149] The system service may update the reference count of the system service according to the reference count change indication. For example, 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.

[0150] When the reference count of a system service reaches 0, it indicates that the service requester has ended its reference to the system service, and the system service can cease operation. In some embodiments, the cessation of the system service can be understood as: the system service ceases operation and triggers the recycling of the system service, releasing the resources occupied by the system service. In some embodiments, the cessation of the system service can be understood as: the system service exits or is uninstalled from the process.

[0151] 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 to recycle and release the resources occupied by the system service. In some embodiments, the stop function can be, for example, an OnReleaseObject function.

[0152] 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 the recycling of the system service to release the resources occupied by the system service.

[0153] 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. 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 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 will not affect the execution of tasks by other system services. 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.

[0154] In some embodiments, when a system service stops running actively, 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.

[0155] In this embodiment, referring to FIG3 , the control method of the system service provided in the embodiment of the present application may include:

[0156] S301: The system service sends a stop request to the Binder driver.

[0157] S302: The Binder driver determines a first node corresponding to the system service and a second node corresponding to the first node.

[0158] S301-S302 may refer to the description of S201-S202.

[0159] S303: The Binder driver sends a notification message to the service request end corresponding to the second node. The notification message is used to instruct the system service request to stop running.

[0160] In some embodiments, a second interface can be deployed in the electronic device, and the Binder driver can call the second interface to send a notification message to the 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.

[0161] Notification messages are used to indicate that a system service has requested to stop running, or to indicate that a system service is about to stop running.

[0162] S304: The service requesting end releases the second node.

[0163] In some embodiments, the service requester may call a ReleaseHandle function to release the second node.

[0164] 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.

[0165] 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.

[0166] S305: The Binder driver deletes the second node.

[0167] 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.

[0168] S307, the Binder driver sends a reference count update indication to the system service. The reference count change indication is used to instruct to update the reference count of the system service.

[0169] 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.

[0170] S305-S308 may refer to the description in S203-S206.

[0171] In some embodiments, when a service requester perceives that a system service has stopped running, different service requesters perform different operations.

[0172] For example, a system service may provide a first sub-service, a second sub-service, and a third sub-service. A 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 next time the service requester requests to use the first sub-service, it can re-acquire the handle of the system service to ensure the use of the first sub-service, thereby ensuring the normal execution of the service requester's task.

[0173] For example, if 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 that uses 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, if the system service is a Wi-Fi system service, when the Wi-Fi system service requests to stop running, the Binder driver can notify the service request end that uses 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.

[0174] In some embodiments, based on the structure of the electronic device provided in the embodiment of the present application (as shown in FIG1 ), the control method of the system service provided in the embodiment of the present application is described in conjunction with FIG4 . FIG4 is a flow chart of the control method of the system service provided in another embodiment of the present application.

[0175] 4 , the control method of the system service provided in the embodiment of the present application may include:

[0176] S401: The system service calls the ReleaseSa function to send a stop request to the Binder driver.

[0177] S402: The Binder driver determines the first node corresponding to the system service.

[0178] S403: The Binder driver determines the second node corresponding to the first node according to the red-black tree.

[0179] S404: The Binder driver instructs the second node to call back the OnSaRelease function to send a notification message to the service requester.

[0180] S405: The service request end calls the ReleaseHandle function to release the second node.

[0181] S406: The Binder driver deletes the second node.

[0182] 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.

[0183] S408. The Binder driver sends a reference count update instruction to the system service.

[0184] S409: The system service updates the reference count of the system service. When the reference count of the system service is 0, the system service calls the OnReleaseObject function and stops running.

[0185] Among them, S401-S409 can refer to the description in S301-S308.

[0186] It should be understood that FIG4 does not show other first nodes corresponding to the service provider, but only shows the first node corresponding to one of the system services provided by the service provider.

[0187] 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 that uses 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.

[0188] 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.

[0189] For example, scenario 1:

[0190] 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 abnormality. 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.

[0191] For example, scenario 2:

[0192] In some embodiments, the service requester may pre-register a monitoring service in the SAMgr, which is used to monitor whether the system service has stopped running. After the service requester registers the monitoring service in the SAMgr, when the system service stops running, the SAMgr may send a notification message to the service requester indicating that the system service has stopped running. In this way, the service requester can also determine that the system service has stopped running.

[0193] 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. This embodiment of the present application does not limit this.

[0194] In the above two scenarios, although the Binder driver did not notify the service requester that used the system service when the system service actively requested to stop running, the service requester can re-acquire the handle the next time it uses the system service, or use SAMgr to determine that the system service has stopped running, and re-acquire the handle the next time it uses the system service. Therefore, even if the Binder driver does not notify the service requester that uses the system service, it does not affect the execution of the service requester's tasks.

[0195] 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.

[0196] 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.

[0197] In some embodiments, the embodiments in Figures 2 to 4 above can be applied 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.

[0198] In some embodiments, the system service control method provided in the embodiments of the present application can also be applied to other system architectures, such as an RPC communication system structure, where the electronic device can include a system service management module, which 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.

[0199] 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.

[0200] 5 , the control method of the system service provided in the embodiment of the present application may include:

[0201] S501: The system service sends a stop request to the system service management module.

[0202] S501 may refer to the description in S201.

[0203] S502: 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.

[0204] In some embodiments, the system service management module may store a red-black tree, 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 description of the Binder driver in S202.

[0205] S503: The system service management module deletes the second node.

[0206] S503 may refer to the description in S203.

[0207] S504: The system service management module updates the reference count of the first node according to the number of deleted second nodes.

[0208] 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 a count threshold.

[0209] In some embodiments, S504 may refer to the description in S204 to S206.

[0210] For example, when the system service management module deletes a second node, the system service management module may decrement the reference count of the first node by 1. Since the first node corresponds to the system service, the system service may also decrement the reference count of the system service by 1 based on 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 decrement the reference count of the first node by 2. Accordingly, the system service may also decrement the reference count of the system service by 2 based on the update of the reference count of the first node.

[0211] The system service corresponds to the first node, and the reference count of the system service can 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 can reduce the reference count of the first node by 1. Because the first node corresponds to the system service, the system service can update the reference count of the system service based on the reference count of the first node. For example, if the reference count of the first node is reduced from 2 to 1, the system service can reduce the reference count of the system service from 2 to 1.

[0212] 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. Please refer to the description in S206.

[0213] 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 embodiment, and reference can be made to the description in the above embodiment.

[0214] 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 the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0215] In one embodiment, the present application also provides an electronic device. Referring to FIG6 , the electronic device may include a processor 601 (e.g., 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 storage. The memory 602 may store various instructions for performing various processing functions and implementing the method steps of the present application.

[0216] Optionally, the electronic device involved in this application may further include: a power supply 603, a communication bus 604, and a communication port 605. The communication port 605 is used to enable communication between the electronic device and other peripheral devices. In this embodiment of the application, the memory 602 is used to store computer-executable program code, which includes instructions; when the processor 601 executes the instructions, the instructions cause the processor 601 of the electronic device to perform the actions in the above-mentioned method embodiment. The implementation principles and technical effects are similar and will not be repeated here.

[0217] 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), one or more digital signal processors (DSPs), or one or more field programmable gate arrays (FPGAs). For another example, when a module is implemented by scheduling program code through a processing element, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code, 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).

[0218] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, 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 the computer program instructions are loaded and executed 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 device. 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, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. 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 drive (SSD)).

[0219] The term "plurality" in this article refers to two or more. The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: 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 the description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.

[0220] It will be understood that the various numerical numbers involved in the embodiments of the present application are merely distinctions for the convenience of description and are not intended to limit the scope of the embodiments of the present application.

[0221] 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

  • System service control method, electronic equipment and readable storage medium

    CN119536966A

  • Method and system for cross-domain access service

    CN106375371A

  • Terminal native crash processing method, terminal and computer readable storage medium

    CN107861854A

  • Service access method and device for dual-system terminal

    CN112068968A

  • Inter-process communication method based on application layer of android and basic application communication system

    US20160344846A1