Java Code Examples for android.app.admin.DevicePolicyManager#ACTION_ADD_DEVICE_ADMIN

The following examples show how to use android.app.admin.DevicePolicyManager#ACTION_ADD_DEVICE_ADMIN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigView.java    From MaxLock with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("CommitPrefEdits")
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    int c = -1;
    switch (compoundButton.getId()) {
        case R.id.first_start_app_xposed:
            c++;
        case R.id.first_start_app_settings:
            c++;
        case R.id.first_start_app_package:
            c++;
            MLPreferences.getPrefsApps(getContext()).edit().putBoolean(app_names[c], b).commit();
            break;
        case R.id.first_start_app_device_admin:
            if (b) {
                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin);
                getContext().startActivity(intent);
            } else {
                devicePolicyManager.removeActiveAdmin(deviceAdmin);
            }
            break;
    }
}
 
Example 2
Source File: PermissionUtils.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
public static void askForAdmin(Activity activity) {

        ComponentName mComponentName = new ComponentName(activity, AdminReceiver.class);
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mComponentName);
        activity.startActivity(intent);
    }
 
Example 3
Source File: GetAdminActivity.java    From odm with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View v) {
	/*
	if (v == lock) {
		boolean active = deviceManger.isAdminActive(compName);
		if (active) {
			deviceManger.lockNow();
		}
	}
	*/
	if (v == enable) {
		Logd(TAG, "Attempting to enable admin");
		Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
		intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName);
		intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "ODM requires admin access for locking and wiping the device.");
		startActivityForResult(intent, RESULT_ENABLE);
	}
}
 
Example 4
Source File: DevicePolicyManagerUtils.java    From FreezeYou with Apache License 2.0 6 votes vote down vote up
public static void openDevicePolicyManager(Context context) {
    showToast(context, R.string.needActiveAccessibilityService);
    ComponentName componentName = new ComponentName(context, DeviceAdminReceiver.class);
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
    context.startActivity(intent);
}
 
Example 5
Source File: MainActivity.java    From Lock with Apache License 2.0 6 votes vote down vote up
private void enableAppAsAdministrator() {
    i("[enableAppAsAdministrator] startActivityForResult: requestCode=%d", REQUEST_CODE_ENABLE_ADMIN);
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mCN);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.receiver_expl));
    startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);
}
 
Example 6
Source File: MainActivity.java    From SnooperStopper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
    boolean isChecked = (boolean) newValue;
    if (isChecked) {
        Log.d(TAG, "switchAdmin.isChecked() == true");
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, snooperStopperDeviceAdmin);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                "Monitors failed unlock attempts and shutdowns phone if limit is reached");
        startActivityForResult(intent, ACTIVATION_REQUEST);
    } else {
        Log.d(TAG, "switchAdmin.isChecked() == false");
        devicePolicyManager.removeActiveAdmin(snooperStopperDeviceAdmin);
        updateSwitchAdminHandler.postDelayed(updateSwitchAdminRunnable, 1000);
    }
    return true;
}
 
Example 7
Source File: SettingFragment.java    From RelaxFinger with GNU General Public License v2.0 6 votes vote down vote up
private void lockScreenChange(boolean newValue) {

        mPreferences.put("lockScreenSwitch", newValue);
        mIsAdmin = mDeviceManager.isAdminActive(mComponentName);

        if (newValue) {

            if (!mIsAdmin) {
                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mComponentName);
                mContext.startActivity(intent);
            }
        } else {

            if (mIsAdmin) {

                mDeviceManager.removeActiveAdmin(mComponentName);
            }
        }

    }
 
Example 8
Source File: MainActivity.java    From product-emm with Apache License 2.0 6 votes vote down vote up
/**
 * Start device admin activation request.
 *
 * @param cdmDeviceAdmin - Device admin component.
 */
private void startDeviceAdminPrompt(ComponentName cdmDeviceAdmin) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    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);
    } else {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |
                        Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}
 
Example 9
Source File: DeviceAdminInteractor.java    From notSABS with MIT License 5 votes vote down vote up
/**
 * Force user to enable administrator
 */
public void forceEnableAdmin(Context context) {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Policy provider");
    ((Activity) context).startActivityForResult(intent, RESULT_ENABLE);
}
 
Example 10
Source File: DeviceAdminSample.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (super.onPreferenceChange(preference, newValue)) {
        return true;
    }
    boolean value = (Boolean) newValue;
    if (preference == mEnableCheckbox) {
        if (value != mAdminActive) {
            if (value) {
                // Launch the activity to have the user enable our admin.
                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
                intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                        mActivity.getString(R.string.add_admin_extra_app_text));
                startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);
                // return false - don't update checkbox until we're really active
                return false;
            } else {
                mDPM.removeActiveAdmin(mDeviceAdminSample);
                enableDeviceCapabilitiesArea(false);
                mAdminActive = false;
            }
        }
    } else if (preference == mDisableCameraCheckbox) {
        mDPM.setCameraDisabled(mDeviceAdminSample, value);
        reloadSummaries();
    }
    return true;
}
 
