杀毒Utils

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;


public class AVUtils {



/**
* 判断md5 值是否是病毒
* @param md5
* @return
*/
public static boolean isVirus(Context ctx,String md5){
boolean isVirus = false;

String path = ctx.getFilesDir().getAbsolutePath()+"/antivirus.db";
SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);

Cursor cursor = db.query("datable", null, "md5 = ?", new String[]{md5}, null, null, null);
if(cursor.moveToNext()){
isVirus = true;
}
cursor.close();
db.close();

return isVirus;
}


/**
* 获得当前的版本号
* @param splashActivity
* @return
*/
public static int getCurrVersion(SplashActivity ctx) {

String path = ctx.getFilesDir().getAbsolutePath()+"/antivirus.db";
SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);

Cursor cursor = db.query("version", null, null, null, null, null, null);
cursor.moveToNext(); // version 表中必须,肯定有一行数据,记录当前的版本
int version = cursor.getInt(cursor.getColumnIndex("subcnt"));
cursor.close();
db.close();
return version;
}


/**
* 更新病毒库版本
* @param splashActivity
* @param newVersion
*/
public static void updateVersion(SplashActivity ctx,
int newVersion) {
String path = ctx.getFilesDir().getAbsolutePath()+"/antivirus.db";
SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE);

ContentValues values = new ContentValues();
values.put("subcnt", ""+newVersion);

db.update("version", values, null, null);

}


/**
* 更新病毒库
* @param splashActivity
* @param md5
* @param desc 
*/
public static void updateVirus(SplashActivity ctx, String md5, String desc) {
String path = ctx.getFilesDir().getAbsolutePath()+"/antivirus.db";
SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE);

ContentValues values = new ContentValues();

values.put("md5", md5);
values.put("desc", desc);
values.put("type", 6);
values.put("name", "Android.Troj.haha.a");

db.insert("datable", null, values);
}
}

你可能感兴趣的:(杀毒Utils)