Direct calling method, device, equipment and medium of hidden API in Android system

By encapsulating the framework.jar package in the SDK and adding the SDK to the application layer and the application framework layer, the direct call of hidden APIs is realized in the Android system, solving the problems of low development efficiency and program exceptions in the existing technology, and improving development efficiency and program stability.

CN114546679BActive Publication Date: 2025-03-14GUANGDONG XIAOTIANCAI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210134723.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-14
Publication Date
2025-03-14
Estimated Expiration
2042-02-14

AI Technical Summary

Technical Problem

In the prior art, calling hidden APIs using the Java reflection mechanism leads to low development efficiency, and the system differences between different Android device versions are large, which may lead to program exceptions.

Method used

Encapsulate the obtained framework.jar package in the SDK, contains methods for calling the hidden API, and add the SDK as a layer between the application layer and the application framework layer, so that the application layer directly calls the hidden API in the application framework layer.

Benefits of technology

By directly calling the hidden API, the development efficiency is improved, the possibility of program exceptions is reduced, and the program stability is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114546679B_ABST
    Figure CN114546679B_ABST
Patent Text Reader

Abstract

The present invention is applicable to the field of computer technology, and provides a method, device, electronic device and storage medium for directly calling a hidden API in an Android system. The method comprises: encapsulating an acquired first framework.jar package in an SDK, wherein the SDK contains an encapsulated method for calling the hidden API, and adding the SDK as a layer between an application layer and an application framework layer, so that the application layer directly calls the hidden API in the application framework layer through the SDK, thereby realizing direct calling of the hidden API by decoupling the application layer and the application framework layer, improving development efficiency, and enhancing program stability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer technology, and in particular relates to a method, device, electronic device and storage medium for directly calling a hidden API in an Android system. Background Art

[0002] In the process of Android development, sometimes we need to implement some special functions or effects. Therefore, we need to call many APIs (Application Programming Interface) that do not exist in the SDK (Software Development Kit) but actually exist, that is, hidden APIs. Such hidden APIs are usually public classes, methods or constants marked with @hide.

[0003] Such hidden APIs include two categories:

[0004] 1. Some hidden API application programming interfaces that come with the Android system;

[0005] 2. In actual development, system developers add some new APIs in the application framework layer (framework layer).

[0006] In the prior art, during the development of the Android APP layer, the Java reflection mechanism is usually used to call the hidden API. Compared with the direct calling method, this reflection calling method requires additional empty code for the hidden API, which is too complicated and has low development efficiency. In addition, there are many types of existing devices, and the Android system versions running in different types of devices may be different, and the differences between different versions of the system are large. During the development process, the Android system running in some devices may cause some program anomalies due to the lack of corresponding hidden APIs. Summary of the invention

[0007] The purpose of the present invention is to provide a method, device, electronic device and storage medium for directly calling a hidden API in an Android system, aiming to solve the problem of low development efficiency caused by using a Java reflection mechanism to call a hidden API in the prior art.

[0008] In one aspect, the present invention provides a method for directly calling a hidden API in an Android system, the method comprising the following steps:

[0009] Encapsulate the first framework.jar package obtained into an SDK, wherein the SDK contains an encapsulated method for calling a hidden API;

[0010] The SDK is added as a layer between the application layer and the application framework layer, so that the application layer directly calls the hidden API in the application framework layer through the SDK.

[0011] Preferably, before the step of packaging the acquired first framework.jar package into an SDK, the method further includes:

[0012] Collect the second framework.jar package loaded by different versions of Android systems;

[0013] The plurality of second framework.jar packages are subjected to a union process to obtain the first framework.jar package.

[0014] Preferably, the step of performing union processing on the plurality of second framework.jar packages comprises:

[0015] Perform dependency configuration on the multiple second framework.jar packages;

[0016] The first framework.jar package is obtained by performing bytecode operation on the multiple second framework.jar packages based on the configured dependency relationship, wherein the bytecode operation is used to scan and take union processing of the API.

[0017] Preferably, the mode used when performing dependency configuration on the multiple second framework.jar packages is the compileOnly mode of gradle.

[0018] Preferably, the method further comprises:

[0019] The SDK is repackaged according to the newly added API, so that the application layer directly calls the hidden API in the application framework layer through the repackaged SDK.

[0020] On the other hand, the present invention also provides a device for directly calling a hidden API in an Android system, the device comprising:

[0021] An SDK packaging unit, used to package the acquired first framework.jar package into an SDK, wherein the SDK includes a packaged method for calling a hidden API; and

