CN111522764A - Plug-in operation processing method, terminal and storage medium - Google Patents

Plug-in operation processing method, terminal and storage medium Download PDF

Info

Publication number
CN111522764A
CN111522764A CN202010263688.8A CN202010263688A CN111522764A CN 111522764 A CN111522764 A CN 111522764A CN 202010263688 A CN202010263688 A CN 202010263688A CN 111522764 A CN111522764 A CN 111522764A
Authority
CN
China
Prior art keywords
thread
external storage
storage device
terminal
processing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010263688.8A
Other languages
Chinese (zh)
Other versions
CN111522764B (en
Inventor
彭学锋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Oppo Chongqing Intelligent Technology Co Ltd
Original Assignee
Oppo Chongqing Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Oppo Chongqing Intelligent Technology Co Ltd filed Critical Oppo Chongqing Intelligent Technology Co Ltd
Priority to CN202010263688.8A priority Critical patent/CN111522764B/en
Publication of CN111522764A publication Critical patent/CN111522764A/en
Application granted granted Critical
Publication of CN111522764B publication Critical patent/CN111522764B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/40Bus structure
    • G06F13/4063Device-to-bus coupling
    • G06F13/4068Electrical coupling
    • G06F13/4081Live connection to bus, e.g. hot-plugging

Abstract

The embodiment of the application discloses a processing method of plugging operation, a terminal and a storage medium, wherein the processing method of the plugging operation comprises the following steps: after receiving the I/O request, establishing a main thread; when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established; and processing the plugging operation corresponding to the external storage equipment through the sub-thread so as to inform the target equipment of the plugging operation.

Description

Plug-in operation processing method, terminal and storage medium
Technical Field
The embodiment of the application relates to the technical field of terminals, in particular to a processing method of plugging operation, a terminal and a storage medium.
Background
With the continuous development of terminal technology, the interaction between the terminal and different devices is increasing, and in general, the terminal and the target device can perform file copy and other transmission through a Media Transfer Protocol (MTP). The MTPServer is a handler MTPServer for interaction between the terminal and the target device, and the MTPServer generally handles interaction with the target device in the same thread. For example, the MTPServer in the terminal processes the operation of copying the file and the operation of pulling out the external storage device in turn.
However, if the time of the previous operation processed by the MTPServer is long, the later waiting operation may Not be executed, and an application unresponsiveness (ANR) may be triggered, which may cause a media library crash in the terminal.
Disclosure of Invention
The embodiment of the application provides a method, a terminal and a storage medium for processing a plug-in operation, which can process the plug-in operation of an external storage device while processing an I/O operation with a target device, so as to avoid triggering of ANR, and further solve the problem of media library crash caused by ANR.
The technical scheme of the embodiment of the application is realized as follows:
in a first aspect, an embodiment of the present application provides a method for processing a plug operation, where the method includes:
after receiving the I/O request, establishing a main thread;
when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established;
and processing the plugging operation corresponding to the external storage equipment through the sub thread so as to inform the target equipment of the plugging operation.
In a second aspect, an embodiment of the present application provides a terminal, where the terminal includes: the set-up unit, the processing unit,
the establishing unit is used for establishing a main thread after receiving the I/O request; when the I/O operation between the main thread and the target device is processed, if a plugging request corresponding to the external storage device is received, establishing a sub-thread;
the processing unit is configured to process, by the sub thread, a plug-in operation corresponding to the external storage device, so as to notify the target device of the plug-in operation.
In a third aspect, an embodiment of the present application provides a terminal, where the terminal includes a processor and a memory storing instructions executable by the processor, and when the instructions are executed by the processor, the processing method for the plug operation is implemented.
In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a program is stored, and the program is applied to a terminal, and when being executed by a processor, the program implements the processing method for plugging and unplugging operations as described above.
The embodiment of the application provides a processing method, a terminal and a storage medium for plugging operation, wherein the terminal establishes a main thread after receiving an I/O request; when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established; and processing the plugging operation corresponding to the external storage equipment through the sub-thread so as to inform the target equipment of the plugging operation. That is to say, in the embodiment of the present application, when the terminal processes the I/O operation with the target device through the main thread, the terminal creates the sub-thread in response to the received plugging request, so that the plugging operation of the external storage device can be processed through the sub-thread, that is, the plugging operation can be processed by the sub-thread while the I/O operation is processed through the main thread. Therefore, the plug-in operation processing method provided by the application can process the plug-in operation of the external storage device while processing the I/O operation with the target device, so that triggering of the ANR can be avoided, and the problem of media library breakdown caused by the ANR is solved.
Drawings
FIG. 1 is a schematic diagram of an MTP application;
FIG. 2 is a schematic diagram of a frame of the MTP;
FIG. 3 is a first flowchart illustrating an implementation of a processing method of a plug operation;
FIG. 4 is a schematic diagram illustrating a second implementation flow of a processing method for plug-in and pull-out operations;
FIG. 5 is a third schematic flow chart illustrating an implementation of a processing method of a plugging operation;
FIG. 6 is a diagram illustrating a current process for plugging/unplugging operations;
FIG. 7 is a first schematic diagram illustrating a process of plugging/unplugging operations according to the present application;
FIG. 8 is a second schematic diagram illustrating a process of plugging/unplugging operations according to the present application;
FIG. 9 is a first schematic diagram of the structure of the terminal;
fig. 10 is a schematic diagram of a terminal structure.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant application and are not limiting of the application. It should be noted that, for the convenience of description, only the parts related to the related applications are shown in the drawings.
MTP is a protocol customized by microsoft for transferring images, music, etc. between computers and portable devices. Android (Android) supports MTP starting from 3.0. The application of MTP has two roles, one is as Initiator and the other is as Responder. Fig. 1 is a schematic diagram of an MTP application, and as shown in fig. 1, for example, an Android terminal is connected to a Personal Computer (PC), the PC serves as an Initiator, and all requests in the MTP are initiated by the Initiator. For example, a PC requests to acquire file data on an Android terminal; the Android terminal serves as a Responder, which processes the request of the Initiator and sends an Event.
Fig. 2 is a schematic diagram of an MTP, and as shown in fig. 2, in a Kernel layer, a Universal Serial Bus (USB) driver is responsible for data exchange, and an MTP driver is responsible for communication with an upper layer and also communicates with a USB driver. The USB driver is responsible for data exchange, and means that after the Android terminal and the PC are connected through a USB data line, actual data exchange is sent to the USB driver through the USB data line. For MTP requests, the MTP driver parses MTP request data from the USB driver and passes the MTP request data to the upper layer. For the MTP feedback transmitted from the upper layer, the MTP driver also transmits the feedback content to the USB driver after packaging.
In the JNI layer, the MTPServer can continuously monitor the MTP request of the Kernel message and perform relevant processing on the corresponding message. Meanwhile, the Event of the MTP is also sent to the MTP driver through the MTPServer. The MtpStorage corresponds to one storage unit; for example, the SD card corresponds to one MtpStorage. Mtppackets and mtpevettpackets are responsible for packing MTP messages. The android _ mtp _ MTPServer is a JNI class, which is a bridge for the MTPServer of the JNI layer and the MTPServer of the Java layer to communicate with each other. android _ mtp _ MtpDatabase is also a JNI class, and the JNI layer realizes the operation on MtpDatabase (Framework layer) through the JNI class.
At the Framework layer, MTPServer acts as a server that provides MTP related services by communicating with the underlying layers. The MtpDatabase functions as a database, but the MtpDatabase does not store data in the database, and essentially acquires required data through a MediaProvider database. The MtpStorage corresponds to a memory cell, and corresponds to the MtpStorage of the JNI layer.
In an application I/On layer, MtpReceiver is responsible for receiving broadcast, and MtpService is started/closed after the broadcast is received; for example, MtpReceiver may initiate MtpService when it receives a message "Android terminal and PC are connected". The MtpService functions to provide a service to manage MTP, which will enable MTPServer and synchronize locally stored content with that of MTP. The role of the MediaProvider in the MTP is to search for local storage content and synchronize the local content; for example, when a new file is added locally, the MediaProvider will notify the MTPServer to perform MTP data synchronization.
The trigger event of starting the MTP service is that the MTP connection is established between the PC and the Android terminal. When the MTP connection is established, the USB driver generates a USB connection message and finally notifies the UsbManager. UsbManager sends out the broadcast, and the broadcast is received by MtpRecever; MtpReceiver receives the broadcast and starts MtpService, and notifies MediaProvider. The MediaProvider can be bound with the MtpService, and if the file structure in the Android terminal changes (such as a new key file), the MediaProvider can inform the MtpService. MtpService is initiated to create MtpDatabase, followed by MTPServer, which is associated with MtpDatabase. Then, the MtpService traverses the local storage device, establishes a corresponding MtpStorage, and adds the MtpStorage to MtpDatabase and MTPServer. Finally, MtpService will initiate MTPServer.
A thread (thread) is the smallest unit that an operating system can perform arithmetic scheduling. It is included in the process and is the actual unit of operation in the process. A thread refers to a single sequential control flow in a process, multiple threads can be concurrently executed in a process, and each thread executes different tasks in parallel. Unix System V and SunOS are also called lightweight processes (light processes), but lightweight processes are more referred to as kernel threads (kernel threads) and user threads (user threads) are called threads.
Threads are the basic unit of independent scheduling and dispatch. The thread may be a kernel thread scheduled by the operating system kernel, such as a Win32 thread; a user Thread which is automatically scheduled by a user process, such as POSIX Thread of a Linux platform; or by the kernel in a mixed schedule with user processes, such as Windows 7 threads.
Multiple threads in the same process will share all system resources in the process, such as virtual address space, file descriptors, signal processing, etc. However, multiple threads in the same process have their own call stack (call stack), their own register context (register context), and their own thread local storage (local storage).
A process may have many threads, each performing a different task in parallel.
The benefit of using multi-threaded programming on multi-core or multi-CPU, or Hyper-threading enabled CPUs, is apparent, i.e. the execution throughput of the program is improved. On a single-CPU and single-core computer, a multithreading technology is used, a part which is frequently blocked due to Input/Output (I/O) processing and man-machine interaction in a process can be separated from a part for intensive calculation to be executed, a special work horse thread is written to execute the intensive calculation, and therefore the execution efficiency of a program is improved.
The processing program MTPServer interacted with the target equipment in the Android terminal is mainly used for processing of copying, deleting, cutting, inquiring and the like of files, and adding and deleting operations of storage equipment and the like. Generally, MTPServer handles interactions with a target device in the same thread. For example, when the terminal processes an I/O operation with a target device, if a plug operation of a Secure Digital Memory Card (SD Card) is detected, a removeStorage operation of the MTPServer needs to be invoked to notify the target device, that is, the MTPServer processes the I/O operation and the plug operation of an external storage device.
However, if the MTPServer takes a long time to process I/O operation, there may be no response ANR triggering the application, resulting in a crash of the media library in the terminal. For example, when the MTPServer copies a file from a target device to a terminal, for a larger file, the I/O operation process may take a long time, and during the process of processing the file copy by the MTPServer, the terminal detects the pull-out process of the T card, and when the media library receives a broadcast of the pull-out of the T card, the removeStorage operation of the MTPServer is called to notify the target device of the operation of removing the T card, and since the MTPServer is processing the I/O operation at this time, the removeStorage must be executed until the I/O operation is executed, which may cause the call of processing the removeStorage by the media library to be unable to be ended, thereby triggering ANR and causing the crash of the media library.
In order to solve the above problem, in the embodiment of the present application, when processing an I/O operation between a terminal and a target device through a main thread, a sub-thread is created in response to a received plugging request, so that the plugging operation of an external storage device can be processed through the sub-thread, that is, the plugging operation can be processed by the sub-thread while processing the I/O operation through the main thread. Therefore, the plug-in operation processing method provided by the application can process the plug-in operation of the external storage device while processing the I/O operation with the target device, so that triggering of the ANR can be avoided, and the problem of media library breakdown caused by the ANR is solved.
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application.
An embodiment of the present application provides a method for processing a plug operation, and fig. 3 is a schematic view illustrating an implementation flow of the method for processing a plug operation, as shown in fig. 3, in an embodiment of the present application, a method for processing a terminal may include the following steps:
step 101, after receiving an I/O request, establishing a main thread.
In the embodiment of the application, the terminal may establish the main thread after receiving the I/O request. The main thread is used for processing the I/O operation indicated by the I/O request.
It should be noted that, in the embodiments of the present application, the terminal may be any device having communication and storage functions, for example: tablet Personal computers, mobile phones, electronic readers, remote controllers, Personal Digital Assistants (PDAs), Portable Media Players (PMPs), navigation devices, wearable devices, smart bands, pedometers, and other terminals.
Further, in an embodiment of the present application, the main thread may be configured to cache the at least one request, and further process a corresponding operation according to the at least one request. For example, the main thread may be used to cache I/O requests, while the main thread may also be used to process corresponding I/O operations according to the I/O requests.
It is understood that in the embodiment of the present application, I represents input and O represents output, wherein I/O operation occurs between the memory and the hard disk. The program runs in the memory, so the terminal needs to read the file data of the hard disk into the memory and then output the data from the memory to the hard disk, which is the I/O operation.
For example, in the present application, the I/O operation may be a copy operation, a delete operation, a cut operation, a query operation, or the like, specifically, an object of the I/O operation may be a file or a folder, and the present application is not limited specifically.
Further, in the embodiment of the present application, the I/O request received by the terminal may be sent by the target device. The target device may be a notebook Computer, a tablet Computer, a Personal Computer (PC), or the like.
For example, in the embodiment of the present application, the terminal may be a mobile phone, and the target device may be a PC.
Fig. 4 is a schematic diagram of an implementation flow of a processing method of a plug operation, as shown in fig. 4, before receiving an I/O request, that is, before step 101, the method for processing by a terminal may further include the following steps:
and step 104, establishing connection with the target equipment based on the MTP.
In the embodiment of the application, the terminal may establish a connection with the target device based on the MTP, so that the I/O request sent by the target device may be received.
That is to say, in the embodiment of the present application, after the terminal and the target device establish a connection, the target device may send an I/O request to the terminal, so that the terminal may respond to the I/O request and process a corresponding I/O operation.
It can be understood that, in the embodiment of the present application, if the I/O request is a copy request of the file a, in response to the I/O request, the terminal may copy the file a in the target device to the terminal when processing the I/O operation, or the target device may also control the terminal to copy the file a in the memory of the terminal to the memory card, or copy the file a in the memory card of the terminal to the memory.
In the embodiment of the application, further, after receiving the I/O request sent by the target device, the terminal may establish a main thread in order to respond to the I/O request, and may then process an I/O operation with the target device through the main thread.
102, when the I/O operation between the main thread and the target device is processed, if a plugging request corresponding to the external storage device is received, establishing a sub-thread.
In the embodiment of the application, after an I/O request is received, when a terminal establishes a main thread and processes an I/O operation between the terminal and a target device through the main thread, if a plugging request corresponding to an external storage device is received, a sub-thread is established. The plug request is used for indicating the plug operation, and the sub-thread is used for processing the plug operation indicated by the plug request.
Further, in an embodiment of the present application, the child thread may be configured to cache the at least one request, and further process a corresponding operation according to the at least one request. For example, the sub-thread may be used to cache the plugging request, and meanwhile, the sub-thread may be further used to process the corresponding plugging operation according to the plugging request.
It is understood that in the embodiments of the present application, the external storage device may be a memory such as an SD card, a T card, or the like. Among them, the SD memory card is a new generation memory device based on a semiconductor flash memory, and is widely used in portable devices such as digital cameras, tablet computers, and multimedia players due to its excellent characteristics of small size, fast data transmission speed, hot-swappability, and the like. The T card, also called microSD, is a very small flash memory card, which is mainly used in mobile phones, but because it has the advantage of small volume, it slowly starts to be used in Global Positioning System (GPS) devices, portable music players and some flash memory disks with increasing capacity.
Further, in the embodiment of the present application, the plugging operation includes a plugging operation and/or a unplugging operation of the external storage device. That is, the plugging operation indicated by the plugging instruction may be an inserting operation, a pulling operation, or an inserting operation and a pulling operation.
For example, in the present application, when the external storage device is inserted into the terminal, the terminal may receive a plugging instruction indicating an insertion operation.
For example, in the present application, when the external storage device is unplugged from the terminal, the terminal may receive an unplugging instruction indicating an unplugging operation.
For example, in the present application, when the external storage device is plugged into the terminal and then is plugged into and pulled out from the terminal, the terminal may receive a plugging instruction indicating a plugging operation and a pulling operation.
In the embodiment of the application, further, after the terminal receives the plugging request, in order to respond to the plugging request, the terminal may establish a sub-thread, so that the plugging operation of the external storage device may be processed through the sub-thread.
It should be noted that, in the embodiment of the present application, the child thread created by the terminal may include the first child thread and/or the second child thread. That is, in the present application, when the terminal establishes the child thread, the first child thread and/or the second child thread may be created according to the plugging request.
Further, in an embodiment of the present application, a first child thread is configured to process the plug-in operation corresponding to the external storage device; the second sub thread is used for processing the pulling-out operation corresponding to the external storage device.
For example, in the present application, if the terminal receives a plug instruction indicating a plug-in operation, the terminal may establish the first child thread.
For example, in the present application, if the terminal receives a plug instruction indicating a unplugging operation, the terminal may establish the second child thread.
For example, in the present application, if the terminal receives a plug-in/pull-out command indicating an insertion operation and a pull-out operation, the terminal may establish a first sub-thread and a second sub-thread.
And 103, processing the plugging operation corresponding to the external storage device through the sub-thread to inform the target device of the plugging operation.
In the embodiment of the application, when the I/O operation between the main thread and the target device is processed, if a plugging request corresponding to the external storage device is received, after the terminal establishes the sub-thread, the plugging operation corresponding to the external storage device can be processed through the sub-thread, so as to inform the target device of the plugging operation.
It can be understood that, in the embodiment of the present application, after the terminal establishes the child thread, the child thread may be used to process a corresponding plugging operation of the external storage device. Specifically, the terminal may notify the target device of an operation of adding and/or removing the external storage device through the child thread.
Further, in an embodiment of the application, when the terminal processes the plugging operation corresponding to the external storage device through the child thread, the terminal may notify the target device of adding the external storage device through the child thread; and/or the terminal informs the target device to remove the external storage device through the sub thread.
For example, in the present application, if the terminal receives a plug-in/pull-out instruction indicating an insertion operation, after the terminal establishes the first child thread, the terminal may notify the target device of adding the external storage device through the first child thread.
For example, in the present application, if the terminal receives a plug instruction indicating a unplugging operation, after the terminal establishes the second child thread, the terminal may notify the target device of removing the external storage device through the second child thread.
For example, in the present application, if the terminal receives a plug-in/pull-out command indicating an insertion operation and a pull-out operation, after the first sub thread and the second sub thread are established, the terminal may notify the target device of adding the external storage device through the first sub thread and then notify the target device of removing the external storage device through the second sub thread.
Therefore, according to the method for processing the plug-in operation, when the terminal processes the I/O operation between the terminal and the target device through the main thread, if the external storage device is plugged in or pulled out, namely the terminal receives the plug-in request, the terminal can create the sub-thread, and then the plug-in operation of the external storage device is processed through the sub-thread to respond to the plug-in request in time, so that the triggering of the ANR is avoided.
It can be understood that the method for processing a plug-in operation provided by the present application is mainly applied to a terminal processing an I/O operation before processing a target device, such as copying or cutting a file, and simultaneously processing an operation of removing or adding an external storage device, so as to solve the problem of application running caused by ANR in a media library program, and belongs to optimization in fast, stable and province.
Specifically, with the method for processing the plug-in operation in steps 101 to 103, just because the main thread and the sub-thread have definite division of labor, in the process of processing the I/O operation with the target device by the main thread, the terminal can process the plug-in operation of the external storage device through the sub-thread without waiting for the completion of the I/O operation and then performing the process of plugging-in operation of the external storage device, thereby avoiding triggering of the ANR, and further solving the problem of application running caused by the ANR in the media library program.
The embodiment of the application provides a processing method of plugging operation, wherein a main thread is established after a terminal receives an I/O request; when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established; and processing the plugging operation corresponding to the external storage equipment through the sub-thread so as to inform the target equipment of the plugging operation. That is to say, in the embodiment of the present application, when the terminal processes the I/O operation with the target device through the main thread, the terminal creates the sub-thread in response to the received plugging request, so that the plugging operation of the external storage device can be processed through the sub-thread, that is, the plugging operation can be processed by the sub-thread while the I/O operation is processed through the main thread. Therefore, the plug-in operation processing method provided by the application can process the plug-in operation of the external storage device while processing the I/O operation with the target device, so that triggering of the ANR can be avoided, and the problem of media library breakdown caused by the ANR is solved.
Based on the foregoing embodiment, in yet another embodiment of the present application, fig. 5 is a schematic view of an implementation flow of a method for processing a plug-in operation, and as shown in fig. 5, before the terminal processes the plug-in operation corresponding to the external storage device through the child thread, that is, before step 103, the method for processing by the terminal may further include the following steps:
and 105, requesting the same mutual exclusion lock for the first sub-thread and the second sub-thread.
In the embodiment of the application, before the terminal processes the plugging operation corresponding to the external storage device through the sub-thread, the terminal may request the same exclusive lock for the first sub-thread and the second sub-thread.
In programming, the concept of object mutual exclusion lock is introduced to ensure the integrity of shared data operation. Each object corresponds to a tag, which may be referred to as a mutex, that is used to ensure that only one thread can access the object at any one time. The locking operation of the mutex mainly includes locking pthread _ mutex _ lock (), unlocking pthread _ mutex _ unlock (), and testing pthread _ mutex _ trylock (), and no matter which type of lock is available, two different threads cannot obtain the lock at the same time, and the lock must wait for unlocking. For common locks and adaptive lock types, the unlocker can be any thread in the same process; the error detection lock is valid only by unlocking by a locker, otherwise, the error detection lock returns to the EPERM; for nested locks, the documentation and implementation requirements must be unlocked by the locker, but experimental results suggest that there is no such limitation, and this difference has not been explained. If the thread in the same process is not unlocked after locking, any other thread can not obtain the lock any more.
That is, in the present application, the first child thread and the second child thread may request the same mutex respectively when starting execution, and thus it is possible to prevent a state error caused by adding or deleting the same external storage device by the child thread. In other words, in the present application, a mutex lock may be added to the terminal to solve the synchronization problem between the first sub-thread that handles the plug-in operation of the external storage device and the second sub-thread that handles the pull-out operation of the external storage device.
Further, in an embodiment of the present application, when the terminal processes the plug-in and pull-out operation corresponding to the external storage device through the child thread, the mutex lock may be released after the plug-in operation of the external storage device is completed through the first child thread; and then processing the unplugging operation of the external storage device through the second sub-thread.
That is, in the embodiment of the present application, before the first child thread accesses the external storage device, the first child thread may lock the mutex; the lock on the mutually exclusive lock leader is then released after the access is complete. Wherein, after locking the mutually exclusive lock, any other thread attempting to lock the mutually exclusive lock again will be blocked until the lock is released.
In the embodiment of the application, further, when the terminal processes the plugging operation corresponding to the external storage device through the sub-thread, the terminal may also set a state parameter of the external storage device first; the unplugging operation of the external storage device may then be processed by the second child thread based on the status parameter.
It is understood that in embodiments of the present application, the status parameter may be used to characterize whether the external storage device is removed.
For example, in the embodiment of the present application, the state parameter set by the terminal may be a removing flag. Wherein, the removing flag can be set to true or false. Specifically, the terminal may set the removing flag to true, so that the external storage device is not accessed and operated until the external storage device is unplugged, and then set the removing flag to false after the external storage device is removed.
It is understood that, in the embodiment of the present application, before the unplugging operation of the external storage device is processed by the second child thread, the terminal may set a removing flag for removeStorage (), which prevents the target device from calling the external storage device when the external storage device has been unplugged but the second child thread has not been processed.
The embodiment of the application provides a processing method of plugging operation, wherein a main thread is established after a terminal receives an I/O request; when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established; and processing the plugging operation corresponding to the external storage equipment through the sub-thread so as to inform the target equipment of the plugging operation. That is to say, in the embodiment of the present application, when the terminal processes the I/O operation with the target device through the main thread, the terminal creates the sub-thread in response to the received plugging request, so that the plugging operation of the external storage device can be processed through the sub-thread, that is, the plugging operation can be processed by the sub-thread while the I/O operation is processed through the main thread. Therefore, the plug-in operation processing method provided by the application can process the plug-in operation of the external storage device while processing the I/O operation with the target device, so that triggering of the ANR can be avoided, and the problem of media library breakdown caused by the ANR is solved.
Based on the foregoing embodiment, in yet another embodiment of the present application, fig. 6 is a schematic diagram of currently processing a plug operation, and fig. 7 is a schematic diagram of processing a plug operation proposed in the present application, which is shown in fig. 6, currently, when a terminal is processing an I/O operation with a target device, if an external storage device is plugged into the terminal or unplugged from the terminal, the terminal may receive a plug request corresponding to the external storage device, and then a media library may receive a plug broadcast of the external storage device (step 201), where the media library is a system program in the terminal, is a content provider, and mainly provides addition, deletion, modification, and query of files in a system; after receiving the plug broadcast, the media library may call removeStorage () and/or addStorage () (step 202) through MtpServer; removeStorage () and/or addStorage () perform a corresponding plug operation after MtpServer has finished processing the current I/O operation (step 203).
That is to say, in the prior art, a google native flow is generally adopted, that is, MtpServer processes interaction with a target device in the same thread, and therefore, if an I/O operation performed by a terminal and the target device takes a long time, for example, a large file is copied from the target device to the terminal, after receiving a plug broadcast, the terminal must wait until MtpServer completes the I/O operation to execute removeStorage () and/or addStorage (), and thus the call of media library processing removeStorage () and/or addStorage () cannot be completed, which may trigger ANR, resulting in a crash of the media library.
Specifically, on Android, if an application responds less sensitively for a while, the system displays a dialog box called an application unresponsive ANR dialog box. The user may choose to "wait" for the program to continue running, or may choose to "force shut down". ANR cannot occur in a smooth and reasonable application, leaving the user to handle this dialog each time. Therefore, it is important to design the response performance in the program so that the system does not display ANR to the user. By default, the longest execution time of Activity in android is 5 seconds, and the longest execution time of Broadcast Receiver is 10 seconds.
In order to solve the problem of media library crash caused by the method for processing the plugging operation shown in fig. 6, according to the method for processing the plugging operation shown in fig. 7, when the terminal processes the I/O operation with the target device, if the external storage device is plugged into the terminal or pulled out of the terminal, the terminal may receive a plugging request corresponding to the external storage device, and then the media library may receive a plugging broadcast of the external storage device (step 301); after receiving the plug broadcast, the media library may call removeStorage () and/or addStorage () (step 302) through MtpServer; the removeStorage () and/or addStorage () establishes a child thread (step 303), specifically, the child thread may include a first child thread and/or a second child thread, the first child thread may be used to process a plug-in operation of the external storage device, and the second child thread may be used to process a pull-out operation of the external storage device; finally, the terminal may process the plugging operation corresponding to the external storage device through the sub thread while continuing to process the I/O operation with the target device through the main thread (step 304).
That is, in the application, the terminal may process a removal operation and/or an addition operation of the external storage device through the sub thread while processing an I/O operation with the target device through the main thread through the creation of the sub thread.
It can be understood that, in the present application, since the main thread and the sub-thread have explicit division of labor, in the process of processing the I/O operation with the target device through the main thread, the terminal may process the plug-in and pull-out operation of the external storage device through the sub-thread without waiting for the completion of the I/O operation to perform the plug-in and pull-out operation of the external storage device, thereby avoiding triggering of the ANR, and further solving the problem of running application caused by the ANR in the media library program.
Based on the foregoing fig. 7 and fig. 8 are schematic diagrams illustrating a second process of performing a plug-in operation proposed by the present application, as shown in fig. 8, after establishing a sub-thread, that is, after step 303, the terminal may request the same mutex (step 305) when the first sub-thread and/or the second sub-thread starts to execute, respectively, so that a synchronization problem between the first sub-thread performing the plug-in operation and the second sub-thread performing the plug-out operation may be solved. Specifically, the terminal may release the mutex after the insertion operation of the external storage device is completed through the first sub-thread processing; and then processing the unplugging operation of the external storage device through the second sub-thread.
Further, in the embodiment of the present application, when the terminal processes the plug-in and pull-out operation corresponding to the external storage device through the child thread, it may first determine whether the plug-in operation is a plug-out operation of the external storage device (step 306), and if the plug-in operation is an external storage device, the terminal may notify the target device of adding the external storage device through the first child thread (step 307); if the external storage device is pulled out, the state parameters of the external storage device can be set firstly; the unplugging operation of the external storage device may then be processed by the second child thread based on the status parameter. Specifically, the terminal may set the remoting flag to true (step 308), so that the external storage device is not accessed and operated until the unplugging operation of the external storage device is completed, then after the external storage device is removed, notify the target device to remove the external storage device through the second child thread (step 309), and finally set the remoting flag to false (step 3010).
The embodiment of the application provides a processing method of plugging operation, wherein a main thread is established after a terminal receives an I/O request; when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established; and processing the plugging operation corresponding to the external storage equipment through the sub-thread so as to inform the target equipment of the plugging operation. That is to say, in the embodiment of the present application, when the terminal processes the I/O operation with the target device through the main thread, the terminal creates the sub-thread in response to the received plugging request, so that the plugging operation of the external storage device can be processed through the sub-thread, that is, the plugging operation can be processed by the sub-thread while the I/O operation is processed through the main thread. Therefore, the plug-in operation processing method provided by the application can process the plug-in operation of the external storage device while processing the I/O operation with the target device, so that triggering of the ANR can be avoided, and the problem of media library breakdown caused by the ANR is solved.
Based on the foregoing embodiments, in another embodiment of the present application, fig. 9 is a schematic diagram of a composition structure of a terminal, and as shown in fig. 9, a terminal 10 according to an embodiment of the present application may include a creating unit 11, a processing unit 12, and a requesting unit 13.
The establishing unit 11 is configured to establish a main thread after receiving the I/O request; when the I/O operation between the main thread and the target device is processed, if a plugging request corresponding to the external storage device is received, establishing a sub-thread;
the processing unit 12 is configured to process, by the sub thread, a plug-in operation corresponding to the external storage device, so as to notify the target device of the plug-in operation.
Further, in the embodiment of the present application, the plugging operation includes a plugging operation and/or a unplugging operation of the external storage device.
Further, in an embodiment of the present application, the establishing unit 11 is specifically configured to create a first child thread and/or a second child thread; the first sub thread is used for processing the inserting operation corresponding to the external storage device; the second sub thread is used for processing the pulling-out operation corresponding to the external storage device.
Further, in an embodiment of the present application, the requesting unit 13 is configured to request the same mutex for the first sub-thread and the second sub-thread before the corresponding plugging operation of the external storage device is processed by the sub-thread.
Further, in the embodiment of the present application, the processing unit 12 is specifically configured to release the mutex after the insertion operation of the external storage device is completed through the first sub-thread processing; processing the unplugging operation of the external storage device by the second child thread.
Further, in an embodiment of the present application, the processing unit 12 is further specifically configured to notify the target device to add the external storage device through the first child thread; and/or notifying the target device to remove the external storage device through the second child thread.
Further, in the embodiment of the present application, the processing unit 12 is further specifically configured to set a state parameter of the external storage device; wherein the status parameter characterizes whether the external storage device is removed; processing, by the second child thread, the pull-out operation of the external storage device based on the state parameter.
Further, in this embodiment of the present application, the establishing unit 11 is further configured to establish a connection with the target device based on MTP before receiving the I/O request.
In an embodiment of the present application, further, fig. 10 is a schematic diagram of a composition structure of a terminal, as shown in fig. 10, the terminal 10 according to the embodiment of the present application may further include a processor 14, a memory 15 storing executable instructions of the processor 14, and further, the terminal 10 may further include a communication interface 16, and a bus 17 for connecting the processor 14, the memory 15, and the communication interface 16.
In an embodiment of the present application, the Processor 14 may be at least one of an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a ProgRAMmable Logic Device (PLD), a Field ProgRAMmable Gate Array (FPGA), a Central Processing Unit (CPU), a controller, a microcontroller, and a microprocessor. It is understood that the electronic devices for implementing the above processor functions may be other devices, and the embodiments of the present application are not limited in particular. The terminal 10 may further comprise a memory 15, which memory 15 may be connected to the processor 14, wherein the memory 15 is adapted to store executable program code comprising computer operating instructions, and wherein the memory 15 may comprise a high speed RAM memory and may further comprise a non-volatile memory, such as at least two disk memories.
In the embodiment of the present application, the bus 17 is used to connect the communication interface 16, the processor 14, and the memory 15 and the intercommunication among these devices.
In an embodiment of the present application, the memory 15 is used for storing instructions and data.
Further, in the embodiment of the present application, the processor 14 is configured to establish a main thread after receiving the I/O request; when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established; and processing the plugging operation corresponding to the external storage equipment through the sub thread so as to inform the target equipment of the plugging operation.
In practical applications, the Memory 15 may be a volatile Memory (volatile Memory), such as a Random-Access Memory (RAM); or a non-volatile Memory (non-volatile Memory), such as a Read-Only Memory (ROM), a flash Memory (flash Memory), a Hard disk (Hard disk Drive, HDD) or a Solid-State Drive (SSD); or a combination of the above types of memories and provides instructions and data to processor 14.
In addition, each functional module in this embodiment may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware or a form of a software functional module.
Based on the understanding that the technical solution of the present embodiment essentially or a part contributing to the prior art, or all or part of the technical solution, may be embodied in the form of a software product stored in a storage medium, and include several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to execute all or part of the steps of the method of the present embodiment. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
According to the terminal provided by the embodiment of the application, after the terminal receives an I/O request, a main thread is established; when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established; and processing the plugging operation corresponding to the external storage equipment through the sub-thread so as to inform the target equipment of the plugging operation. That is to say, in the embodiment of the present application, when the terminal processes the I/O operation with the target device through the main thread, the terminal creates the sub-thread in response to the received plugging request, so that the plugging operation of the external storage device can be processed through the sub-thread, that is, the plugging operation can be processed by the sub-thread while the I/O operation is processed through the main thread. Therefore, the plug-in operation processing method provided by the application can process the plug-in operation of the external storage device while processing the I/O operation with the target device, so that triggering of the ANR can be avoided, and the problem of media library breakdown caused by the ANR is solved.
An embodiment of the present application provides a computer-readable storage medium, on which a program is stored, and when the program is executed by a processor, the program implements a processing method of the plugging operation as described above.
Specifically, the program instructions corresponding to a method for processing a plugging operation in the present embodiment may be stored on a storage medium such as an optical disc, a hard disc, a usb disk, or the like, and when the program instructions corresponding to the method for processing a plugging operation in the storage medium are read or executed by an electronic device, the method includes the following steps:
after receiving the I/O request, establishing a main thread;
when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established;
and processing the plugging operation corresponding to the external storage equipment through the sub thread so as to inform the target equipment of the plugging operation.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of implementations of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart block or blocks and/or flowchart block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks in the flowchart and/or block diagram block or blocks.
The above description is only a preferred embodiment of the present application, and is not intended to limit the scope of the present application.

Claims (11)

1. A processing method for plugging operation is characterized by comprising the following steps:
after receiving an input/output (I/O) request, establishing a main thread;
when I/O operation between the main thread and target equipment is processed, if a plugging request corresponding to external storage equipment is received, a sub-thread is established;
and processing the plugging operation corresponding to the external storage equipment through the sub thread so as to inform the target equipment of the plugging operation.
2. The method according to claim 1, wherein the plugging operation comprises a plugging operation and/or a unplugging operation of the external storage device.
3. The method of claim 2, wherein the establishing a child thread comprises:
creating a first child thread and/or a second child thread; the first sub thread is used for processing the inserting operation corresponding to the external storage device; the second sub thread is used for processing the pulling-out operation corresponding to the external storage device.
4. The method according to claim 3, wherein before the processing, by the child thread, the plugging operation corresponding to the external storage device, the method further comprises:
and requesting the same mutual exclusion lock for the first sub-thread and the second sub-thread.
5. The method according to claim 4, wherein the processing, by the child thread, the plugging operation corresponding to the external storage device includes:
releasing the mutex after the insertion operation of the external storage device is completed through the first sub-thread processing;
processing the unplugging operation of the external storage device by the second child thread.
6. The method according to claim 3, wherein the processing, by the child thread, the plug operation corresponding to the external storage device to notify the target device of the plug operation includes:
notifying the target device of adding the external storage device through the first child thread; and/or the presence of a gas in the gas,
notifying the target device of removing the external storage device through the second child thread.
7. The method according to claim 5, wherein the processing, by the child thread, the plugging operation corresponding to the external storage device includes:
setting state parameters of the external storage equipment; wherein the status parameter characterizes whether the external storage device is removed;
processing, by the second child thread, the pull-out operation of the external storage device based on the state parameter.
8. The method of claim 1, wherein prior to receiving the I/O request, the method further comprises:
and establishing connection with the target equipment based on a Media Transfer Protocol (MTP).
9. A terminal, characterized in that the terminal comprises: the set-up unit, the processing unit,
the establishing unit is used for establishing a main thread after receiving the I/O request; when the I/O operation between the main thread and the target device is processed, if a plugging request corresponding to the external storage device is received, establishing a sub-thread;
the processing unit is configured to process, by the sub thread, a plug-in operation corresponding to the external storage device, so as to notify the target device of the plug-in operation.
10. A terminal, characterized in that the terminal comprises: a processor, a memory storing instructions executable by the processor, the instructions when executed by the processor implementing the method of any one of claims 1-8.
11. A computer-readable storage medium, on which a program is stored, for use in a terminal, characterized in that the program, when executed by a processor, implements the method according to any one of claims 1-8.
CN202010263688.8A 2020-04-07 2020-04-07 Plug-in operation processing method, terminal and storage medium Active CN111522764B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010263688.8A CN111522764B (en) 2020-04-07 2020-04-07 Plug-in operation processing method, terminal and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010263688.8A CN111522764B (en) 2020-04-07 2020-04-07 Plug-in operation processing method, terminal and storage medium

Publications (2)

Publication Number Publication Date
CN111522764A true CN111522764A (en) 2020-08-11
CN111522764B CN111522764B (en) 2023-02-28

Family

ID=71902379

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010263688.8A Active CN111522764B (en) 2020-04-07 2020-04-07 Plug-in operation processing method, terminal and storage medium

Country Status (1)

Country Link
CN (1) CN111522764B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111984570A (en) * 2020-07-14 2020-11-24 深圳市优必选科技股份有限公司 Device hot plug detection method and device

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070271404A1 (en) * 2006-05-16 2007-11-22 Sun Microsystems, Inc. Realtime multithreaded hot-plug control
CN102625939A (en) * 2009-07-10 2012-08-01 塞尔蒂卡姆公司 System and method for managing electronic assets
JP2012173956A (en) * 2011-02-21 2012-09-10 Yokogawa Electric Corp Host device to which usb device is connected and program of the same
US20150007105A1 (en) * 2011-12-29 2015-01-01 Beijing Qihoo Technology Company Limited Method and device for preventing apparent death of window
CN105446806A (en) * 2014-09-28 2016-03-30 广州市动景计算机科技有限公司 Processing method and apparatus for application not responding
CN106155741A (en) * 2016-06-30 2016-11-23 努比亚技术有限公司 A kind of avoid application program without response processing means and method
CN106502808A (en) * 2016-10-28 2017-03-15 广东欧珀移动通信有限公司 A kind of method of copied files, device and terminal
CN109861966A (en) * 2018-12-06 2019-06-07 北京达佳互联信息技术有限公司 Method, apparatus, terminal and the storage medium of processing status event
CN110704216A (en) * 2019-08-26 2020-01-17 北京三快在线科技有限公司 Application no-response detection method and device for terminal and electronic equipment

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070271404A1 (en) * 2006-05-16 2007-11-22 Sun Microsystems, Inc. Realtime multithreaded hot-plug control
CN102625939A (en) * 2009-07-10 2012-08-01 塞尔蒂卡姆公司 System and method for managing electronic assets
JP2012173956A (en) * 2011-02-21 2012-09-10 Yokogawa Electric Corp Host device to which usb device is connected and program of the same
US20150007105A1 (en) * 2011-12-29 2015-01-01 Beijing Qihoo Technology Company Limited Method and device for preventing apparent death of window
CN105446806A (en) * 2014-09-28 2016-03-30 广州市动景计算机科技有限公司 Processing method and apparatus for application not responding
CN106155741A (en) * 2016-06-30 2016-11-23 努比亚技术有限公司 A kind of avoid application program without response processing means and method
CN106502808A (en) * 2016-10-28 2017-03-15 广东欧珀移动通信有限公司 A kind of method of copied files, device and terminal
CN109861966A (en) * 2018-12-06 2019-06-07 北京达佳互联信息技术有限公司 Method, apparatus, terminal and the storage medium of processing status event
CN110704216A (en) * 2019-08-26 2020-01-17 北京三快在线科技有限公司 Application no-response detection method and device for terminal and electronic equipment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111984570A (en) * 2020-07-14 2020-11-24 深圳市优必选科技股份有限公司 Device hot plug detection method and device

Also Published As

Publication number Publication date
CN111522764B (en) 2023-02-28

Similar Documents

Publication Publication Date Title
AU2018261579B2 (en) Backup and restore framework for distributed computing systems
Kim et al. Hyperloop: group-based NIC-offloading to accelerate replicated transactions in multi-tenant storage systems
US11392461B2 (en) Method and apparatus for processing information
US9411812B2 (en) File system management
JP2017528809A (en) Secure data access after memory failure
CN110971700B (en) Method and device for realizing distributed lock
RU2746155C2 (en) Destroying an object based on the sequence of actions performed
CN106777394B (en) Cluster file system
CN112732406B (en) Cloud platform virtual machine recovery method and computer equipment
US20170085653A1 (en) Method, device and system for message distribution
US9805038B2 (en) Efficient conflict resolution among stateless processes
CN111522764B (en) Plug-in operation processing method, terminal and storage medium
CN113342554B (en) IO multiplexing method, medium, device and operating system
CN106874343B (en) Data deletion method and system for time sequence database
CN110825536B (en) Communication method and device between tasks in embedded real-time operating system
WO2015184902A1 (en) Concurrent processing method for intelligent split-screen and corresponding intelligent terminal
US9418175B2 (en) Enumeration of a concurrent data structure
US8538917B2 (en) System and method for file coordination
CN116578446B (en) Virtual machine backup method, device and system, electronic equipment and storage medium
CN115202884B (en) Method for adding read write lock of high-performance system based on polling and application
CN113704297B (en) Processing method, module and computer readable storage medium for business processing request
CN110879747B (en) Resource management method and device
CN112988460B (en) Data backup method and device for virtual machine
CN111858002B (en) Concurrent processing method, system and device based on asynchronous IO
CN116737724A (en) Cache data full synchronization method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant