File scanning method, file scanning device and electronic equipment

By determining the modification time and size of the folder, the file scanning process is optimized, which solves the problem of file scanning overhead and high power consumption in electronic devices, and achieves more efficient file scanning and database updates.

CN118869879APending Publication Date: 2024-10-29HUAWEI TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310478155.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-04-26
Publication Date
2024-10-29

AI Technical Summary

Technical Problem

The file scanning process in electronic devices involves large overhead and power consumption, which affects user experience. Especially when the number of files increases, it is difficult for existing technologies to effectively reduce these overheads and power consumption.

Method used

By obtaining information such as the modification time and size of the folder, it is determined whether the folder has changed. If no change has occurred, the data comparison of the files and folders under it will be skipped, and only the actual changed folder and file information will be updated. Database to optimize the file scanning process.

Benefits of technology

It effectively reduces the overhead and power consumption in the file scanning process, improves user experience, reduces unnecessary data comparisons and database updates, and improves the performance of electronic devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118869879A_ABST
    Figure CN118869879A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a file scanning method, a file scanning device and electronic equipment. The method comprises the steps that first information is obtained, the first information is used for determining a first directory to be scanned, and a first node is a father node of a second node; when the second node is traversed, if the second node corresponds to the file, whether data information of the folder corresponding to the first node is changed or not is determined, and the data information of the folder comprises the modification time of the folder; when the data information of the folder corresponding to the first node does not change, the comparison of whether the data information of the file corresponding to the second node changes or not is skipped, and the data information of the file comprises at least one of the file modification time, the file type, the file storage path and the file size. According to the file scanning method, the file scanning device and the electronic equipment provided by the embodiment of the invention, the overhead and the power consumption in the file scanning process can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present application relate to the field of electronic devices, and more specifically, to a file scanning method, a file scanning device, and an electronic device. Background Art

[0002] The operating system of the electronic device scans the media files, thereby updating the latest data information of the media files into the database, so that the application or process can use the corresponding media files through the database.

[0003] During the file scanning process, the operating system needs to traverse and scan all files and folders in a specific directory to find the files that need to update data information. As the number of files stored on electronic devices increases, the file scanning process has a large overhead and power consumption, which affects the user experience. Summary of the invention

[0004] Embodiments of the present application provide a file scanning method, a file scanning device, and an electronic device, which can reduce the overhead and power consumption during the file scanning process.

[0005] In a first aspect, a file scanning method is provided, which is applied to an electronic device, comprising: obtaining first information, the first information being used to determine a first directory to be scanned, a first node and a second node being nodes under the first directory, the first node being a parent node of the second node, and the first node corresponding to a folder; when traversing to the second node, if the second node corresponds to a file, determining whether data information of the folder corresponding to the first node has changed, the data information of the folder including a modification time of the folder; when the data information of the folder corresponding to the first node has not changed, skipping a comparison of whether the data information of the file corresponding to the second node in the file system has changed relative to the data information of the file corresponding to the second node in the database, the data information of the file including at least one of the modification time of the file, the file type, the file storage path, and the file size.

[0006] The first information may be information that triggers file scanning, and the module or unit that performs file scanning may determine that the directory to be scanned is the first directory based on the first information. The first directory is a directory in the file system, and the file system is a system in the operating system of the electronic device that is responsible for managing and organizing files and data stored in the memory (the file system is also called a file management system), and the file system organizes files according to a certain structure, such as a tree structure. Each node of the tree structure corresponds to a folder (wherein the folder can also be called a directory or subdirectory) or a file. The first directory points to a node of the tree structure, and the node may correspond to the root directory of the entire file system (that is, the node is the root node of the directory tree of the entire file system), so that the first directory to be scanned may be all files and folders in the entire file system; the node may also correspond to any level of subdirectory under the root directory, so that the first directory to be scanned may be part of the files or folders in the file system. When performing file scanning, it is necessary to scan the folders or files corresponding to the node pointed to by the first directory and all nodes below the node. The first information may be information such as broadcast, or may be other forms of indication information. The files or folders to be scanned corresponding to the first directory are stored in a memory, which may be a system memory or an SD card of an electronic device, an external storage device inserted into the electronic device, or a storage medium or unit of other devices connected to the electronic device.

[0007] The first node is a node under the first directory, which can be understood as the first node being the root node of the first directory tree corresponding to the first directory, or it can be nodes at all levels under the root node.

[0008] If a file is modified, the modification time of the file will change, and at the same time, the modification time of the parent folder of the file will also change. Therefore, it is possible to determine whether there is a modified file in the parent folder based on whether the modification time of the parent folder has changed. If there is no modified file in the folder, skipping the scanning of these files can reduce the overhead of file scanning.

[0009] Traversing to a certain node can be understood as when performing a file scan, the scanning progress reaches the file or folder corresponding to a certain node. Traversing to a certain node is also equivalent to scanning a certain node (file or folder) or enumerating a certain node (file or folder) or accessing a certain node (file or folder).

[0010] When performing file scanning, the data of each node of the first directory tree corresponding to the directory to be scanned (first directory) can be traversed in a certain order, and the first directory tree may include a root node, and the first node and the second node are both nodes in the first directory tree. When traversing to the node corresponding to the file, it can be determined whether to compare the data information of the node according to whether the data information of the folder corresponding to its parent node has changed. When the data information of the folder corresponding to its parent node has not changed, the comparison of the data information of the node can be skipped. When the data information of the folder corresponding to its parent node has changed, it is necessary to traverse each node under the folder and compare whether the data information of the file or folder corresponding to each node has changed, and update the change of the data information to the database.

[0011] Optionally, if the node corresponding to the folder is traversed (scanned to the folder), that is, the second node corresponds to the folder, it is necessary to determine whether the data information of the folder corresponding to the second node has changed. If the data information of the folder has changed, it is necessary to update the data information of the folder to the database to avoid affecting the next file scan. If the data information of the folder is not updated, even if the files under the folder have not changed during the next scan, the data information of the folder will still be determined to have changed, and the files under the folder need to be scanned. If the data information of the folder has not changed, the data information of the folder can be marked as unchanged in various ways, such as by adding the identifier of the folder or the identifier of the node corresponding to the folder to a specific list, or each time the folder is scanned during the file scanning process, a field can be added to the folder to indicate whether the data information of the folder has changed, that is, it is stored as the attribute information of the folder during the scan. When the files under the folder are scanned, it is determined whether the data information of the folder has changed by reading the attribute information of the folder. The attribute information will be updated each time it is scanned.

[0012] In combination with the first aspect, in some implementations of the first aspect, when the type of the folder corresponding to the first node is a leaf folder, the leaf folder is a folder without subfolders, and the method further includes: skipping the traversal of the sibling nodes of the second node.

[0013] In this embodiment, the type of the folder corresponding to the first node can be further determined. If the folder corresponding to the first node is a leaf folder, the traversal of the second node's sibling nodes can be directly skipped after traversing to the second node. The second node can be the first child node of the first node traversed by the media library. Since there are no other folders under the leaf folder, if the data information of the folder has not changed, the data information of the file must not have changed. At this time, skipping the comparison of the data information of the files under the folder and skipping the traversal of other file nodes after traversing to the first file node can reduce the overhead and power consumption caused by file scanning.