[0022] The SDK adding unit is used to add the SDK as a layer between the application layer and the application framework layer, so that the application layer directly calls the hidden API in the application framework layer through the SDK.

[0023] Preferably, the device further comprises:

[0024] A collecting unit, used for collecting the second framework.jar package loaded by different versions of Android systems; and

[0025] The union processing unit is used to perform union processing on the multiple second framework.jar packages to obtain the first framework.jar package.

[0026] Preferably, the union processing unit comprises:

[0027] A dependency configuration unit, used to perform dependency configuration on the plurality of second framework.jar packages; and

[0028] The packaging subunit is used to perform bytecode operation on the multiple second framework.jar packages based on the configured dependency relationship to obtain the first framework.jar package, wherein the bytecode operation is used to scan and take union processing of the API.

[0029] On the other hand, the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0030] On the other hand, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0031] The present invention encapsulates the acquired first framework.jar package in an SDK, which includes an encapsulated method for calling a hidden API, and adds the SDK as a layer between the application layer and the application framework layer, so that the application layer can directly call the hidden API in the application framework layer through the SDK, thereby realizing direct calling of the hidden API by decoupling the application layer and the application framework layer, improving development efficiency and enhancing program stability. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1A This is a flowchart of the implementation of the method for directly calling a hidden API in an Android system provided by the first embodiment of the present invention;

[0033] Figure 1B This is an example diagram of a newly created layer provided in the first embodiment of the present invention;

[0034] Figure 2 is a flowchart of the implementation of the device for directly calling a hidden API in an Android system provided by the second embodiment of the present invention; and

[0035] Figure 3 It is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION

[0036] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. It should also be understood that in the description of the present application specification and the attached claims, the terms "first", "second", etc. are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.

[0037] The specific implementation of the present invention is described in detail below in conjunction with specific embodiments:

[0038] Embodiment 1:

[0039] Figure 1A The implementation process of the direct calling method of the hidden API in the Android system provided by the first embodiment of the present invention is shown. For the convenience of explanation, only the part related to the embodiment of the present invention is shown, which is described in detail as follows:

[0040] In step S101, the acquired first framework.jar package is packaged in an SDK, and the SDK includes a packaged method for calling a hidden API.

[0041] The embodiment of the present invention is applicable to an electronic device, which is a device installed with an Android system, specifically, the electronic device can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA) and other terminal devices, and the embodiment of the present application does not impose any restrictions on the specific type of electronic device. It should be noted here that the method for calling a hidden API described in this embodiment refers to an executable code block.

[0042] In the prior art, when developing Android APP (Android application), the android.jar package provided by the SDK is used, and the internal API (internal API) and hidden API (hidden API) are removed from the android.jar. Therefore, it is impossible to directly call some hidden APIs that do not exist in these SDKs during development. However, when the Android application is running on an electronic device, it will load the framework.jar package in the system application framework layer, that is, load / system / framework / framework.jar. The only difference between the framework.jar package and the android.jar package is that it does not remove the internal API and hidden API. Therefore, the first framework.jar package can be the framework.jar package loaded when the Android application is running on the electronic device, or it can be the framework.jar package manually edited by the developer according to actual needs after obtaining the above-mentioned loaded framework.jar package.

[0043] Considering that in the actual development process, it may be necessary to adapt to multiple versions of Android devices at the same time, and different versions of Android devices load different framework.jar packages, that is, different versions of Android system application framework layers are also different. Therefore, it is usually necessary to debug each version of the Android system separately, and the manpower cost and time cost of debugging in the development process are high. Therefore, the framework.jar package loaded by the Android system under a single version cannot meet all the actual development needs of developers, that is, it cannot meet the hidden API requirements of the application framework layer of multiple versions of Android systems at the same time during the development process. Therefore, preferably, before the step of encapsulating the obtained first framework.jar package in an SDK, the second framework.jar packages loaded by different versions of Android systems are collected, and the multiple second framework.jar packages are processed by taking the union of the two packages to obtain the above-mentioned first framework.jar package, so as to meet the calling requirements of the hidden API in the actual development process by collecting the APIs of different versions of the system.

