Method and system for judging network connection state based on vehicle-mounted Aop annotation
By using AOP annotations and AspectJ compilation in Android development, network connection status judgment is achieved without modifying the original business code, solving the problems of serious code coupling and low development efficiency, and improving development efficiency and user experience.
Patent Information
- Application Number
- CN202411597264.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-02-28
AI Technical Summary
In Android development, network connection status judging codes are prone to serious code coupling, low development efficiency and high workload problems.
Using AOP (sectional-oriented programming) annotation method, compiling and customizing the annotation through AspectJ, network judgment logic is inserted without modifying the original business code to realize the judgment of network connection status.
It avoids coupling of specific business codes, reduces development workload, improves development efficiency, and improves user experience through automated network judgments.
Smart Images

Figure CN119544555A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a method for determining a network connection status based on vehicle-mounted Aop annotations. Background Art
[0002] Currently, in the process of Android development and use, it is essential to judge the network connection status. All in-vehicle networking applications need to judge the network status. When there is no network, some default pages of network abnormalities need to be displayed, and multimedia applications cannot play songs when there is no network. At this time, network status prompts are also required.
[0003] Aspect-Oriented Programming (AOP) is currently very convenient to use in Spring and its functions are very powerful, but its use in Android development is very limited.
[0004] However, in a large project, adding network judgment code to many places can easily lead to problems such as serious coupling, low development efficiency, and heavy development workload. Summary of the invention
[0005] In view of the above problems existing in the prior art, the present invention provides a method and system for determining the network connection status based on vehicle-mounted Aop annotations, so as to solve the problems of severe code coupling, heavy workload and low development efficiency; the method of the present invention can add network judgment based on AOP annotation network judgment without modifying the original business code; by inserting network judgment at a specific connection point, the user experience can be enhanced, and when there is no network, media playback can be performed, the user is directly prompted with the network status, and a dialog box pops up to guide the user to open the network settings.
[0006] The present invention is achieved through the following technical solutions:
[0007] In a first aspect, the present invention provides a method for determining a network connection status based on vehicle-mounted Aop annotations, which specifically includes the following steps:
[0008] Step 1: Introduce the configuration environment of AsepcJ;
[0009] Step 2: Write custom annotations for network judgment;
[0010] Step 3: Write the network judgment logic code;
[0011] Step 4: Execute local static compilation of the project;
[0012] Step 5: Use annotations to make network judgments in specific businesses.
[0013] Furthermore, step one specifically includes the following contents:
[0014] S11. Introduce the asepcj framework, write relevant configuration codes, and reference the AspectJ compilation method of the aspect-oriented framework;
[0015] S13. By defining tasks in the Gradle script to execute AspectJ compilation, the configuration environment of AsepcJ is completed.
[0016] Furthermore, in step 3, write the network judgment aspect logic code, which specifically includes the following contents:
[0017] S31, write a matching rule for defining a cut point, where the cut point matching rule includes multiple connection points represented by wildcards or regular expressions;
[0018] S32. Use @Before pre-notification to weave the code into the target method before the entry point and insert the code to perform network judgment;
[0019] S33. Use @After post-notification to weave the code into the target method after the entry point and insert the code to perform network judgment;
[0020] S34. Use @Around to write network judgment logic that can be inserted into the original business code to control the calling order of the original method. If you need to execute the original code logic again, you need to call the ProceedingJoinPoint.proceed() method to execute it.
[0021] Furthermore, in step 3, the following conditions must be met when writing different crosscut points:
[0022] A1. Use precise matching rules to write point-cut expressions to exclude all file packages that do not need to be scanned.
[0023] A2. The annotation modifier is public.
[0024] Furthermore, step 4 specifically includes the following contents:
[0025] S41. Execute compilation to build the Apk installation package. During the compilation phase, AspectJ traverses all class files in the project to find eligible entry points. After the class file is generated and before the dex file is generated, it traverses and matches all the entry points declared in the AspectJ file, and then weaves the Aspect code into the target .class.
[0026] S42. After the code is woven, multiple JoinPoints will be added to the new .class. The JoinPoints are used to establish a connection between the .class and the Aspect code so that the code can be called at runtime.
[0027] Furthermore, step five specifically includes the following contents:
[0028] S51, marking the annotation of network judgment at the service code of the network to be judged and passing in relevant parameters according to business requirements;
[0029] S52. Execute the network judgment logic at the cut point through the marked annotations.
[0030] In a second aspect, the present invention provides a system for determining a network connection status based on a vehicle-mounted Aop annotation, which is used to implement the method for determining a network connection status based on a vehicle-mounted Aop annotation described in the first aspect of the present invention, comprising:
[0031] Import module, used to import AsepcJ configuration environment;
[0032] The first writing module is used to write custom annotations for network judgment;
[0033] The second writing module is used to write the network judgment section logic code;
[0034] Execution module, used to perform local static compilation of the project;
[0035] The judgment module is used to use annotations to make network judgments in specific businesses.
[0036] In the third aspect, the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it implements a method for determining the network connection status based on vehicle-mounted Aop annotation as described in any one of the embodiments of the present invention.
[0037] In a fourth aspect, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for determining a network connection status based on vehicle-mounted Aop annotation as described in any one of the present inventions.
[0038] Compared with the prior art, the advantages of the present invention are as follows:
[0039] The present invention discloses a method and system for determining the network connection status based on vehicle-mounted Aop annotations. Through custom annotations and AspectJ compilation, the execution code of the network determination method is injected into a specific function, thereby realizing the function of specific network determination and avoiding coupling with specific services. The technical problems of scattered distribution of network determination codes, large development workload, low development efficiency and code duplication in existing projects are solved, thereby reducing development workload and improving development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following is a brief introduction to the drawings required for the specific embodiments or the description of the prior art. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn according to the actual scale.
[0041] Figure 1 A flowchart of a method for determining a network connection status based on vehicle-mounted Aop annotations according to the present invention;
[0042] Figure 2 It is a structural block diagram of a system for determining network connection status based on vehicle-mounted Aop annotations of the present invention;
[0043] Figure 3 This is a schematic diagram of the structure of an electronic device in Example 3 of the present invention. DETAILED DESCRIPTION
[0044] In order to clearly and completely describe the technical solution and its specific working process of the present invention, the specific implementation methods of the present invention are as follows in conjunction with the accompanying drawings of the specification:
[0045] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0046] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may mean that the first and second features are in direct contact, or the first and second features are in indirect contact through an intermediate medium. Moreover, a first feature being "above", "above" or "above" a second feature may mean that the first feature is directly above or obliquely above the second feature, or simply means that the first feature is higher in level than the second feature. A first feature being "below", "below" or "below" a second feature may mean that the first feature is directly below or obliquely below the second feature, or simply means that the first feature is lower in level than the second feature.
[0047] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0048] Example 1
[0049] like Figure 1 As shown, this embodiment provides a method for determining the network connection status based on vehicle-mounted Aop annotation, which specifically includes the following steps:
[0050] Step 1: Introduce the configuration environment of AsepcJ, including the following contents:
[0051] S11. Introduce the asepcj framework, write relevant configuration codes, and reference the AspectJ compilation method of the aspect-oriented framework;
[0052] S13. By defining tasks in the Gradle script to execute AspectJ compilation, the configuration environment of AsepcJ is completed.
[0053] Step 2: Write custom annotations for network judgment;
[0054] Step 3: Write the network judgment aspect logic code, which includes the following contents:
[0055] S31, write a matching rule for defining a cut point, where the cut point matching rule includes multiple connection points represented by wildcards or regular expressions;
[0056] S32. Use @Before pre-notification to weave the code into the target method before the entry point and insert the code to perform network judgment;
[0057] S33. Use @After post-notification to weave the code into the target method after the entry point and insert the code to perform network judgment;
[0058] S34. Use @Around to write network judgment logic that can be inserted into the original business code to control the calling order of the original method. If you need to execute the original code logic again, you need to call the ProceedingJoinPoint.proceed() method to execute it.
[0059] Among them, the following conditions must be met to write different crosscut points:
[0060] A1. Use precise matching rules to write point-cut expressions to exclude all file packages that do not need to be scanned.
[0061] A2. The annotation modifier is public.
[0062] Step 4: Execute local static compilation of the project, including the following:
[0063] S41. Execute compilation to build the Apk installation package. During the compilation phase, AspectJ traverses all class files in the project to find eligible entry points. After the class file is generated and before the dex file is generated, it traverses and matches all the entry points declared in the AspectJ file, and then weaves the Aspect code into the target .class.
[0064] S42. After the code is woven, multiple JoinPoints will be added to the new .class. The JoinPoints are used to establish a connection between the .class and the Aspect code so that the code can be called at runtime.
[0065] Step 5: Use annotations to make network judgments at specific business locations, including the following:
[0066] S51, marking the annotation of network judgment at the service code of the network to be judged and passing in relevant parameters according to business requirements;
[0067] S52. Execute the network judgment logic at the cut point through the marked annotations.
[0068] In this embodiment, network judgment is added to a specific method. First, the annotation method CheckNet is defined, and then the CheckNetAspect aspect class is created to handle the specific judgment of the network business logic. The annotation call is made on the specific method to which the network judgment is to be added. When the program is executed, the marked annotation function is automatically detected, and then the network judgment method is automatically executed. In this way, network judgment can be performed without modifying the original code, which decouples the code, reduces duplicate code, reduces development work, and has high reusability.
[0069] Example 2
[0070] like Figure 2 As shown, this embodiment provides a system for determining network connection status based on vehicle-mounted Aop annotations, which is used to implement the method for determining network connection status based on vehicle-mounted Aop annotations described in Embodiment 1 of the present invention, including:
[0071] Import module, used to import AsepcJ configuration environment;
[0072] The first writing module is used to write custom annotations for network judgment;
[0073] The second writing module is used to write the network judgment section logic code;
[0074] Execution module, used to perform local static compilation of the project;
[0075] The judgment module is used to use annotations to make network judgments in specific businesses.
[0076] Example 3
[0077] Figure 3 This is a schematic diagram of the structure of a computer device in Example 3 of the present invention. Figure 3 A block diagram of an exemplary computer device 12 suitable for use in implementing embodiments of the present invention is shown. Figure 3 The computer device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0078] like Figure 3 As shown, the computer device 12 is in the form of a general-purpose computing device. The components of the computer device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that connects various system components (including the system memory 28 and the processing unit 16).
[0079] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0080] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0081] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 3 not shown, usually called a "hard drive"). Although Figure 3 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.
[0082] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in the memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0083] The computer device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), may also communicate with one or more devices that enable a user to interact with the computer device 12, and / or communicate with any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 22. In addition, the computer device 12 in this embodiment, the display 24 does not exist as an independent individual, but is embedded in the mirror surface, and when the display surface of the display 24 is not displayed, the display surface of the display 24 and the mirror surface are visually integrated. In addition, the computer device 12 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) through a network adapter 20. As shown in the figure, the network adapter 20 communicates with other modules of the computer device 12 through a bus 18. It should be understood that although not shown in the figures, other hardware and / or software modules may be used in conjunction with the computer device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0084] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, for example, implementing a method for determining a network connection status based on vehicle-mounted Aop annotations provided in an embodiment of the present invention.
[0085] Example 4
[0086] Embodiment 4 of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, a method for determining the network connection status based on vehicle-mounted Aop annotation as provided in all embodiments of the present application is implemented.
[0087] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used or used in conjunction with an instruction execution system, device, or device.
[0088] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0089] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0090] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0091] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for determining network connection status based on vehicle-mounted Aop annotation, characterized in that: The specific steps include: Step 1: Introduce the configuration environment of AsepcJ; Step 2: Write custom annotations for network judgment; Step 3: Write the network judgment logic code; Step 4: Execute local static compilation of the project; Step 5: Use annotations to make network judgments in specific businesses.
2. A method for determining network connection status based on vehicle-mounted Aop annotation as claimed in claim 1, characterized in that: Step 1 specifically includes the following: S11. Introduce the asepcj framework, write relevant configuration codes, and reference the AspectJ compilation method of the aspect-oriented framework; S13. By defining tasks in the Gradle script to execute AspectJ compilation, the configuration environment of AsepcJ is completed.
3. A method for determining network connection status based on vehicle-mounted Aop annotation as claimed in claim 1, characterized in that: In step 3, write the network judgment aspect logic code, which includes the following contents: S31, write a matching rule for defining a cut point, where the cut point matching rule includes multiple connection points represented by wildcards or regular expressions; S32. Use @Before pre-notification to weave the code into the target method before the entry point and insert the code to perform network judgment; S33. Use @After post-notification to weave the code into the target method after the entry point and insert the code to perform network judgment; S34. Use @Around to write network judgment logic that can be inserted into the original business code to control the calling order of the original method. If you need to execute the original code logic again, you need to call the ProceedingJoinPoint.proceed() method to execute it.
4. The method for determining the network connection status based on vehicle-mounted Aop annotation as claimed in claim 1, characterized in that: In step 3, the following conditions must be met to write different crosscut points: A1. Use precise matching rules to write point-cut expressions to exclude all file packages that do not need to be scanned. A2. The annotation modifier is public.
5. The method for determining the network connection status based on vehicle-mounted Aop annotation as claimed in claim 1, characterized in that: Step 4 specifically includes the following: S41. Execute compilation to build the Apk installation package. During the compilation phase, AspectJ traverses all class files in the project to find eligible entry points. After the class file is generated and before the dex file is generated, it traverses and matches all the entry points declared in the AspectJ file, and then weaves the Aspect code into the target .class. S42. After the code is woven, multiple JoinPoints will be added to the new .class. The JoinPoints are used to establish a connection between the .class and the Aspect code so that the code can be called at runtime.
6. A method for determining network connection status based on vehicle-mounted Aop annotation as claimed in claim 1, characterized in that: Step 5 specifically includes the following: S51, marking the annotation of network judgment at the service code of the network to be judged and passing in relevant parameters according to business requirements; S52. Execute the network judgment logic at the cut point through the marked annotations.
7. A system for determining network connection status based on vehicle-mounted Aop annotations, used to implement a method for determining network connection status based on vehicle-mounted Aop annotations as claimed in any one of claims 1 to 6, characterized in that: include: Import module, used to import AsepcJ configuration environment; The first writing module is used to write custom annotations for network judgment; The second writing module is used to write the network judgment section logic code; Execution module, used to perform local static compilation of the project; The judgment module is used to use annotations to make network judgments in specific businesses.
8. A computer device, characterized in that: It includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements a method for determining the network connection status based on vehicle-mounted Aop annotation as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the program is executed by a processor, a method for determining a network connection status based on vehicle-mounted Aop annotation as described in any one of claims 1 to 6 is implemented.