package com.example.thefinalproject;

import java.util.List;

import com.example.thefinalproject.R;

import MD5.MD5Encoder;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;

public class AntiVirus extends Activity {
protected static final int STOP = 100;
private ImageView iv;
private ProgressBar pb;
private LinearLayout ll;
private AnimationDrawable anim;
private ScrollView sv;
private SQLiteDatabase db;
private boolean flagscanning = false;
private Handler handler = new Handler() {

@Override
public void handleMessage(Message msg) {

super.handleMessage(msg);
if(msg.what==STOP){
ll.removeAllViews();
anim.stop();

}
String str = (String) msg.obj;
TextView tv = new TextView(getApplicationContext());
tv.setText(str);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(tv);
sv.scrollBy(0, 20);

System.out.println(str);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.antivirus_screen);
db = SQLiteDatabase.openDatabase("/sdcard/antivirus.db", null,
SQLiteDatabase.OPEN_READONLY);
iv = (ImageView) this.findViewById(R.id.iv);
pb = (ProgressBar) this.findViewById(R.id.progressBar1);
ll = (LinearLayout) this.findViewById(R.id.ll);
iv.setBackgroundResource(R.drawable.anti_anim);
sv = (ScrollView) this.findViewById(R.id.sv);
anim = (AnimationDrawable) iv.getBackground();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if(flagscanning)
return false;

if (event.getAction() == MotionEvent.ACTION_UP) {
flagscanning= true;
anim.start();
new Thread() {
public void run() {
List<PackageInfo> infos = getPackageManager()
.getInstalledPackages(
PackageManager.GET_UNINSTALLED_PACKAGES
| PackageManager.GET_SIGNATURES);
// 获取每一个应用程序的签名 获取到这个签名后 需要在数据库里面查询
pb.setMax(infos.size());
int total = 0;
int virustotal = 0;
for (PackageInfo info : infos) {
total++;
try {
sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Message msg = Message.obtain();
msg.obj = "正在扫描" + info.packageName;
handler.sendMessage(msg);
Signature[] signs = info.signatures;
String str = signs[0].toCharsString();
String md5 = MD5Encoder.encode(str);

if("6c20c50051ad1dedce0528e0f3dfbc96".equals(md5)){
System.err.println("----------");
}
Cursor cursor = db.rawQuery(
"select desc from datable where md5=?",
new String[] { md5 });
if (cursor.moveToFirst()) {
String desc = cursor.getString(0);
msg = Message.obtain();
msg.obj = info.packageName + ": " + desc;

handler.sendMessage(msg);
virustotal++;
}
cursor.close();
pb.setProgress(total);

}
Message msg = Message.obtain();
msg.what = STOP;
msg.obj = "扫描完毕 ,共发现" + virustotal + "个病毒";
handler.sendMessage(msg);
flagscanning = false;
pb.setProgress(0);
};
}.start();
}
return super.onTouchEvent(event);
}

@Override
protected void onDestroy() {
if (db.isOpen())
db.close();
super.onDestroy();
}
}

更多相关文章

  1. 为什么我的Android应用程序偶尔可以非常快地耗尽电池?
  2. 如何在android 5.0(L)中运行应用程序活动名称?
  3. Android应用程序启动过程上
  4. Java Android套接字连接。错误的IP地址导致应用程序停止响应
  5. Android 为你的应用程序添加快捷方式【优先级高的快捷方式】
  6. 添加脚本到Android应用程序
  7. 如何使用java RESTful Web服务将通知推送到Android应用程序
  8. android 获取正在运行的应用程序列表
  9. 如何开始为Android开发应用程序? [重复]

随机推荐

  1. Binder详解
  2. Android 应用程序开发基础
  3. 【安卓开发】UI设计基础4:用网格布局 Grid
  4. 开发人员应该了解的 Android(安卓)常用术
  5. 深入源码解析Android中的Handler,Message
  6. Android 启动模拟器是出现“Failed to al
  7. Android 4.0+ 版本中的EditText字符重叠
  8. Android面试系列文章2018之Android部分事
  9. Android(安卓)apk的安装、卸载
  10. Android中使用事件总线的优缺点