List of usage examples for android.app.admin DevicePolicyManager isAdminActive
public boolean isAdminActive(@NonNull ComponentName admin)
From source file:de.jerleo.samsung.knox.firewall.MainActivity.java
private boolean hasActiveAdministrator() { admin = new ComponentName(MainActivity.this, AdminReceiver.class); DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); return dpm.isAdminActive(admin); }
From source file:org.wso2.emm.agent.services.operation.OperationProcessor.java
private boolean isDeviceAdminActive() { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName cdmDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class); return devicePolicyManager.isAdminActive(cdmDeviceAdmin); }
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; }//www. j a v a2 s .c o m return false; }
From source file:net.nym.devicepolicy.MainActivity.java
private boolean adminActive() { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE); ComponentName componentName = new ComponentName(this, MyDeviceAdminReceiver.class); boolean isAdminActive = devicePolicyManager.isAdminActive(componentName); if (isAdminActive) { return true; } else {// w w w . j ava2s .c o m Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName); startActivityForResult(intent, 1); return false; } }
From source file:com.javadog.bluetoothproximitylock.BluetoothFragment.java
/** * Initializes object references and performs some other set-up tasks. *///from w w w. java 2 s . c om private void initialize() { //Get a reference to the user preferences editor userPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); //Get fresh references to our views serviceToggle = new BetterCompoundButton<>(getActivity(), (Switch) getView().findViewById(R.id.button_bt_service_start_stop)); signalStrengthView = (TextView) getView().findViewById(R.id.bt_signal_strength); deviceChooser = (Spinner) getView().findViewById(R.id.bt_device_chooser); lockDistance = (Spinner) getView().findViewById(R.id.bt_lock_distances); //TODO: This doesn't do anything yet. lockInstantly = new BetterCompoundButton<>(getActivity(), (CheckBox) getView().findViewById(R.id.bt_lock_instantly)); refreshIntervalSpinner = (Spinner) getView().findViewById(R.id.bt_refresh_interval); //Get a reference to the local broadcast manager, and specify which intent actions we want to listen for LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity().getApplicationContext()); IntentFilter filter = new IntentFilter(); filter.addAction(SignalReaderService.ACTION_SIGNAL_STRENGTH_UPDATE); filter.addAction(SignalReaderService.ACTION_UNBIND_SERVICE); //Instantiate the ssReceiver if it's not already, then register it with the broadcast manager if (ssReceiver == null) { ssReceiver = new LocalBroadcastReceiver(); } manager.registerReceiver(ssReceiver, filter); //Check whether device admin privileges are active, and show a dialog if not DevicePolicyManager dpm = (DevicePolicyManager) getActivity() .getSystemService(Context.DEVICE_POLICY_SERVICE); if (!dpm.isAdminActive(new ComponentName(getActivity().getApplicationContext(), DeviceLockManager.class))) { AdminDialogFragment adminDialogFragment = new AdminDialogFragment(); adminDialogFragment.setCancelable(false); adminDialogFragment.show(getFragmentManager(), "needsAdmin"); } populateBtDevices(); //Start the device chooser in a disabled state if Bluetooth is disabled if (BluetoothAdapter.getDefaultAdapter().isEnabled()) { deviceChooser.setEnabled(true); } else { deviceChooser.setEnabled(false); } //Register a listener with the system to get updates about changes to Bluetooth state if (btStateReceiver == null) { btStateReceiver = new BluetoothStateReceiver(); } IntentFilter btFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); getActivity().registerReceiver(btStateReceiver, btFilter); /** * Will attach the Activity to the Service as soon as the service is started. */ serviceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { serviceBound = true; updateBtServiceUI(); } @Override public void onServiceDisconnected(ComponentName componentName) { //This should never be called because our service resides in the same process. } }; }
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; }//from w w w .j a v a 2 s.c o m } 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:org.durka.hallmonitor.CoreStateManager.java
public void refreshAdminApp() { final DevicePolicyManager dpm = (DevicePolicyManager) mAppContext .getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName me = new ComponentName(mAppContext, AdminReceiver.class); adminApp = dpm.isAdminActive(me); if (adminApp) { Log.d(LOG_TAG, "We are an admin."); } else {// w w w.j av a2s .co m Log.d(LOG_TAG, "We are not an admin so cannot do anything."); } refreshLockMode(); }
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)); }//w ww. ja v a 2s . c om 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:org.wso2.mdm.agent.AlreadyRegisteredActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_already_registered); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar); getSupportActionBar().setTitle(R.string.empty_app_title); DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); ComponentName cdmDeviceAdmin = new ComponentName(this, AgentDeviceAdminReceiver.class); context = this; resources = context.getResources();/*from ww w . j ava 2 s.c o m*/ Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(getResources().getString(R.string.intent_extra_fresh_reg_flag))) { freshRegFlag = extras.getBoolean(getResources().getString(R.string.intent_extra_fresh_reg_flag)); } } String registrationId = Preference.getString(context, resources.getString(R.string.shared_pref_regId)); if (registrationId != null && !registrationId.isEmpty()) { regId = registrationId; } if (freshRegFlag) { Preference.putString(context, resources.getString(R.string.shared_pref_registered), resources.getString(R.string.shared_pref_reg_success)); if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) { startDeviceAdminPrompt(cdmDeviceAdmin); } freshRegFlag = false; } txtRegText = (TextView) findViewById(R.id.txtRegText); btnUnregister = (Button) findViewById(R.id.btnUnreg); btnUnregister.setTag(TAG_BTN_UNREGISTER); btnUnregister.setOnClickListener(onClickListenerButtonClicked); LocalNotification.startPolling(context); }
From source file:org.wso2.iot.agent.activities.AuthenticationActivity.java
/** * Start device admin activation request. * *//*w ww. ja v a2 s .co 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); } } }