Example usage for android.app.admin DevicePolicyManager EXTRA_ADD_EXPLANATION

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

Introduction

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

Prototype

String EXTRA_ADD_EXPLANATION

To view the source code for android.app.admin DevicePolicyManager EXTRA_ADD_EXPLANATION.

Click Source Link

Document

An optional CharSequence providing additional explanation for why the admin is being added.

Usage

From source file:com.example.samsungmdm.MainActivity.java

private void grantAdminPrivileges() {
    mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mAdminName = new ComponentName(this, MyDeviceAdminReceiver.class);

    if (!mDPM.isAdminActive(mAdminName)) {
        //Not yet device admin
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "This needs to be added");
        startActivityForResult(intent, REQUEST_ENABLE);
    }//from  w w w.  j  a v  a2 s  .  c o m
}

From source file:com.decad3nce.aegis.AegisActivity.java

public void addAdmin() {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, DEVICE_ADMIN_COMPONENT);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
            getResources().getString(R.string.device_admin_reason));
    startActivityForResult(intent, ACTIVATION_REQUEST);
}

From source file:com.toppatch.mv.ui.activities.LoginActivity2.java

private void enableAdmin() {
    DevicePolicyManager mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName mDeviceAdmin = new ComponentName(this, TopPatchAdmin.class);
    if (mDPM != null) {
        try {/*from  w ww .  j  a  v a  2  s .  co m*/

            //Add filter to listen to the choice made by the user to accept the terms or not.
            IntentFilter filter = new IntentFilter();
            filter.addAction(EnterpriseLicenseManager.ACTION_LICENSE_STATUS);
            actionReceiver = new SamsungReceiver();
            registerReceiver(actionReceiver, filter);

            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdmin);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                    "Please Activate The Admin To Let Us Steal All Your Data And Sell It To Obama!");
            startActivityForResult(intent, RESULT_ENABLE);
        } catch (Exception e) {
            Log.w(TAG, "Exception: " + e);
        }
    } else {
        Log.e(TAG, "mDPM is null");
        //TODO device doesn't support MDM...report this shit.
    }
}

From source file:com.configurer.easyscreenlock.MainActivity.java

private void activateDeviceAdmin() {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.usage_info));
    startActivityForResult(intent, ACTIVATION_REQUEST_CODE);
}

From source file:edu.ucdenver.androidsecurity.MainActivity.java

private void loadAdminRequestScreen() {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminPoliciesManager.getmDeviceAdmin());
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.description_receiver));
    startActivityForResult(intent, DEVICE_ADMIN_REQUEST);
}

From source file:org.wso2.mdm.agent.AlreadyRegisteredActivity.java

/**
 * Start device admin activation request.
 * @param cdmDeviceAdmin - Device admin component.
 *///www.j  a va 2s .c  o  m
private void startDeviceAdminPrompt(ComponentName cdmDeviceAdmin) {
    Intent deviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cdmDeviceAdmin);
    deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
            getResources().getString(R.string.device_admin_enable_alert));
    startActivityForResult(deviceAdminIntent, ACTIVATION_REQUEST);
}

From source file:com.tomer.alwayson.SettingsFragment.java