[0014] In combination with the first aspect, in some implementations of the first aspect, when the type of the folder corresponding to the first node is a redundant folder, the redundant folder is a folder with subfolders, and the method further includes: continuing to traverse the sibling nodes of the second node.

[0015] When the folder type is not a leaf folder (it is a redundant folder), the child nodes of the first node (files or folders under the redundant folder) can be traversed in sequence, and when traversing to the child node of the corresponding file, skip the comparison of the data information of the file corresponding to the child node and continue to traverse the next child node.

[0016] That is to say, when the technical solution of the present application is implemented, it is possible to not distinguish the type of folder, traverse the nodes under the folder whose data information has not changed one by one, and determine whether to skip the comparison of the data information of the file or folder based on whether the node corresponds to a file or a folder (for files, there is no need to compare the data information, but for folders, data information needs to be compared). It is also possible to distinguish the type of folder, and for files under leaf folders whose data information has not changed, after scanning the first file, skip the comparison of the data information of the current file and skip the traversal of other files under the folder; for files under redundant folders whose data information has not changed, it is necessary to traverse each node in turn, and when a file is scanned, skip the comparison of the data information of the file, and only compare the data information of the scanned folder.

[0017] In an embodiment of the present application, the data information of a folder includes the modification time of the folder, and optionally, the data information of the folder also includes the size of the folder. After the modification time of a file changes, the modification time of its parent folder will also change, while the modification time of the parent folder of the parent folder will not change. When the size of a file changes, there may be three situations (the configurations of different operating systems may be different) as to whether the size of its parent folder and the size of the parent folder of the parent folder change: Situation 1, the size of the parent folder changes, while the size of the parent folder of the parent folder does not change; Situation 2, the size of the parent folder changes, and the size of the parent folder of the parent folder also changes (the sizes of the n-level folders above the parent folder all change); Situation 3: the size of the parent folder does not change, and the size of the parent folder of the parent folder does not change.

[0018] When the data information of a folder includes the size of the folder and the modification time of the folder, that is, only when the size and modification time of the folder have not changed, it is judged that the data information of the folder has not changed. In case 1, since the change in the file size only affects the size of its parent folder, and does not affect the size of the upper level or multiple levels of the folder of its parent folder, the effect is the same as the change in the modification time of the file, so increasing the judgment of the size of the folder is basically consistent with the result of judging the modification time of the folder alone. Only when, for example, the user modifies the file in the interval between two scans and the interval between the two scans is less than the accuracy of the modification time of the folder, for example, less than 1s, the modification time of the file will not show a change due to the accuracy problem, but the file size may have changed due to the user's modification of the file, so that the data information of the parent folder of the file is judged to have changed. In this way, increasing the size of the folder as an indicator can avoid missing the scanning of the files under the folder, thereby improving the applicable scenarios of the embodiments of the present application. In case 2, since the change in the file size not only affects the size of its parent folder but also affects the size of the folder of the parent node of its parent node, when the file size changes, the data information of the parent folder corresponding to the direct branch node where the file is located changes. Figure 3For example, when the file size corresponding to node 17 changes, the size of the folder corresponding to node 7, node 4 and node 1 all change. When scanning the file, it is necessary to compare the files corresponding to node 8 and node 9. This situation will cause the scanning overhead to be still high. If the file size corresponding to node 10 changes, the size of the folder corresponding to node 5, node 2 and node 1 will change synchronously, and the size of the folder corresponding to node 6 will not change. The technical solution of the embodiment of the present application can still reduce the scanning overhead in this case. Therefore, the size of the folder can be considered when judging whether the data information of the folder has changed; however, in order to reduce the scanning overhead as much as possible, the size of the folder can be ignored when judging whether the data information of the folder has changed. In case 3, since the change in file size does not affect the size of its parent folder, the size of the folder will never change, and it is the size when the folder is initially established. Then the judgment on whether the size of the folder has changed is a redundant judgment. When the modification time of the parent folder changes (the size of the parent folder remains unchanged), the data information of the folder changes; when the modification time of the parent folder does not change (the size of the folder remains unchanged, and the data information of the folder does not change).

[0019] In addition, when judging whether the data information of a folder has changed, it is necessary to indirectly judge whether the files under the folder have been modified from whether the data information of the folder has changed. In order to reduce the file scanning overhead as much as possible, in addition to the modification time of the folder, only indicators that meet certain adjustments can be used as the standard for judging whether the data information of the folder has changed, such as the indicators that meet conditions 1 and 3 introduced in the previous article (indicators that meet condition 2 can also be considered, which also has a certain effect of reducing the file scanning overhead). However, when updating the data information of a file or folder to the database or judging whether the data information of a file has changed, the purpose is to update the data information to the database. You can only update the indicators used in the judgment, or you can directly put all the information of the file or folder into the database, that is, directly read various information from the file system based on the file or folder, and update the various information into the database.

[0020] In combination with the first aspect, in some implementations of the first aspect, before traversing to the second node, the method also includes: comparing whether the data information of the folder corresponding to the first node in the file system has changed relative to the data information of the folder corresponding to the first node in the database; when the data information of the folder corresponding to the first node in the file system has not changed relative to the data information of the folder corresponding to the first node in the database, storing the identifier of the first node in a first list; wherein, determining whether the data information of the folder corresponding to the first node has changed includes: when the identifier of the first node is in the first list, determining that the data information of the folder corresponding to the first node has not changed; when the identifier of the first node is not in the first list, determining that the data information of the folder corresponding to the first node has changed.

[0021] In this embodiment, since the data of each node to be scanned has a certain order, when traversing to a folder node, the data information can be compared and it can be determined whether the data information has changed, so that the identifier of the folder or corresponding node whose data information has not changed is stored in a corresponding list, so that when a file in the folder is subsequently scanned, the scanning strategy for the file and the files corresponding to its sibling nodes can be determined according to whether the folder to which the file belongs is in the corresponding list.

[0022] Specifically, when the types of folders are not distinguished, the identifiers of the folders or corresponding nodes whose data information has not changed may be stored in the first list.

[0023] When distinguishing the types of folders, the leaf folders or corresponding node identifiers whose data information has not changed may be stored in the second list, and the redundant folders or corresponding node identifiers whose data information has not changed may be stored in the third list.

[0024] In combination with the first aspect, in some implementations of the first aspect, if the second node corresponds to a folder, the method also includes: comparing whether the data information of the folder corresponding to the second node in the file system has changed relative to the data information of the folder corresponding to the second node in the database; when the data information of the folder corresponding to the second node in the file system has changed relative to the data information of the folder corresponding to the second node in the database, updating the data information of the folder corresponding to the second node in the file system to the database.

[0025] In this embodiment, when traversing to a folder node, it is necessary to compare the data information of the folder in the file system with the data information of the folder in the database to determine whether the data information of the folder has changed. If it has changed, the data information is updated to the database so that the next time the file is scanned, the scanning process will not be prolonged due to non-update. If it has not changed, the identifier of the folder or the corresponding node can be stored in the corresponding list for determining the corresponding scanning strategy when the sub-files or sub-folders under the folder are scanned later.

