Application package name acquisition method, electronic device, and computer storage medium
By receiving and storing the process identifier and package name of the calling application in the electronic device, and using the system username to obtain a second package name list and perform a query match, the accuracy and security issues of application package name acquisition in the prior art are solved. This enables rapid acquisition of application package names in electronic devices, improves the accuracy and security of application package name acquisition, and ensures that the target application package name is determined from the correct second package name list. It also reduces the number of transmissions and function parameters, thereby improving the security and legitimacy of obtaining application package names.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-20
- Publication Date
- 2026-03-17
AI Technical Summary
Existing technologies using package name retrieval methods cannot guarantee correctness and legality, posing security risks. Furthermore, passing package names to functions increases code readability and security risks.
By receiving the process identifier and package name of the calling application and storing them together, the system username is used to obtain a second list of package names, and a query and match is performed on the data in the list. This reduces the risk of interface function transmission and forgery, and ensures the accuracy and legality of package name acquisition.
It improves the accuracy and security of application package name retrieval, reduces the number of times package names are passed and the number of function parameters are passed, and enhances code readability and security.
Smart Images

Figure CN114385275B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal technology, and in particular to a method for obtaining application package names, electronic devices, and computer storage media. Background Technology
[0002] During development, it is typically necessary to obtain relevant information about the calling application, such as fingerprint information, application name, application icon, version number, version name, minimum SDK version, startup items or permissions, in order to perform functions such as validating the legitimacy of the calling application, displaying the application name and icon, or redirecting to the application. This relevant information about the calling application needs to be obtained using the application package name; therefore, it is necessary to obtain the application package name of the calling application.
[0003] In existing technologies, one approach involves applications with data access attributes (SharedUserId) calling remote interfaces. However, the application package name obtained from the UID (Linux User ID, system username) can be multiple, making it difficult to determine which package name is the truly needed one. Furthermore, passing the application package name as a function parameter allows for package name spoofing, resulting in low credibility and posing security risks. Additionally, passing the package name as a function parameter increases the number of parameters passed, leading to decreased code readability. Moreover, passing the package name as a function parameter requires passing it with every function call, increasing the frequency of package name passing, further complicating code readability, and increasing the security risks and complexity of obtaining the application package name.
[0004] It is evident that existing application package name acquisition methods cannot guarantee correctness and legality. Summary of the Invention
[0005] This application discloses an application package name acquisition method, electronic device, and computer storage medium, which can eliminate the security risks of passing package names through functions in the prior art, reduce the number of times package names are passed and the number of function parameters, and improve the legality and correctness of application package name acquisition.
[0006] The first aspect of this application discloses a method for obtaining application package names. The method includes: based on the connection between a calling application and a first application, receiving a first package name passed by the application through calling a preset interface function, and obtaining the process identifier of the calling application; associating and storing the process identifier and the corresponding first package name to obtain a data pair list; obtaining a second package name list of the calling application through the system username of the calling application, the second package name list containing at least one application package name; obtaining the process identifier of the calling application as a query condition, querying the data pair list to obtain the application package name corresponding to the process identifier to be queried, and using the obtained application package name as the query package name; matching the query package name with the second package names in the second package name list, and if there is an application package name in the second package name list that matches the query package name, then determining the application package name that matches the query package name as the target application package name.
[0007] In this application, the accuracy of the second package name list is ensured because it is obtained directly from the internal resources of the calling application based on the system username. By determining an application package name from the second package name list as the target application package name, the target application package name is identified from the correct second package name list, improving the accuracy of the target application package name. Furthermore, it significantly reduces the security risks associated with passing package names through interface functions, reduces the number of times the application package name is passed and the number of parameters passed to interface functions, and improves the security and legitimacy of obtaining the application package name.
[0008] In some optional implementations, the application package name acquisition method further includes: if there is no application package name in the second package name list that matches the queried package name, then returning a prompt message indicating that the application package name is forged to the calling application to indicate that the calling application has failed to make the call.
[0009] Through the above technical solution, the first application sends a prompt message that the application package name of the calling application is forged. The calling application fails to make the call, and thus does not execute the related programs after the query package name, thereby ensuring the security of the first application.
[0010] In some optional implementations, before receiving the application package name passed by the calling application through calling a preset interface function as the first package name, the method further includes: establishing a remote connection with the calling application in response to a remote connection instruction from the calling application.
[0011] Through the above technical solution, after the first application successfully connects with the calling application, the calling application quickly calls the preset interface function, so that the first application can obtain the application package name of the calling application passed by the calling application.
[0012] In some alternative implementations, the calling application is an Android-based application or a HarmonyOS-based application.
[0013] In some optional implementations, associating the process identifier with the corresponding first package name includes: associating the process identifier with the first package name using a Map structure.
[0014] The above technical solution enables the process identifier and the first package name to be associated and mapped for storage. This allows subsequent determination of the corresponding application package name based only on the process identifier, eliminating the need to pass the application package name through interface functions with parameters. It also reduces the number of times the application package name is passed and the number of parameters passed to the interface functions, thereby improving the security and convenience of obtaining the application package name.
[0015] In some optional implementations, the step of associating and storing the process identifier and the first package name using a Map structure includes storing the process identifier as the key and the first package name corresponding to the process identifier as the value in the Map structure.
[0016] By using the above technical solution and taking the process identifier as the key, the corresponding first package name can be found quickly, which greatly improves the speed of finding the application package name.
[0017] In some optional implementations, the step of using the process identifier to be queried as a query condition to query the data pair list, obtaining the first package name corresponding to the process identifier to be queried, and using the obtained package name as the query package name includes: determining the query key corresponding to the process identifier to be queried, retrieving the value corresponding to the query key in the Map structure, and determining the value corresponding to the query key as the query package name.
[0018] In some optional implementations, obtaining the second package name list of the calling application based on the system username of the calling application includes: obtaining the system username of the calling application; and obtaining the second package name list of the calling application based on the system username.
[0019] The above technical solution ensures that the first application obtains the correct application package name because the second package name list is obtained based on the system username.
[0020] In some optional implementations, receiving the first package name passed by the calling application through a preset interface function includes: establishing the calling application and the first application, wherein the calling application has a SharedUserId attribute; establishing a service in the first application and binding the service through the calling application; and passing the application package name of the calling application through function parameters to determine it as the first package name.
[0021] The above technical solution enables the acquisition of the first package name for Android and HarmonyOS applications.
[0022] In some optional implementations, before passing the application package name of the calling application through function parameters and determining it as the first package name, the method further includes: establishing cross-process communication between the first application and the calling application.
[0023] The above technical solution establishes cross-process communication between the first application and the calling client for the corresponding services (Android services or HarmonyOS services), ensuring that the first application obtains the correct application package name passed by the calling client application.
[0024] A second aspect of this application discloses an electronic device, including a processor and a memory; the memory is used to store instructions; the processor is used to invoke the instructions in the memory, causing the electronic device to execute the application package name acquisition method.
[0025] A third aspect of this application discloses a computer-readable storage medium storing at least one instruction that, when executed by a processor, implements the application package name acquisition method.
[0026] In some optional embodiments, the fourth aspect of this application discloses an application package name acquisition device, wherein the application package name acquisition method runs in an electronic device, and the application package name acquisition device includes a plurality of functional modules, wherein the plurality of functional modules are used to execute the application package name acquisition method.
[0027] Furthermore, the technical effects brought about by the fourth aspect can be found in the descriptions of the methods in the above-mentioned method section, and will not be repeated here. Attached Figure Description
[0028] Figure 1 This is a schematic diagram illustrating the interaction between multiple applications in an electronic device provided in the embodiments of this application.
[0029] Figure 2 This is a flowchart of an application package name acquisition method provided in an embodiment of this application.
[0030] Figure 3This is a flowchart of an application package name acquisition method provided in another embodiment of this application.
[0031] Figure 4 This is a flowchart of the method for obtaining application package names based on the Android system provided in the embodiments of this application.
[0032] Figure 5 This is a flowchart of the method for obtaining application package names based on the HarmonyOS system provided in the embodiments of this application.
[0033] Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0034] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0035] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. The terminology used in this application's specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. It should be understood that, unless otherwise stated, " / " in this application means "or". For example, A / B can mean A or B. "And / or" in this application is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. "At least one" refers to one or more. "More than one" refers to two or more. For example, at least one of a, b, or c can represent: a, b, c, a and b, a and c, b and c, and a, b, and c (seven cases).
[0036] refer to Figure 1 The diagram illustrates the interaction between multiple applications in an electronic device 10 according to an embodiment of this application. Specifically, the electronic device 10 has multiple applications installed, such as a first application and a second application. The second application serves as the calling application in this embodiment, enabling the first application to obtain the application package name of the second application. The specific process can be found in the following description. Figure 2The detailed description provided. The second application can be one or more, for example... Figure 1 The examples shown are Application 1, Application 2, ..., Application n.
[0037] In one embodiment of this application, the electronic device 10 may be a mobile phone, tablet computer, personal digital assistant, smart TV, e-reader, wearable device, or the like.
[0038] refer to Figure 2 The diagram shows a flowchart of a package name acquisition method in one embodiment of this application. The method is applied in a first application of an electronic device, for example... Figure 1 In the electronic device 10 shown, to more clearly illustrate the method for obtaining the application package name of the calling application, multiple applications in the electronic device are classified into a first application and a second application. In the embodiments provided in this application, the second application is used as the calling application. Figure 2 The process shown is the process executed by the first application to obtain the application package name of the calling application (i.e., the second application).
[0039] Step S101: Based on the connection between the calling application and the first application, receive the application package name passed by the calling application through calling a preset interface function as the first package name, and obtain the process identifier of the calling application.
[0040] In some embodiments of this application, before receiving the application package name of the calling application, a remote connection can be established between the calling application and the first application. Specifically, the calling application sends a remote connection instruction to the first application; the first application responds to the remote connection instruction with the calling application and calls back the callback function of the calling application upon successful connection, thereby establishing a remote connection with the calling application. Based on the remote connection, the calling application obtains the application package name of the calling application, i.e., the first package name, by calling a preset interface function, and passes the first package name to the first application; that is, the first application receives the first package name passed by the calling application.
[0041] The preset interface function is used to pass the application package name of the script file. For example, the preset interface function can be testTransPackageName(String currentPackageName). The process identifier (ID) is used to uniquely identify the application's process. This process identifier is obtained according to the method provided by the system. There is a one-to-one correspondence between the process identifier and the first package name. Specifically, in the scenario of cross-process communication, the calling application in the electronic device passes the first package name of the calling application that has successfully connected with the first application in the form of a string when calling the interface function. Thus, the first application receives the first package name of the calling application. When multiple calling applications call the first application, for example, if the calling applications (such as application A, application B, etc.) need to call the first application (such as application C), then step S101 is repeated. That is, the receiving application obtains the first package name by calling the preset interface function and obtains the process identifier of the calling application. In other words, the calling application sends the preset interface function to the first application to pass the first package name of the calling application, thereby receiving multiple first package names and obtaining multiple process identifiers corresponding to the multiple first package names. It is worth noting that when multiple client applications simultaneously use this implementation to call the interface of the first application, the first application will receive multiple first packet names.
[0042] It should be noted that when the calling application and the first application establish a connection for the first time, the calling application passes the first package name to the first application by calling the interface function. Therefore, the calling application only needs to pass the first package name once, so that other interface functions do not need to pass the application package name every time, reducing the number of times the interface functions pass parameters and improving the efficiency of obtaining the first package name.
[0043] As an optional implementation, receiving the first package name passed by the calling application through a preset interface function specifically includes: establishing the calling application and the first application, wherein the calling application has a SharedUserId attribute; establishing a service in the first application and binding the service through the calling application; and passing the application package name of the calling application through function parameters to determine it as the first package name.
[0044] In this optional implementation, if both the calling application and the first application are Android applications, a cross-process communication interface, test.aidl, is agreed upon for the calling application and the first application. These interfaces are placed in the src / main / aidl directories of the calling application and the first application, respectively. A function A for passing a string package name and a function B for testing the acquisition of the second application's package name on the server are added to the test.aidl interface. For example, function A could be testTransPackageName(String currentPackageName), and function B could be testServiceUsePackageName(). The calling application binds to the first application's service, and in the onServiceConnected() callback function after successful binding, function A is called to pass the calling application's package name to the server.
[0045] If both the calling application and the first application are HarmonyOS applications, a cross-process communication interface, test.idl, is agreed upon for both applications. This interface is placed in the ohos / app / idl directories of both applications. In test.idl, a function A is added to pass a string package name, and a function B is added to test obtaining the application package name of the first application on the server. The calling application connects to the service of the first application. Upon successful connection, the onAbilityConnectDone() function calls function A. For example, function A can be testTransPackageName(String currentPackageName), and function B can be testServiceUsePackageName(). Passing the application package name of the calling application to the server achieves the retrieval of the first package name of the Android or HarmonyOS application.
[0046] As an optional implementation, before passing the application package name of the second application via function parameters and determining it to be the first package name, the method further includes:
[0047] Establish cross-process communication between the first application and the calling application.
[0048] In this optional implementation, inter-process communication refers to communication between different processes. In order to obtain the application package names passed by multiple calling applications with the SharedUserId attribute, i.e., the second package name list, it is necessary to establish service inter-process communication between the first application and the second application to ensure that the first application obtains the correct application package names, i.e., the second package name list, passed by the calling applications.
[0049] Step S102: Associate and store the process identifier and the corresponding first package name to obtain a data pair list.
[0050] In this embodiment, a process identifier is associated with a first package name; that is, the process identifier and the application package name passed by the calling application are stored as a data pair. The data pair list in this embodiment can contain one or more data pairs. If multiple calling clients communicate with the first application, the data pair list will contain multiple data pairs. The first application associates the process identifier with the corresponding first package name in a one-to-one correspondence, so that the corresponding first package name can be determined only based on the process identifier, thereby enabling the verification of the first package name.
[0051] As an optional implementation, the step of associating and storing the process identifier and the corresponding first package name includes:
[0052] The process identifier and the first package name are associated and stored using a Map structure.
[0053] In this optional implementation, a Map structure is a data structure that maps key objects to value objects, with each element containing a pair of key and value objects. When retrieving an element from a Map structure, providing only the key object will return the corresponding value object, resulting in extremely fast lookup speeds. In the embodiments of this application, a Map structure can be used to associate and map process identifiers with the first package name. Subsequently, only the corresponding first package name needs to be determined based on the process identifier as the application package name, eliminating the need to pass the application package name via parameter-based interface functions. This reduces the number of times the application package name is passed and the number of parameters passed to interface functions, thus improving the security and convenience of obtaining the application package name.
[0054] As an optional implementation, the step of associating and storing the process identifier and the first package name using a Map structure includes:
[0055] The process identifier is used as the key and the first package name is used as the value, and stored in a Map structure.
[0056] In this optional implementation, the process identifier is used as the key, and the corresponding first package name is used as the value. Understandably, for a Map structure, the value is found by traversing the key. Therefore, using the process identifier as the key allows for quick retrieval of the corresponding first package name, significantly improving the speed of finding the application package name.
[0057] Step S103: Obtain the second package name list of the calling application through the system username of the calling application. The second package name list contains at least one application package name.
[0058] Each application (App) has a unique system username (Linux UserID, or UID). This UID identifies that the application's files are only visible to that application itself; therefore, one UID corresponds to one application package name. The application package name of the calling application is obtained through the UID. Multiple applications with the SharedUserId attribute can be configured to run in the same process and can access the databases and files in other applications' data directories. Therefore, one UID can correspond to multiple application package names of the calling applications. In other words, a second list of application package names is obtained based on the system username assigned to the calling application. Since the system username allows direct access to the application's resource data, the correctness of the application package names in the second list is guaranteed.
[0059] As an optional implementation, obtaining the second package name list of the calling application based on the system username of the calling application includes:
[0060] Obtain the system username of the calling application;
[0061] The second package name list of the calling application is obtained based on the system username.
[0062] In this optional implementation, methods for obtaining the system username (UID) of the calling application include, but are not limited to: calculating using the `ps` command, viewing the PID, and exporting the `data / system / packages.list` file. After obtaining the system username of the calling application, the application package name corresponding to the system username is obtained by executing the `getPackageManager().getNameForUid(UID)` command. Since the second package name list is obtained based on the system username, it ensures that the first application obtains the correct application package name.
[0063] Step S104: Obtain the process identifier of the calling application as a query condition, perform a query in the data pair list, obtain the first package name corresponding to the process identifier to be queried, and use the obtained first package name as the query package name.
[0064] In the embodiments of this application, the query condition refers to the identifier corresponding to the process that needs to be queried and verified, which serves as the query index. Specifically, a process identifier of the calling application is randomly obtained as the query condition, and then the corresponding application package name is queried from the data pair list as the query package name. It can be understood that the query package name is an application package name in the first package name.
[0065] As an optional implementation, a query is performed on the data pair list to obtain the first package name corresponding to the process identifier to be queried. The query package name includes:
[0066] Determine the query key corresponding to the process identifier to be queried, retrieve the value corresponding to the query key in the Map structure, and determine the value corresponding to the query key as the query package name.
[0067] In this optional implementation, the process identifier to be queried is used as the query key. The Map structure is traversed, and the value corresponding to the key that matches the query key is the query package name.
[0068] Step S105: Match the query package name with each application package name in the second package name list. If there is an application package name in the second package name list that matches the query package name, then determine the application package name that matches the query package name as the target application package name.
[0069] The first package name is the application package name passed as a parameter in an interface function. Since these first package names are all externally transmitted, there is a risk of forgery. The application package names in the second package name list are correct, but there are multiple of them, making it difficult to confirm the true application package name. Therefore, to ensure the legality and correctness of the obtained application package name, in this embodiment, the query package name is matched against each application package name in the second package name list; that is, a search is performed in the second package name list to determine if there is an application package name that matches the query package name. If an application package name that matches the query package name is found, then the application package name that matches the query package name is determined to be the target application package name; that is, the query package name is the target application package name.
[0070] By determining an application package name from the second package name list as the target application package name, the accuracy of the target application package name is improved by identifying the correct second package name list. Furthermore, it significantly reduces the security risks associated with passing the package name through interface functions, reduces the number of times the application package name is passed and the number of parameters passed to interface functions, and improves the security and legitimacy of obtaining the application package name of the calling application.
[0071] Furthermore, after obtaining the target application package name, relevant information of the calling application can be determined based on the target application package name, such as application name, application icon, version number, version name, minimum SDK version, startup items, permissions, provider components, signature, etc. As an optional implementation, the application package name acquisition method further includes:
[0072] Step S106: If there is no application package name in the second package name list that matches the queried package name, return a prompt message indicating that the application package name is forged to the calling application to indicate that the calling application has failed to call.
[0073] In this optional implementation, if no application package name matching the queried package name is found in the second package name list, it indicates that the first package name matching the queried package name is a forged package name. At this time, the first application returns a prompt message indicating that the application package name is forged, and the call to the calling application fails, thereby not executing the application related to the queried package name and ensuring the security of the application.
[0074] As an optional implementation, before the application package name passed by the receiving end application through calling a preset interface function is used as the first package name, the following steps are also included:
[0075] In response to a remote connection command to the calling application, a remote connection is established with the calling application.
[0076] In this optional implementation, the first application establishes a remote connection with the calling application so that after the first application successfully connects with the calling application, the calling application can quickly call a preset interface function, allowing the first application to obtain the application package name passed by the calling application.
[0077] As an optional implementation, the calling application can be an Android-based application or a HarmonyOS-based application.
[0078] In this optional implementation, the application package name acquisition method in this application embodiment is applicable to both Android system applications and HarmonyOS system applications.
[0079] refer to Figure 3 The diagram shown is a flowchart of a package name acquisition method according to another embodiment of this application. The method is applied in electronic devices, for example... Figure 1 The electronic device 10 shown above. As mentioned above, to more clearly illustrate the method for obtaining the application package name of the calling application, the multiple applications in the electronic device are classified into a first application and a second application, wherein the second application serves as the calling application. Figure 3In the illustrated embodiment, the first application can be a remote process, and the second application can be a calling application that invokes the remote process. In one specific implementation, the step of the first application obtaining the application package name of the second application is as follows:
[0080] Step S301: The second application sends a remote connection command to the first application. After successfully establishing a connection with the first application, the second application immediately calls a preset interface function to pass the package name of the second application to the first application.
[0081] Step S302: The first application receives the packet name passed from the second application and obtains the process identifier of the second application.
[0082] Step S303: The first application uses the process identifier of the second application as the key and the package name passed by the second application as the value, and stores it in the Map structure of the first application.
[0083] Step S304: The second application calls other interfaces of the first application.
[0084] Step S305: The first application obtains the UID of the second application, and the first application obtains the list of package names corresponding to the UID based on the UID.
[0085] Step S306: The first application obtains the process identifier of the second application, and based on the process identifier, queries the Map structure in step S303 to find the packet name passed when establishing the connection.
[0086] Step S307: Compare the package name queried in step S306 with the package name list in step S305. If the package name list in step S305 contains the package name queried in step S306, the package name obtained in step S306 is determined to be the target application package name. If the package name list in step S305 does not contain the package name queried in step S306, it is determined that there is a package name forgery, and the second application cannot be called successfully.
[0087] refer to Figure 4 The diagram shows a flowchart of a method for obtaining application package names based on the Android system. This method is used in electronic devices, such as... Figure 1 The electronic device 10 shown may specifically include the following steps:
[0088] Step S401: Create a second Android application and a first Android application, wherein the second Android application has the SharedUserId attribute;
[0089] Step S402: Establish a service in the first Android application and bind the service through the second Android application;
[0090] Step S403: Return a message indicating successful binding. In the callback function for successful binding, pass the application package name of the second Android application through function parameter passing and confirm it as the first package name.
[0091] Step S404: The service obtains the process identifier of the second Android application at the interface implementation location that receives the transmitted string package name, and stores the process identifier and the first package name in a Map structure with the process identifier as the key and the first package name as the value.
[0092] Step S405: The second Android application calls other interfaces of the first Android application;
[0093] Step S406: The service obtains the system username of the second Android application at the implementation location of the test function, and obtains the second package name list based on the system username;
[0094] Step S407: Using the process identifier as the query condition, perform a query in the Map structure to obtain the application package name corresponding to the process identifier to be queried, and use the obtained application package name as the query package name;
[0095] Step S408: Match the query package name with each application package name in the second package name list. If there is an application package name in the second package name list that matches the query package name, then determine the application package name that matches the query package name as the target application package name.
[0096] Step S409: If there is no application package name in the second package name list that matches the queried package name, then return an application package name forgery prompt message to the service to indicate that the service call failed.
[0097] refer to Figure 5 The diagram shows a flowchart of a method for obtaining application package names based on the HarmonyOS system. This method is applied in electronic devices, such as... Figure 1 The electronic device 10 shown may specifically include the following steps:
[0098] Step S501: Create a second HarmonyOS application and a first HarmonyOS application, wherein the second HarmonyOS application has a SharedUserId attribute;
[0099] Step S502: Establish a service in the first HarmonyOS application and connect to the service through the second HarmonyOS application;
[0100] Step S503: Return a connection success message. In the connection success callback function, pass the application package name of the second Android application through function parameter passing and confirm it as the first package name.
[0101] Step S504: The service obtains the process identifier of the second HarmonyOS application at the interface implementation location that receives the transmitted string package name, and stores the process identifier and the first package name in a Map structure with the process identifier as the key and the first package name as the value.
[0102] Step S505: The second HarmonyOS application calls other interfaces of the first HarmonyOS application;
[0103] Step S506: The service obtains the system username of the second HarmonyOS application at the implementation location of the test function, obtains the second package name list based on the system username, and obtains the process identifier to be queried for the service.
[0104] Step S507: Using the process identifier as the query condition, perform a query in the Map structure to obtain the application package name corresponding to the process identifier, and use the obtained application package name as the query package name;
[0105] Step S508: Match the query package name with each application package name in the second package name list. If there is an application package name in the second package name list that matches the query package name, then determine the application package name that matches the query package name as the target application package name.
[0106] Step S509: If there is no application package name in the second package name list that matches the queried package name, then return an application package name forgery prompt message to the service to indicate that the service call failed.
[0107] refer to Figure 6 The diagram shown is a structural schematic of an electronic device 60 in an embodiment of this application. This electronic device 60 can be the electronic device 10 described in the above embodiments. The electronic device 60 includes, but is not limited to, a processor 601 and a memory 602. These devices can be connected via one or more communication buses 603. The memory 602 stores one or more computer programs 604. The one or more computer programs 604 are configured to be executed by the processor 601. The one or more computer programs 604 include multiple instructions, which, when executed by the processor 601, can implement the application package name acquisition method executed on the electronic device 10 in the above embodiments, thereby achieving the function of acquiring the application package name of the application installed on the electronic device 10.
[0108] This embodiment also provides a computer storage medium storing computer instructions. When the computer instructions are executed on an electronic device, the electronic device performs the above-described related method steps to implement the application package name acquisition method in the above embodiment.
[0109] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement the application package name acquisition method described above.
[0110] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component, or module. The apparatus may include a connected processor and a memory; wherein the memory is used to store computer execution instructions, and when the apparatus is running, the processor may execute the computer execution instructions stored in the memory to cause the chip to execute the application package name acquisition method in the above method embodiments.
[0111] In this embodiment, the electronic device, computer storage medium, computer program product or chip are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding method provided above, and will not be repeated here.
[0112] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0113] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0114] The unit described as a separate component may or may not be physically separate. The component shown as a unit can be one physical unit or multiple physical units, that is, it can be located in one place or distributed in multiple different places. Some or all of the units can be selected to achieve the purpose of the solution in this embodiment according to actual needs.
[0115] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0116] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0117] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0118] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this application without departing from the spirit and scope of the technical solutions of this application.
Claims
1. A method for obtaining application package names, applied to a first application of an electronic device, characterized in that, The method comprises: Based on the connection of the calling end application and the first application, receiving the application package name passed by the calling end application through calling a preset interface function as a first package name, and obtaining a process identifier of the calling end application; Storing the process identifier and the corresponding first package name in association to obtain a data pair list; Obtaining a second package name list of the calling end application according to a system username of the calling end application, the second package name list containing at least one application package name; Obtaining the process identifier of the calling end application as a query condition, querying in the data pair list, obtaining the first package name corresponding to the process identifier, and taking the obtained first package name as a query package name; Matching the query package name with the application package name in the second package name list, and if the second package name list contains an application package name consistent with the query package name, determining the application package name consistent with the query package name as a target application package name.
2. The application package name obtaining method of claim 1, wherein, Further comprising: If the second package name list does not contain an application package name consistent with the query package name, returning application package name forgery prompt information to the calling end application to indicate that the calling end application fails to call.
3. The application package name obtaining method of claim 1, wherein, Before the receiving the application package name passed by the calling end application through calling a preset interface function as a first package name, further comprising: In response to a remote connection instruction of the calling end application, establishing a remote connection with the calling end application.
4. The application package name obtaining method of claim 1, wherein, The calling end application is an application based on an Android system or an application based on a Hongmeng system.
5. The application package name obtaining method of claim 1, wherein, The storing the process identifier and the corresponding first package name in association comprises: Storing the process identifier and the first package name in association in a Map structure.
6. The application package name obtaining method of claim 5, wherein, The storing the process identifier and the first package name in association in a Map structure comprises: Storing the process identifier as a key and the first package name as a value in a Map structure.
7. The application package name acquisition method according to claim 6, wherein The querying in the data pair list, obtaining the first package name corresponding to the process identifier, and taking the obtained first package name as a query package name comprises: Determining a to-be-queried key corresponding to a to-be-queried process identifier, retrieving a value corresponding to the to-be-queried key in the Map structure, and determining the value corresponding to the to-be-queried key as the query package name.
8. The application package name acquisition method according to claim 1, wherein The obtaining a second package name list of the calling end application according to a system username of the calling end application comprises: Obtaining a system username of the calling end application; Based on the system username, obtaining the second package name list of the calling end application.
9. The application package name obtaining method of claim 4, wherein, The receiving the application package name passed by the calling end application through calling a preset interface function comprises: Starting the calling end application and the first application, the calling end application having a SharedUserId attribute; Establishing a service in the first application and binding the service through the calling end application; Passing the application package name of the calling end application through function parameter passing to determine as the first package name.
10. The application package name obtaining method of claim 9, wherein, Before the passing the application package name of the calling end application through function parameter passing to determine as the first package name, further comprising: Establishing service cross-process communication between the first application and the calling end application.
11. An electronic device, comprising: An electronic device comprising a processor and a memory; the memory is configured to store instructions; the processor is configured to invoke the instructions in the memory, so that the electronic device executes the application package name obtaining method according to any one of claims 1 to 10.
12. A computer-readable storage medium, characterized in that, The computer readable storage medium stores at least one instruction, and the at least one instruction is executed by a processor to implement the application package name obtaining method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Message reminding method and device, storage medium and electronic equipment
CN109697359A