[0044] After collecting framework.jar packages loaded by multiple versions of Android systems, considering that once the API is repeated during the actual compilation process, it will cause compilation failure, therefore, it is necessary to ensure that the API in the first framework.jar package is not repeated. Therefore, preferably, when the multiple second framework.jar packages are processed for union, the multiple second framework.jar packages are configured for dependency, and the multiple second framework.jar packages are bytecode operated based on the configured dependency relationship to obtain the first framework.jar package, thereby ensuring that the subsequent SDK compilation passes smoothly by removing the repeated API. Among them, the bytecode operation is used to scan and union the API. In a specific implementation, the multiple second framework.jar packages can be configured for dependency using the preset mode of gradle, and based on the configured dependency relationship, the pre-compiled android gradle plug-in is used to scan all the APIs in the second framework.jar, and then the same APIs are removed, and finally merged into a total framework.jar package, that is, the above-mentioned first framework.jar package, the first framework.jar contains all the APIs in the framework.jar, and all APIs will not be repeated. Among them, the preset mode only needs to ensure that the SDK compilation code stage is available. Taking into account that some program exceptions may occur during the API call process due to the non-existence of the hidden API, preferably, the mode used for dependency configuration of multiple second framework.jar packages is gradle's compileOnly mode to ensure that the subsequent SDK compilation passes smoothly and that the program is normal during the API call process.

[0045] As an example, if there are three second framework.jar packages collected, namely framework-A.jar package, framework-B.jar package and framework-C.jar package, framework-A.jar package contains API 1 and API 2, framework-B.jar package contains API 1 and API 3, and framework-C.jar package contains API 2 and API 3, then the first framework.jar package obtained contains API 1, API 2 and API3, and there are no duplicates.

[0046] In step S102, SDK is added as a layer between the application layer and the application framework layer, so that the application layer directly calls the hidden API in the application framework layer through the SDK.

[0047] In an embodiment of the present invention, in order to achieve decoupled development of the application framework layer (Application Framework) and the application layer (Applications), a new layer can be created between the two layers for decoupling, so that the system layer and the application layer can interact through the newly created layer. The newly created layer is the above-mentioned SDK that can be called by the application layer. In this way, the application layer no longer needs to call some hidden APIs of the application framework layer through the reflection mechanism, but only needs to call the encapsulated methods in the SDK. The encapsulated methods will actually call the API in the application framework layer corresponding to the first framework.jar package, thereby speeding up the development efficiency and improving the program stability. Figure 1B is a diagram showing an example of a structure of a new layer provided in the first embodiment of the present invention. Figure 1B The ultraframework is the new layer.

[0048] It should be pointed out here that when the application is actually compiled and run, the Android system's own framework.jar package is still used.

[0049] After the SDK is added as a layer between the application layer and the application framework layer, considering that there will be some new requirements for API calls, it is preferred to repackage the SDK according to the newly added API so that the application layer can directly call the hidden API in the application framework layer through the repackaged SDK, thereby further improving development efficiency by maintaining the SDK.

[0050] In an embodiment of the present invention, the obtained first framework.jar package is encapsulated in an SDK, which includes an encapsulated method for calling a hidden API. The SDK is added as a layer between the application layer and the application framework layer, so that the application layer can directly call the hidden API in the application framework layer through the SDK, thereby realizing the direct calling of the hidden API by decoupling the application layer and the application framework layer, improving development efficiency and enhancing program stability.

[0051] Embodiment 2:

[0052] Figure 2 The structure of the device for directly calling a hidden API in an Android system provided by the second embodiment of the present invention is shown. For the sake of convenience, only the part related to the embodiment of the present invention is shown, including:

[0053] An SDK packaging unit, used to package the acquired first framework.jar package into an SDK, wherein the SDK includes a packaged method for calling a hidden API; and

[0054] The SDK adding unit is used to add the SDK as a layer between the application layer and the application framework layer, so that the application layer can directly call the hidden API in the application framework layer through the SDK.

[0055] Preferably, the device further comprises:

[0056] A collecting unit, used for collecting the second framework.jar package loaded by different versions of Android systems; and

[0057] The union processing unit is used to perform union processing on the multiple second framework.jar packages to obtain the first framework.jar package.

[0058] Preferably, the union processing unit comprises:

[0059] A dependency configuration unit, used to perform dependency configuration on the plurality of second framework.jar packages using a preset mode of gradle; and

[0060] The packaging subunit is used to perform bytecode operation on the multiple second framework.jar packages using a pre-compiled gradle plug-in based on the configured dependency relationship to obtain the first framework.jar package, wherein the bytecode operation is used to scan and take union processing of the API.

[0061] Preferably, the mode used when performing dependency configuration on multiple second framework.jar packages is the compileOnly mode of gradle.

[0062] Preferably, the device further comprises:

[0063] The updating unit is used to repackage the SDK according to the newly added API, so that the application layer directly calls the hidden API in the application framework layer through the repackaged SDK.

[0064] In the embodiment of the present invention, each unit of the device for directly calling a hidden API in an Android system can be implemented by a corresponding hardware or software unit, and each unit can be an independent software or hardware unit, or can be integrated into a software or hardware unit, which is not intended to limit the present invention. The specific implementation of each unit of the device for directly calling a hidden API in an Android system can refer to the description of the aforementioned method embodiment, which will not be repeated here.