[0026] In combination with the first aspect, in some implementations of the first aspect, the method also includes: when traversing to the third node, the third node is a child node of the second node, and the third node corresponds to a file. If the data information of the folder corresponding to the second node has not changed, skip the comparison of whether the data information of the file corresponding to the third node in the file system has changed relative to the data information of the file corresponding to the third node in the database; if the data information of the folder corresponding to the second node has changed, compare whether the data information of the file corresponding to the third node in the file system has changed relative to the data information of the file corresponding to the third node in the database.

[0027] When a file in a folder is scanned, the scanning strategy for the file can be determined based on whether the data information in the folder has changed.

[0028] In combination with the first aspect, in some implementations of the first aspect, the data information of the folder includes the size of the folder.

[0029] Optionally, the data information of a folder may also include at least one of the storage path of the folder, the number of files contained in the folder, and the number of folders contained in the folder. Furthermore, in order to minimize the overhead of file scanning, when a certain indicator of the data information of a file changes, the corresponding indicator of the data information of the parent folder of the file changes, and the corresponding indicator of the parent folder of the parent folder (and the parent folder's n-level parent folder) cannot change; or, when a certain indicator of the data information of a file changes, the data information of the parent folder of the folder and the corresponding indicator of the parent folder of the parent folder (and the parent folder's n-level parent folder) cannot change. That is, only when the corresponding indicator of the file changes, the impact on the corresponding indicator of the parent folder and the parent folder's parent folder is similar to the impact of the file size in the above-mentioned case 1 and case 3, the corresponding indicator can be considered when judging whether the data information of the folder has changed. For details, please refer to the above-mentioned introduction, which will not be repeated here.

[0030] In combination with the first aspect, in some implementations of the first aspect, the first information includes the first directory.

[0031] The directory to be scanned may be carried in the first information, and the first directory may be determined by an application or a process according to a storage path of a file modified by a user.

[0032] In combination with the first aspect, in some implementations of the first aspect, the operating system of the electronic device is an Android system.

[0033] When the operating system of the electronic device is an Android system, the above file scanning method can be performed by the media library of the electronic device. Optionally, the operating system of the electronic device can also be a Linux operating system, a Windows operating system, etc.

[0034] In a second aspect, a file scanning device is provided, including: an acquisition unit, used to acquire first information, the first information is used to determine a first directory to be scanned, a first node and a second node are nodes under the first directory, the first node is the parent node of the second node, and the first node corresponds to a folder; a processing unit, used to: when traversing to the second node, if the second node corresponds to a file, determine whether data information of the folder corresponding to the first node has changed, the data information of the folder includes the modification time of the folder; when the data information of the folder corresponding to the first node has not changed, skip the comparison of the data information of the file corresponding to the second node in the file system with the data information of the file corresponding to the second node in the database, the data information of the file includes at least one of the modification time of the file, the file type, the file storage path, and the file size.

[0035] In combination with the second aspect, in some implementations of the second aspect, when the type of the folder corresponding to the first node is a redundant folder, the redundant folder is a folder with subfolders, and the processing unit is further used to: continue traversing the sibling nodes of the second node.

[0036] In combination with the second aspect, in some implementations of the second aspect, the type of the folder corresponding to the first node is a redundant folder.

[0037] In combination with the second aspect, in some implementations of the second aspect, the processing unit is further used to: compare whether the data information of the folder corresponding to the first node in the file system has changed relative to the data information of the folder corresponding to the first node in the database; when the data information of the folder corresponding to the first node in the file system has not changed relative to the data information of the folder corresponding to the first node in the database, store the identifier of the first node in a first list; wherein the processing unit is specifically used to: when the identifier of the first node is in the first list, determine that the data information of the folder corresponding to the first node has not changed; when the identifier of the first node is not in the first list, determine that the data information of the folder corresponding to the first node has changed.

[0038] In combination with the second aspect, in some implementations of the second aspect, if the second node corresponds to a folder, the processing unit is also used to: compare whether the data information of the folder corresponding to the second node in the file system has changed relative to the data information of the folder corresponding to the second node in the database; when the data information of the folder corresponding to the second node in the file system has changed relative to the data information of the folder corresponding to the second node in the database, update the data information of the folder corresponding to the second node in the file system to the database.

[0039] In combination with the second aspect, in some implementations of the second aspect, the processing unit is further used to: when traversing to the third node, the third node is a child node of the second node, and the third node corresponds to a file. If the data information of the folder corresponding to the second node has not changed, skip comparing whether the data information of the file corresponding to the third node in the file system has changed relative to the data information of the file corresponding to the third node in the database; if the data information of the folder corresponding to the second node has changed, compare whether the data information of the file corresponding to the third node in the file system has changed relative to the data information of the file corresponding to the third node in the database.

[0040] In combination with the second aspect, in some implementations of the second aspect, the data information of the folder includes the size of the folder.

[0041] In combination with the second aspect, in some implementations of the second aspect, the first information includes the first directory.

[0042] According to a third aspect, an electronic device is provided, comprising the file scanning device according to the second aspect or any implementation of the second aspect.

[0043] In a fourth aspect, a computer storage medium is provided, which, when the computer instructions are executed on an electronic device, enables the electronic device to execute the method described in the first aspect or any implementation of the first aspect to the second aspect or any implementation of the second aspect.

[0044] In a fifth aspect, an electronic device is provided, comprising: a memory for storing computer instructions; and a processor for executing the computer instructions stored in the memory, so that the electronic device executes the method described in the first aspect or any one of the implementations of the first aspect.

[0045] In a sixth aspect, a chip system is provided, characterized in that it comprises at least one processor, and when program instructions are executed in the at least one processor, the at least one processor executes the method described in the first aspect or any one implementation of the first aspect.

[0046] In a seventh aspect, a chip is provided, comprising a processor and a data interface, wherein the processor reads instructions stored in a memory through the data interface to execute the method described in the first aspect and any possible implementation method of the first aspect.

[0047] Optionally, as an implementation, the chip may further include a memory, wherein the memory stores instructions.

[0048] The processor is used to execute instructions stored in the memory. When the instructions are executed, the processor is used to execute the method described in the first aspect and any possible implementation manner of the first aspect.

[0049] The above chip may specifically be a field programmable gate array or a dedicated integrated circuit. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 It is a schematic diagram of the software structure of an electronic device to which the embodiments of the present application are applicable.

[0051] Figure 2 It is a schematic flow chart of the file scanning method provided in an embodiment of the present application.

[0052] Figure 3 A schematic diagram of the tree structure is shown.

[0053] Figure 4 A schematic diagram of the modules or units involved in the technical solution of the embodiment of the present application is shown.

[0054] Figure 5 A schematic block diagram of a document scanning device provided in an embodiment of the present application is shown.

[0055] Figure 6A schematic block diagram of another document scanning device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0056] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0057] The terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one, two or more. The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.

[0058] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0059] The method provided in the embodiments of the present application is applied to electronic devices, including but not limited to mobile phones, tablet computers, vehicle-mounted devices, wearable devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), smart screens, and other electronic devices with display screens. The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.

[0060] For example, Figure 1The software system of the electronic device of the embodiment of the present application can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. Take the system as an example to illustrate the software structure.

[0061] Figure 1 FIG. 1 shows a software structure diagram of an electronic device to which the embodiment of the present application is applicable. Figure 1 As shown in FIG. 1 , the layered architecture divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, The system is divided into four layers, from top to bottom: application layer, application framework layer, system runtime layer (including system library and Android runtime) and kernel layer. Below the kernel layer is the hardware layer.

