Android Open Source - Aegis Wipe Task






From Project

Back to project page Aegis.

License

The source code is released under:

GNU General Public License

If you think the Android project Aegis listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.decad3nce.aegis;
//from   www.ja v  a  2s.co m
import android.app.ProgressDialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.Log;

import com.decad3nce.aegis.Fragments.SMSWipeFragment;

import java.io.File;

/**
 * Created by Decad3nce on 8/14/13.
 */
public class WipeTask extends AsyncTask<Void, Void, Void> {
    private ProgressDialog dialog = null;
    private Context context;
    private File[] sdcards;
    private String address;
    private DevicePolicyManager devicePolicyManager;
    private SharedPreferences preferences;

    public WipeTask(Context context, File[] sdcards, String address) {
        this.address = address;
        this.context = context;
        this.sdcards = sdcards;
    }

    @Override
    protected void onPreExecute() {
        dialog = new ProgressDialog(context);
        dialog.setTitle(context.getResources().getString(R.string.app_name));
        dialog.setMessage(context.getResources().getString(R.string.aegis_wipe_in_progress));
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        dialog.show();

        devicePolicyManager = (DevicePolicyManager) context
                .getSystemService(Context.DEVICE_POLICY_SERVICE);
        preferences = PreferenceManager
                .getDefaultSharedPreferences(context);
    }

    @Override
    protected Void doInBackground(Void... params) {
        boolean wipesdcards  = preferences.getBoolean(
                SMSWipeFragment.PREFERENCES_WIPE_SDCARD_PREF,
                context.getResources().getBoolean(
                        R.bool.config_default_wipe_sdcard));

        if(wipesdcards) {
            for(int i = 0; i < sdcards.length; ++i){
                wipeSdcard(sdcards[i]);
            }
            Utils.sendSMS(context, address,
                    context.getResources().getString(R.string.util_sendsms_wipe_sdcard_pass));
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        dialog.dismiss();

        //Call after background worker to not interfere with system resources
        if (devicePolicyManager
                .isAdminActive(AegisActivity.DEVICE_ADMIN_COMPONENT)) {
            try {
                Utils.sendSMS(context, address,
                        context.getResources().getString(R.string.util_sendsms_wipe_pass));
                devicePolicyManager.wipeData(0);
            } catch (Exception e) {
                Utils.sendSMS(context, address,
                        context.getResources().getString(R.string.util_sendsms_wipe_fail) + " " + e.toString());
            }
        }
    }

    public void wipeSdcard(File locations) {
        Log.v("aeGis", "Wiping " + locations.getName());
        try {
            File[] filenames = locations.listFiles();
            if (filenames != null && filenames.length > 0) {
                for (File tempFile : filenames) {
                    if (tempFile.isDirectory()) {
                        wipeDirectory(tempFile.toString());
                        tempFile.delete();
                    } else {
                        tempFile.delete();
                    }
                }
            } else {
                locations.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void wipeDirectory(String name) {
        File directoryFile = new File(name);
        File[] filenames = directoryFile.listFiles();
        if (filenames != null && filenames.length > 0) {
            for (File tempFile : filenames) {
                if (tempFile.isDirectory()) {
                    wipeDirectory(tempFile.toString());
                    tempFile.delete();
                } else {
                    tempFile.delete();
                }
            }
        } else {
            directoryFile.delete();
        }
    }
}




Java Source Code List

com.decad3nce.aegis.AegisActivity.java
com.decad3nce.aegis.AlarmService.java
com.decad3nce.aegis.BackupDropboxAccountsActivity.java
com.decad3nce.aegis.BackupGoogleAccountsActivity.java
com.decad3nce.aegis.BackupUtils.java
com.decad3nce.aegis.DeviceAdmin.java
com.decad3nce.aegis.DialerCodeReceiver.java
com.decad3nce.aegis.DrawerLayoutAdapter.java
com.decad3nce.aegis.FontAdapter.java
com.decad3nce.aegis.LoginActivity.java
com.decad3nce.aegis.PhoneTrackerActivity.java
com.decad3nce.aegis.RegisterActivity.java
com.decad3nce.aegis.RootTask.java
com.decad3nce.aegis.SIMStateReceiver.java
com.decad3nce.aegis.SMSReceiver.java
com.decad3nce.aegis.Utils.java
com.decad3nce.aegis.WipeBaseActivity.java
com.decad3nce.aegis.WipeTask.java
com.decad3nce.aegis.Fragments.AboutFragment.java
com.decad3nce.aegis.Fragments.AdvancedSettingsFragment.java
com.decad3nce.aegis.Fragments.BackupAccountsDialogFragment.java
com.decad3nce.aegis.Fragments.ChooseBackupProgramDialogFragment.java
com.decad3nce.aegis.Fragments.InstallToSystemDialogFragment.java
com.decad3nce.aegis.Fragments.SIMListFragment.java
com.decad3nce.aegis.Fragments.SMSAlarmFragment.java
com.decad3nce.aegis.Fragments.SMSDataFragment.java
com.decad3nce.aegis.Fragments.SMSLocateFragment.java
com.decad3nce.aegis.Fragments.SMSLockFragment.java
com.decad3nce.aegis.Fragments.SMSWipeFragment.java