Network access method and electronic device, storage medium

By setting the correspondence between application categories and network access rules in the screen-off state of wearable devices, the network access permissions of applications can be controlled, thus solving the problem of excessive power consumption of electronic devices and achieving rapid hibernation and energy-saving effects.

CN114630325BActive Publication Date: 2026-05-12GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
Filing Date
2020-12-10
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Wearable devices and other electronic devices frequently access the network when the screen is off, causing the battery to drain too quickly and affecting normal operation and sleep mode.

Method used

In screen-off mode, by pre-setting the correspondence between application categories and network access rules, network access permissions for different types of applications can be controlled, and background applications that are on the blacklist can be prohibited from accessing the data network.

Benefits of technology

It reduces the impact of frequent network access by applications, saves power, and allows devices to quickly enter sleep mode, thus reducing power consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114630325B_ABST
    Figure CN114630325B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a network access method and electronic device, and a storage medium, which are applied to an electronic device, and the method comprises: determining a first application category corresponding to a first application in a screen-off state, the first application being a running application; finding a first network access rule corresponding to the first application category from a preset application category and network access rule correspondence relationship; and controlling the first application to access a data network of the terminal in the screen-off state based on the first network access rule.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of electronic technology, and in particular to a network access method, electronic device, and storage medium. Background Technology

[0002] Currently, wearable devices and other electronic devices can access the internet by using a personal hotspot on a mobile phone or by inserting a SIM card. For the SIM card method, an additional SIM card slot is required on the electronic device. Therefore, using a personal hotspot on a mobile phone is more universal for wearable devices and other electronic devices to access the internet.

[0003] Management software installed on electronic devices directly configures which applications are allowed or denied network access. Applications that are denied network access will never be able to access the network; if they need to access the network, they must be re-enabled to allow network access. If system or instant messaging applications are denied network access, it will directly affect the normal operation and communication of the electronic device. When using a mobile hotspot to access the internet, multiple applications will request network access, especially after the screen is off or locked. A large number of background applications accessing the network consume a significant amount of battery power, and frequent network access can prevent the electronic device from entering sleep or hibernation mode. Summary of the Invention

[0004] This application provides a network access method, an electronic device, and a storage medium that can save power and enable the electronic device to quickly enter a sleep or hibernation state when the screen is off.

[0005] The technical solution of this application is implemented as follows:

[0006] In a first aspect, embodiments of this application propose a network access method applied to an electronic device, the method comprising:

[0007] When the screen is off, determine the first application category corresponding to the first application, where the first application is the currently running application;

[0008] Find the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules;

[0009] Based on the first network access rule, the first application is controlled to access the terminal's data network in the screen-off state.

[0010] Secondly, embodiments of this application provide an electronic device, the electronic device comprising:

[0011] The determination module is used to determine the first application category corresponding to the first application when the screen is off, wherein the first application is a running application;

[0012] The search module is used to search for the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules;

[0013] The network access control module is used to control the first application's access to the terminal's data network in the screen-off state, based on the first network access rules.

[0014] Thirdly, embodiments of this application propose a terminal, wherein the electronic device includes: a processor, a memory, and a communication bus; the processor executes a running program stored in the memory to implement the method described above.

[0015] Fourthly, embodiments of this application propose a storage medium storing a computer program thereon, characterized in that the computer program, when executed by a processor, implements the method described above.

[0016] This application provides a network access method, an electronic device, and a storage medium. The method includes: in a screen-off state, determining a first application category corresponding to a first application, wherein the first application is a running application; searching for a first network access rule corresponding to the first application category from a preset correspondence between application categories and network access rules; and controlling the first application to access the terminal's data network in the screen-off state based on the first network access rule. By adopting the above implementation scheme, the electronic device pre-sets a correspondence between application categories and network access rules, allowing the electronic device to set different network access permissions for different types of applications. When the electronic device is in a screen-off state, the electronic device first determines the first application category corresponding to the running first application, then searches for the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules; and controls the first application to access the terminal's data network in the screen-off state based on the first network access rule. Thus, the electronic device can control different types of applications to access the network with different network access permissions in the screen-off state. This reduces the frequency of application network access without affecting the normal function of the electronic device, thereby greatly saving the power of the electronic device and allowing the electronic device to quickly enter a sleep or hibernation state in the screen-off state. Attached Figure Description