[0062] The application layer can include a series of application (APP) packages. Figure 1 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.

[0063] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 1 As shown, the application framework layer may include a window manager, a content provider, a phone manager, a resource manager, a notification manager, a view system, a card service engine, and the like.

[0064] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0065] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0066] The phone manager is used to provide communication functions for electronic devices, such as the management of call status (including answering, hanging up, etc.).

[0067] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0068] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0069] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0070] The system runtime library layer (libraries) can be divided into two parts: system libraries and Android runtime.

[0071] Android runtime is the Android operating environment, including the core library and virtual machine. Android runtime is responsible for the scheduling and management of the Android system. The core library consists of two parts: one is the function that the Java language needs to call, and the other is the Android core library.

[0072] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0073] The system library is the support of the application framework and may include multiple functional modules, such as: surface manager, media libraries, 2D graphics engine (such as SGL), 3D graphics processing library (such as OpenGL ES), image processing library, etc.

[0074] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0075] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0076] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis and layer processing, etc.

[0077] A 2D graphics engine is a drawing engine for 2D drawings.

[0078] The kernel layer is the layer between hardware and software, which is used to provide essential functions of the operating system such as file management, memory management, process management, network protocol stack, etc. The kernel layer includes at least display driver, camera driver, audio driver, sensor driver, Bluetooth driver, etc.

[0079] After detecting a specific event or receiving a scan instruction, the electronic device needs to perform a full disk scan of the files or folders stored in the electronic device or scan the specified directory of the file system, so as to update the data information of the file to the database of the media library for use by other applications or processes. For example, when a user uses an application or process to modify a file, the electronic device needs to scan the file corresponding to the directory (or default directory) indicated by the application or process. For another example, when the electronic device is restarted, the media library will perform a full disk scan to update the changes to the file to the database. However, a large number of files may be stored on the electronic device, and the power consumption of the scanning process is relatively large, which may cause the electronic device processor to consume a large amount of power, causing the electronic device to freeze and heat up, affecting the user experience.

[0080] The present application embodiment provides a file scanning method that can reduce the overhead and power consumption caused by file scanning. Figure 2 As shown, the method includes:

[0081] S210, obtaining first information, where the first information is used to determine a first directory to be scanned, where the first node and the second node are nodes under the first directory, where the first node is a parent node of the second node, and where the first node corresponds to a folder.

[0082] S220, when traversing to the second node, if the second node corresponds to a file, determine whether the data information of the folder corresponding to the first node has changed, the data information of the folder including the modification time of the folder.

[0083] S230, when the data information of the folder corresponding to the first node has not changed, skip the comparison of whether the data information of the file corresponding to the second node in the file system has changed relative to the data information of the second node in the database, the data information of the file includes at least one of the file modification time, file type, file storage path, and file size.

[0084] The technical solution provided in the embodiment of the present application can be applied to various operating systems, such as the Android system, and can also be applied to system, system, System, etc.

[0085] Taking the Android system as an example, the file scanning method of the embodiment of the present application can be executed by the media library, for example, it can be executed by the scanning module (media scanner) of the media library. When applied to other operating systems, the file scanning method can also be executed by other modules or units. As long as the module or unit has the function of file scanning, the technical solution provided by the embodiment of the present application can be executed. The following mainly takes the execution by the media library of the Android operating system as an example to introduce the technical solution of the embodiment of the present application.

[0086] In S210 , the media library obtains first information, where the first information is used to determine a first directory to be scanned.

[0087] The media library can determine the first directory to be scanned based on the first information. In some embodiments, the first directory can be carried in the first information, or the first directory may not be carried in the first information, but the media library determines the first directory based on the first information. The first directory is a directory in the file system of the electronic device, and may include files and folders stored in the system memory and / or SD card of the electronic device, and may also include files and folders in an external storage device inserted into the electronic device, and may also include files and folders in other electronic devices connected to the electronic device.

[0088] For example, when the electronic device restarts, the system may send a restart broadcast (first information), and the media library can scan all folders and files of the electronic device (stored in the system memory and SD card) according to the restart broadcast. In this case, the restart broadcast does not carry the first directory, but the media library determines that all files and folders in the system memory and SD card of the electronic device need to be scanned according to the restart broadcast.

[0089] For another example, when the electronic device detects the connection or insertion event of an external device, a mount broadcast (first information) may be sent when the external device is inserted or connected, so that the media library can perform a file scan, and the scan directory may be all files and folders stored in the inserted external device. At this time, the mount broadcast may not carry the first information, but the media library determines that the first directory to be scanned includes all files and / or folders of the external device according to the mount broadcast.

[0090] For another example, when a user saves, edits, or deletes one or more files through an application or process of an electronic device, the application or process may trigger a scan broadcast (first information). If the scan broadcast carries a first directory, the media library may scan the specified first directory, which may be determined by the application or process based on the relevant storage path of the saved, edited, or deleted files; if the scan broadcast does not carry the first directory, the media library may scan all files and folders in the system memory and SD card of the electronic device.

[0091] It should be understood that in cases of restart, external storage device connection, etc., the embodiments of the present application are not limited to scanning according to the directories introduced above. In some embodiments, the directories to be scanned may be optimized in various ways to reduce the scope of the scan. The first directory that the media library needs to scan may be optimized in various ways.

[0092] The media library traversing to the second node in S220 can be understood as the scanning process of the media library reaching the file or folder corresponding to the second node. The second node corresponds to the storage path of the file or folder. After the media library determines the first directory to be scanned, it will traverse multiple nodes under the first directory and scan the files or folders corresponding to the traversed nodes. The technical solution of the embodiment of the present application can skip the traversal or scanning of the data of some nodes, which will be described in detail later.

[0093] Currently, files are stored in electronic devices or storage devices in a tree structure. Each node of the tree structure corresponds to a folder or a file (a folder can also be called a directory or a subdirectory), and the tree structure can include multiple nodes, wherein the multiple nodes in the tree structure include the root node of the tree. Any node under the root node can be used as the root node of a subtree of the tree. Assuming that all nodes under the first directory that needs to be scanned when the media library performs a file scan (including the root node pointed to by the first directory) can constitute a first directory tree (the first directory tree can be a directory tree corresponding to all files and folders in the entire file system, or it can be a subtree of the directory tree). In order to describe the embodiments of the present application, the following is a description of the embodiments of the present application. Figure 3 The structure of the first directory tree is exemplarily shown, and several terms used in the embodiments of the present application are introduced.

[0094] like Figure 3 As shown, the first directory tree includes 18 nodes, and each node under the first directory to be scanned can constitute the first directory tree, that is, the directory tree that the media library needs to scan files. Figure 3In the diagram, boxes are used to represent folders, and circles are used to represent files. Then nodes 1 to 7 correspond to folders, and nodes 8 to 18 correspond to files. The lower-level nodes connected to a node are child nodes of the node, for example, nodes 10, 11, and 12 are all child nodes of node 5. Multiple child nodes of the same node are sibling nodes, for example, nodes 5 and 6 are sibling nodes. The upper-level node connected to a child node is the parent node of the child node, for example, node 4 is the parent node of nodes 7, 8, and 9. A leaf node is a node that does not have child nodes, for example, nodes 8 to 18 are all leaf nodes.

