Example usage for android.app.admin DevicePolicyManager wipeData

List of usage examples for android.app.admin DevicePolicyManager wipeData

Introduction

In this page you can find the example usage for android.app.admin DevicePolicyManager wipeData.

Prototype

public void wipeData(int flags) 

Source Link

Document

Ask that all user data be wiped.

Usage

From source file:org.wso2.emm.agent.AuthenticationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_authentication);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar);
    getSupportActionBar().setTitle(Constants.EMPTY_STRING);

    context = this;
    deviceInfo = new DeviceInfo(context);
    etDomain = (EditText) findViewById(R.id.etDomain);
    etUsername = (EditText) findViewById(R.id.etUsername);
    etPassword = (EditText) findViewById(R.id.etPassword);
    radioBYOD = (RadioButton) findViewById(R.id.radioBYOD);
    loginLayout = (LinearLayout) findViewById(R.id.errorLayout);
    etDomain.setFocusable(true);/*w w w.  j a v  a 2 s .  c o m*/
    etDomain.requestFocus();
    btnRegister = (Button) findViewById(R.id.btnRegister);
    btnRegister.setOnClickListener(onClickAuthenticate);
    btnRegister.setEnabled(false);

    // change button color background till user enters a valid input
    btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey));
    btnRegister.setTextColor(getResources().getColor(R.color.black));

    if (Constants.HIDE_LOGIN_UI) {
        loginLayout.setVisibility(View.GONE);
    }

    if (Constants.DEFAULT_OWNERSHIP == Constants.OWNERSHIP_COSU) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            startLockTask();
        }
    }

    textViewWipeData = (TextView) this.findViewById(R.id.textViewWipeData);
    if (Constants.DEFAULT_OWNERSHIP == Constants.OWNERSHIP_COSU && Constants.DISPLAY_WIPE_DEVICE_BUTTON) {
        textViewWipeData.setVisibility(View.VISIBLE);
        textViewWipeData.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                new AlertDialog.Builder(AuthenticationActivity.this).setTitle(getString(R.string.app_name))
                        .setMessage(R.string.wipe_confirmation)
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getApplicationContext()
                                        .getSystemService(Context.DEVICE_POLICY_SERVICE);
                                devicePolicyManager.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE
                                        | DevicePolicyManager.WIPE_RESET_PROTECTION_DATA);
                            }
                        }).setNegativeButton(android.R.string.no, null).show();
            }
        });
    }

    etUsername.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            enableSubmitIfReady();
        }

        @Override
        public void afterTextChanged(Editable s) {
            enableSubmitIfReady();
        }
    });

    etPassword.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            enableSubmitIfReady();
        }

        @Override
        public void afterTextChanged(Editable s) {
            enableSubmitIfReady();
        }
    });

    if (org.wso2.emm.agent.proxy.utils.Constants.Authenticator.AUTHENTICATOR_IN_USE
            .equals(org.wso2.emm.agent.proxy.utils.Constants.Authenticator.MUTUAL_SSL_AUTHENTICATOR)) {

        AuthenticatorFactory authenticatorFactory = new AuthenticatorFactory();
        authenticator = authenticatorFactory.getClient(
                org.wso2.emm.agent.proxy.utils.Constants.Authenticator.AUTHENTICATOR_IN_USE,
                AuthenticationActivity.this, Constants.AUTHENTICATION_REQUEST_CODE);
        authenticator.doAuthenticate();
    }

    //This is an override to ownership type.
    if (Constants.DEFAULT_OWNERSHIP != null) {
        deviceType = Constants.DEFAULT_OWNERSHIP;
        Preference.putString(context, Constants.DEVICE_TYPE, deviceType);
    }

    // This is added so that in case due to an agent customisation, if the authentication
    // activity is called the AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED is set, the activity
    // must be finished.
    if (Constants.AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED == true) {
        finish();
    }

}