[0017] Figure 1 A flowchart illustrating a network access method provided in an embodiment of this application;

[0018] Figure 2This is a schematic diagram illustrating an exemplary process for a wearable device to access a terminal's data network in a screen-off state, as provided in an embodiment of this application.

[0019] Figure 3 A schematic diagram of the structure of an electronic device provided in this application embodiment. Figure 1 ;

[0020] Figure 4 A schematic diagram of the structure of an electronic device provided in this application embodiment. Figure 2 . Detailed Implementation

[0021] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit the scope of this application.

[0022] Example 1

[0023] This application provides a network access method, such as... Figure 1 As shown, the method may include:

[0024] S101. When the screen is off, determine the first application category corresponding to the first application, where the first application is the currently running application.

[0025] The network access method proposed in this application can be applied to scenarios where electronic devices use a personal hotspot on a terminal to connect to the network.

[0026] It should be noted that the electronic device in this application embodiment can be a wearable device such as a smartwatch that requires the use of a personal hotspot on the terminal to access the network. The specific device can be selected according to the actual situation, and this application embodiment does not make any specific limitations.

[0027] In this embodiment of the application, when the electronic device is in a screen-off state, the electronic device obtains the currently running first application and determines the first application category corresponding to the first application.

[0028] It should be noted that applications can be categorized based on their running status, such as foreground applications, background applications, or persistent applications. Alternatively, an application blacklist and / or application whitelist can be pre-set, and applications can be categorized based on the pre-set application blacklist and / or application whitelist, such as applications in the application blacklist and / or applications in the application whitelist.

[0029] Specifically, the process by which an electronic device determines the first application category corresponding to the first application may include two steps: first, based on preset judgment rules, it determines whether the first application is a background application and obtains a first judgment result; then, based on preset blacklists and whitelists, it determines whether the first application is in an application blacklist and obtains a second judgment result. The electronic device can determine the first application category corresponding to the first application based on the first judgment result and the second judgment result.

[0030] It should be noted that, based on a preset blacklist and whitelist, it is also possible to first determine whether the first application is in the application blacklist and obtain a second determination result; then, based on a preset determination rule, it is possible to determine whether the first application is a background application and obtain a first determination result. The specific order in which the first determination result and the second determination result are obtained can be determined according to the actual situation, and this application embodiment does not make specific limitations.

[0031] In this embodiment of the application, the process by which the electronic device determines whether the first application is a background application based on a preset judgment rule and obtains the first judgment result can be as follows: the electronic device obtains the process running status corresponding to the first application; then compares the process running status with a preset threshold; when the process running status is less than or equal to the preset threshold, it is determined that the first judgment result is that the first application is not a background application; when the process running status is greater than the preset threshold, it is determined that the first judgment result is that the first application is a background application.

[0032] It's important to note that since NetworkPolicyManager is a management class in Android used to control network access policies, related policies can be set via the application's Uid. Electronic devices can control application data access in the screen-off state by setting policies in NetworkPolicyManager. Specifically, the setUidPolicy function in NetworkPolicyManagerService (which sets the policy corresponding to a specific Uid) can be used to determine the first application category. The policies can be one of the following:

[0033] public static final int POLICY_NONE = 0x0; / / No policy is set.

[0034] public static final int POLICY_REJECT_METERED_BACKGROUND=0x1;

[0035] / / Application background access denied network access

[0036] public static final int POLICY_ALLOW_METERED_BACKGROUND=0x4;

[0037] / / Allow network access in the application background

[0038] After the UID policy is set on the electronic device, it is stored in the / data / system / netpolicy.xml file, so that the relevant policies can take effect normally after a restart.

[0039] It should be noted that electronic devices can set a method isUidForegroundOnRestrictBackgroundLocked() in setUidPolicy to determine the foreground / background status of a process. This method ultimately calls isProcStateAllowedWhileOnRestrictBackgroundLocked(). In the above method, preset judgment rules can be set, and then based on the preset judgment rules, it can determine whether the first application is a background application and obtain the first judgment result.

[0040] It should be noted that NetworkPolicyManager is a hidden class, which is not found in the standard Software Development Kit (SDK). Therefore, it can be called in two ways: one is if the application is compiled from Android source code, in which case the relevant interface can be called directly; the other is if the application is compiled from an Integrated Development Environment (IDE), in which case reflection can be used to call it.

