Mobile phone Management application Research "3"--garbage cleanup

Source: Internet
Author: User
Tags root access
<span id="Label3"></p><p><p>Welcome Reprint. Reprint please specify: HTTP://BLOG.CSDN.NET/ZHGXHUAA</p></p><p><p><br></p></p>Description<br><p><p>In the general article mentioned garbage cleanup, this article will focus on the cache, uninstall residue, useless data, such as "static content" cleanup, There is about the system process cleanup and mobile phone acceleration related functions. will be put in the "mobile phone accelerator" to introduce the Study.</p></p><p><p><br></p></p>What is garbage?<br>On the definition of system garbage<br>today, There are many mobile phone management software that have garbage cleanup capabilities. This article also to do a simple analysis and introduction of garbage cleaning. Before the formal Analysis. Let's first look at "what is System garbage?" ”。 In the Baidu undergraduate, about "system garbage" is the definition of: system garbage. The system is no longer required for the general term of the File.<p><p></p></p><p><p>When you browse the webpage, install and uninstall the program residue files and register the key Values. These are files that have no effect on the System. It can only add a burden to the system, so it is called Garbage.<br></p></p><p><p>About system garbage in fact, "all of the resources, files, and caches that we no longer need." Is Rubbish. " We clean up the system garbage to clean up the files that are no longer needed.</p></p><p><p><br></p></p>What can be cleaned up in Android<p><p><br>First look at the current popularity of mobile phone management software, all of those as able to clean up the Garbage. The following is the garbage cleanup section of four mobile phone management software with a higher usage rate:</p></p><p><p><br></p></p><p style="text-align: center"><p style="text-align: center"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>Combined with these mobile phone management software, The summary of garbage that can be cleaned up on Android phones is as Follows:</p></p><p><p>A. Applying A cache file</p></p><p><p>B. Applying uninstall residue</p></p><p><p>C. Useless installation package</p></p><p><p>D. Memory Data</p></p><p><p>E. System garbage (logs, thumbnails, empty directories, etc.)</p></p><p><p>F. Advertising files</p></p><p><p>G. Large files (files with file sizes larger than a certain value)</p></p><p><p>H. Useless files on SD card</p></p><p><p>In cleaning up these junk files, some require root privileges, some do not need. The next step will be a unified introduction Analysis.</p></p><br>Android app Data management strategy<p style="text-align: left"><p style="text-align: left"></p></p><p align="left"><p align="left"><br></p></p><p align="left"><p align="left">After understanding the definition of junk files, here are some of the management strategies for app data in Android:</p></p><p align="left"><p align="left">Data storage in Android can be easily divided into internal storage (mainly refers to the application data folder) and external storage (mainly SD Card) two Cases.</p></p><p><p>Android does not have the same management strategy for these two different situations.</p></p><p><p>The data in the built-in storage is stored in the principle of process Isolation. External storage is stored using the principle of global sharing.</p></p><p align="left"><p align="left">It is generally necessary to clean up the application private data in the built-in storage, and it is generally not necessary to clean up the data in the external storage without special Permission.</p></p><br>High-speed cleaning and deep cleaning<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>"high-speed cleanup" and "deep cleanup" are found in very many mobile phone management software. Here's a quick Look:</p></p><p><p></p></p> <ul> <ul> <li>The so-called high-speed cleanup, in fact, is often referred to in the garbage scanning only two to three layers of folders, temporarily do not need to do some deep traversal and other time-consuming operation.</li> <li>The so-called deep cleaning, often refers to all the garbage can be cleaned up a comprehensive scan, the folder deep Traversal.</li> </ul> </ul><p><p></p></p><p><p>Here's one thing to Say. The seemingly distinct, but actually can be mutually integrated, a viable strategy is:</p></p><p><p>After the management software starts, Choose the system spare time, do the deep scan regularly, do the high-speed scan when the user is triggered manually.</p></p><p><p>But here comes another question: when scanning for spare, the appropriate strategy, when to start, and when to pause, must be ensured without affecting the normal use of the Application.</p></p><br>System Garbage Cleanup<p style="text-align: left"><p style="text-align: left"><br></p></p>Apply Cache cleanup<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>For the cleanup of application cache, This article describes two implementation scenarios. The application cache cleanup is implemented by itself, and the application cache cleanup is implemented using the system interface, which is described separately.</p></p><br>Implement app Cache Cleanup yourself<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>To clean up the app cache, first understand how the App's cache is Stored. Generally speaking. The cache that is applied in Android contains the following sections, for Example:</p></p><p><p>a./data/data/<span style="color: rgb(51,51,51)"> package_name</span> /cache (application cache)</p></p><p><p>B./mnt/sdcard/android/<span style="color: rgb(51,51,51)"> package_name</span> /cache (external application cache, froyo support Later)</p></p><p><p>C./data/data/package_name/database/webview.db<span style="color: red">*</span>(webview cache)</p></p><p><p>D./data/data/package_name/database/webviewcache.db<span style="color: red">*</span>(webview cache)</p></p><p><p>E. Some other/data/data/<span style="color: rgb(51,51,51)"> package_name</span> /<span style="color: red">*</span>cache folder (app Cache)</p></p><p><p>F./data/data/package_name/files (can also choose to clean up when comparing strict cleaning strategies)</p></p><p><p>For files that are saved under the/data/data/<span style="color: rgb(51,51,51)"> package_name</span> folder. The app itself and the app with which it shares the UserID have all read and write permissions, and other applications do not have read and write permissions, such as the Following:</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>From the above analysis, we draw the first solution to clean up the application cache:</p></p><p><p>Under the premise of gaining root Privileges. Traverse the cache folder of the scanned app, assuming that it is deleted. The following two paragraphs are part of the demo sample code that calculates the cache size and cleans up the cache:</p></p><p><p>Code snippet to calculate the cache size Section:</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>To clean up the cached part of the code snippet:</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>Of course. The scanning and cleanup work here can also be done with JNI in C code, and the implementation is similar. You can refer to the Free_cache function in @frameworks/native/cmds/installd/commands.c if the C code is Cached.</p></p><br>Application cache cleanup with system interface<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left">Friends who have used Android phones believe that the "erase cache" feature is in the app details page of the Phone's Settings----and the following should be on my personal phone:<br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: center"><p style="text-align: center"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>Ok. To Here. The question is, can we use the system interface to implement the "clear cache" function? The app details page in Android is located in @/packages/apps/settings/src/com/android/settings/applications/installedappdetails.java.</p></p><p><p>The code for cleaning the application Cache section in Installedappdetails is seen in the following example:</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>The implementation of the deleteapplicationcachefiles in Packagemanager such as the Following:</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>Here are some things to keep in mind, such as the Following:</p></p><p><p>A. The Deleteapplicationcachefiles interface is hide and cannot be called directly in the Code.</p></p><p><p>B. you need to declare Delete_cache_files permissions using the Deleteapplicationcachefiles interface.</p></p><p><p></p></p><p><p>C. The System application cache cannot be purged through the deleteapplicationcachefiles interface.</p></p><p><p>D. the cache cleanup result is completed by the Ipackagedataobserver interface Callback.</p></p><p><p></p></p><p><p>In addition to the Deleteapplicationcachefiles interface, Packagemanager also has the following two interfaces that can be selected for invocation:</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>The following is a partial demonstration sample code that uses a different cache cleanup method, such as the Following:</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>Here is a partial demo sample code that gets the size of each app Cache:</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"><br></p></p>Comparison of two implementation schemes<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>After two application cache cleanup methods are described, here is a simple comparison to choose from when using:</p></p><p><p>A. From the scope: the first way to clean up the scope is broader and more thorough. Another way to clean up non-system applications is to clean up all applications and even apply your own definition of cache Files.</p></p><p><p>B. from Permissions: the first method requires root Permissions. Another way is simply to specify Delete_cache_files in Androidmanifest.</p></p><p><p>C. from Security: take the first approach with the right strategy, and avoid cleaning up the cache that should not be cleaned out.</p></p><p><p>In summary, the first way of cleaning up a wider and more thorough, in the case of root access, it is recommended to use the first way.</p></p><br>Apply Uninstall Residue Cleanup<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>As described in 1.3, application-installed data is stored in both internal and external storage methods.</p></p><p><p>The data in the corresponding built-in storage will be deleted on its own initiative when the app is Deleted. There's no need to Care. Many Android apps, however, create their own application-specific folders on the mobile Terminal's Memory Card. A media file used to store cached files, temporary files, or video, audio, or books downloaded over a Network. But. When the Android app is Uninstalled. Files that remain on the memory card are not Deleted. Most of these files are useless to the user and belong to the junk File. Assuming that users frequently install and uninstall new software, the memory card will generate a large number of application residue files, not only occupy the memory card space, and make the memory card file management difficult to get up.</p></p><p><p>therefore, it is necessary to realize the identification and cleanup of residual folders in Android Applications.</p></p><p><p>One of the key points in applying uninstall residue cleanup is to apply the identification of residual Folders.</p></p><p><p>Here are two possible scenarios:</p></p><br>Scenario One: Maintaining file mapping information<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>Applying the package name (unique) to a file on an SD card in a file or database can be used to apply the package name key, because the package name is unique for different applications. Not Repeated. Use the file on the SD card as Value. Establish the mappings as seen Below:</p></p> <table border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td valign="top"><p>Key</p></td> <td valign="top"><p>Value</p></td> </tr> <tr> <td valign="top"><p>App Package name (unique)</p></td> <td valign="top"><p>Directory</p></td> </tr> </tbody> </table><p><p>Infers whether the app has a corresponding file exists after it has been checked to the app uninstall Event. There is a prompt for the user to Delete.</p></p><p><p>The following are some of the issues that need to be used for such a scenario:</p></p><p><p>A. Mapping table creation: mapping tables need to be established for applications with high frequency and user Volume. It is best to have background scanning application established, and then sent to the client, but also to the client to report the information to the background, the background Correction. The establishment of a mapping table is the key to Recognition.</p></p><p><p>B. error identification problem: in general, data from different applications is placed in different directories, and there is no Repetition. however, in practice, there will inevitably be repeated situations. There are two ways to handle this scenario:</p></p><p><p>1) mapping relationship refinement to File. When you finish deleting the file, then infer whether the upper directory is Empty. NULL is Removed.</p></p><p><p>2) There are multiple application mappings that repeatedly infer that all apps have been uninstalled before deleting the Directory.</p></p><p><p></p></p><br>Scenario Two: documenting the application installation process<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>The universality of the scheme is not as strong as the first one, but it can also be used as an implementation scheme.</p></p><p><p>Scenarios such as the Following:</p></p><p><p>1) when installing through the management software, the files generated by the application are installed through log records. When the application executes, monitor the changes of the SD file and discover the Changes. The current application (at the top of the execution Stack) is the creator of the File. The same is recorded in the log as such a corresponding relationship.</p></p><p><p>2) when uninstalling an app through the management Software. Run the inverse process based on the log Information.</p></p><br>Useless installation package cleanup<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>It is easier to clean up a useless installation package.</p></p><p><p>The criteria for inferring a useless installation package are:</p></p><p><p>A. the apk file exists in the storage folder. But the APK has been installed</p></p><p><p>B. the apk file is corrupted</p></p><p><p>There are two ways to handle a scan installation package:</p></p><p><p>A. deep scan: Scan all folders on the SD card</p></p><p><p>B. high-speed scanning, just scan the phone management software (pea pod, 360 mobile phone helper, app bao, etc.) and browser (UCWeb, qq browser) and download Folder.</p></p><p><p>It is also possible to clean up other download files according to this IDEA.</p></p><br>System Garbage Cleanup<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>System garbage Cleanup contains temporary files, thumbnails, system logs, Invalid files, blank files and other cleanup, the following to do the Introduction.</p></p><br>Clean up the System log<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>Log files are divided into the system log and the application log, respectively, their respective storage locations are:</p></p><p><p>1) the location of the system log such as the following (different phones may vary):</p></p><p><p>A./data/local/tmp/*</p></p><p><p>B./data/tmp/*</p></p><p><p>C./data/system/usagestats/*</p></p><p><p>D./data/system/appusagestates/*</p></p><p><p>E./data/system/dropbox/*</p></p><p><p>F./data/tombstones/*</p></p><p><p>g./data/anr/*</p></p><p><p>H./dev/log/main</p></p><p><p>2) Application log storage location can be inferred: sd card suffix named ". log" or "*log.txt" and other end of the File.</p></p><p><p></p></p><br>Clean up thumbnail image<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>There is a hidden folder under the Dicm folder on the SD card, called ". thumbnails", which holds the cache of the system Picture. Cleaning up the cache is mostly about cleaning up this folder. App folders may also have thumbnail files. But not easy to identify, so it is not recommended to clean up, can be placed to clean up the residual data together.</p></p><br>Clean up invalid files and blank files<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>Inference Criteria:</p></p><p><p>A. the length of the file is 0 and it is a blank file that can be deleted</p></p><p><p>B. The directory does not include any files or directories, and it is thought to be a blank directory. be able to Delete.</p></p><p><p>C. In addition to both of the Above. It is also possible to scan the creation time of a file, and a file that is not used for a very long time feels invalid.</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p>Large file cleanup<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>The identification of large files is relatively simple, only to infer whether the file size exceeds a certain threshold (for example: pea pods feel larger than 10M size file). But here are two points to note:</p></p><p><p>A. Large files are usually video files or application data (such as Baidu map data). For these files in cleanup it is recommended to default to "unchecked" Status.</p></p><p><p></p></p><p><p>B. be able to make full use of the mapping relationships established in 2.2.1 to provide more accurate recommendations on whether large files are recommended for Deletion.</p></p><p><p>For the identification and processing of advertising files and so on here no longer repeat, the principle is similar to the Above.</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p>Summarize<p style="text-align: left"><p style="text-align: left"><br></p></p><p style="text-align: left"><p style="text-align: left"></p></p><p><p>The method in this article is basically able to realize the full cleanup of the junk files in the Android System. The emphasis here Is:</p></p><p><p>A. Garbage cleaning is a double-edged sword, must have the appropriate strategy. otherwise, it affects the user experience Instead.</p></p><p><p>B. Be sure to hold this attitude when cleaning up junk files: it's better to be wrong than to Be.</p></p><p><p></p></p><p><p>At last. Hopefully this article will bring a little help to all the friends who are interested in garbage cleanup and cell phone Management. Will be Honored. There are no questions whatsoever to welcome communication and Discussion. The next article will introduce "mobile phone acceleration"</p></p><br><p style="text-align: left"><p style="text-align: left"><br></p></p> <p><p>Mobile phone Management application Research "3"--garbage cleanup</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.