List of usage examples for android.app.admin DevicePolicyManager resetPassword
public boolean resetPassword(String password, int flags)
From source file:org.digitalcampus.oppia.application.AdminGCMListener.java
@Override public void onMessageReceived(String from, Bundle messageData) { Log.d(TAG, "Push message received from: " + from); if (from.startsWith("/topics/")) { // message received from some topic. } else {// w ww . j a va 2 s. c o m String type = messageData.getString(MESSAGE_TYPE); if ((type != null) && (type.equals(TYPE_ADMIN))) { if (!BuildConfig.FLAVOR.equals("admin")) { //Is not the admin-flavor app (we don't have the permission, would produce crash) Log.d(TAG, "Device Administration is disabled :("); return; } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean adminEnabled = prefs.getBoolean(PrefsActivity.PREF_REMOTE_ADMIN, false); //First, we need to check if admin option is enabled if (!adminEnabled) { Log.d(TAG, "Device Administration is disabled :("); return; } String action = messageData.getString(MESSAGE_ACTION); Log.d(TAG, "Remote admin action: " + action); if (ACTION_DISABLE_CAMERA.equals(action)) { ComponentName adminReceiver = new ComponentName(this, AdminReceiver.class); DevicePolicyManager policyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); policyManager.setCameraDisabled(adminReceiver, true); sendNotification(getString(R.string.notification_remote_admin_camera_disabled)); } else if (ACTION_ENABLE_CAMERA.equals(action)) { ComponentName adminReceiver = new ComponentName(this, AdminReceiver.class); DevicePolicyManager policyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); policyManager.setCameraDisabled(adminReceiver, false); sendNotification(getString(R.string.notification_remote_admin_camera_enabled)); } else if (ACTION_PASSWORD_LOCK.equals(action)) { String password = messageData.getString(MESSAGE_PASSWORD); if ((password != null) && !password.equals("")) { DevicePolicyManager policyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); policyManager.resetPassword(password, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY); policyManager.lockNow(); } } } } }