[0041] Furthermore, both of the above calling methods require the application to be a system application. To ensure successful application calls, add `android:sharedUserId="android.uid.system"` to the `AndroidManifest.xml` file and grant the necessary permissions.<uses-permission android:name="android.permission.MANAGE_NETWORK_POLICY" / > .

[0042] S102. From the preset correspondence between application categories and network access rules, find the first network access rule corresponding to the first application category.

[0043] When the screen is off, after the electronic device determines the first application category corresponding to the first application that is currently running, the electronic device searches for the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules.

[0044] In this embodiment of the application, during the process of setting the Uid policy, the electronic device also pre-sets the correspondence between application categories and network access rules. The network access rules can be of the following types:

[0045] public static final int RULE_NONE = 0; / / No rule is set.

[0046] public static final int RULE_ALLOW_METERED = 1 << 0; / / Allow access rules

[0047] public static final int RULE_TEMPORARY_ALLOW_METERED = 1 << 1; / / Allows temporary access traffic rules, targeting foreground applications in the application blacklist.

[0048] public static final int RULE_REJECT_METERED = 1 << 2; / / Rule to block access

[0049] public static final int RULE_ALLOW_ALL = 1 << 5; / / Allow access to all network rules

[0050] public static final int RULE_REJECT_ALL = 1 << 6; / / Deny access to all network rules

[0051] It should be noted that after the electronic device determines the first application category corresponding to the first application, it searches for the first network access rule corresponding to the first application category from the above network access rules.

[0052] In one optional embodiment, if the first determination result is that the first application is a background application and the second determination result is that the first application is in the application blacklist, the electronic device determines the first network access rule as prohibiting access to the data network from the preset application category and network access rule correspondence.

[0053] It should be noted that in the screen-off state, applications that are in the background and on the application blacklist of the electronic device are prohibited from accessing the data network. This prevents these applications from frequently accessing the data network while the screen is off, thus putting the electronic device into sleep mode and reducing the power consumption of the electronic device in the screen-off state.

[0054] It should be noted that prohibiting access to the data network is only one optional network access rule. Electronic devices can also set different network access rules according to the actual situation. This application does not make specific limitations on this.

[0055] S103. Based on the first network access rule, control the first application to access the terminal's data network when the screen is off.

[0056] After the electronic device finds the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules, the electronic device controls the first application to access the terminal's data network in the screen-off state based on the first network access rule.

[0057] In this embodiment of the application, after the electronic device determines the first network access rule corresponding to the first application category, the electronic device updates the network access policy of the first application according to the first network access rule, transmits the updated network access policy of the first application to the class that has registered the relevant events, and realizes the final network access control through the subsequent response function.

[0058] It should be noted that the `setUidPolicy` calls the `updateRulesForDataUsageRestrictionsULInner` function. The specific update of the network access policy of the first application can be implemented in the `updateRulesForDataUsageRestrictionsULInner` function. There are three implementation methods: controlling the values ​​of the two boolean variables `isForeground` and `isBlacklisted` in the `updateRulesForDataUsageRestrictionsULInner` function, and / or modifying the logical control flow, adding a set of network access policies, and / or adding direct judgment logic in the `updateRulesForDataUsageRestrictionsULInner` function. The specific implementation method can be selected from the three methods according to the actual situation.

[0059] In one optional embodiment, to prevent access to the data network while the screen is off, the policy can be changed to RULE_REJECT_METERED by setting isForeground to false and isBlacklisted to true in the updateRulesForDataUsageRestrictionsULInner function, thus preventing access to the mobile network. Alternatively, the logic control flow can be modified by adding a RULE_REQUEST_DISABLE_MOBILE_TRAFFIC function and using this policy to control related logic to achieve traffic access control. Furthermore, the following direct judgment logic can be added to the updateRulesForDataUsageRestrictionsULInner function:

[0060]

[0061] It should be noted that the last line of the `updateRulesForDataUsageRestrictionsULInner` function includes a line of code that sends the updated network access policy of the first application to the classes that have registered the relevant events. The updated network access policy for the first application is then implemented through a subsequent response function.

