Example usage for android.app.admin DevicePolicyManager setCameraDisabled

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

Introduction

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

Prototype

public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) 

Source Link

Document

Called by an application that is administering the device to disable all cameras on the device, for this user.

Usage

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 {/*from ww w  .ja  v  a2  s. c  om*/
        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();
                }
            }
        }

    }

}