[0095] After it is determined whether each node corresponds to a file or a folder, the type of folder can be further determined. When the node corresponds to a file, the node generally does not have a child node, so the file corresponding to the node does not need to be further classified. When the node corresponds to a folder, if there is a node corresponding to the folder in the child node of the node (that is, the folder has a subfolder), then the node corresponds to a redundant folder (that is, the type of the folder is a redundant folder), and if there is no node corresponding to the folder in the child node of the node (that is, the folder has no subfolder), then the node corresponds to a leaf folder (that is, the type of the folder is a leaf folder). For example, the child nodes of node 5 and node 6 both correspond to files, and node 5 and node 6 correspond to leaf folders. The child nodes of node 4 include node 7, and node 7 corresponds to a folder (leaf folder), so node 4 corresponds to a redundant folder.

[0096] When scanning the first directory, the media library can traverse each node in the first directory tree in a certain order (may skip the traversal of some nodes), still with Figure 3 Taking the illustrated first directory tree as an example, the media library can traverse each node in the first directory tree in the order of root node-left subtree-right subtree. Specifically, each node of the first directory tree can be traversed in the order of: node 1-node 2-node 5-node 10-node 11-node 12-node 6-node 13-node 14-node 3-node 15-node 16-node 4-node 7-node 17-node 18-node 8-node 9. When the traversed node corresponds to a file, the data information of the file in the file system can be read, and the data information is updated to the database, thereby completing the scanning of the file. In an embodiment of the present application, in order to reduce the overhead during file scanning, the traversal or scanning of the node can be skipped when certain nodes meet certain conditions.

[0097] The first node and the second node are both nodes under the first directory (nodes in the first directory tree). The first node is the parent node of the second node. The first node corresponds to a folder, and a node with a child node corresponds to a folder, or it can be said that a node with a child node is a folder node or a directory node. The first node has a child node, the second node. The first node can be, for example, Figure 3 In other words, the first node may be the root node of the first directory tree corresponding to the first directory, or may be nodes at all levels under the root node. The second node may be a folder node or a leaf node, and the leaf node generally corresponds to a file, or it can be said that the leaf node is a file node.

[0098] In S220, when the media library traverses to the second node, it can be determined whether the second node corresponds to a folder or a file through the data information of the second node (file or folder) read from the database, for example, by reading the field indicating the file or folder type to determine whether the second node corresponds to a file or a folder.

[0099] When the media library determines the file corresponding to the second node, it can adopt different scanning strategies for the second node (the file corresponding to the second node) and the files or folders corresponding to its brother nodes according to whether the data information of the parent folder of the second node (the folder corresponding to the parent node, the folder corresponding to the first node) has changed.

[0100] The data information of the folder corresponding to the first node may change because the data information read in the file system for the folder corresponding to the first node is inconsistent with the data information of the folder in the database, or the data information may be read in the storage device or unit but not in the database.

[0101] When the data information of the folder corresponding to the first node changes, it means that the files under the folder corresponding to the first node have changed. It is necessary to traverse the files under the folder corresponding to the first node one by one and compare the data information of the files, so as to find the modified files and update the data information of the files to the database. In addition, if there are folders under the folder corresponding to the first node, it is also necessary to compare whether the data information of the folders has changed.

[0102] According to the scanning process described above, the scanning of the folder can be performed before the scanning of its child nodes, and the comparison of the data information of the folder can also be performed before traversing to its child nodes. That is to say, the comparison of the data information of the folder corresponding to the first node can be performed before traversing to the second node.

[0103] In an embodiment of the present application, after traversing to the first node and comparing the data information of the folder corresponding to the first node, the identifier of the first node or the identifier of the folder corresponding to the first node can be stored in the first list when the data information of the folder corresponding to the first node has not changed. Therefore, when the media library scans the file corresponding to the second node, it can be directly determined whether the data information of the folder corresponding to the first node has changed by whether the identifier of the first node is in the first list, and then the scanning strategy for the files or folders corresponding to the second node and its sibling nodes can be determined.

[0104] In S230 , when the media library determines that the data information of the folder corresponding to the first node has not changed, the comparison of the data information of the file corresponding to the second node may be skipped.

[0105] If the media library is in the first list through the folder corresponding to the first node or the identifier of the first node, it can be determined that the data information of the folder corresponding to the first node has not changed, so that the files under the folder corresponding to the first node have not been modified, and the data information of the files corresponding to the second node has not changed. At this time, skipping the comparison of the data information of the files corresponding to the second node can reduce the overhead and power consumption caused by scanning.

[0106] Optionally, if the media library learns that the folder corresponding to the first node or the identifier of the first node is not in the first list, it can be determined that the data information of the folder corresponding to the first node has changed, and thus the data information of the files in the folder corresponding to the first node has changed. In order to update the data information of the changed files into the database, it is necessary to compare the data information of the files one by one, that is, to scan all files in the folder corresponding to the first node according to the general file scanning method.

[0107] When the data information of a folder changes, it is usually caused by the change of the files under the folder. When the files change, the data information of the files will also change, which in turn causes the data information of the folder to change. For example, when a user edits the content or format of a file, the modification time of the file will change, and the modification time of the folder to which the file belongs will also change.

[0108] In the embodiment of the present application, the data information of the folder includes the modification time of the folder. In the tree structure storage mode, when the modification time of a file changes, the modification time of its parent folder will also change, while the modification time of the parent folder of the parent folder will not change. Therefore, if the modification time of the parent folder does not change, it can be indirectly judged that the files under the parent folder have not been modified, and then skipping the traversal or scanning of these files can reduce the overhead of file scanning.

[0109] The data information of a folder may also include at least one of the size of the folder, the number of files and folders contained in the folder, the storage path of the folder, etc. That is, when comparing whether the data information of a folder has changed, the media library may determine whether the data information of the folder has changed by comparing only the modification time of the folder; when determining whether the data information of the folder has changed, at least one of the size of the folder, the storage path of the folder, the number of files and folders contained in the folder may also be referred to.

[0110] Taking the size of a folder as an example, when the file size changes, there may be three situations (the configurations of different operating systems may be different) as to whether the size of its parent folder and the size of the parent folder of the parent folder change: Situation 1, the size of the parent folder changes, but the size of the parent folder of the parent folder does not change (the sizes of the n-level folders above the parent folder do not change); Situation 2, the size of the parent folder changes, and the size of the parent folder of the parent folder also changes (the sizes of the n-level folders above the parent folder all change); Situation 3: the size of the parent folder does not change, and the size of the parent folder of the parent folder does not change either.