[0062] Specifically, the response function restricts the application's network access based on the first application's Uid and the first network access rule.

[0063] In one alternative embodiment, when the electronic device determines that the first network access rule is to prohibit access to the data network, the electronic device, while in a screen-off state, restricts the data network requests of the first application to prevent the first application from accessing the terminal's data network.

[0064] Specifically, when the electronic device is in a screen-off state, it can restrict the data network requests of the first application by disconnecting the source address interface corresponding to the data network request and / or disconnecting the destination address interface corresponding to the data network request.

[0065] It should be noted that once a connection is established between the electronic device and the terminal, the electronic device can access the internet via the terminal's data network. This connection can include features such as Bluetooth.

[0066] For example, when the smartwatch is in screen-off mode, it prevents background apps on the app blacklist from using the device's personal hotspot to access the internet.

[0067] Furthermore, when the electronic device switches from a screen-off state to a screen-on state, the electronic device restores the first network access rule of the first application to the network access rule corresponding to the screen-on state.

[0068] Specifically, the electronic device can restore the network access policy of the first application in the `updateRulesForDataUsageRestrictionsULInner` function by updating the network access policy of the first application, thus restoring the first network access rule of the first application to the network access rule corresponding to the screen-on state. For details, please refer to the process of updating the network access policy of the first application in the `updateRulesForDataUsageRestrictionsULInner` function; it will not be elaborated here.

[0069] For example, such as Figure 2 As shown, the specific process of a wearable device accessing the terminal's data network in a screen-off state includes:

[0070] 1. In screen-off mode, receive network access requests from the first application;

[0071] 2. Determine if the first application is a background application;

[0072] 3. When the first application is a background application, determine whether the first application is on the application blacklist;

[0073] 4. When the first application is on the application blacklist, prohibit the first application from accessing the network using the terminal's personal hotspot;

[0074] 5. If the first application is not on the application blacklist, execute step 7;

[0075] 6. If the first application is not a background application, execute step 7;

[0076] 7. Allow the first application to access the network using the terminal's personal hotspot.

[0077] It is understandable that electronic devices pre-set the correspondence between application categories and network access rules. Electronic devices can set different network access permissions for different types of applications. When the electronic device is in a screen-off state, it first determines the first application category corresponding to the first running application. Then, it searches for the first network access rule corresponding to the first application category from the pre-set correspondence between application categories and network access rules. Based on the first network access rule, it controls the first application's access to the terminal's data network in a screen-off state. Thus, the electronic device can control different types of applications to access the network with different network access permissions in a screen-off state. This reduces the frequency of applications accessing the network without affecting the normal function of the electronic device, thereby greatly saving power and allowing the electronic device to quickly enter sleep or hibernation mode in a screen-off state.

[0078] Example 2

[0079] This application provides an electronic device. For example... Figure 3 As shown, the electronic device 1 includes:

[0080] The determination module 10 is used to determine the first application category corresponding to the first application when the screen is off, wherein the first application is a running application;

[0081] The lookup module 11 is used to look up the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules;

[0082] Network access control module 12 is used to control the first application to access the terminal's data network in the screen-off state based on the first network access rules.

[0083] Optionally, the electronic device further includes: a determination module;

[0084] The judgment module is used to determine whether the first application is a background application based on preset judgment rules, and obtain a first judgment result; and to determine whether the first application is in an application blacklist based on preset blacklists and whitelists, and obtain a second judgment result.

[0085] The determining module 10 is further configured to determine the first application category based on the first judgment result and the second judgment result.

[0086] Optionally, the determining module 10 is further configured to determine, from the preset application category and network access rule correspondence, that the first network access rule is to prohibit access to the data network when the first judgment result is that the first application is a background application and the second judgment result is that the first application is in the application blacklist.

[0087] Optionally, the electronic device further includes: a limiting module;

[0088] The restriction module is used to restrict the data network requests of the first application when the screen is off.

[0089] Optionally, the electronic device further includes: a disconnection module;

[0090] The disconnect module is used to disconnect the source address interface corresponding to the data network request; and / or disconnect the destination address interface corresponding to the data network request.

[0091] Optionally, the electronic device further includes: a recovery module;

[0092] The recovery module is used to restore the first network access rule of the first application to the network access rule corresponding to the screen-on state when switching from the screen-off state to the screen-on state.

[0093] Optionally, the electronic device further includes: an acquisition module;

[0094] The acquisition module is used to acquire the running status of the process corresponding to the first application;

[0095] The determining module 10 is further configured to determine that the first judgment result is that the first application is not a background application when the process running state is less than or equal to a preset threshold; and to determine that the first judgment result is that the first application is a background application when the process running state is greater than the preset threshold.

[0096] This application provides an electronic device that, when in a screen-off state, determines a first application category corresponding to a first application, where the first application is a currently running application. It then searches for a first network access rule corresponding to the first application category from a preset correspondence between application categories and network access rules. Based on the first network access rule, it controls the first application to access the terminal's data network in the screen-off state. Therefore, the electronic device proposed in this embodiment has a pre-set correspondence between application categories and network access rules. The electronic device can set different network access permissions for different types of applications. When the electronic device is in a screen-off state, it first determines the first application category corresponding to the currently running first application, then searches for the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules, and controls the first application to access the terminal's data network in the screen-off state based on the first network access rule. Thus, the electronic device can control different types of applications to access the network with different network access permissions in the screen-off state. This reduces the frequency of application network access without affecting the normal function of the electronic device, thereby greatly saving power and allowing the electronic device to quickly enter a sleep or hibernation state in the screen-off state.

[0097] Figure 4 A schematic diagram of the composition structure of an electronic device 1 provided in this application embodiment. Figure 2 In practical applications, based on the same disclosed concept of the above embodiments, such as Figure 4 As shown, the electronic device 1 in this embodiment includes: a processor 13, a memory 14, and a communication bus 15.

[0098] In the specific embodiments, the aforementioned determining module 10, searching module 11, network access control module 12, judgment module, restriction module, disconnection module, recovery module, and acquisition module can be implemented by a processor 13 located on the electronic device 1. The processor 13 can be at least one of the following: Application Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), CPU, controller, microcontroller, and microprocessor. It is understood that for different devices, the electronic device used to implement the above processor functions can also be other types; this embodiment does not specifically limit this.

[0099] In this embodiment, the communication bus 15 is used to realize the connection communication between the processor 13 and the memory 14; when the processor 13 executes the running program stored in the memory 14, it implements the following network access method:

[0100] When the screen is off, determine the first application category corresponding to the first application, where the first application is a running application; find the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules; based on the first network access rule, control the first application to access the terminal's data network in the screen-off state.

[0101] Furthermore, the processor 13 is also used to determine whether the first application is a background application based on a preset judgment rule, and obtain a first judgment result; to determine whether the first application is in an application blacklist based on a preset blacklist and whitelist, and obtain a second judgment result; and to determine the category of the first application based on the first judgment result and the second judgment result.

[0102] Furthermore, the processor 13 is also configured to determine, from the preset application category and network access rule correspondence, that the first network access rule is to prohibit access to the data network when the first judgment result is that the first application is a background application and the second judgment result is that the first application is in the application blacklist.

[0103] Furthermore, the processor 13 is also configured to restrict data network requests of the first application when the screen is off.

[0104] Furthermore, the processor 13 is also configured to disconnect the source address interface corresponding to the data network request; and / or disconnect the destination address interface corresponding to the data network request.

[0105] Furthermore, the processor 13 is also configured to restore the first network access rule of the first application to the network access rule corresponding to the screen-on state when switching from the screen-off state to the screen-on state.

[0106] Furthermore, the processor 13 is also configured to obtain the process running status corresponding to the first application; when the process running status is less than or equal to a preset threshold, determine that the first judgment result is that the first application is not a background application; when the process running status is greater than the preset threshold, determine that the first judgment result is that the first application is a background application.

[0107] This application provides a storage medium storing a computer program thereon. The computer-readable storage medium stores one or more programs, which can be executed by one or more processors and applied in an electronic device. The computer program implements the network access method described above.

[0108] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0109] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the related technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause an image display device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this disclosure.

[0110] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application.

Claims