@Override
public boolean onPreferenceChange(final Preference preference, Object o) {
    if (preference.getKey().equals("watchface_clock")) {
        int value = Integer.parseInt((String) o);
        if (value > 2) {
            if (Globals.ownedItems != null) {
                if (Globals.ownedItems.size() > 0) {
                    return true;
                } else {
                    PreferencesActivity.quicklyPromptToSupport(getActivity(), Globals.mService, rootView);
                    return false;
                }/* w  ww  . ja va 2 s. c om*/
            } else {
                PreferencesActivity.quicklyPromptToSupport(getActivity(), Globals.mService, rootView);
            }
        } else {
            return true;
        }
    }

    prefs.apply();
    Utils.logDebug("Preference change", preference.getKey() + " Value:" + o.toString());

    if (preference.getKey().equals("notifications_alerts")) {
        if ((boolean) o)
            return checkNotificationsPermission(context, true);
        return true;
    }
    if (preference.getKey().equals("persistent_notification") && !(boolean) o) {
        Snackbar.make(rootView, R.string.warning_1_harm_performance, 10000)
                .setAction(R.string.action_revert, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((CheckBoxPreference) preference).setChecked(true);
                        restartService();
                    }
                }).show();
        restartService();
    }
    if (preference.getKey().equals("enabled")) {
        restartService();
    }
    if (preference.getKey().equals("proximity_to_lock")) {
        if (Shell.SU.available() || Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            return true;
        else {
            DevicePolicyManager mDPM = (DevicePolicyManager) context
                    .getSystemService(Context.DEVICE_POLICY_SERVICE);
            final ComponentName mAdminName = new ComponentName(context, DAReceiver.class);
            if ((mDPM != null && mDPM.isAdminActive(mAdminName))) {
                return true;
            }
            new AlertDialog.Builder(getActivity())
                    .setTitle(getString(android.R.string.dialog_alert_title) + "!")
                    .setMessage(getString(R.string.warning_7_disable_fingerprint))
                    .setPositiveButton(getString(android.R.string.yes), (dialogInterface, i) -> {
                        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
                        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                                getString(R.string.settings_proximity));
                        startActivityForResult(intent, DEVICE_ADMIN_REQUEST_CODE);
                    }).setNegativeButton(getString(android.R.string.no), (dialogInterface, i) -> {
                        dialogInterface.dismiss();
                    }).show();
            return false;
        }
    }
    if (preference.getKey().equals("startafterlock") && !(boolean) o) {
        Snackbar.make(rootView, R.string.warning_4_device_not_secured, 10000)
                .setAction(R.string.action_revert, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((CheckBoxPreference) preference).setChecked(true);
                    }
                }).show();
    }
    if (preference.getKey().equals("doze_mode") && (boolean) o) {
        if (Shell.SU.available()) {
            if (!DozeManager.isDumpPermissionGranted(context))
                DozeManager.grantPermission(context, "android.permission.DUMP");
            if (!DozeManager.isDevicePowerPermissionGranted(context))
                DozeManager.grantPermission(context, "android.permission.DEVICE_POWER");
            return true;
        }
        Snackbar.make(rootView, R.string.warning_11_no_root, Snackbar.LENGTH_LONG).show();
        return false;
    }
    if (preference.getKey().equals("camera_shortcut") || preference.getKey().equals("google_now_shortcut")) {
        try {
            if (!hasUsageAccess()) {
                Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
                PackageManager packageManager = getActivity().getPackageManager();
                if (intent.resolveActivity(packageManager) != null) {
                    startActivity(intent);
                } else {
                    Toast.makeText(context,
                            "Please grant usage access permission manually for the app, your device can't do it automatically.",
                            Toast.LENGTH_LONG).show();
                }
                return false;
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
    if (preference.getKey().equals("battery_saver"))
        if ((boolean) o) {
            ((TwoStatePreference) findPreference("doze_mode")).setChecked(true);
            setUpBatterySaverPermission();
        }
    return true;
}

From source file:com.dudu.aios.ui.activity.MainRecordActivity.java

private void activeManage() {
    // ??(??Intent) - AndroidManifest.xml
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);

    // ??//from  w  ww .  ja v  a2  s  .  co m
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);

    // ??(additional explanation) ?????
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "???");

    startActivityForResult(intent, MY_REQUEST_CODE);
}

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

/**
 * Start device admin activation request.
 *
 *//*from   ww w.  j  a  va2s . c  o m*/
private void startDeviceAdminPrompt() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP
            && devicePolicyManager.isProfileOwnerApp(getPackageName())) {
        checkManifestPermissions();
        CommonUtils.callSystemApp(context, null, null, null);
        Log.i("onActivityResult", "Administration enabled!");
    } else {
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(
                Context.DEVICE_POLICY_SERVICE);
        ComponentName cdmDeviceAdmin = new ComponentName(AuthenticationActivity.this,
                AgentDeviceAdminReceiver.class);
        if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) {
            Intent deviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cdmDeviceAdmin);
            deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                    getResources().getString(R.string.device_admin_enable_alert));
            startActivityForResult(deviceAdminIntent, ACTIVATION_REQUEST);
        }
    }
}

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

public void requestAdmin() {
    if (!adminApp && preference_all.getBoolean("pref_lockmode", false) && configurationActivity != null) {
        ComponentName me = new ComponentName(mAppContext, AdminReceiver.class);
        Log.d(LOG_TAG, "launching dpm overlay");
        mAppContext.startActivity(new Intent(getContext(), Configuration.class)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION
                        | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS));
        Log.d(LOG_TAG, "Started configuration activity.");
        Intent coup = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        coup.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, me);
        coup.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, mAppContext.getString(R.string.admin_excuse));
        getConfigurationActivity().startActivityForResult(coup, CoreApp.DEVICE_ADMIN_WAITING);
    }//from  www.j a v  a 2  s . co  m
}