From source file:org.wso2.iot.agent.activities.AuthenticationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {//from w w w .j a v  a 2  s  .c o m
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

    setContentView(R.layout.activity_authentication);
    RelativeLayout relativeLayout = (RelativeLayout) this.findViewById(R.id.relavtiveLayoutAuthentication);

    if (Constants.DEFAULT_OWNERSHIP.equals(Constants.OWNERSHIP_COSU)) {
        relativeLayout.setVisibility(RelativeLayout.GONE);
    }
    deviceInfo = new DeviceInfo(context);
    etDomain = (EditText) findViewById(R.id.etDomain);
    etUsername = (EditText) findViewById(R.id.etUsername);
    etPassword = (EditText) findViewById(R.id.etPassword);
    etDomain.setFocusable(true);
    etDomain.requestFocus();
    btnSignIn = (Button) findViewById(R.id.btnSignIn);
    btnSignIn.setOnClickListener(onClickAuthenticate);
    btnSignIn.setEnabled(false);

    // change button color background till user enters a valid input
    btnSignIn.setBackgroundResource(R.drawable.btn_grey);
    btnSignIn.setTextColor(ContextCompat.getColor(this, R.color.black));
    TextView textViewSignIn = (TextView) findViewById(R.id.textViewSignIn);
    LinearLayout loginLayout = (LinearLayout) findViewById(R.id.loginLayout);

    if (Preference.hasPreferenceKey(context, Constants.TOKEN_EXPIRED)) {
        etDomain.setEnabled(false);
        etDomain.setTextColor(ContextCompat.getColor(this, R.color.black));
        etUsername.setEnabled(false);
        etUsername.setTextColor(ContextCompat.getColor(this, R.color.black));
        btnSignIn.setText(R.string.btn_sign_in);
        etPassword.setFocusable(true);
        etPassword.requestFocus();
        String tenantedUserName = Preference.getString(context, Constants.USERNAME);
        int tenantSeparator = tenantedUserName.lastIndexOf('@');
        etUsername.setText(tenantedUserName.substring(0, tenantSeparator));
        etDomain.setText(tenantedUserName.substring(tenantSeparator + 1, tenantedUserName.length()));
        isReLogin = true;
        textViewSignIn.setText(R.string.msg_need_to_sign_in);
    } else if (Constants.CLOUD_MANAGER != null) {
        isCloudLogin = true;
        etDomain.setVisibility(View.GONE);
        textViewSignIn.setText(R.string.txt_sign_in_cloud);
    }

    if (Preference.getBoolean(context, Constants.PreferenceFlag.DEVICE_ACTIVE) && !isReLogin) {
        Intent intent = new Intent(AuthenticationActivity.this, AlreadyRegisteredActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
        return;
    }

    TextView textViewSignUp = (TextView) findViewById(R.id.textViewSignUp);
    if (!isReLogin && Constants.SIGN_UP_URL != null) {
        Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
            @Override
            public String transformUrl(Matcher match, String url) {
                return Constants.SIGN_UP_URL;
            }
        };
        Pattern pattern = Pattern.compile(getResources().getString(R.string.txt_sign_up_linkify));
        Linkify.addLinks(textViewSignUp, pattern, null, null, transformFilter);
    } else {
        textViewSignUp.setVisibility(View.GONE);
    }

    if (Constants.HIDE_LOGIN_UI) {
        loginLayout.setVisibility(View.GONE);
    }

    if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            startLockTask();
        }
    }

    TextView textViewWipeData = (TextView) this.findViewById(R.id.textViewWipeData);
    if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP) && Constants.DISPLAY_WIPE_DEVICE_BUTTON) {
        textViewWipeData.setVisibility(View.VISIBLE);
        textViewWipeData.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                new AlertDialog.Builder(AuthenticationActivity.this).setTitle(getString(R.string.app_name))
                        .setMessage(R.string.wipe_confirmation)
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getApplicationContext()
                                        .getSystemService(Context.DEVICE_POLICY_SERVICE);
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
                                    devicePolicyManager.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE
                                            | DevicePolicyManager.WIPE_RESET_PROTECTION_DATA);
                                } else {
                                    devicePolicyManager.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE);
                                }
                            }
                        }).setNegativeButton(android.R.string.no, null).show();
            }
        });
    }

    ImageView logo = (ImageView) findViewById(R.id.imageViewLogo);
    if (Constants.COSU_SECRET_EXIT) {
        logo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                kioskExit++;
                if (kioskExit == 6) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        stopLockTask();
                    }
                    finish();
                }
            }
        });
    }

    etUsername.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            enableSubmitIfReady();
        }

        @Override
        public void afterTextChanged(Editable s) {
            enableSubmitIfReady();
        }
    });

    etPassword.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            enableSubmitIfReady();
        }

        @Override
        public void afterTextChanged(Editable s) {
            enableSubmitIfReady();
        }
    });

    if (org.wso2.iot.agent.proxy.utils.Constants.Authenticator.AUTHENTICATOR_IN_USE
            .equals(org.wso2.iot.agent.proxy.utils.Constants.Authenticator.MUTUAL_SSL_AUTHENTICATOR)) {

        AuthenticatorFactory authenticatorFactory = new AuthenticatorFactory();
        ClientAuthenticator authenticator = authenticatorFactory.getClient(
                org.wso2.iot.agent.proxy.utils.Constants.Authenticator.AUTHENTICATOR_IN_USE,
                AuthenticationActivity.this, Constants.AUTHENTICATION_REQUEST_CODE);
        authenticator.doAuthenticate();
    }

    //This is an override to ownership type.
    if (Constants.DEFAULT_OWNERSHIP != null) {
        deviceType = Constants.DEFAULT_OWNERSHIP;
        Preference.putString(context, Constants.DEVICE_TYPE, deviceType);
    } else {
        deviceType = Constants.OWNERSHIP_BYOD;
    }

    if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP)) {
        Intent intent = getIntent();
        if (intent.hasExtra("android.app.extra.token")) {
            adminAccessToken = intent.getStringExtra("android.app.extra.token");
            proceedToAuthentication();
        }
    }

    // This is added so that in case due to an agent customisation, if the authentication
    // activity is called the AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED is set, the activity
    // must be finished.
    if (Constants.AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED) {
        finish();
    }
}