Example 11
Source File: AlreadyRegisteredActivity.java    From product-emm with Apache License 2.0 5 votes vote down vote up
/**
 * Start device admin activation request.
 * @param cdmDeviceAdmin - Device admin component.
 */
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);
}
 
Example 12
Source File: DeviceAdminReceiverLock.java    From libcommon with Apache License 2.0 5 votes vote down vote up
public static void requestScreenLock(@NonNull final Activity activity, final boolean finish) {
	if (!checkScreenLock(activity, finish)) {
		// スクリーンをロックできなかった時はデバイス管理者が無効になってるはずなのでデバイス管理者有効画面を表示する
		final Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
		intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, new ComponentName(activity, DeviceAdminReceiverLock.class));
		intent.putExtra(EXTRA_REQUEST_FINISH, finish);
		activity.startActivityForResult(intent, REQ_SCREEN_LOCK);
	}
}
 
Example 13
Source File: DeviceAdminInteractor.java    From SABS with MIT License 5 votes vote down vote up
/**
 * Force user to enable administrator
 */
public void forceEnableAdmin(Context context) {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Policy provider");
    ((Activity) context).startActivityForResult(intent, RESULT_ENABLE);
}
 
Example 14
Source File: ControlYourDeviceActivity.java    From AdminControl with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show android system dialog to request device admin permission.
 * */
private void promptDeviceAdmin() {
        Intent requestDeviceAdminIntent =
                new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        requestDeviceAdminIntent
                .putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceOwnerComponent);
        startActivityForResult(requestDeviceAdminIntent, ACTIVATION_REQUEST);
}
 
Example 15
Source File: SettingsFragment.java    From always-on-amoled with GNU General Public License v3.0 4 votes vote down vote up
private void askDeviceAdmin(@StringRes int message) {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(message));
    startActivityForResult(intent, DEVICE_ADMIN_REQUEST_CODE);
}
 
Example 16
Source File: URMUtils.java    From rebootmenu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 用辅助功能锁屏
 *
 * @param activity            1
 * @param componentName       2
 * @param requestCode         3
 * @param devicePolicyManager 4
 * @param needConfig          是否需要 配置管理员
 */

public static void lockScreen(@NonNull Activity activity, ComponentName componentName, int requestCode, DevicePolicyManager devicePolicyManager, boolean needConfig) {
    new DebugLog("lockScreen", DebugLog.LogLevel.V);
    //设备管理器是否启用
    boolean active = devicePolicyManager.isAdminActive(componentName);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        //自动移除不必要的管理员,避免在卸载时造成困扰
        if (active) devicePolicyManager.removeActiveAdmin(componentName);
        //请求打开辅助服务设置
        if (!isAccessibilitySettingsOn(activity.getApplicationContext())) {
            new TextToast(activity.getApplicationContext(), activity.getString(R.string.service_disabled));
            try {
                activity.startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
            } catch (Throwable t) {
                t.printStackTrace();
                UIUtils.visibleHint(activity, R.string.accessibility_settings_not_found);
            }
        } else
            LocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(UnRootAccessibility.LOCK_SCREEN_ACTION));
        activity.finish();
    } else {
        if (!active) {
            //请求启用
            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, activity.getString(R.string.service_explanation));
            try {
                activity.startActivityForResult(intent, requestCode);
            } catch (ActivityNotFoundException e) {
                UIUtils.visibleHint(activity, R.string.hint_add_dev_admin_activity_not_found);
            }
        } else {
            devicePolicyManager.lockNow();
            if (needConfig)
                //如果需要二次确认,禁用设备管理器。(这里的策略和root模式的锁屏无需确认不同)
                if (!ConfigManager.get(ConfigManager.NO_NEED_TO_CONFIRM)) {
                    devicePolicyManager.removeActiveAdmin(componentName);
                }
            activity.finish();
        }
    }
}
 
Example 17
Source File: PreferencesOther.java    From habpanelviewer with GNU General Public License v3.0 4 votes vote down vote up
private void installAsAdmin() {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, AdminReceiver.COMP);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.deviceAdminDescription));
    startActivityForResult(intent, Constants.REQUEST_DEVICE_ADMIN);
}
 
Example 18
Source File: MyScreenLocker.java    From SimplePomodoro-android with MIT License 4 votes vote down vote up
public void activeManage() {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, mActivity.getString(R.string.screen_locker_warnning));
    mActivity.startActivityForResult(intent, 0);
}