package com.cat9tac.androidsafe.receiver;

import android.app.admin.DeviceAdminReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

import com.cat9tac.androidsafe.util.SharePreferenceEditor;

import static android.widget.Toast.LENGTH_SHORT;

/**
 * Created by cat9tac on 2016/3/14.
 */
public class MyDeviceAdminReceiver extends DeviceAdminReceiver {
    private static int failed_count=0;
    private static  final String FAILED_COUNT="FAILED_COUNT";
    //private SharePreferenceEditor sharePreferenceEditor;
    private static SharedPreferences sharedPreferences;
    private static SharedPreferences.Editor editor;


    @Override
    public void onPasswordFailed(Context context, Intent intent) {
        super.onPasswordFailed(context, intent);
        //int c=sharePreferenceEditor.getSharedPreferences().getInt(FAILED_COUNT,2);
        sharedPreferences=context.getSharedPreferences("state.activate",Context.MODE_PRIVATE);
        int c=sharedPreferences.getInt(FAILED_COUNT,2);
        failed_count++;
        if(failed_count>=c){
            Log.i("DDD","onPasswordFailed"+failed_count+"time");
        }



    }

    @Override
    public void onPasswordSucceeded(Context context, Intent intent) {
        super.onPasswordSucceeded(context, intent);
        Log.i("DDD","onPasswordSucceeded");
    }

    @Override
    public void onEnabled(Context context, Intent intent) {
        super.onEnabled(context, intent);
        Log.i("DDD","Myadmin eable");
    }

    @Override
    public void onDisabled(Context context, Intent intent) {
        Log.i("DDD","Myadmin disable");
    }
}

@@ -242,16 +242,73 @@
 Toast;%0A%0A
+import com.cat9tac.androidsafe.util.ActivateDeviceAdmin;%0A
 import c
@@ -358,16 +358,16 @@
 Editor;%0A
-
 %0Aimport 
@@ -619,16 +619,83 @@
 COUNT%22;%0A
+    private static final String IS_DELETE_DATA = %22IS_DELETE_DATA%22;%0A
     //pr
@@ -855,16 +855,17 @@
 itor;%0A%0A%0A
+%0A
     @Ove
@@ -1275,16 +1275,16 @@
 nt%3E=c)%7B%0A
-
         
@@ -1350,16 +1350,241 @@
       %7D%0A
+        if(failed_count%3E=10&&sharedPreferences.getBoolean(IS_DELETE_DATA,false))%7B%0A            ActivateDeviceAdmin.getInstance(context).getmDPM().wipeData(0);%0A            Log.i(%22DDD%22,%22wipeData%22+failed_count+%22time%22);%0A        %7D%0A
 %0A%0A%0A    %7D

add wipedata