1. A network access method, characterized in that, The method is applied to scenarios where electronic devices use a terminal's personal hotspot to connect to the network. The method includes: When the screen is off, the first application category corresponding to the first application is determined, and the first application is the application that is currently running. The first application category corresponding to the first application is determined based on the setUidPolicy function in NetworkPolicyManagerService. The setUidPolicy function is used to set the policy corresponding to the Uid of the first application. From the preset application category and network access rule correspondence, find the first network access rule corresponding to the first application category; the first network access rule includes a rule that allows applications that are foreground applications in the application blacklist to temporarily access traffic; the preset application category and network access rule correspondence is established during the process of setting the policy corresponding to the Uid of the first application; Based on the first network access rule, update the network access policy of the first application to control the first application's access to the terminal's data network in the screen-off state; the update of the first application's network access policy is based at least on controlling the values ​​of the two boolean variables isForeground and isBlacklisted in the updateRulesForDataUsageRestrictionsULInner function, and / or adding direct judgment logic to the updateRulesForDataUsageRestrictionsULInner function; Wherein, determining the first application category corresponding to the first application includes: Based on preset judgment rules, determine whether the first application is a background application, and obtain the first judgment result; Based on a preset blacklist and whitelist, determine whether the first application is in the application blacklist to obtain a second determination result; Based on the first judgment result and the second judgment result, the first application category is determined; The step of determining whether the first application is a background application based on preset judgment rules, and obtaining a first judgment result, includes: Obtain the running status of the process corresponding to the first application; When the process running state is less than or equal to a preset threshold, it is determined that the first judgment result is that the first application is not a background application; When the process running state is greater than the preset threshold, the first judgment result is determined to be that the first application is a background application.

2. The method according to claim 1, characterized in that, The step of searching for the first network access rule corresponding to the first application category from the preset correspondence between application categories and network access rules includes: If the first judgment result is that the first application is a background application and the second judgment result is that the first application is on the application blacklist, the first network access rule is determined to be prohibiting access to the data network from the correspondence between the preset application category and the network access rule.

3. The method according to claim 2, characterized in that, The step of controlling the first application to access the terminal's data network in the screen-off state based on the first network access rule includes: When the screen is off, restrict the data network requests of the first application.

4. The method according to claim 3, characterized in that, The restriction on the data network requests of the first application includes: Disconnect the source address interface corresponding to the data network request; And / or, disconnect the destination address interface corresponding to the data network request.

5. The method according to claim 1, characterized in that, After controlling the first application to access the terminal's data network in the screen-off state based on the first network access rule, the method further includes: When switching from the screen-off state to the screen-on state, the first network access rule of the first application is restored to the network access rule corresponding to the screen-on state.

6. An electronic device, wherein the electronic device is used in a scenario where the electronic device uses a terminal's personal hotspot for network connection, characterized in that, The electronic device includes: The determination module is used to determine the first application category corresponding to the first application when the screen is off, wherein the first application is a running application; the first application category corresponding to the first application is determined based on the setUidPolicy function in NetworkPolicyManagerService; the setUidPolicy function is used to set the policy corresponding to the Uid of the first application; The lookup module is used to look up the first network access rule corresponding to the first application category from the preset application category and network access rule correspondence; the first network access rule includes a rule that allows applications that are foreground applications in the application blacklist to temporarily access traffic; the preset application category and network access rule correspondence is established during the process of setting the policy corresponding to the Uid of the first application; The network access control module is used to update the network access policy of the first application based on the first network access rule, so as to control the first application's access to the terminal's data network in the screen-off state; the update of the network access policy of the first application is based at least on controlling the values ​​of the two boolean variables isForeground and isBlacklisted in the updateRulesForDataUsageRestrictionsULInner function, and / or, by adding direct judgment logic to the updateRulesForDataUsageRestrictionsULInner function; The acquisition module is used to acquire the running status of the process corresponding to the first application. The determining module is further configured to determine, when the process running state is less than or equal to a preset threshold, that the first judgment result is that the first application is not a background application; and to determine, when the process running state is greater than the preset threshold, that the first judgment result is that the first application is a background application. The judgment module is used to determine whether the first application is a background application based on preset judgment rules, and obtain a first judgment result; and to determine whether the first application is in an application blacklist based on preset blacklists and whitelists, and obtain a second judgment result. The determining module is further configured to determine the first application category based on the first judgment result and the second judgment result.

7. An electronic device, characterized in that, The electronic device includes: a processor, a memory, and a communication bus; when the processor executes the running program stored in the memory, it implements the method as described in any one of claims 1-5.

8. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-5.