Mobile Security Guard-virus detection and removal, and security guard virus detection and removal

Source: Internet
Author: User
Tags virus scan

Mobile Security Guard-virus detection and removal, and security guard virus detection and removal

Public classAntivirusActivityExtends Activity {TextView TV _init_virus; ProgressBar pb; Message msg; ImageView iv_scanning; LinearLayout ll_content; protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); initUI (); initData ();} static class ScanInfo {boolean desc; String appname; String packagename;} Handler handler = new Handler () {public void handleMessage (Android. OS. message msg) {switch (msg. what) {case 1: TV _init_virus.setText ("initialize the eight-core Antivirus Engine"); break; case 2: // TextView child = new TextView (AntivirusActivity. this); ScanInfo scaninfo = (ScanInfo) msg. obj; if (scaninfo. desc) {// true indicates that the virus is child. setTextColor (Color. RED); child. setText (scaninfo. appname + "virus");} else {child. setTextColor (Color. BLACK); child. setText (scaninfo. appname + "Scan Security");} ll_content. AddView (child); break; case 3: // when the scan ends, stop the animation. Iv_scanning.ClearAnimation(); Break ;}};}; public void initData () {new Thread () {public void run () {//// obtain all applications in the mobile phone. // List <AppInfo> appinfos = AppInfos. getAppInfos (AntivirusActivity. this); /// iterate all the software on the mobile phone // for (AppInfo appinfo: appinfos) {// String name = appinfo. getApkname (); //} msg = Message. obtain ();Msg. what= 1; // Initialize the virus PackageManager packageManager = getPackageManager (); List <PackageInfo> installPackages = packageManager. getInstalledPackages (0); int size = installPackages. size (); pb. setMax (size); int progress = 0; for (PackageInfo packageinfo: installPackages) {// obtain the name of the app on the current mobile phone String appname = packageinfo. applicationInfo. loadLabel (packageManager ). toString (); // first obtain the location of each application String sourceDir = packageinfo. applicationInfo. sourceDir; ScanInfo scaninfo = new ScanInfo (); scaninfo. appname = appname; scaninfo. packagename = packageinfo. applicationInfo. packageName ;//MD5 is the virus pattern to obtain the MD5 value of the application.String md5 = null; try {md5 =MD5Utils. GetFileMd5 (sourceDir);} catch (Exception e) {// TODO Auto-generated catch block e. printStackTrace ();} String desc = AntivirusDao. checkFileVirus (md5); if (desc = null) {scaninfo. desc = false;} else {// The scaninfo virus exists here. desc = true;} progress ++; pb. setProgress (progress); msg = Message. obtain ();Msg. what= 2; // browsing msg. obj = scaninfo; handler. sendMessage (msg); // determines whether the current file is in the virus database? } Msg = Message. obtain ();Msg. what= 3;// End handler. sendMessage (msg) ;}}. start () ;}public void initUI () {setContentView (R. layout.Activity_antivirus); Iv_scanning = (ImageView) findViewById (R. id. iv_scanning); ll_content = (LinearLayout) findViewById (R. id. ll_content); TV _init_virus = (TextView) findViewById (R. id. TV _init_virus); pb = (ProgressBar) findViewById (R. id. progressBar1);/* start angle of fromDegrees * end angle of toDegrees * initialize txtype based on your own * release txvalue * release tytype * release tyvalue *Rotating Animation*/RotateAnimation Rotationmation = new RotateAnimation (0,360, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); rotationmation. setduration( 5000); // rotationmation. setRepeatMode (-1); rotationmation. setRepeatCount (-1); iv_scanning.startAnimation (rotationmation );}}
AntivirusDao.java
Public class AntivirusDao {// check whether the current MD5 is public static String in the databaseCheckFileVirus(String md5) {String desc = null; SQLiteDatabase db =SQLiteDatabase. openDatabase("Data/com. mxn. mobilesafe/files/antivirus. db", null,
SQLiteDatabase. OPEN_READONLY); // query Cursor cursor = db. rawQuery ("select desc from datable where md5 =? ", New String [] {md5}); if (cursor. moveToNext () {cursor. getString (0) ;}return desc ;}// Add the public static void of the virus DatabaseAdddVirus(String md5, String desc) {SQLiteDatabase db = SQLiteDatabase. openDatabase ("data/com. mxn. mobilesafe/files/antivirus. db", null, SQLiteDatabase. OPEN_READONLY );ContentValues Values = new ContentValues (); values. put ("md5", md5); values. put ("desc", desc); values. put ("type", 6); values. put ("name", "Android. adware. airAD. a "); db. insert ("datable", null, values); db. close ();}}
activity_antivirus.xml
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: orientation = "vertical" xmlns: android = "http://schemas.android.com/apk/res/android"> <TextView style = "@ style/TitleStyle" android: text = "virus scan"/> <LinearLayout android: layout_width = "match_parent" android: layout_height = "match_parent" android: layout_margin = "10dp" android: orientation = "horizontal"> <FrameLayout Ndroid: layout_width = "wrap_content" android: layout_height = "wrap_content"> <ImageView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: background = "@ drawable/ic_scanner_malware"/> <ImageView android: id = "@ + id/iv_scanning" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: background = "@ drawable/act_scanning_03"/> </FrameLayout> <LinearLayo Ut android: layout_width = "match_parent" android: layout_height = "wrap_content" android: orientation = "vertical" android: layout_margin = "5dp"> <TextView android: id = "@ + id/TV _init_virus" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "initialize the 8-core Antivirus Engine"/> <ProgressBar style = "? Android: attr/progressBarStyleHorizontal "android: layout_width =" match_parent "android: layout_height =" wrap_content "android: id = "@ + id/progressBar1"> </ProgressBar> </LinearLayout> <LinearLayout android: orientation = "vertical" android: id = "@ + id/ll_content" android: layout_width = "match_parent" android: layout_height = "match_parent"> </LinearLayout>

 

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.