Method and device for application program to access SIM card, electronic equipment and storage medium
By establishing a communication channel with the SIM card in the mobile terminal and sending instructions of the second application one by one, the problem of disordered instructions when multiple applications access the SIM card at the same time is solved, and the correctness of the instruction execution order and the consistency of data are achieved.
Patent Information
- Application Number
- CN202411683933.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-03-28
AI Technical Summary
In a mobile terminal, when multiple applications access the SIM card at the same time, it may lead to resource contention, disordered order of instruction execution and data conflict, resulting in some instructions being unable to be executed correctly.
The communication channel is established with the SIM card through the first application, and after the channel is established, the protocol instructions sent by the second application are received, stored in the data queue, and sent to the third program in the SIM card one by one, so as to avoid instruction disorder caused by the simultaneous access of multiple instructions.
It effectively avoids the problem of command disorder when multiple applications access SIM cards at the same time, ensuring the correctness of instruction execution order and data consistency.
Smart Images

Figure CN119729417A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of wireless communications, and in particular to a method for an application to access a SIM card, a device for an application to access a SIM card, an electronic device and a computer-readable storage medium. Background Art
[0002] With the continuous evolution of communication networks and terminal technologies, mobile terminal services are becoming increasingly diverse, and the demand for SIM cards has become more widespread and common. Modern smartphones are not only used for calls and text messages, but also integrate multiple functions, such as mobile payment, identity authentication, digital signatures, etc. These functions usually rely on smart cards (SE) to provide security. Therefore, more and more scenarios require multiple applications on mobile terminals to access smart cards through the 7816 specification at the same time, or to issue APDU instructions to the same AID application in the SE at the same time.
[0003] For example, when multiple applications try to access the SIM card at the same time, resource contention may occur, resulting in a disordered execution order of instructions, or even the failure of some instructions to be executed correctly. In addition, if multiple applications try to operate on the APDU (Application Protocol Data Unit) instructions under the same AID application, data conflicts may occur, resulting in inconsistent data or operation failure. This concurrent access situation may cause problems such as instruction confusion or failure to execute individual instructions. Summary of the invention
[0004] In view of the above problems, embodiments of the present invention are proposed to provide a method, device, electronic device and storage medium for an application to access a SIM card, which overcome the above problems or at least partially solve the above problems.
[0005] In a first aspect, an embodiment of the present invention provides a method for an application to access a SIM card, which is applied to a terminal device, wherein the terminal device is deployed with a SIM card and runs a first application and at least one second application, and the SIM card runs at least one third application; the method includes:
[0006] The first application establishes a communication channel connection with the SIM card;
[0007] After the communication channel is connected, the first application receives the first protocol instruction sent by the at least one second application, and stores the first protocol instruction sent by the at least one second application in a data queue;
[0008] The first application sends the first protocol instructions in the data queue to the third program in the SIM card one by one through the communication channel.
[0009] Optionally, the first application program establishes a communication channel connection with the SIM card, including:
[0010] The first application receives a communication channel establishment request sent by the second application;
[0011] After receiving the communication channel establishment request, determining whether the communication channel between the first application and the SIM card is established;
[0012] If the communication channel between the first application and the SIM card is not established, the first application establishes a communication channel with the SIM card and sends a channel establishment response to the second application.
[0013] Optionally, the first application program establishes a communication channel connection with the SIM card, further comprising:
[0014] If the communication channel between the first application and the SIM card has been established, sending a channel establishment response to the second application;
[0015] Optionally, sending a channel establishment response to the second application includes:
[0016] If the first application successfully establishes a communication channel with the SIM card, sending a channel establishment success response to the second application;
[0017] If the first application fails to establish a communication channel with the SIM card, a channel establishment failure response is sent to the second application.
[0018] Optionally, after receiving the communication channel establishment request, determining whether the communication channel between the first application and the SIM card is established includes:
[0019] After receiving the communication channel establishment request, determining whether the communication service between the first application and the SIM card is connected;
[0020] If the communication service between the first application and the SIM card is not connected, the first application and the SIM card reconnect the communication service;
[0021] If the communication service between the first application and the SIM card is connected, a communication channel is established between the first application and the SIM card.
[0022] Optionally, if the communication service between the first application and the SIM card is not connected, reconnecting the first application and the SIM card with the communication service includes:
[0023] If the communication service between the first application and the SIM card is not connected, the first application sends a communication service connection request to the SIM card;
[0024] Acquire an available communication service interface according to the received communication service connection request;
[0025] Opening a communication session corresponding to the communication service interface according to the acquired communication service interface, and opening a logical channel corresponding to the communication session;
[0026] The communication service connection is confirmed to be successful according to the logical channel opening result.
[0027] Optionally, the method further comprises:
[0028] The first application receives the instruction execution result sent by the third program in the SIM card; the instruction execution result is sent by the third program after executing the first protocol instruction;
[0029] The first application sends the instruction execution result to the corresponding second application.
[0030] In a second aspect, an embodiment of the present invention provides a device for an application to access a SIM card, which is applied to a terminal device, wherein the terminal device is deployed with a SIM card and runs a first application and at least one second application, and the SIM card runs at least one third application; the device includes:
[0031] A channel connection module, used for calling the first application to establish a communication channel connection with the SIM card;
[0032] an instruction receiving module, configured to, after the communication channel is connected, call the first application to receive the first protocol instruction sent by the at least one second application, and store the first protocol instruction sent by the at least one second application into a data queue;
[0033] The instruction sending module is used to call the first application program to send the first protocol instructions in the data queue to the third program in the SIM card one by one through the communication channel.
[0034] Optionally, the channel connection module includes:
[0035] A request sending submodule, used for calling the first application to receive a communication channel establishment request sent by the second application;
[0036] a channel determination submodule, configured to, after receiving the communication channel establishment request, call the first application to determine whether a communication channel between the first application and the SIM card is established;
[0037] The first response sending submodule is used to call the first application to establish a communication channel with the SIM card if the communication channel between the first application and the SIM card is not established, and send a channel establishment response to the second application.
[0038] Optionally, the channel connection module further includes:
[0039] The second response sending submodule is used to call the first application to send the channel establishment response to the second application if the communication channel between the first application and the SIM card has been established.
[0040] Optionally, the first response sending submodule includes:
[0041] A response judgment unit is used to call the first application to send a channel establishment success response to the second application if the first application successfully establishes a communication channel with the SIM card; if the first application fails to establish a communication channel with the SIM card, call the first application to send a channel establishment failure response to the second application.
[0042] Optionally, the channel determination submodule includes:
[0043] a communication service determination unit, configured to, after receiving the communication channel establishment request, call the first application to determine whether the communication service between the first application and the SIM card is connected; if the communication service between the first application and the SIM card is not connected, call the first application to reconnect the communication service with the SIM card; if the communication service between the first application and the SIM card is connected, call the first application to establish a communication channel with the SIM.
[0044] Optionally, the communication service determination unit includes:
[0045] a service request sending subunit, configured to, if the communication service between the first application and the SIM card is not connected, call the first application to send a communication service connection request to the SIM card;
[0046] A service interface acquisition subunit, configured to call the first application to acquire an available communication service interface according to the received communication service connection request;
[0047] a logical channel opening subunit, configured to call the first application to open a communication session corresponding to the communication service interface according to the acquired communication service interface, and to open a logical channel corresponding to the communication session;
[0048] A result confirmation subunit is used to call the first application to confirm that the communication service connection is successful according to the result of opening the logical channel.
[0049] The device also includes:
[0050] An instruction sending module, used for calling the first application to receive the instruction execution result sent by the third program in the SIM card; the instruction execution result is sent after the third program executes the first protocol instruction;
[0051] The instruction execution module is used to call the first application program and send the instruction execution result to the corresponding second application program.
[0052] In a third aspect, the present invention shows an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of a method for an application to access a SIM card as described above are implemented.
[0053] In a fourth aspect, the present invention shows a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for an application to access a SIM card as described above are implemented.
[0054] The embodiments of the present invention include the following advantages:
[0055] The embodiment of the present invention provides a method for an application to access a SIM card, which is applied to a terminal device, wherein the terminal device is deployed with a SIM card and runs a first application and at least one second application, and the SIM card runs at least one third application; the method comprises: the first application establishes a communication channel connection with the SIM card; after the communication channel is connected, the first application receives a first protocol instruction sent by at least one second application, and stores the first protocol instruction sent by at least one second application in a data queue; the first application sends the first protocol instruction in the data queue to the third program in the SIM card one by one through the communication channel. By establishing a communication channel with the SIM card to interact, when multiple second applications send multiple instructions to the SIM card at the same time, the first application sends them according to the data queue, which can avoid the instruction disorder problem caused by the simultaneous access of multiple instructions. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 is a flowchart of the steps of a method for an application to access a SIM card according to an embodiment of the present invention;
[0057] Figure 2 is a timing diagram of a method for an application to access a SIM card according to an embodiment of the present invention;
[0058] Figure 3 It is a structural block diagram of a device for an application to access a SIM card according to an embodiment of the present invention;
[0059] Figure 4 is a structural block diagram of an electronic device provided by an embodiment of the present invention;
[0060] Figure 5 It is a structural block diagram of a computer-readable storage medium provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0061] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0062] One of the core concepts of the embodiment of the present invention is that when multiple applications try to access the SIM card at the same time, resource contention may occur, resulting in confusion in the order of instruction execution, or even some instructions cannot be executed correctly. Therefore, a method for application access to the SIM card is proposed, which is applied to a terminal device, the terminal device is deployed with a SIM card and runs a first application and at least one second application, and the SIM card runs at least one third application; the method includes: the first application establishes a communication channel connection with the SIM card; after the communication channel is established, the first application receives the first protocol instruction sent by at least one second application, and stores the first protocol instruction sent by at least one second application in a data queue; the first application sends the first protocol instruction in the data queue to the third program in the SIM card one by one through the communication channel. By establishing a communication channel with the SIM card to interact, when multiple second applications send multiple instructions to the SIM card at the same time, the first application sends them according to the data queue, which can avoid the instruction disorder problem caused by the simultaneous access of multiple instructions.
[0063] Reference Figure 1 , shows a flowchart of a method for an application to access a SIM card according to an embodiment of the present invention, which is applied to a terminal device, wherein the terminal device is deployed with a SIM card and runs a first application and at least one second application, and the SIM card runs at least one third application; the method comprises:
[0064] Step 101, the first application establishes a communication channel connection with the SIM card;
[0065] A first application, at least one second application, and a SIM card are deployed on the terminal device, and at least one third application is inside the SIM card. The first application is connected and interacted with the second application, and the first application is connected and interacted with the SIM card. When the second application needs to access the SIM card, the second application sends the relevant protocol instructions to the first application, and sends the instructions to the SIM card through the first application. The third application in the SIM card completes the relevant operations according to the instructions.
[0066] When the first application sends the instruction to the SIM card, it cannot be sent directly, so a communication channel needs to be established, and the first application needs to send the instruction to the SIM card through the communication channel.
[0067] In this embodiment, when the second application needs to access the SIM card, it will first send a communication channel establishment request to the first application. The first application completes the establishment of the communication channel connection based on the received communication channel establishment request. When the communication channel is successfully established, the first application can interact with the SIM card through the communication channel.
[0068] In some embodiments, step 101 may include the following sub-steps:
[0069] Sub-step S11, the first application receives a communication channel establishment request sent by the second application;
[0070] In this embodiment, when the second application needs to access the SIM card, it will first send a communication channel establishment request to the first application. The second application needs to construct a communication channel establishment request and send it to the first application. The first application needs to monitor and receive the communication channel establishment request sent by the second application. When receiving the request, the request content is parsed to extract information such as the request type, request ID, and source application. According to the request type, the first application performs corresponding operations, such as establishing a communication channel.
[0071] Sub-step S12, after receiving the communication channel establishment request, determining whether the communication channel between the first application and the SIM card is established;
[0072] After receiving the communication channel establishment request, determining whether the communication channel between the first application and the SIM card has been established is to ensure that the first application can effectively communicate with the third application on the SIM card.
[0073] In this embodiment, after receiving the communication channel establishment request sent by the second application, the first application parses the request content and checks the status of the current communication channel to determine whether it has been established. Different operations are performed according to the status of the communication channel: if the communication channel has been established, the request is directly processed without establishing the communication channel again; if the communication channel has not been established, an attempt is made to establish the communication channel and update the communication channel status.
[0074] In some embodiments, step S12 may include the following sub-steps:
[0075] Sub-step S121, after receiving the communication channel establishment request, determining whether the communication service between the first application and the SIM card is connected;
[0076] When establishing a communication channel, you need to connect to the communication service first, and then establish the communication channel. Only after the communication service is successfully connected and the communication channel is established can the communication channel be successfully established and the reliability of the communication channel be ensured.
[0077] In this embodiment, after receiving the communication channel establishment request sent by the second application, the first application checks the connection status of the current communication service to determine whether it is already connected.
[0078] Sub-step S122, if the communication service between the first application and the SIM card is not connected, reconnecting the communication service between the first application and the SIM card;
[0079] After the communication service is connected, the first application will store the established object. When connecting again, it can be determined whether the communication service is connected by whether the object is empty.
[0080] In this embodiment, after receiving the communication channel establishment request, if the communication service between the first application and the SIM card is not connected, it is necessary to reconnect the communication service. After the first application receives the communication channel establishment request sent by the second application, it checks that the object stored after the communication service is connected is empty to confirm that the communication service between the first application and the SIM card is not connected, and it is necessary to reconnect the communication service and update the communication service status.
[0081] In some embodiments, step S122 may include the following sub-steps:
[0082] If the communication service between the first application and the SIM card is not connected, the first application sends a communication service connection request to the SIM card;
[0083] In this embodiment, after receiving the communication channel establishment request, if the communication service between the first application and the SIM card is not connected, the first application needs to send a communication service connection request to the SIM card and update the communication service connection status. After receiving the communication service connection request, the SIM card will return a response, and the first application needs to process the response and update the communication service status according to the response result. This ensures that the communication between the first application and the third application on the SIM card is reliable and effective.
[0084] Acquire an available communication service interface according to the received communication service connection request;
[0085] The communication service interface (Readers) is an interface used to communicate with secure elements (such as SIM cards, eSE, etc.). The communication service interface is part of the communication service. The available communication service interface can be obtained through the communication service. Each communication service interface corresponds to a secure element.
[0086] In this embodiment, after receiving the communication service connection request, the SIM card returns available communication service interface information. The first application needs to parse the response and obtain the available communication service interface to communicate with the third application on the SIM card.
[0087] Opening a communication session corresponding to the communication service interface according to the acquired communication service interface, and opening a logical channel corresponding to the communication session;
[0088] A communication session is a session in the Android system used to communicate with secure elements (such as SIM cards, eSE, etc.). Through a communication session, an application can open a logical channel and send APDU commands to interact with the secure element.
[0089] Logical Channel is a logical channel used in the Android system to communicate with secure elements (such as SIM cards, eSE, etc.). Through the logical channel, applications can send APDU commands and receive responses to interact with secure elements.
[0090] In this embodiment, after obtaining the communication service interface, the first application needs to open the communication session corresponding to the communication service interface. According to the type and address of the communication service interface, the communication session is initialized, and an attempt is made to establish a communication session with the third application on the SIM card. After opening the communication session, the first application needs to open the logical channel corresponding to the communication session, initialize the logical channel according to the type and configuration of the communication session, and if the connection is successful, update the logical channel status to "opened".
[0091] The communication service connection is confirmed to be successful according to the logical channel opening result.
[0092] In this embodiment, after opening the logical channel, the first application needs to confirm the opening result of the logical channel, check the opening status of the logical channel, determine whether it is successfully opened, and perform corresponding operations based on the opening result of the logical channel. If the logical channel is opened successfully, the communication service connection is confirmed to be successful and the communication service status is updated, and the operations after the communication service connection is successful are performed.
[0093] Sub-step S123: if the communication service between the first application and the SIM card is connected, a communication channel is established between the first application and the SIM card.
[0094] In this embodiment, after receiving the communication channel establishment request sent by the second application, the first application checks the status of the current communication service to determine whether it is already connected. If the communication service is already connected, the communication channel is directly established. According to the type and address of the communication service interface, the communication channel is initialized, and an attempt is made to establish a communication channel with the third application on the SIM card. If the connection is successful, the communication channel status is updated.
[0095] Sub-step S13, if the communication channel between the first application and the SIM card is not established, the first application establishes a communication channel with the SIM card and sends a channel establishment response to the second application;
[0096] In this embodiment, if the first application detects that a communication channel is not currently established with the SIM card, the first application attempts to establish a communication channel with the SIM card. If the communication channel is successfully established, the first application will proceed to the next step. If the communication channel is not successfully established, the first application may need to record error information and may try to re-establish the channel or notify the user. Once the communication channel is successfully established, the first application needs to send a channel establishment response to the second application. After the second application receives the channel establishment response, it performs corresponding operations according to the response content: if the channel is successfully established, the second application can start communicating with the SIM card through the channel; if the channel fails to be established, the second application may need to notify the user or take other measures to handle the failure.
[0097] In some embodiments, step S13 may include the following sub-steps:
[0098] Sub-step S131, if the first application successfully establishes a communication channel with the SIM card, sending a channel establishment success response to the second application;
[0099] In this embodiment, after the first application successfully establishes a communication channel with the SIM card, the first application needs to send a channel establishment success response to the second application to indicate that the communication channel is successfully established. First, the first application needs to detect whether a communication channel has been successfully established with the SIM card. If the communication channel is successfully established, the first application sends a channel establishment success response to the second application. After the second application receives the channel establishment success response, it can perform subsequent operations according to the response content.
[0100] Sub-step S132: if the first application fails to establish a communication channel with the SIM card, a channel establishment failure response is sent to the second application.
[0101] In this embodiment, after the first application fails to establish a communication channel with the SIM card, the first application needs to send a channel establishment failure response to the second application to indicate that the communication channel establishment failed. First, the first application needs to detect whether a communication channel has been successfully established with the SIM card. If the communication channel establishment fails, the first application sends a channel establishment failure response to the second application. After receiving the channel establishment failure response, the second application performs a response operation according to the response content, and needs to re-establish the communication channel.
[0102] In some embodiments, step 101 may include the following sub-steps:
[0103] Sub-step S21, if the communication channel between the first application and the SIM card has been established, sending a channel establishment response to the second application;
[0104] In this embodiment, if the communication channel between the first application and the SIM card has been established, the first application can directly send a channel establishment response to the second application, where the response is used to indicate that the channel has been successfully established. After receiving the channel establishment response, the second application can start communicating with the SIM card through the channel.
[0105] Step 102, after the communication channel is connected, the first application receives the first protocol instruction sent by the at least one second application, and stores the first protocol instruction sent by the at least one second application in a data queue;
[0106] The first protocol instruction is the APDU instruction. The APDU instruction is a standard protocol for communicating with a smart card (such as a SIM card), and is usually composed of four parts: CLA (Class), INS (Instruction), P1 (Parameter 1), P2 (Parameter 2), and an optional data field and a response length field.
[0107] The data queue is the command queue, which is a technology used to manage and schedule multiple APDU commands. In some cases, an application may need to send multiple APDU commands in succession, and these commands need to be executed in sequence. The command queue can help ensure that the commands are sent in the correct order and the next command will not be sent until the current command is completed.
[0108] In this embodiment, first, ensure that the communication channel between the first application and the SIM card has been established. The first application needs to monitor the instructions from the second application and receive them, and store the received first protocol instructions in the data queue. Then, the first application can take the instructions from the data queue and process them. This method ensures the sequence and reliability of the instructions.
[0109] Step 103: the first application sends the first protocol instructions in the data queue to the third program in the SIM card one by one through the communication channel.
[0110] In this embodiment, after the first application receives the first protocol instruction sent by the second application and stores it in the data queue, the first application needs to send the first protocol instructions in the data queue one by one to the third program in the SIM card through the established communication channel. The first application takes out the first protocol instructions from the data queue one by one, sends the taken out first protocol instructions to the third program in the SIM card through the established communication channel, receives and processes the response returned by the SIM card, and decides whether to continue to send the next instruction according to the response result.
[0111] In some embodiments, the method further comprises the steps of:
[0112] Step 201, the first application receives the instruction execution result sent by the third program in the SIM card; the instruction execution result is sent by the third program after executing the first protocol instruction;
[0113] The results of instruction execution include instruction execution failure and instruction execution success. After receiving the first protocol instruction, the third program in the SIM card executes the operation according to the instruction. If the instruction execution fails, the reason for the failure will be returned. The user can decide whether to re-establish the communication channel based on the reason for the failure. If the instruction execution is successful, the result obtained according to the instruction operation will be directly returned.
[0114] In this embodiment, after the first application sends the first protocol instruction to the third program in the SIM card, the first application needs to receive the instruction execution result sent by the third program in the SIM card. The first application sends the first protocol instruction to the third program in the SIM card through the established communication channel, and the first application also needs to receive the instruction execution result sent by the third program in the SIM card. The first application processes the received instruction execution result and decides whether to continue to send the next instruction according to the result.
[0115] Step 202: The first application sends the instruction execution result to the corresponding second application.
[0116] The relevant first protocol instruction is issued by the second application. When the third program in the SIM card completes the execution of the instruction and returns the result, the result is returned to the first application. Therefore, the first application also needs to return the instruction execution result to the second application before the second application completes the access operation to the SIM card.
[0117] In this embodiment, the first application receives the instruction execution result sent by the third program in the SIM card, sends the received instruction execution result to the corresponding second application, and processes the sent result to ensure that the result has been successfully sent.
[0118] Reference Figure 2 , shows a timing diagram of a method for an application to access a SIM card provided by an embodiment of the present invention, wherein the timing of the method includes the following specific details:
[0119] according to Figure 2 It can be seen that when at least one second application needs to access the SIM card, the second application needs to first send a communication channel establishment request to the first application. After receiving the communication channel establishment request, the first application needs to determine whether the current communication service is connected. If the communication service is already connected, the communication channel can be established directly. If the communication service is not connected, it is necessary to establish a communication service connection, obtain the available communication interface according to the communication service, open the communication session corresponding to the communication interface, and open the logical channel corresponding to the communication session according to the communication session. After the logical channel is successfully opened, the SIM card will return the result of opening the logical channel to the first application, and the first application confirms that the communication channel is successfully established based on the result of opening the logical channel.
[0120] When the communication channel is successfully established, the second application will send the first protocol instruction to the first application. The first application will add the received first protocol instruction to the data queue and send the instructions to the third application in the SIM card in sequence according to the instruction sequence. The third application in the SIM card completes the relevant operations according to the instruction and returns the instruction execution result to the first application. The first application will send the received instruction execution result to the second application.
[0121] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0122] Reference Figure 3 , shows a device for an application to access a SIM card provided by an embodiment of the present invention, which is applied to a terminal device, wherein the terminal device is deployed with a SIM card and runs a first application and at least one second application, and the SIM card runs at least one third application; the device includes:
[0123] A channel connection module 301 is used to call the first application to establish a communication channel connection with the SIM card;
[0124] In this embodiment, when the second application needs to access the SIM card, it will first send a communication channel establishment request to the first application. The first application completes the establishment of the communication channel connection based on the received communication channel establishment request. When the communication channel is successfully established, the first application can interact with the SIM card through the communication channel.
[0125] The instruction receiving module 302 is used to call the first application to receive the first protocol instruction sent by the at least one second application after the communication channel is connected, and store the first protocol instruction sent by the at least one second application into a data queue;
[0126] In this embodiment, first, ensure that the communication channel between the first application and the SIM card has been established. The first application needs to monitor the instructions from the second application and receive them, and store the received first protocol instructions in the data queue. Then, the first application can take the instructions from the data queue and process them. This method ensures the sequence and reliability of the instructions.
[0127] The instruction sending module 303 is used to call the first application program to send the first protocol instructions in the data queue to the third program in the SIM card one by one through the communication channel.
[0128] In this embodiment, after the first application receives the first protocol instruction sent by the second application and stores it in the data queue, the first application needs to send the first protocol instructions in the data queue one by one to the third program in the SIM card through the established communication channel. The first application takes out the first protocol instructions from the data queue one by one, sends the taken out first protocol instructions to the third program in the SIM card through the established communication channel, receives and processes the response returned by the SIM card, and decides whether to continue to send the next instruction according to the response result.
[0129] The channel connection module 301 includes:
[0130] A request sending submodule, used for calling the first application to receive a communication channel establishment request sent by the second application;
[0131] In this embodiment, when the second application needs to access the SIM card, it will first send a communication channel establishment request to the first application. The second application needs to construct a communication channel establishment request and send it to the first application. The first application needs to monitor and receive the communication channel establishment request sent by the second application. When receiving the request, the request content is parsed to extract information such as the request type, request ID, and source application. According to the request type, the first application performs corresponding operations, such as establishing a communication channel.
[0132] a channel determination submodule, configured to, after receiving the communication channel establishment request, call the first application to determine whether a communication channel between the first application and the SIM card is established;
[0133] In this embodiment, after receiving the communication channel establishment request sent by the second application, the first application parses the request content and checks the status of the current communication channel to determine whether it has been established. Different operations are performed according to the status of the communication channel: if the communication channel has been established, the request is directly processed without establishing the communication channel again; if the communication channel has not been established, an attempt is made to establish the communication channel and update the communication channel status.
[0134] The first response sending submodule is used to call the first application to establish a communication channel with the SIM card if the communication channel between the first application and the SIM card is not established, and send a channel establishment response to the second application.
[0135] In this embodiment, if the first application detects that a communication channel is not currently established with the SIM card, the first application attempts to establish a communication channel with the SIM card. If the communication channel is successfully established, the first application will proceed to the next step. If the communication channel is not successfully established, the first application may need to record error information and may try to re-establish the channel or notify the user. Once the communication channel is successfully established, the first application needs to send a channel establishment response to the second application. After the second application receives the channel establishment response, it performs corresponding operations according to the response content: if the channel is successfully established, the second application can start communicating with the SIM card through the channel; if the channel fails to be established, the second application may need to notify the user or take other measures to handle the failure.
[0136] The channel connection module 301 further includes:
[0137] The second response sending submodule is used to call the first application to send the channel establishment response to the second application if the communication channel between the first application and the SIM card has been established.
[0138] In this embodiment, if the communication channel between the first application and the SIM card has been established, the first application can directly send a channel establishment response to the second application, where the response is used to indicate that the channel has been successfully established. After receiving the channel establishment response, the second application can start communicating with the SIM card through the channel.
[0139] The first response sending submodule includes:
[0140] A response judgment unit is used to call the first application to send a channel establishment success response to the second application if the first application successfully establishes a communication channel with the SIM card; if the first application fails to establish a communication channel with the SIM card, call the first application to send a channel establishment failure response to the second application.
[0141] In this embodiment, after the first application successfully establishes a communication channel with the SIM card, the first application needs to send a channel establishment success response to the second application to indicate that the communication channel is successfully established. First, the first application needs to detect whether a communication channel has been successfully established with the SIM card. If the communication channel is successfully established, the first application sends a channel establishment success response to the second application. After the second application receives the channel establishment success response, it can perform subsequent operations according to the response content. After the first application fails to establish a communication channel with the SIM card, the first application needs to send a channel establishment failure response to the second application to indicate that the communication channel fails to be established. First, the first application needs to detect whether a communication channel has been successfully established with the SIM card. If the communication channel fails to be established, the first application sends a channel establishment failure response to the second application. After the second application receives the channel establishment failure response, it performs a response operation according to the response content and needs to re-establish the communication channel.
[0142] The channel judgment submodule includes:
[0143] a communication service determination unit, configured to, after receiving the communication channel establishment request, call the first application to determine whether the communication service between the first application and the SIM card is connected; if the communication service between the first application and the SIM card is not connected, call the first application to reconnect the communication service with the SIM card; if the communication service between the first application and the SIM card is connected, call the first application to establish a communication channel with the SIM.
[0144] In this embodiment, in the first application, after receiving the communication channel establishment request sent by the second application, the connection status of the current communication service is checked to determine whether it is already connected. After receiving the communication channel establishment request, if the communication service between the first application and the SIM card is not connected, it is necessary to reconnect the communication service. After the first application receives the communication channel establishment request sent by the second application, it checks that the object stored after the communication service is connected is empty to confirm that the communication service between the first application and the SIM card is not connected, it is necessary to reconnect the communication service and update the communication service status. If the communication service is already connected, the communication channel is established directly. According to the type and address of the communication service interface, the communication channel is initialized, and an attempt is made to establish a communication channel with the third application on the SIM card. If the connection is successful, the communication channel status is updated.
[0145] The communication service determination unit comprises:
[0146] a service request sending subunit, configured to, if the communication service between the first application and the SIM card is not connected, call the first application to send a communication service connection request to the SIM card;
[0147] In this embodiment, after receiving the communication channel establishment request, if the communication service between the first application and the SIM card is not connected, the first application needs to send a communication service connection request to the SIM card and update the communication service connection status. After receiving the communication service connection request, the SIM card will return a response, and the first application needs to process the response and update the communication service status according to the response result. This ensures that the communication between the first application and the third application on the SIM card is reliable and effective.
[0148] A service interface acquisition subunit, configured to call the first application to acquire an available communication service interface according to the received communication service connection request;
[0149] In this embodiment, after receiving the communication service connection request, the SIM card returns available communication service interface information. The first application needs to parse the response and obtain the available communication service interface to communicate with the third application on the SIM card.
[0150] a logical channel opening subunit, configured to call the first application to open a communication session corresponding to the communication service interface according to the acquired communication service interface, and to open a logical channel corresponding to the communication session;
[0151] In this embodiment, after obtaining the communication service interface, the first application needs to open the communication session corresponding to the communication service interface. According to the type and address of the communication service interface, the communication session is initialized, and an attempt is made to establish a communication session with the third application on the SIM card. After opening the communication session, the first application needs to open the logical channel corresponding to the communication session, initialize the logical channel according to the type and configuration of the communication session, and if the connection is successful, update the logical channel status to "opened".
[0152] A result confirmation subunit is used to call the first application to confirm that the communication service connection is successful according to the result of opening the logical channel.
[0153] In this embodiment, after opening the logical channel, the first application needs to confirm the opening result of the logical channel, check the opening status of the logical channel, determine whether it is successfully opened, and perform corresponding operations based on the opening result of the logical channel. If the logical channel is opened successfully, the communication service connection is confirmed to be successful and the communication service status is updated, and operations after the communication service connection is successful are performed.
[0154] The device also includes:
[0155] An instruction sending module, used for calling the first application to receive the instruction execution result sent by the third program in the SIM card; the instruction execution result is sent after the third program executes the first protocol instruction;
[0156] In this embodiment, after the first application sends the first protocol instruction to the third program in the SIM card, the first application needs to receive the instruction execution result sent by the third program in the SIM card. The first application sends the first protocol instruction to the third program in the SIM card through the established communication channel, and the first application also needs to receive the instruction execution result sent by the third program in the SIM card. The first application processes the received instruction execution result and decides whether to continue to send the next instruction according to the result.
[0157] The instruction execution module is used to call the first application program and send the instruction execution result to the corresponding second application program.
[0158] In this embodiment, the first application receives the instruction execution result sent by the third program in the SIM card, sends the received instruction execution result to the corresponding second application, and processes the sent result to ensure that the result has been successfully sent.
[0159] Reference Figure 4 , showing a structural block diagram of an electronic device 40 provided in an embodiment of the present invention, comprising: a processor 401, a memory 402, and a computer program 4021 stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the steps of the method for an application to access a SIM card described in any one of the above items are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0160] Reference Figure 5 , showing a structural block diagram of a computer-readable storage medium 50 provided in an embodiment of the present invention, on which a computer program 501 is stored. When the computer program is executed by a processor, the steps of the method for an application to access a SIM card described in any one of the above items are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0161] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0162] Those skilled in the art will appreciate that the embodiments of the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more machine-readable media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0163] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0164] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0165] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0166] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0167] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0168] The method for an application to access a SIM card and the device for an application to access a SIM card provided by the present invention are introduced in detail above. The principle and implementation mode of the present invention are explained in this article by using specific examples. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation mode and the scope of application. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A method for an application to access a SIM card, characterized in that: Applied to a terminal device, the terminal device is deployed with a SIM card and runs a first application and at least one second application, and the SIM card runs at least one third application; the method comprises: The first application establishes a communication channel connection with the SIM card; After the communication channel is connected, the first application receives the first protocol instruction sent by the at least one second application, and stores the first protocol instruction sent by the at least one second application in a data queue; The first application sends the first protocol instructions in the data queue to the third program in the SIM card one by one through the communication channel.
2. The method according to claim 1, characterized in that The first application establishes a communication channel connection with the SIM card, including: The first application receives a communication channel establishment request sent by the second application; After receiving the communication channel establishment request, determining whether the communication channel between the first application and the SIM card is established; If the communication channel between the first application and the SIM card is not established, the first application establishes a communication channel with the SIM card and sends a channel establishment response to the second application.
3. The method according to claim 1, characterized in that The first application establishes a communication channel connection with the SIM card, further comprising: If the communication channel between the first application and the SIM card has been established, the channel establishment response is sent to the second application.
4. The method according to claim 2, characterized in that: The sending a channel establishment response to the second application comprises: If the first application successfully establishes a communication channel with the SIM card, sending a channel establishment success response to the second application; If the first application fails to establish a communication channel with the SIM card, a channel establishment failure response is sent to the second application.
5. The method according to claim 2, characterized in that: After receiving the communication channel establishment request, determining whether the communication channel between the first application and the SIM card is established includes: After receiving the communication channel establishment request, determining whether the communication service between the first application and the SIM card is connected; If the communication service between the first application and the SIM card is not connected, the first application and the SIM card reconnect the communication service; If the communication service between the first application and the SIM card is connected, a communication channel is established between the first application and the SIM card.
6. The method according to claim 5, characterized in that If the communication service between the first application and the SIM card is not connected, the first application and the SIM card reconnect the communication service, including: If the communication service between the first application and the SIM card is not connected, the first application sends a communication service connection request to the SIM card; Acquire an available communication service interface according to the received communication service connection request; Opening a communication session corresponding to the communication service interface according to the acquired communication service interface, and opening a logical channel corresponding to the communication session; The communication service connection is confirmed to be successful according to the logical channel opening result.
7. The method according to claim 1, characterized in that The method further comprises: The first application receives the instruction execution result sent by the third program in the SIM card; the instruction execution result is sent by the third program after executing the first protocol instruction; The first application sends the instruction execution result to the corresponding second application.
8. A device for an application to access a SIM card, characterized in that: Applied to a terminal device, the terminal device is deployed with a SIM card and runs a first application and at least one second application, and the SIM card runs at least one third application; the device includes: A channel connection module, used for calling the first application to establish a communication channel connection with the SIM card; an instruction receiving module, configured to, after the communication channel is connected, call the first application to receive the first protocol instruction sent by the at least one second application, and store the first protocol instruction sent by the at least one second application into a data queue; The instruction sending module is used to call the first application program to send the first protocol instructions in the data queue to the third program in the SIM card one by one through the communication channel.
9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the method for an application program to access a SIM card according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for an application program to access a SIM card according to any one of claims 1 to 7 are implemented.