[0065] Embodiment three:

[0066] Figure 3 The structure of an electronic device provided by the third embodiment of the present invention is shown. For the convenience of description, only the part related to the embodiment of the present invention is shown.

[0067] The electronic device 3 of the embodiment of the present invention includes a processor 30, a memory 31, and a computer program 32 stored in the memory 31 and executable on the processor 30. When the processor 30 executes the computer program 32, the steps in the above-mentioned method embodiments are implemented, such as steps S101 to S102 shown in FIG. 1. Alternatively, when the processor 30 executes the computer program 32, the functions of each unit in the above-mentioned device embodiments are implemented, such as Figure 2 The functions of the units 21 to 22 are shown.

[0068] In an embodiment of the present invention, the obtained first framework.jar package is encapsulated in an SDK, which includes an encapsulated method for calling a hidden API. The SDK is added as a layer between the application layer and the application framework layer, so that the application layer can directly call the hidden API in the application framework layer through the SDK, thereby realizing the direct calling of the hidden API by decoupling the application layer and the application framework layer, improving development efficiency and enhancing program stability.

[0069] Embodiment 4:

[0070] In an embodiment of the present invention, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed by a processor, the steps in the above method embodiment are implemented, for example, steps S101 to S102 shown in FIG. 1. Alternatively, when the computer program is executed by a processor, the functions of each unit in the above device embodiment are implemented, for example, Figure 2 The functions of the units 21 to 22 are shown.

[0071] In an embodiment of the present invention, the obtained first framework.jar package is encapsulated in an SDK, which includes an encapsulated method for calling a hidden API. The SDK is added as a layer between the application layer and the application framework layer, so that the application layer can directly call the hidden API in the application framework layer through the SDK, thereby realizing the direct calling of the hidden API by decoupling the application layer and the application framework layer, improving development efficiency and enhancing program stability.

[0072] The computer-readable storage medium of the embodiment of the present invention may include any entity or device or recording medium capable of carrying computer program code, for example, ROM / RAM, magnetic disk, optical disk, flash memory and other memories.

[0073] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for directly calling a hidden API in an Android system, characterized in that: The method comprises the following steps: Encapsulating the obtained first framework.jar package in an SDK, wherein the SDK includes an encapsulated method for calling a hidden API, wherein the first framework.jar package is obtained in the following manner: collecting second framework.jar packages loaded by different versions of Android systems, performing dependency configuration on the collected multiple second framework.jar packages, and performing bytecode operation on the multiple second framework.jar packages based on the configured dependency relationship to obtain the first framework.jar package, wherein the bytecode operation is used to scan and perform union processing on the API; The SDK is added as a layer between the application layer and the application framework layer, so that the application layer directly calls the hidden API in the application framework layer through the SDK.

2. The method according to claim 1, characterized in that The mode used when performing dependency configuration on the multiple second framework.jar packages is the compileOnly mode of gradle.

3. The method according to claim 1, characterized in that The method further comprises: The SDK is repackaged according to the newly added API, so that the application layer directly calls the hidden API in the application framework layer through the repackaged SDK.

4. A device for directly calling a hidden API in an Android system, characterized in that: The device comprises: an SDK encapsulation unit, for encapsulating the obtained first framework.jar package in an SDK, wherein the SDK includes an encapsulated method for calling a hidden API, wherein the first framework.jar package is obtained by: collecting second framework.jar packages loaded by different versions of Android systems, performing dependency configuration on the collected multiple second framework.jar packages, and performing bytecode operations on the multiple second framework.jar packages based on the configured dependency relationships to obtain the first framework.jar package, wherein the bytecode operations are used to scan and union the APIs; and The SDK adding unit is used to add the SDK as a layer between the application layer and the application framework layer, so that the application layer directly calls the hidden API in the application framework layer through the SDK.

5. The device for directly calling a hidden API in an Android system as claimed in claim 4, characterized in that: The mode used when performing dependency configuration on the multiple second framework.jar packages is the compileOnly mode of gradle.

6. The device for directly calling a hidden API in an Android system as claimed in claim 4, characterized in that: Also includes: The SDK is repackaged according to the newly added API, so that the application layer directly calls the hidden API unit in the application framework layer through the repackaged SDK.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 3 are implemented.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.

Citation Information

Patent Citations

  • Method and device for playing TS stream

    CN108600826A

  • SDK generation and self-upgrading method and device, readable medium and equipment

    CN113407165A