[0111] When the data information of a folder includes the size of the folder and the modification time of the folder, that is, only when the size and modification time of the folder have not changed, it is judged that the data information of the folder has not changed. In case 1, since the change in file size only affects the size of its parent folder, and does not affect the size of the upper-level or multi-level folders of its parent folder, the effect is the same as the change in the modification time of the file, then adding the judgment of the size of the folder is basically consistent with the result of judging the modification time of the folder alone. Only when, for example, the user modifies the file during the interval between two scans and the interval between the two scans is less than the accuracy of the modification time of the folder, for example, less than 1s, the modification time of the file will not show a change due to the accuracy problem, but the file size may have changed due to the user's modification of the file, so that the data information of the parent folder of the file is judged to have changed. Adding the judgment indicator of the size of the folder to scan the files under the folder can improve the applicable scenarios of the embodiments of the present application. In case 2, since the change in file size not only affects the size of its parent folder but also affects the size of the folder of the parent node of its parent node, when the file size changes, the data information of the parent folder corresponding to the direct branch node where the file is located changes. Figure 3For example, when the file size corresponding to node 17 changes, the size of the folder corresponding to node 7, node 4 and node 1 all change. When scanning the file, it is necessary to compare the files corresponding to node 8 and node 9. This situation will cause the scanning overhead to be still high. If the file size corresponding to node 10 changes, the size of the folder corresponding to node 5, node 2 and node 1 will change synchronously, and the size of the folder corresponding to node 6 will not change. The technical solution of the embodiment of the present application can still reduce the scanning overhead in this case. Therefore, the size of the folder can be considered when judging whether the data information of the folder has changed; however, in order to reduce the scanning overhead as much as possible, the size of the folder can be ignored when judging whether the data information of the folder has changed. In case 3, since the change in file size does not affect the size of its parent folder, the size of the folder will never change, and it is the size when the folder is initially established. Then the judgment on whether the size of the folder has changed is a redundant judgment. When the modification time of the parent folder changes (the size of the parent folder remains unchanged), the data information of the folder changes; when the modification time of the parent folder does not change (the size of the folder remains unchanged, and the data information of the folder does not change).

[0112] In order to reduce the file scanning overhead as much as possible, the index used to determine whether the data information of a folder has changed needs to meet the following conditions: when a certain index of the data information of a file changes, the corresponding index of the data information of the parent folder of the file changes, and the corresponding index of the parent folder of the parent folder (and the parent folder's n-level parent folder) cannot change; or, when a certain index of the data information of a file changes, the data information of the parent folder of the folder and the corresponding index of the parent folder of the parent folder (and the parent folder's n-level parent folder) cannot change. That is, only when the corresponding index of the file changes, the impact on the corresponding index of the parent folder and the parent folder's parent folder is similar to the impact of the file size in the above-mentioned case 1 and case 3, the corresponding index can be considered when determining whether the data information of the folder has changed. For details, please refer to the above-mentioned introduction, which will not be repeated here. Of course, considering the index that meets case 2 also has the effect of reducing the file scanning overhead, and this application is not limited to whether these indicators that meet case 2 are considered when determining whether the data information of a folder has changed.

[0113] When judging whether the data information of a folder has changed, in order to minimize the file scanning overhead, in addition to the modification time of the folder, only indicators that meet certain conditions can be used as the standard for judging whether the data information of the folder has changed, such as the indicators that meet conditions 1 and 3 mentioned above. However, when judging whether the data information of a file has changed (or when updating the data information of a file or folder to the database), the purpose is to update the data information to the database. You can only update the indicators used in the judgment, or directly add all the indicators of the data information of the file or folder to the database, or directly read the various information of the file or folder in the file system without distinguishing the various indicators, and update the various information to the database.

[0114] The data information of a file includes at least one of the modification time of the file, the file type, the file storage path, and the file size, but is not limited to these indicators.

[0115] If the second node traversed by the media library in step S220 corresponds to a folder, the media library can compare the data information of the folder corresponding to the second node in the file system with the data information of the folder corresponding to the second node in the database to see whether it has changed. When the data information of the folder corresponding to the second node changes, the data information of the folder corresponding to the second node in the file system is updated to the database; if the data information of the folder corresponding to the second node has not changed, the identifier of the folder corresponding to the second node or the identifier of the second node is stored in the first list, so that when traversing to the child node of the second node, its scanning strategy can be determined by whether the identifier of its parent node is in the first list. For relevant details, please refer to the processing method when the second node corresponds to the file, which will not be repeated here.

[0116] When implementing the technical solution of the embodiment of the present application, it is only necessary to determine twice whether the data information of the folder corresponding to its parent node has changed when the node corresponds to a file, thereby reducing the overhead of the entire file scanning process. When the data of the node is a folder, it is not necessary to consider whether the data information of the folder corresponding to its parent node has changed. Just compare whether the data information of the folder has changed. If it has changed, update the data information of the folder to the database. If it has not changed, the identifier of the folder or the identifier of the node can be stored in the first list for reference in determining the scanning strategy when enumerating the files under the folder.

[0117] Furthermore, when traversing to a node corresponding to a folder, the type of the folder can be distinguished, and different scanning strategies can be used for files corresponding to its child nodes according to different folder types.

[0118] Specifically, the folders can be divided into leaf folders and redundant folders in the manner described above. When scanning the folder corresponding to the first node, if it is determined that there is only a node corresponding to the file under the folder corresponding to the first node (that is, there is no subfolder under the folder corresponding to the first node), the folder corresponding to the first node is determined to be a leaf folder; if there is a node corresponding to the folder under the folder corresponding to the first node (that is, the folder corresponding to the first node has a subfolder), the folder corresponding to the first node is defined as a redundant folder. In order to facilitate the subsequent traversal to the second node to conveniently determine the type of folder corresponding to the first node, the identifier of the leaf folder whose data information has not changed or the identifier of the corresponding node can be stored in the second list, and the identifier of the redundant folder whose data information has not changed or the identifier of the corresponding node can be stored in the third list. In this way, when traversing to the second node, the type of folder corresponding to the first node can be determined based on whether the folder corresponding to the first node or the identifier of the first node is in the corresponding list.

[0119] If the folder corresponding to the first node is a leaf folder, then while skipping the comparison of the data information of the file corresponding to the second node, the traversal of the second node's sibling nodes can be skipped, that is, when performing file scanning, the sibling nodes of the second node are directly skipped. Since the data information of the folder corresponding to the first node has not changed, and the folder corresponding to the first node is a leaf folder, its child nodes all correspond to files, and the data information of all files has not changed, skipping the traversal and scanning of other nodes under the folder can further reduce the overhead of file scanning.

[0120] If the folder corresponding to the first node is a redundant folder, the comparison of the data information of the file corresponding to the second node can be skipped, and the traversal of the next node (the brother node of the second node) can be continued. Next, it can be further determined whether the next node corresponds to a file or a folder. If it is a file, the comparison of the data information of the file can be skipped; if it is a folder, the data information of the folder can be compared to see if it has changed. For details, please refer to the processing of the data of the second node, which will not be repeated here. In this way, when scanning the data under the redundant folder, if the data information of the redundant folder has not changed, although it is still necessary to traverse each node, when traversing to the file node, the comparison of the data information of the file can be directly skipped, which can also reduce the overhead and power consumption of file scanning, thereby improving the user experience.

