Example usage for android.app.admin DevicePolicyManager removeActiveAdmin

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

Introduction

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

Prototype

public void removeActiveAdmin(@NonNull ComponentName admin) 

Source Link

Document

Remove a current administration component.

Usage

From source file:org.wso2.emm.agent.utils.CommonUtils.java

/**
 * Disable admin privileges./*from   w  w  w  .  j a  va2 s  .  co m*/
 * @param context - Application context.
 */
public static void disableAdmin(Context context) {
    DevicePolicyManager devicePolicyManager;
    ComponentName demoDeviceAdmin;
    devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
    devicePolicyManager.removeActiveAdmin(demoDeviceAdmin);
}

From source file:net.nym.devicepolicy.MainActivity.java

private boolean removeAdmin() {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);

    ComponentName componentName = new ComponentName(this, MyDeviceAdminReceiver.class);
    boolean isAdminActive = devicePolicyManager.isAdminActive(componentName);
    if (isAdminActive) {
        devicePolicyManager.removeActiveAdmin(componentName);
        return true;
    }/*from   ww  w  . ja v  a  2  s .  c o  m*/
    return false;
}

From source file:org.wso2.mdm.agent.utils.CommonUtils.java

/**
 * Clear application data./*from  w ww.j  a  va 2 s  .  co m*/
 * @param context - Application context.
 */
public static void clearAppData(Context context) {
    DevicePolicyManager devicePolicyManager;
    ComponentName demoDeviceAdmin;
    Resources resources = context.getResources();

    devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
    SharedPreferences mainPref = context.getSharedPreferences(
            context.getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE);

    Editor editor = mainPref.edit();
    editor.putString(context.getResources().getString(R.string.shared_pref_policy),
            resources.getString(R.string.shared_pref_default_string));
    editor.putString(context.getResources().getString(R.string.shared_pref_isagreed),
            resources.getString(R.string.shared_pref_device_active));
    editor.putString(context.getResources().getString(R.string.shared_pref_regId),
            resources.getString(R.string.shared_pref_default_string));
    editor.putString(context.getResources().getString(R.string.shared_pref_registered),
            resources.getString(R.string.shared_pref_device_active));
    editor.putString(context.getResources().getString(R.string.shared_pref_ip),
            resources.getString(R.string.shared_pref_default_string));
    editor.putString(context.getResources().getString(R.string.shared_pref_sender_id),
            resources.getString(R.string.shared_pref_default_string));
    editor.putString(context.getResources().getString(R.string.shared_pref_eula),
            resources.getString(R.string.shared_pref_default_string));
    editor.putString(resources.getString(R.string.shared_pref_device_active),
            resources.getString(R.string.shared_pref_reg_fail));
    editor.commit();

    devicePolicyManager.removeActiveAdmin(demoDeviceAdmin);
}

From source file:org.durka.hallmonitor.CoreStateManager.java

public void stopServices(boolean override_keep_admin) {

    Log.d(LOG_TAG, "Stop all services called.");

    if (getServiceRunning(ViewCoverHallService.class)) {
        mAppContext.stopService(new Intent(mAppContext, ViewCoverHallService.class));
    }/*from w w  w. j  a v  a 2s.  co  m*/
    if (getServiceRunning(ViewCoverProximityService.class)) {
        mAppContext.stopService(new Intent(mAppContext, ViewCoverProximityService.class));
    }
    if (getServiceRunning(NotificationService.class)) {
        mAppContext.stopService(new Intent(mAppContext, NotificationService.class));
    }
    if (getServiceRunning(CoreService.class)) {
        mAppContext.stopService(new Intent(mAppContext, CoreService.class));
    }

    // Relinquish device admin (unless asked not to)
    if (!override_keep_admin && !preference_all.getBoolean("pref_keep_admin", false)) {
        DevicePolicyManager dpm = (DevicePolicyManager) mAppContext
                .getSystemService(Context.DEVICE_POLICY_SERVICE);
        ComponentName me = new ComponentName(mAppContext, AdminReceiver.class);
        if (dpm.isAdminActive(me)) {
            dpm.removeActiveAdmin(me);
        }
    }
}

From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java

final private void switchDeviceAdminStatus(boolean activate) {
    DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    final ComponentName darcn = new ComponentName(mContext, DevAdmReceiver.class);
    if (activate && !dpm.isAdminActive(darcn)) {
        NotifyEvent ntfy = new NotifyEvent(mContext);
        ntfy.setListener(new NotifyEventListener() {
            @Override/*from w  w w  .ja  v  a2 s  . c o m*/
            public void positiveResponse(Context c, Object[] o) {
                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, darcn);
                startActivityForResult(intent, 10);
            }

            @Override
            public void negativeResponse(Context c, Object[] o) {
            }
        });
        if (mApplicationRunFirstTime) {
            mGlblParms.commonDlg.showCommonDialog(false, "I",
                    mContext.getString(R.string.msgs_main_screen_lock_confirm_title),
                    mContext.getString(R.string.msgs_main_screen_lock_confirm_msg), ntfy);
        } else
            ntfy.notifyToListener(true, null);

    } else if (!activate)
        dpm.removeActiveAdmin(darcn);
}