// Path: app/src/main/java/com/itheima/mobilesafe/db/AppsLockDbOpenHelper.java
// public class AppsLockDbOpenHelper extends SQLiteOpenHelper {
//     public AppsLockDbOpenHelper(Context context) {
//         super(context, "appslock.db", null, 1);
//     }
// 
//     @Override
//     public void onCreate(SQLiteDatabase db) {
//         db.execSQL("create table apps (_id integer primary key autoincrement, name varchar(20))");
//     }
// 
//     @Override
//     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// 
//     }
// }
// 
// Path: app/src/main/java/com/itheima/mobilesafe/utils/BroadcastActions.java
// public class BroadcastActions {
//     public final static String ADMIN_PERMISSION = "ADMIN_PERMISSION";
//     public final static String SAFE_PHONE = "SAFE_PHONE";
//     public final static String DISABLE_SWIPING = "DISABLE_SWIPING";
//     public final static String LOCATION_INFO = "LOCATION_INFO";
//     public final static String FINISHED_UNINSTALLING = "FINISHED_UNINSTALLING";
//     public final static String STOP_WATCHDOG = "STOP_WATCHDOG";
//     public final static String UPDATE_WATCHDOG = "UPDATE_WATCHDOG";
// }


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.itheima.mobilesafe.db.AppsLockDbOpenHelper;
import com.itheima.mobilesafe.utils.BroadcastActions;
import java.util.ArrayList;
import java.util.List;
import tw.com.softworld.messagescenter.AsyncResponse;
import tw.com.softworld.messagescenter.Server;
            sv.pushBoolean(BroadcastActions.UPDATE_WATCHDOG, true);
        }
    }

    /**
     * 查询数据库太慢，改成查内存（使用queryAll()）
     *
     * @param packageName
     * @return
     */
    @Override
    public boolean find(String packageName) {
        boolean isExist = false;
        SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
        if (db.isOpen()) {
            Cursor cursor = db.rawQuery("select * from " + TABLE + " where name=?", new String[]{packageName});
            if (cursor.moveToNext())
                isExist = true;
            cursor.close();
            db.close();
        }
        return isExist;
    }

    @Override
    public void remove(String packageName) {
        SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
        if (db.isOpen()) {
            db.delete(TABLE, "name=?", new String[]{packageName});
            db.close();
// Path: app/src/main/java/com/itheima/mobilesafe/db/AppsLockDbOpenHelper.java
// public class AppsLockDbOpenHelper extends SQLiteOpenHelper {
//     public AppsLockDbOpenHelper(Context context) {
//         super(context, "appslock.db", null, 1);
//     }
// 
//     @Override
//     public void onCreate(SQLiteDatabase db) {
//         db.execSQL("create table apps (_id integer primary key autoincrement, name varchar(20))");
//     }
// 
//     @Override
//     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// 
//     }
// }
// 
// Path: app/src/main/java/com/itheima/mobilesafe/utils/BroadcastActions.java
// public class BroadcastActions {
//     public final static String ADMIN_PERMISSION = "ADMIN_PERMISSION";
//     public final static String SAFE_PHONE = "SAFE_PHONE";
//     public final static String DISABLE_SWIPING = "DISABLE_SWIPING";
//     public final static String LOCATION_INFO = "LOCATION_INFO";
//     public final static String FINISHED_UNINSTALLING = "FINISHED_UNINSTALLING";
//     public final static String STOP_WATCHDOG = "STOP_WATCHDOG";
//     public final static String UPDATE_WATCHDOG = "UPDATE_WATCHDOG";
// }


// Path: app/src/main/java/com/itheima/mobilesafe/db/dao/AppsLockDao.java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.itheima.mobilesafe.db.AppsLockDbOpenHelper;
import com.itheima.mobilesafe.utils.BroadcastActions;
import java.util.ArrayList;
import java.util.List;
import tw.com.softworld.messagescenter.AsyncResponse;
import tw.com.softworld.messagescenter.Server;

            sv.pushBoolean(BroadcastActions.UPDATE_WATCHDOG, true);
        }
    }

    /**
     * 查询数据库太慢，改成查内存（使用queryAll()）
     *
     * @param packageName
     * @return
     */
    @Override
    public boolean find(String packageName) {
        boolean isExist = false;
        SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
        if (db.isOpen()) {
            Cursor cursor = db.rawQuery("select * from " + TABLE + " where name=?", new String[]{packageName});
            if (cursor.moveToNext())
                isExist = true;
            cursor.close();
            db.close();
        }
        return isExist;
    }

    @Override
    public void remove(String packageName) {
        SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
        if (db.isOpen()) {
            db.delete(TABLE, "name=?", new String[]{packageName});
            db.close();
            sv.pushBoolean(BroadcastActions.UPDATE_WATCHDOG, true);