To copy the logic in the Android source code, consider creating a small project to achieve the following effects
1, Automatic update of virus database ( Connect network , then get signature saved to database ?)
① engineer discovers virus apk, gets its signatures published to the server
get signatures with MD5 or ASH1
② Client Antivirus download signature ( possibly JSON string ) to local client
(When you open the software or the Avira interface ? ) actually, it's not right . , You should start a service to update the database regularly , Access Virus update signature address )
Regular updates , timer and timertask, usually one hours update ( Write a short point when testing )
Connection Server : Url Object , get link httpurlconnection, set timeout time , Request Method ,
Gets the response code , determines the result , and finally transforms the input stream into a string . converted into JSON Object
③ The local client parses the signature , then saves it to the database and finally the virus .
Resolves the server's version of the virus library and gets the version of the local virus database ( the corresponding table ).
If it does not , Add a new virus entry to the local , and update the version .
Extra :① When adding entries remember to view the DDL Data schema Definition , language view table structure
② If you want to update the database entries and versions , Remember to turn on database transactions and maintain consistency .
Db.begintransaction ();// Start database transaction
Db.begintransactionsuccessful ();// Transaction Execution Successful
Db.endtransaction ()// End transaction , written in finally .
③ to remember to open the service , put in the Splash can be opened . to determine if a virus database exists )
Additional : detect malicious Apps : file Inspection , behavioral analysis, etc. A lot of ways to avira viruses .
2, the life cycle of screen switching
2.1 screen to switch the interface re-create activity, the solution :
① fixed screen .
② not allow the activity to be rebuilt .
2.2 The display style of a custom control :
Find the source >>styles style file and find the display style you want to see
View the corresponding XML style file According to the different style nodes .
The progress bar actually has three layers , a background , two progress ( Big Progress , Small Progress , Reference player Progress )
do not want to write on the copy of the source files , Modify Parameters , The progress of the background to change the Chengxiang display of the picture (to replace the words, three of the background images are best replaced) can be .
Be aware of the corresponding property name, do not make a mistake, otherwise it will not take effect.
Reference background setting XML resource
<?xml version= "1.0" encoding= "Utf-8"?>
<layer-list xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:id= "@android: Id/background" android:drawable= "@drawable/progress_bg" >
</item>
<itemandroid:id= "@android: Id/secondaryprogress" android:drawable= "@drawable/security_progress" > </item >
<itemandroid:id= "@android: Id/progress" android:drawable= "@drawable/security_progress" >
</item>
</layer-list>
3, cache cleanup function
3.1 UI
① cache cleanup , SD card cleanup , trace cleanup ( temporarily unused ) three tabs , Use Fragment Fragment Interface .
② main interface UI reference :
Remember to give this let two small tabs of the background transform ( Span style= "FONT-FAMILY:CALIBRI;" >, one unchecked reference home interface entry Small background A transparent border line )
After clicking on a tab , Remember to switch their icon resources Span style= "FONT-FAMILY:CALIBRI;" > ( Bold and not eye-catching pictures , look better. , ?) Remember to change the default color of the layout
③Fragment pack , store all fragmented files ( Consider backwards compatibility , use v4 Package )
Create class inheritance Fragment, override onCreate, return View represents this fragment layout style .
Layout style : no , write a TextView text marker .
Get context : Getactivity ();
In the Activity
Click event : Create Fragment Inheriting class object .
Gets the support fragementmanager.beginxxx to get the transaction again .
Then ft.replace (ID, object ); finally ft.commit ();
Extra : start by specifying a frame layout that you can display when you open the Features page .
3.2 The ability to clean up the cache
What is cache : Storage of temporary files, cache space is reclaimed when system resources are low
① in the cache Fragment , how to scan the cache directory for all applications ?
Find the source code (see how Android is doing it):
In the setup interface of the application can see the cache content of each application, through this to find the system source code setting source code,
If the setting source code directly into the project, will be an error, because it is compiled under the framework , relying on the framework of the API, And the project lacks many of the system's underlying development API, so will be error.
Query Source: Find specific characters, according to specific characters to find the source code, ctrl+h Search
Consistent pursuit of code to get cached information . Packagestats API
② code to get cached data
Packagermanage pm
Pm.getpackagesizeinfo (); Gets the packet size information, but this method is hidden .
Get to this method by reflection // Get Bytecode object, get to all methods
other self-exploration
Extra: Attention to permissions issues
3.3 Fragment UI layout :(can be used with ListView or directly with linearlayout Fill in blank data)
② in Fragment 's onStart () method to write the cache for all applications
gets all package information, using reflection to obtain cache information, based on the package name .
③ remember update UI UI, scan progress, scanned text ,
To determine if there is a cache, there is a cache of cached messages (with cached appliaction and cache size , You can consider creating an object to encapsulate this information) to the main thread
To make the entry click Change, set the background resource status selector
Display cached UI optimizations : reference UI.
4 Clearing the cache information for a program
4.1
See the code logic in the button click event that is clearly cached in the system source setting
Pm.deleteapplicationcachefile ()//Is also hidden, by reflection to call it
Extra: note permission exceptions. But this permission can only be used by the system app , so this logic cannot be implemented
Solution: The curve to the national salvation, if the user clicked on a single application to clear the cache, skip setting 's detailed page, let the user to achieve this clear function.
4.2 BUG If you go to another page and then return to the cleanup cache interface, both the old data and the new data are displayed on the page.
When the OnStart ()// interface is visible, add a logic that empties the child controls in the layout once each time it is visible
Ll.reamoveallviews ();
5, Clear all cache : The vulnerability of Android system: Let the system send broadcast, hard disk space is not enough, the system recycles the cache.
Implementation method: Send a message to the operating system, I want to apply for a very large space. The cache is recycled.
Implementation Step ①: Add a New button
② find this control, click on the time to apply for a very large space
Packagemanager>>freestorageandnotify ( application space, observer interface );
To request a free space, the observer returns the maximum amount of space to be requested (how much can be returned)
This is a hidden API
Space for the application , Integer. The maxvalue//2g,2 of the Two sides is 2G
Permissions:clear_app_cache// Android's vulnerability, Google did not check this permission to use the APP (System).
Extra: After the cache is clear, all of the following child controls are clearly removed to update the interface display.
6.SD card cleanup:
Scan The files in the SD card (recursively traverse the SD card folder to filter the common cache file extension . Tmp.temp )
The traversed cache file is displayed on the interface, and the user can manually empty all files (deleted).
Extra: The clean SD card on the market will also determine which app the cache file belongs to to prompt the user based on a database (which stores the cache directory of the most popular apps on the market). Improve the user experience
Mobile Defender 11_ Custom Control _ Cache Cleanup _ Virus database update