[0121] Still Figure 3For example, assuming that only the data information of the files corresponding to nodes 13 and 15 has changed, when scanning the files in the folder corresponding to node 5, the traversal of the brother nodes of node 10 can be skipped after traversing to node 10. When scanning the files in the folder corresponding to node 6, since the data information of the folder corresponding to node 6 has changed, it is necessary to traverse nodes 13 and 14 in sequence and compare whether the data information of the files corresponding to nodes 13 and 14 has changed. When scanning the files in the folder corresponding to node 3, since the data information of the folder corresponding to node 3 has changed, it is necessary to traverse nodes 15 and 16 in sequence and compare whether the data information of the files corresponding to nodes 15 and 16 has changed. When scanning the folder corresponding to node 4, since the data information of the folder corresponding to node 4 has not changed, and the folder corresponding to node 4 includes files and folders, the data of each node under node 4 can be traversed in sequence. For example, when traversing to node 7, it can be determined that node 7 corresponds to a folder, and whether the data information of the folder corresponding to node 7 has changed. If it has not changed, when scanning the file corresponding to node 17 in the folder corresponding to node 7, the comparison of the data information of the file corresponding to node 17 can be skipped, and the traversal of node 18 can be skipped. Then, it can be traversed to node 8. When it is determined that the data of node 8 is a file, the comparison of the data information of the file corresponding to node 8 can be skipped and the data of node 9 can be continued to be traversed. When it is determined that node 9 corresponds to a file, the comparison of the data information of the file corresponding to node 9 can be skipped.

[0122] When an electronic device stores a large number of files, for example, a current user's mobile phone usually stores a large number of media files such as photos, when scanning files using the file scanning method introduced in the embodiment of the present application, the overhead and power consumption of the electronic device can be greatly reduced.

[0123] In an embodiment of the present application, when traversing each node, the traversal and scanning can be performed in the order of traversing the parent node first and then traversing the child nodes of the parent node (the traversal of some nodes may be skipped). When traversing to the parent node, if it is determined that the data information of the folder corresponding to the parent node has not changed, the identifier of the parent node can be recorded in a corresponding list. For example, the types of folders can be recorded in one list regardless of the type of folders, or the types of folders can be distinguished and the leaf folders and redundant folders whose data information has not changed can be recorded in the same list. In this way, when traversing to the child nodes of the parent node, corresponding processing can be performed according to whether the parent node of the child node is in the corresponding list.

[0124] However, the embodiments of the present application are not limited to indicating whether the data information of the folder of the parent node has changed by a list. For example, the folders can be divided into folders whose data information has not changed and folders whose data information has changed, and the types of all folders can be marked by file attribute values. When traversing to the file node, the corresponding scanning strategy can be determined according to the type of the marked parent node. Alternatively, the folders can be divided into redundant folders whose data information has changed, redundant folders whose data information has not changed, leaf folders whose data information has not changed, and leaf folders whose data information has changed, and when traversing to the file node, the corresponding scanning strategy can be determined according to the classification of the parent node.

[0125] Above Figure 2 The technical solution provided by the embodiment of the present application is introduced as an example. Figure 4 The modules or units involved in the implementation of the technical solution of the embodiment of the present application are shown. Figure 4 As shown, the following interaction steps will be performed between each module or unit:

[0126] S410, the application sends a broadcast to notify the media library of the directory to be scanned.

[0127] S410 may be performed after the user uses the application to modify the file stored in the electronic device. The application may be, for example, a document processing application or a photo processing application, and the application may also be replaced by a corresponding process. The user may modify the file content or the file storage location, file format, etc. The directory to be scanned may be determined according to the directory of the modified file.

[0128] S420, the scanning module of the media library synchronizes the data information changes in the directory to be scanned to the database of the media library.

[0129] In S420, the media library may receive (for example, through the media scanning receiving interface MediaScannerReceiver) the broadcast and trigger a scanning instruction to instruct the scanning module of the media library to scan the files and folders in the scanned directory. The scanning module may be a media scanning service (MediaScannerService) process. And the data information of the folder and / or file is updated during the scanning process. For details of the scanning and updating process, please refer to Figure 2 The description of the embodiments of the present invention will not be repeated here.

[0130] S430, the database of the media library is refreshed and synchronized to the application.

[0131] In S430, after the media library updates the database with the data information of the file or folder in the file system, the media library can synchronize the refreshed database to the application that is viewing or modifying the media file, so that the user can view the latest data information of the media file through the application.

[0132] Figure 5 The present invention provides a document scanning device 500, which includes an acquisition unit 510510 and a processing unit 520520. The acquisition unit 510 and the processing unit 520 can implement Figure 2 The various steps of the method embodiment.

[0133] Specifically, the file scanning device 500 includes: an acquisition unit 510, used to acquire first information, the first information is used to determine a first directory to be scanned, the first node and the second node are nodes under the first directory, the first node is the parent node of the second node, and the first node corresponds to a folder; a processing unit 520, used to: when traversing to the second node, if the second node corresponds to a file, determine whether the data information of the folder corresponding to the first node has changed, and the data information of the folder includes the modification time of the folder; when the data information of the folder corresponding to the first node has not changed, skip the comparison of the data information of the file corresponding to the second node in the file system with the data information of the file corresponding to the second node in the database, and the data information of the file includes at least one of the modification time of the file, the file type, the file storage path, and the file size.

[0134] In the embodiment of the present application, when the type of the folder corresponding to the first node is a redundant folder, the redundant folder is a folder with subfolders, and the processing unit 520 is further used to: continue traversing the sibling nodes of the second node.

[0135] In the embodiment of the present application, the type of the folder corresponding to the first node is a redundant folder.

[0136] In an embodiment of the present application, the processing unit 520 is further used to: compare whether the data information of the folder corresponding to the first node in the file system has changed relative to the data information of the folder corresponding to the first node in the database; when the data information of the folder corresponding to the first node in the file system has not changed relative to the data information of the folder corresponding to the first node in the database, store the identifier of the first node in the first list; wherein the processing unit 520 is specifically used to: when the identifier of the first node is in the first list, determine that the data information of the folder corresponding to the first node has not changed; when the identifier of the first node is not in the first list, determine that the data information of the folder corresponding to the first node has changed.

[0137] In an embodiment of the present application, if the second node corresponds to a folder, the processing unit 520 is also used to: compare whether the data information of the folder corresponding to the second node in the file system has changed relative to the data information of the folder corresponding to the second node in the database; when the data information of the folder corresponding to the second node in the file system has changed relative to the data information of the folder corresponding to the second node in the database, update the data information of the folder corresponding to the second node in the file system to the database.

[0138] In an embodiment of the present application, the processing unit 520 is also used for: when traversing to the third node, the third node is a child node of the second node, and the third node corresponds to a file. If the data information of the folder corresponding to the second node has not changed, skip the comparison of whether the data information of the file corresponding to the third node in the file system has changed relative to the data information of the file corresponding to the third node in the database; if the data information of the folder corresponding to the second node has changed, compare whether the data information of the file corresponding to the third node in the file system has changed relative to the data information of the file corresponding to the third node in the database.

[0139] In an embodiment of the present application, the data information of the folder includes the size of the folder.

[0140] In the embodiment of the present application, the first information includes the first directory.

[0141] Figure 6 A document scanning device 600 provided in an embodiment of the present application is shown. Figure 6 The document scanning device 600 shown may correspond to the document scanning device described above. Specifically, the document scanning device 600 may be Figure 5A specific example of a file scanning device in the embodiment of the present application. The file scanning device 600 includes: a processor 620. In an embodiment of the present application, the processor 620 is used to implement corresponding control management operations, for example, the processor 620 is used to support the file scanning device 600 to perform the method or operation or function of the aforementioned embodiment. Optionally, the file scanning device 600 may also include: a memory 610 and a communication interface 630; the processor 620, the communication interface 630 and the memory 610 may be interconnected or interconnected through a bus 640. Among them, the communication interface 630 is used to support the file scanning device to communicate with other devices, etc., and the memory 610 is used to store program codes and data of the file scanning device. The processor 620 calls the code or data stored in the memory 610 to implement corresponding operations. The memory 610 may be coupled to the processor or not. The coupling in the embodiment of the present application is an indirect coupling or communication connection between the file scanning device, unit or module, which may be electrical, mechanical or other forms, and is used for information interaction between the file scanning device, unit or module.

[0142] Among them, the processor 620 can be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a transistor logic device, a hardware component or any combination thereof. It can implement or execute various exemplary logic blocks, modules and circuits described in combination with the contents disclosed in this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a digital signal processor and a microprocessor, and so on. The communication interface 630 can be a transceiver, circuit, bus, module or other type of communication interface. The bus 640 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0143] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0144] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0145] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0146] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0147] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0148] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks or optical disks.

[0149] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A document scanning method, applied to an electronic device, It is characterized in that include: Acquire first information, where the first information is used to determine a first directory to be scanned, where a first node and a second node are nodes under the first directory, where the first node is a parent node of the second node, and where the first node corresponds to a folder; When traversing to the second node, if the second node corresponds to a file, determining whether data information of a folder corresponding to the first node has changed, the data information of the folder including the modification time of the folder; When the data information of the folder corresponding to the first node has not changed, skip the comparison of whether the data information of the file corresponding to the second node in the file system has changed relative to the data information of the file corresponding to the second node in the database, and the data information of the file includes at least one of the file modification time, file type, file storage path, and file size.

2. The method according to claim 1, It is characterized in that When the type of the folder corresponding to the first node is a leaf folder, the leaf folder is a folder without subfolders, and the method further includes: Skip traversing the sibling nodes of the second node.

3. The method according to claim 1, It is characterized in that When the type of the folder corresponding to the first node is a redundant folder, the redundant folder is a folder with subfolders, and the method further includes: Continue traversing the sibling nodes of the second node.

4. The method according to any one of claims 1 to 3, It is characterized in that Before traversing to the second node, the method further includes: Comparing whether data information of the folder corresponding to the first node in the file system has changed relative to data information of the folder corresponding to the first node in the database; When data information of the folder corresponding to the first node in the file system has not changed relative to data information of the folder corresponding to the first node in the database, storing the identifier of the first node in the first list; wherein determining whether the data information of the folder corresponding to the first node has changed includes: When the identifier of the first node is in the first list, determining that the data information of the folder corresponding to the first node has not changed; When the identifier of the first node is not in the first list, it is determined that the data information of the folder corresponding to the first node changes.

5. The method according to any one of claims 1 to 4, It is characterized in that If the second node corresponds to a folder, the method further includes: comparing whether data information of the folder corresponding to the second node in the file system has changed relative to data information of the folder corresponding to the second node in the database; When the data information of the folder corresponding to the second node in the file system changes relative to the data information of the folder corresponding to the second node in the database, the data information of the folder corresponding to the second node in the file system is updated to the database.

6. The method according to claim 5, It is characterized in that The method further comprises: When traversing to the third node, the third node is a child node of the second node, and the third node corresponds to a file. If the data information of the folder corresponding to the second node has not changed, skip comparing whether the data information of the file corresponding to the third node in the file system has changed with the data information of the file corresponding to the third node in the database; If the data information of the folder corresponding to the second node changes, compare the data information of the file corresponding to the third node in the file system with the data information of the file corresponding to the third node in the database to see whether it changes.

7. The method according to any one of claims 1 to 6, It is characterized in that The data information of the folder includes the size of the folder.

8. The method according to any one of claims 1 to 7, It is characterized in that The first information includes the first directory.

9. The method according to any one of claims 1 to 8, It is characterized in that The operating system of the electronic device is Android system.

10. A document scanning device, It is characterized in that include: an acquisition unit, configured to acquire first information, wherein the first information is used to determine a first directory to be scanned, wherein a first node and a second node are nodes under the first directory, the first node is a parent node of the second node, and the first node corresponds to a folder; A processing unit for: When traversing to the second node, if the second node corresponds to a file, determining whether data information of a folder corresponding to the first node has changed, the data information of the folder including the modification time of the folder; When the data information of the folder corresponding to the first node has not changed, the comparison of the data information of the file corresponding to the second node in the file system with the data information of the file corresponding to the second node in the database is skipped, and the data information of the file includes at least one of the file modification time, file type, file storage path, and file size.

11. The device according to claim 10, It is characterized in that When the type of the folder corresponding to the first node is a leaf folder, which is a folder without subfolders, the processing unit is further configured to: Skip traversing the sibling nodes of the second node.

12. The device according to claim 10, It is characterized in that When the type of the folder corresponding to the first node is a redundant folder, and the redundant folder is a folder having subfolders, the processing unit is further configured to: Continue traversing the sibling nodes of the second node.

13. The device according to any one of claims 10 to 12, It is characterized in that The processing unit is further used for: Comparing whether data information of the folder corresponding to the first node in the file system has changed with data information of the folder corresponding to the first node in the database; When the data information of the folder corresponding to the first node in the file system has not changed relative to the data information of the folder corresponding to the first node in the database, the identifier of the first node is stored in the first list; wherein the processing unit is specifically used to: When the identifier of the first node is in the first list, determining that the data information of the folder corresponding to the first node has not changed; When the identifier of the first node is not in the first list, it is determined that the data information of the folder corresponding to the first node changes.

14. The device according to any one of claims 10 to 13, It is characterized in that If the second node corresponds to a folder, the processing unit is further configured to: Comparing whether data information of the folder corresponding to the second node in the file system has changed with data information of the folder corresponding to the second node in the database; When the data information of the folder corresponding to the second node in the file system changes relative to the data information of the folder corresponding to the second node in the database, the data information of the folder corresponding to the second node in the file system is updated to the database.

15. The device according to claim 14, It is characterized in that The processing unit is further used for: When traversing to the third node, the third node is a child node of the second node, and the third node corresponds to a file. If the data information of the folder corresponding to the second node has not changed, skip comparing whether the data information of the file corresponding to the third node in the file system has changed with the data information of the file corresponding to the third node in the database; If the data information of the folder corresponding to the second node changes, compare the data information of the file corresponding to the third node in the file system with the data information of the file corresponding to the third node in the database to see whether it changes.

16. The device according to any one of claims 10 to 15, It is characterized in that The data information of the folder includes the size of the folder.

17. The device according to any one of claims 10 to 16, It is characterized in that The first information includes the first directory.

18. An electronic device comprising the document scanning device according to any one of claims 10 to 17.

19. A computer storage medium, when the computer instructions are executed on an electronic device, enables the electronic device to execute the method according to any one of claims 1 to 9.

20. An electronic device, It is characterized in that include: Memory, for storing computer instructions; A processor, configured to execute computer instructions stored in the memory so as to enable the electronic device to perform the method as claimed in any one of claims 1 to 9.

21. A chip system, It is characterized in that The method comprises at least one processor, and when the program instructions are executed in the at least one processor, the at least one processor is caused to perform the method according to any one of claims 1 to 9.

Citation Information

Cited By

  • Resource catalogue method, resource catalogue tree generation method and device and electronic equipment

    CN119226565A