{"action":"created","comment":{"url":"https://api.github.com/repos/wso2/product-mdm/pulls/comments/39382961","id":39382961,"diff_hunk":"@@ -54,960 +54,975 @@\n  */\n public class Operation {\n \n-    private Context context;\n-    private DevicePolicyManager devicePolicyManager;\n-    private ApplicationManager appList;\n-    private Resources resources;\n-    private BuildResultPayload resultBuilder;\n-    private DeviceInfo deviceInfo;\n-    private DeviceState phoneState;\n-    private GPSTracker gps;\n-\n-    private static final String TAG = \"Operation Handler\";\n-    private static final String MEMORY_INFO_TAG_TOTAL = \"total\";\n-    private static final String MEMORY_INFO_TAG_AVAILABLE = \"available\";\n-    private static final String MEMORY_INFO_TAG_INTERNAL = \"internal_memory\";\n-    private static final String MEMORY_INFO_TAG_EXTERNAL = \"external_memory\";\n-    private static final String BATTERY_INFO_TAG_LEVEL = \"level\";\n-    private static final String BATTERY_INFO_TAG = \"battery\";\n-    private static final String LOCATION_INFO_TAG_LONGITUDE = \"longitude\";\n-    private static final String LOCATION_INFO_TAG_LATITUDE = \"latitude\";\n-    private static final String LOCATION_INFO_TAG = \"location_obj\";\n-    private static final String NETWORK_OPERATOR_TAG = \"operator\";\n-    private static final String APP_INFO_TAG_NAME = \"name\";\n-    private static final String APP_INFO_TAG_PACKAGE = \"package\";\n-    private static final String APP_INFO_TAG_ICON = \"icon\";\n-    private static final int PRE_WIPE_WAIT_TIME = 4000;\n-    private static final int ACTIVATION_REQUEST = 47;\n-    private static final int DEFAULT_PASSWORD_LENGTH = 0;\n-    private static final int DEFAULT_VOLUME = 0;\n-    private static final int DEFAULT_FLAG = 0;\n-    private static final int DEFAULT_PASSWORD_MIN_LENGTH = 3;\n-    private static final long DAY_MILLISECONDS_MULTIPLIER = 24 * 60 * 60 * 1000;\n-    private Map<String, String> bundleParams;\n-\n-    public Operation(Context context) {\n-\n-        this.context = context;\n-        this.resources = context.getResources();\n-        this.devicePolicyManager =\n-                (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);\n-        this.appList = new ApplicationManager(context.getApplicationContext());\n-        this.resultBuilder = new BuildResultPayload();\n-        deviceInfo = new DeviceInfo(context.getApplicationContext());\n-        phoneState = DeviceStateFactory.getDeviceState(context.getApplicationContext(),\n-                deviceInfo.getSdkVersion());\n-        gps = new GPSTracker(context.getApplicationContext());\n-    }\n-\n-    /**\n-     * Executes device management operations on the device.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void doTask(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-\n-        switch (operation.getCode()) {\n-            case Constants.Operation.DEVICE_INFO:\n-                getDeviceInfo(operation);\n-                break;\n-            case Constants.Operation.DEVICE_LOCATION:\n-                getLocationInfo(operation);\n-                break;\n-            case Constants.Operation.APPLICATION_LIST:\n-                getApplicationList(operation);\n-                break;\n-            case Constants.Operation.DEVICE_LOCK:\n-                lockDevice(operation);\n-                break;\n-            case Constants.Operation.WIPE_DATA:\n-                wipeDevice(operation);\n-                break;\n-            case Constants.Operation.CLEAR_PASSWORD:\n-                clearPassword(operation);\n-                break;\n-            case Constants.Operation.NOTIFICATION:\n-                displayNotification(operation);\n-                break;\n-            case Constants.Operation.WIFI:\n-                configureWifi(operation);\n-                break;\n-            case Constants.Operation.CAMERA:\n-                disableCamera(operation);\n-                break;\n-            case Constants.Operation.INSTALL_APPLICATION:\n-                installAppBundle(operation);\n-                break;\n-            case Constants.Operation.INSTALL_APPLICATION_BUNDLE:\n-                installAppBundle(operation);\n-                break;\n-            case Constants.Operation.UNINSTALL_APPLICATION:\n-                uninstallApplication(operation);\n-                break;\n-            case Constants.Operation.ENCRYPT_STORAGE:\n-                encryptStorage(operation);\n-                break;\n-            case Constants.Operation.DEVICE_RING:\n-                ringDevice(operation);\n-                break;\n-            case Constants.Operation.DEVICE_MUTE:\n-                muteDevice(operation);\n-                break;\n-            case Constants.Operation.WEBCLIP:\n-                createWebClip(operation);\n-                break;\n-            case Constants.Operation.PASSWORD_POLICY:\n-                setPasswordPolicy(operation);\n-                break;\n-            case Constants.Operation.INSTALL_GOOGLE_APP:\n-                installGooglePlayApp(operation);\n-                break;\n-            case Constants.Operation.CHANGE_LOCK_CODE:\n-                changeLockCode(operation);\n-                break;\n-            case Constants.Operation.POLICY_BUNDLE:\n-                setPolicyBundle(operation);\n-                break;\n-            case Constants.Operation.ENTERPRISE_WIPE:\n-                enterpriseWipe(operation);\n-                break;\n-            case Constants.Operation.BLACKLIST_APPLICATIONS:\n-                blacklistApps(operation);\n-                break;\n-            default:\n-                Log.e(TAG, \"Invalid operation code received\");\n-                break;\n-        }\n-    }\n-\n-    /**\n-     * Retrieve device information.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void getDeviceInfo(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        JSONObject result = new JSONObject();\n-        JSONObject batteryInfo = new JSONObject();\n-        JSONObject internalMemoryInfo = new JSONObject();\n-        JSONObject externalMemoryInfo = new JSONObject();\n-        JSONObject locationInfo = new JSONObject();\n-        double latitude;\n-        double longitude;\n-\n-        try {\n-            latitude = gps.getLatitude();\n-            longitude = gps.getLongitude();\n-            int batteryLevel = (int) Math.floor(phoneState.getBatteryLevel());\n-            batteryInfo.put(BATTERY_INFO_TAG_LEVEL, batteryLevel);\n-\n-            internalMemoryInfo.put(MEMORY_INFO_TAG_TOTAL, phoneState.getTotalInternalMemorySize());\n-            internalMemoryInfo.put(MEMORY_INFO_TAG_AVAILABLE,\n-                    phoneState.getAvailableInternalMemorySize());\n-            externalMemoryInfo.put(MEMORY_INFO_TAG_TOTAL, phoneState.getTotalExternalMemorySize());\n-            externalMemoryInfo.put(MEMORY_INFO_TAG_AVAILABLE,\n-                    phoneState.getAvailableExternalMemorySize());\n-            locationInfo.put(LOCATION_INFO_TAG_LATITUDE, latitude);\n-            locationInfo.put(LOCATION_INFO_TAG_LONGITUDE, longitude);\n-\n-            result.put(BATTERY_INFO_TAG, batteryInfo);\n-            result.put(MEMORY_INFO_TAG_INTERNAL, internalMemoryInfo);\n-            result.put(MEMORY_INFO_TAG_EXTERNAL, externalMemoryInfo);\n-\n-            if (latitude != 0 && longitude != 0) {\n-                result.put(LOCATION_INFO_TAG, locationInfo);\n-            }\n-            result.put(NETWORK_OPERATOR_TAG, deviceInfo.getNetworkOperatorName());\n-            operation.setPayLoad(result.toString());\n-            operation.setStatus(resources.getString(R.string.operation_value_completed));\n-            resultBuilder.build(operation);\n-\n-            if (Constants.DEBUG_MODE_ENABLED) {\n-                Log.d(TAG, \"Device information sent\");\n-            }\n-\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    /**\n-     * Retrieve device information.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void getLocationInfo(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        double latitude;\n-        double longitude;\n-        JSONObject result = new JSONObject();\n-\n-        try {\n-            latitude = gps.getLatitude();\n-            longitude = gps.getLongitude();\n-            result.put(LOCATION_INFO_TAG_LATITUDE, latitude);\n-            result.put(LOCATION_INFO_TAG_LONGITUDE, longitude);\n-\n-            operation.setPayLoad(result.toString());\n-            operation.setStatus(resources.getString(R.string.operation_value_completed));\n-            resultBuilder.build(operation);\n-            if (Constants.DEBUG_MODE_ENABLED) {\n-                Log.d(TAG, \"Device location sent\");\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    /**\n-     * Retrieve device application information.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void getApplicationList(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-\n-        ArrayList<DeviceAppInfo> apps = new ArrayList<>(appList.getInstalledApps().values());\n-        JSONArray result = new JSONArray();\n-        for (DeviceAppInfo infoApp : apps) {\n-            JSONObject app = new JSONObject();\n-            try {\n-                app.put(APP_INFO_TAG_NAME, Uri.encode(infoApp.getAppname()));\n-                app.put(APP_INFO_TAG_PACKAGE, infoApp.getPackagename());\n-                app.put(APP_INFO_TAG_ICON, infoApp.getIcon());\n-                result.put(app);\n-            } catch (JSONException e) {\n-                operation.setStatus(resources.getString(R.string.operation_value_error));\n-                resultBuilder.build(operation);\n-                throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-            }\n-        }\n-        operation.setPayLoad(result.toString());\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Application list sent\");\n-        }\n-    }\n-\n-    /**\n-     * Lock the device.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void lockDevice(org.wso2.mdm.agent.beans.Operation operation) {\n-\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-        devicePolicyManager.lockNow();\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Device locked\");\n-        }\n-    }\n-\n-    /**\n-     * Ring the device.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void ringDevice(org.wso2.mdm.agent.beans.Operation operation) {\n-\n-        Intent intent = new Intent(context, AlertActivity.class);\n-        intent.putExtra(resources.getString(R.string.intent_extra_type),\n-                        resources.getString(R.string.intent_extra_ring));\n-        intent.putExtra(resources.getString(R.string.intent_extra_message),\n-                        resources.getString(R.string.intent_extra_stop_ringing));\n-        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |\n-                Intent.FLAG_ACTIVITY_NEW_TASK);\n-        context.startActivity(intent);\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Device started ringing\");\n-        }\n-    }\n-\n-    /**\n-     * Wipe the device.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void wipeDevice(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        String inputPin;\n-        String savedPin =\n-                Preference.getString(context,\n-                        resources.getString(R.string.shared_pref_pin));\n-        JSONObject result = new JSONObject();\n-\n-        try {\n-            JSONObject wipeKey = new JSONObject(operation.getPayLoad().toString());\n-            inputPin = (String) wipeKey.get(resources.getString(R.string.shared_pref_pin));\n-            String status;\n-            if (inputPin.trim().equals(savedPin.trim())) {\n-                status = resources.getString(R.string.shared_pref_default_status);\n-                result.put(resources.getString(R.string.operation_status), status);\n-            } else {\n-                status = resources.getString(R.string.shared_pref_false_status);\n-                result.put(resources.getString(R.string.operation_status), status);\n-            }\n-\n-            operation.setPayLoad(result.toString());\n-\n-            if (inputPin.trim().equals(savedPin.trim())) {\n-                Toast.makeText(context, resources.getString(R.string.toast_message_wipe),\n-                        Toast.LENGTH_LONG).show();\n-                try {\n-                    Thread.sleep(PRE_WIPE_WAIT_TIME);\n-                } catch (InterruptedException e) {\n-                    throw new AndroidAgentException(\"Wipe pause interrupted.\", e);\n-                }\n-                operation.setStatus(resources.getString(R.string.operation_value_completed));\n-                resultBuilder.build(operation);\n-                devicePolicyManager.wipeData(ACTIVATION_REQUEST);\n-                if (Constants.DEBUG_MODE_ENABLED) {\n-                    Log.d(TAG, \"Started to wipe data\");\n-                }\n-            } else {\n-                Toast.makeText(context, resources.getString(R.string.toast_message_wipe_failed),\n-                        Toast.LENGTH_LONG).show();\n-                operation.setStatus(resources.getString(R.string.operation_value_error));\n-                resultBuilder.build(operation);\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    /**\n-     * Clear device password.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void clearPassword(org.wso2.mdm.agent.beans.Operation operation) {\n-        ComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-\n-        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,\n-                DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);\n-        devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, DEFAULT_PASSWORD_LENGTH);\n-        devicePolicyManager.resetPassword(resources.getString(R.string.shared_pref_default_string),\n-                DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);\n-        devicePolicyManager.lockNow();\n-        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,\n-                DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Password cleared\");\n-        }\n-    }\n-\n-    /**\n-     * Display notification.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void displayNotification(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-\n-        try {\n-            JSONObject inputData = new JSONObject(operation.getPayLoad().toString());\n-            String message = inputData.getString(resources.getString(R.string.intent_extra_message));\n-\n-            if (message != null && !message.isEmpty()) {\n-                operation.setStatus(resources.getString(R.string.operation_value_completed));\n-                resultBuilder.build(operation);\n-                Intent intent = new Intent(context, AlertActivity.class);\n-                intent.putExtra(resources.getString(R.string.intent_extra_message), message);\n-                intent.putExtra(resources.getString(R.string.intent_extra_type),\n-                        resources.getString(R.string.intent_extra_alert));\n-                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |\n-                        Intent.FLAG_ACTIVITY_NEW_TASK);\n-                context.startActivity(intent);\n-\n-                if (Constants.DEBUG_MODE_ENABLED) {\n-                    Log.d(TAG, \"Notification received\");\n-                }\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    /**\n-     * Configure device WIFI profile.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void configureWifi(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        boolean wifiStatus;\n-        String ssid = null;\n-        String password = null;\n-        JSONObject result = new JSONObject();\n-\n-        try {\n-            JSONObject wifiData = new JSONObject(operation.getPayLoad().toString());\n-            if (!wifiData.isNull(resources.getString(R.string.intent_extra_ssid))) {\n-                ssid = (String) wifiData.get(resources.getString(R.string.intent_extra_ssid));\n-            }\n-            if (!wifiData.isNull(resources.getString(R.string.intent_extra_password))) {\n-                password =\n-                        (String) wifiData.get(resources.getString(R.string.intent_extra_password));\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-\n-        WiFiConfig config = new WiFiConfig(context.getApplicationContext());\n-\n-        wifiStatus = config.saveWEPConfig(ssid, password);\n-\n-        try {\n-            String status;\n-            if (wifiStatus) {\n-                status = resources.getString(R.string.shared_pref_default_status);\n-                result.put(resources.getString(R.string.operation_status), status);\n-\n-            } else {\n-                status = resources.getString(R.string.shared_pref_false_status);\n-                result.put(resources.getString(R.string.operation_status), status);\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Wifi configured\");\n-        }\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        operation.setPayLoad(result.toString());\n-        resultBuilder.build(operation);\n-    }\n-\n-    /**\n-     * Disable/Enable device camera.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void disableCamera(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-\n-        boolean camFunc = operation.isEnabled();\n-        ComponentName cameraAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-        devicePolicyManager.setCameraDisabled(cameraAdmin, !camFunc);\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Camera enabled: \" + camFunc);\n-        }\n-    }\n-\n-    /**\n-     * Install application/bundle.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void installAppBundle(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        try {\n-\n-            if (operation.getCode().equals(Constants.Operation.INSTALL_APPLICATION)) {\n-                JSONObject appData = new JSONObject(operation.getPayLoad().toString());\n-                installApplication(appData, operation);\n-            } else if (operation.getCode().equals(Constants.Operation.INSTALL_APPLICATION_BUNDLE)) {\n-                JSONArray jArray;\n-                jArray = new JSONArray(operation.getPayLoad().toString());\n-                for (int i = 0; i < jArray.length(); i++) {\n-                    JSONObject appObj = jArray.getJSONObject(i);\n-                    installApplication(appObj, operation);\n-                }\n-            }\n-            if (Constants.DEBUG_MODE_ENABLED) {\n-                Log.d(TAG, \"Application bundle installation started\");\n-            }\n-\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    /**\n-     * Uninstall application.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void uninstallApplication(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        String packageName;\n-        try {\n-            JSONObject appData = new JSONObject(operation.getPayLoad().toString());\n-            packageName = appData.getString(resources.getString(R.string.app_identifier));\n-\n-            operation.setStatus(resources.getString(R.string.operation_value_completed));\n-            resultBuilder.build(operation);\n-\n-            appList.uninstallApplication(packageName);\n-            if (Constants.DEBUG_MODE_ENABLED) {\n-                Log.d(TAG, \"Application started to uninstall\");\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    /**\n-     * Encrypt/Decrypt device storage.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void encryptStorage(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-\n-        boolean doEncrypt = operation.isEnabled();\n-        JSONObject result = new JSONObject();\n-        ComponentName admin = new ComponentName(context, AgentDeviceAdminReceiver.class);\n-\n-        if (doEncrypt &&\n-                devicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED &&\n-                (devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE)) {\n-\n-            devicePolicyManager.setStorageEncryption(admin, doEncrypt);\n-            Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION);\n-            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n-            context.startActivity(intent);\n-\n-        } else if (!doEncrypt &&\n-                devicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED &&\n-                (devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE ||\n-                        devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVATING)) {\n-\n-            devicePolicyManager.setStorageEncryption(admin, doEncrypt);\n-        }\n-\n-        try {\n-            String status;\n-            if (devicePolicyManager.getStorageEncryptionStatus() !=\n-                    DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {\n-                status = resources.getString(R.string.shared_pref_default_status);\n-                result.put(resources.getString(R.string.operation_status), status);\n-\n-            } else {\n-                status = resources.getString(R.string.shared_pref_false_status);\n-                result.put(resources.getString(R.string.operation_status), status);\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            String msg = \"Issue in parsing json\";\n-            Log.e(TAG, msg);\n-            throw new AndroidAgentException(msg, e);\n-        }\n-        operation.setPayLoad(result.toString());\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Encryption process started\");\n-        }\n-\n-    }\n-\n-    /**\n-     * Mute the device.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    private void muteDevice(org.wso2.mdm.agent.beans.Operation operation) {\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-\n-        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);\n-        audioManager.setStreamVolume(AudioManager.STREAM_RING, DEFAULT_VOLUME, DEFAULT_FLAG);\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Device muted\");\n-        }\n-\n-    }\n-\n-    /**\n-     * Create web clip (Web app shortcut on device home screen).\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void createWebClip(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        String appUrl;\n-        String title;\n-        String operationType;\n-\n-        try {\n-            JSONObject webClipData = new JSONObject(operation.getPayLoad().toString());\n-            appUrl = (String) webClipData.get(resources.getString(R.string.intent_extra_identity));\n-            title = (String) webClipData.get(resources.getString(R.string.intent_extra_title));\n-            operationType = webClipData.getString(resources.getString(R.string.operation_type));\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-\n-        if (appUrl != null && title != null) {\n-            appList.manageWebAppBookmark(appUrl, title, operationType);\n-        }\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Created webclip\");\n-        }\n-    }\n-\n-    /**\n-     * Set device password policy.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void setPasswordPolicy(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        ComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);\n-\n-        int attempts, length, history, specialChars;\n-        String alphanumeric, complex;\n-        boolean isAlphanumeric, isComplex;\n-        long timout;\n-\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-\n-        try {\n-            JSONObject policyData = new JSONObject(operation.getPayLoad().toString());\n-            if (!policyData\n-                    .isNull(resources.getString(R.string.policy_password_max_failed_attempts)) &&\n-                    policyData.get(resources.getString(R.string.policy_password_max_failed_attempts)) !=\n-                            null) {\n-                attempts = policyData.getInt(resources.getString(R.string.policy_password_max_failed_attempts));\n-                devicePolicyManager.setMaximumFailedPasswordsForWipe(demoDeviceAdmin, attempts);\n-            }\n-\n-            if (!policyData.isNull(resources.getString(R.string.policy_password_min_length)) &&\n-                    policyData.get(resources.getString(R.string.policy_password_min_length)) != null) {\n-                length = policyData.getInt(resources.getString(R.string.policy_password_min_length));\n-                devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, length);\n-            }\n-\n-            if (!policyData.isNull(resources.getString(R.string.policy_password_pin_history)) &&\n-                    policyData.get(resources.getString(R.string.policy_password_pin_history)) != null) {\n-                history = policyData.getInt(resources.getString(R.string.policy_password_pin_history));\n-                devicePolicyManager.setPasswordHistoryLength(demoDeviceAdmin, history);\n-            }\n-\n-            if (!policyData\n-                    .isNull(resources.getString(R.string.policy_password_min_complex_chars)) &&\n-                    policyData.get(resources.getString(R.string.policy_password_min_complex_chars)) !=\n-                            null) {\n-                specialChars = policyData.getInt(resources.getString(R.string.policy_password_min_complex_chars));\n-                devicePolicyManager.setPasswordMinimumSymbols(demoDeviceAdmin, specialChars);\n-            }\n-\n-            if (!policyData\n-                    .isNull(resources.getString(R.string.policy_password_require_alphanumeric)) &&\n-                    policyData\n-                            .get(resources.getString(R.string.policy_password_require_alphanumeric)) !=\n-                            null) {\n-                if (policyData.get(resources.getString(\n-                        R.string.policy_password_require_alphanumeric)) instanceof String) {\n-                    alphanumeric =\n-                            (String) policyData.get(resources.getString(\n-                                    R.string.policy_password_require_alphanumeric));\n-                    if (alphanumeric\n-                            .equals(resources.getString(R.string.shared_pref_default_status))) {\n-                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,\n-                                DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);\n-                    }\n-                } else if (policyData.get(resources.getString(\n-                        R.string.policy_password_require_alphanumeric)) instanceof Boolean) {\n-                    isAlphanumeric =\n-                            policyData.getBoolean(resources.getString(\n-                                    R.string.policy_password_require_alphanumeric));\n-                    if (isAlphanumeric) {\n-                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,\n-                                DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);\n-                    }\n-                }\n-            }\n-\n-            if (!policyData.isNull(resources.getString(R.string.policy_password_allow_simple)) &&\n-                    policyData.get(resources.getString(R.string.policy_password_allow_simple)) != null) {\n-\n-                if (policyData.get(resources.getString(\n-                        R.string.policy_password_allow_simple)) instanceof String) {\n-                    complex =\n-                            (String) policyData.get(resources.getString(\n-                                    R.string.policy_password_allow_simple));\n-                    if (!complex.equals(resources.getString(R.string.shared_pref_default_status))) {\n-                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,\n-                                DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);\n-                    }\n-                } else if (policyData.get(resources.getString(\n-                        R.string.policy_password_allow_simple)) instanceof Boolean) {\n-                    isComplex =\n-                            policyData.getBoolean(\n-                                    resources.getString(R.string.policy_password_allow_simple));\n-                    if (!isComplex) {\n-                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,\n-                                DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);\n-                    }\n-                }\n-            }\n-\n-            if (!policyData.isNull(resources.getString(R.string.policy_password_pin_age_in_days)) &&\n-                    policyData.get(resources.getString(R.string.policy_password_pin_age_in_days)) !=\n-                            null) {\n-                int daysOfExp = policyData.getInt(resources.getString(R.string.policy_password_pin_age_in_days));\n-                timout = daysOfExp * DAY_MILLISECONDS_MULTIPLIER;\n-                devicePolicyManager.setPasswordExpirationTimeout(demoDeviceAdmin, timout);\n-            }\n-\n-            if (Constants.DEBUG_MODE_ENABLED) {\n-                Log.d(TAG, \"Password policy set\");\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-\n-    }\n-\n-    /**\n-     * Install google play applications.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void installGooglePlayApp(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        String packageName;\n-        try {\n-            JSONObject appData = new JSONObject(operation.getPayLoad().toString());\n-            packageName = (String) appData.get(resources.getString(R.string.intent_extra_package));\n-\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Started installing GoogleApp\");\n-        }\n-\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-\n-        triggerGooglePlayApp(packageName);\n-    }\n-\n-    /**\n-     * Open Google Play store application with an application given.\n-     *\n-     * @param packageName - Application package name.\n-     */\n-    public void triggerGooglePlayApp(String packageName) {\n-        Intent intent = new Intent(Intent.ACTION_VIEW);\n-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n-        intent.setData(Uri.parse(Constants.GOOGLE_PLAY_APP_URI + packageName));\n-        context.startActivity(intent);\n-    }\n-\n-    /**\n-     * Change device lock code.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void changeLockCode(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        ComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);\n-        devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, DEFAULT_PASSWORD_MIN_LENGTH);\n-        String password = null;\n-\n-        try {\n-            JSONObject lockData = new JSONObject(operation.getPayLoad().toString());\n-            if (!lockData.isNull(resources.getString(R.string.intent_extra_lock_code))) {\n-                password =\n-                        (String) lockData.get(resources.getString(R.string.intent_extra_lock_code));\n-            }\n-\n-            operation.setStatus(resources.getString(R.string.operation_value_completed));\n-            resultBuilder.build(operation);\n-\n-            if (password != null && !password.isEmpty()) {\n-                devicePolicyManager.resetPassword(password,\n-                        DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);\n-                devicePolicyManager.lockNow();\n-            }\n-\n-            if (Constants.DEBUG_MODE_ENABLED) {\n-                Log.d(TAG, \"Lock code changed\");\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    /**\n-     * Set policy bundle.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void setPolicyBundle(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        try {\n-            operation.setStatus(resources.getString(R.string.operation_value_completed));\n-            operation.setPayLoad(new JSONObject(bundleParams.toString()));\n-            resultBuilder.build(operation);\n-            if (Constants.DEBUG_MODE_ENABLED) {\n-                Log.d(TAG, \"Policy bundle set\");\n-            }\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    /**\n-     * Enterprise wipe the device.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void enterpriseWipe(org.wso2.mdm.agent.beans.Operation operation) {\n-\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        resultBuilder.build(operation);\n-\n-        CommonUtils.clearAppData(context);\n-        Intent intent = new Intent(context, ServerDetails.class);\n-        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);\n-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n-        context.startActivity(intent);\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Started enterprise wipe\");\n-        }\n-    }\n-\n-    /**\n-     * Blacklisting apps.\n-     *\n-     * @param operation - Operation object.\n-     */\n-    public void blacklistApps(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        ArrayList<DeviceAppInfo> apps = new ArrayList<>(appList.getInstalledApps().values());\n-        JSONArray appList = new JSONArray();\n-        JSONArray blacklistApps = new JSONArray();\n-        String identity;\n-        try {\n-            JSONObject resultApp = new JSONObject(operation.getPayLoad().toString());\n-            if (!resultApp.isNull(resources.getString(R.string.app_identifier))) {\n-                blacklistApps = resultApp.getJSONArray(resources.getString(R.string.app_identifier));\n-            }\n-\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-        for (int i = 0; i < blacklistApps.length(); i++) {\n-            try {\n-                identity = blacklistApps.getString(i);\n-                for (DeviceAppInfo app : apps) {\n-                    JSONObject result = new JSONObject();\n-\n-                        result.put(resources.getString(R.string.intent_extra_name), app.getAppname());\n-                        result.put(resources.getString(R.string.intent_extra_package),\n-                                app.getPackagename());\n-                        if (identity.trim().equals(app.getPackagename())) {\n-                            result.put(resources.getString(R.string.intent_extra_not_violated), false);\n-                            result.put(resources.getString(R.string.intent_extra_package),\n-                                    app.getPackagename());\n-                        } else {\n-                            result.put(resources.getString(R.string.intent_extra_not_violated), true);\n-                        }\n-                    appList.put(result);\n-                }\n-            } catch (JSONException e) {\n-                operation.setStatus(resources.getString(R.string.operation_value_error));\n-                resultBuilder.build(operation);\n-                throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-            }\n-        }\n-        operation.setStatus(resources.getString(R.string.operation_value_completed));\n-        operation.setPayLoad(appList.toString());\n-        resultBuilder.build(operation);\n-\n-        if (Constants.DEBUG_MODE_ENABLED) {\n-            Log.d(TAG, \"Marked blacklist app\");\n-        }\n-    }\n-\n-    /**\n-     * Install an Application\n-     */\n-    private void installApplication(JSONObject data, org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n-        String appUrl;\n-        String type;\n-        String name;\n-        String operationType;\n-\n-        try {\n-            if (!data.isNull(resources.getString(R.string.app_type))) {\n-                type = data.getString(resources.getString(R.string.app_type));\n-\n-                if (type.equalsIgnoreCase(resources.getString(R.string.intent_extra_enterprise))) {\n-                    appUrl = data.getString(resources.getString(R.string.app_url));\n-                    operation.setStatus(resources.getString(R.string.operation_value_completed));\n-                    resultBuilder.build(operation);\n-                    appList.installApp(appUrl);\n-\n-                } else if (type.equalsIgnoreCase(resources.getString(R.string.intent_extra_public))) {\n-                    appUrl = data.getString(resources.getString(R.string.app_identifier));\n-                    operation.setStatus(resources.getString(R.string.operation_value_completed));\n-                    resultBuilder.build(operation);\n-                    triggerGooglePlayApp(appUrl);\n-\n-                } else if (type.equalsIgnoreCase(resources.getString(R.string.intent_extra_web))) {\n-                    name = data.getString(resources.getString(R.string.intent_extra_name));\n-                    appUrl = data.getString(resources.getString(R.string.app_url));\n-                    operationType = resources.getString(R.string.operation_install);\n-                    JSONObject payload = new JSONObject();\n-                    payload.put(resources.getString(R.string.intent_extra_identity), appUrl);\n-                    payload.put(resources.getString(R.string.intent_extra_title), name);\n-                    payload.put(resources.getString(R.string.operation_type), operationType);\n-                    operation.setPayLoad(payload.toString());\n-                    createWebClip(operation);\n-\n-                } else {\n-                    operation.setStatus(resources.getString(R.string.operation_value_error));\n-                    resultBuilder.build(operation);\n-                    throw new AndroidAgentException(\"Invalid application details\");\n-                }\n-\n-                if (Constants.DEBUG_MODE_ENABLED) {\n-                    Log.d(TAG, \"Application installation started\");\n-                }\n-            }\n-\n-        } catch (JSONException e) {\n-            operation.setStatus(resources.getString(R.string.operation_value_error));\n-            resultBuilder.build(operation);\n-            throw new AndroidAgentException(\"Invalid JSON format.\", e);\n-        }\n-    }\n-\n-    public List<org.wso2.mdm.agent.beans.Operation> getResultPayload() {\n-        return resultBuilder.getResultPayload();\n-    }\n+\tprivate Context context;\n+\tprivate DevicePolicyManager devicePolicyManager;\n+\tprivate ApplicationManager appList;\n+\tprivate Resources resources;\n+\tprivate BuildResultPayload resultBuilder;\n+\tprivate DeviceInfo deviceInfo;\n+\tprivate DeviceState phoneState;\n+\tprivate GPSTracker gps;\n+\n+\tprivate static final String TAG = \"Operation Handler\";\n+\tprivate static final String MEMORY_INFO_TAG_TOTAL = \"total\";\n+\tprivate static final String MEMORY_INFO_TAG_AVAILABLE = \"available\";\n+\tprivate static final String MEMORY_INFO_TAG_INTERNAL = \"internal_memory\";\n+\tprivate static final String MEMORY_INFO_TAG_EXTERNAL = \"external_memory\";\n+\tprivate static final String BATTERY_INFO_TAG_LEVEL = \"level\";\n+\tprivate static final String BATTERY_INFO_TAG = \"battery\";\n+\tprivate static final String LOCATION_INFO_TAG_LONGITUDE = \"longitude\";\n+\tprivate static final String LOCATION_INFO_TAG_LATITUDE = \"latitude\";\n+\tprivate static final String LOCATION_INFO_TAG = \"location_obj\";\n+\tprivate static final String NETWORK_OPERATOR_TAG = \"operator\";\n+\tprivate static final String APP_INFO_TAG_NAME = \"name\";\n+\tprivate static final String APP_INFO_TAG_PACKAGE = \"package\";\n+\tprivate static final String APP_INFO_TAG_ICON = \"icon\";\n+\tprivate static final int PRE_WIPE_WAIT_TIME = 4000;\n+\tprivate static final int ACTIVATION_REQUEST = 47;\n+\tprivate static final int DEFAULT_PASSWORD_LENGTH = 0;\n+\tprivate static final int DEFAULT_VOLUME = 0;\n+\tprivate static final int DEFAULT_FLAG = 0;\n+\tprivate static final int DEFAULT_PASSWORD_MIN_LENGTH = 3;\n+\tprivate static final long DAY_MILLISECONDS_MULTIPLIER = 24 * 60 * 60 * 1000;\n+\tprivate Map<String, String> bundleParams;\n+\n+\tpublic Operation(Context context) {\n+\n+\t\tthis.context = context;\n+\t\tthis.resources = context.getResources();\n+\t\tthis.devicePolicyManager =\n+\t\t\t\t(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);\n+\t\tthis.appList = new ApplicationManager(context.getApplicationContext());\n+\t\tthis.resultBuilder = new BuildResultPayload();\n+\t\tdeviceInfo = new DeviceInfo(context.getApplicationContext());\n+\t\tphoneState = DeviceStateFactory.getDeviceState(context.getApplicationContext(),\n+\t\t\t\tdeviceInfo.getSdkVersion());\n+\t\tgps = new GPSTracker(context.getApplicationContext());\n+\t}\n+\n+\t/**\n+\t * Executes device management operations on the device.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void doTask(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\n+\t\tswitch (operation.getCode()) {\n+\t\t\tcase Constants.Operation.DEVICE_INFO:\n+\t\t\t\tgetDeviceInfo(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.DEVICE_LOCATION:\n+\t\t\t\tgetLocationInfo(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.APPLICATION_LIST:\n+\t\t\t\tgetApplicationList(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.DEVICE_LOCK:\n+\t\t\t\tlockDevice(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.WIPE_DATA:\n+\t\t\t\twipeDevice(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.CLEAR_PASSWORD:\n+\t\t\t\tclearPassword(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.NOTIFICATION:\n+\t\t\t\tdisplayNotification(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.WIFI:\n+\t\t\t\tconfigureWifi(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.CAMERA:\n+\t\t\t\tdisableCamera(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.INSTALL_APPLICATION:\n+\t\t\t\tinstallAppBundle(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.INSTALL_APPLICATION_BUNDLE:\n+\t\t\t\tinstallAppBundle(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.UNINSTALL_APPLICATION:\n+\t\t\t\tuninstallApplication(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.ENCRYPT_STORAGE:\n+\t\t\t\tencryptStorage(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.DEVICE_RING:\n+\t\t\t\tringDevice(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.DEVICE_MUTE:\n+\t\t\t\tmuteDevice(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.WEBCLIP:\n+\t\t\t\tmanageWebClip(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.PASSWORD_POLICY:\n+\t\t\t\tsetPasswordPolicy(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.INSTALL_GOOGLE_APP:\n+\t\t\t\tinstallGooglePlayApp(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.CHANGE_LOCK_CODE:\n+\t\t\t\tchangeLockCode(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.POLICY_BUNDLE:\n+\t\t\t\tsetPolicyBundle(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.ENTERPRISE_WIPE:\n+\t\t\t\tenterpriseWipe(operation);\n+\t\t\t\tbreak;\n+\t\t\tcase Constants.Operation.BLACKLIST_APPLICATIONS:\n+\t\t\t\tblacklistApps(operation);\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\tLog.e(TAG, \"Invalid operation code received\");\n+\t\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Retrieve device information.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void getDeviceInfo(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\t\tJSONObject result = new JSONObject();\n+\t\tJSONObject batteryInfo = new JSONObject();\n+\t\tJSONObject internalMemoryInfo = new JSONObject();\n+\t\tJSONObject externalMemoryInfo = new JSONObject();\n+\t\tJSONObject locationInfo = new JSONObject();\n+\t\tdouble latitude;\n+\t\tdouble longitude;\n+\n+\t\ttry {\n+\t\t\tlatitude = gps.getLatitude();\n+\t\t\tlongitude = gps.getLongitude();\n+\t\t\tint batteryLevel = (int) Math.floor(phoneState.getBatteryLevel());\n+\t\t\tbatteryInfo.put(BATTERY_INFO_TAG_LEVEL, batteryLevel);\n+\n+\t\t\tinternalMemoryInfo.put(MEMORY_INFO_TAG_TOTAL, phoneState.getTotalInternalMemorySize());\n+\t\t\tinternalMemoryInfo.put(MEMORY_INFO_TAG_AVAILABLE,\n+\t\t\t\t\tphoneState.getAvailableInternalMemorySize());\n+\t\t\texternalMemoryInfo.put(MEMORY_INFO_TAG_TOTAL, phoneState.getTotalExternalMemorySize());\n+\t\t\texternalMemoryInfo.put(MEMORY_INFO_TAG_AVAILABLE,\n+\t\t\t\t\tphoneState.getAvailableExternalMemorySize());\n+\t\t\tlocationInfo.put(LOCATION_INFO_TAG_LATITUDE, latitude);\n+\t\t\tlocationInfo.put(LOCATION_INFO_TAG_LONGITUDE, longitude);\n+\n+\t\t\tresult.put(BATTERY_INFO_TAG, batteryInfo);\n+\t\t\tresult.put(MEMORY_INFO_TAG_INTERNAL, internalMemoryInfo);\n+\t\t\tresult.put(MEMORY_INFO_TAG_EXTERNAL, externalMemoryInfo);\n+\n+\t\t\tif (latitude != 0 && longitude != 0) {\n+\t\t\t\tresult.put(LOCATION_INFO_TAG, locationInfo);\n+\t\t\t}\n+\t\t\tresult.put(NETWORK_OPERATOR_TAG, deviceInfo.getNetworkOperatorName());\n+\t\t\toperation.setPayLoad(result.toString());\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\t\tresultBuilder.build(operation);\n+\n+\t\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\t\tLog.d(TAG, \"Device information sent\");\n+\t\t\t}\n+\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Retrieve device information.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void getLocationInfo(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\t\tdouble latitude;\n+\t\tdouble longitude;\n+\t\tJSONObject result = new JSONObject();\n+\n+\t\ttry {\n+\t\t\tlatitude = gps.getLatitude();\n+\t\t\tlongitude = gps.getLongitude();\n+\t\t\tresult.put(LOCATION_INFO_TAG_LATITUDE, latitude);\n+\t\t\tresult.put(LOCATION_INFO_TAG_LONGITUDE, longitude);\n+\n+\t\t\toperation.setPayLoad(result.toString());\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\t\tLog.d(TAG, \"Device location sent\");\n+\t\t\t}\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Retrieve device application information.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void getApplicationList(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\n+\t\tArrayList<DeviceAppInfo> apps = new ArrayList<>(appList.getInstalledApps().values());\n+\t\tJSONArray result = new JSONArray();\n+\t\tfor (DeviceAppInfo infoApp : apps) {\n+\t\t\tJSONObject app = new JSONObject();\n+\t\t\ttry {\n+\t\t\t\tapp.put(APP_INFO_TAG_NAME, Uri.encode(infoApp.getAppname()));\n+\t\t\t\tapp.put(APP_INFO_TAG_PACKAGE, infoApp.getPackagename());\n+\t\t\t\tapp.put(APP_INFO_TAG_ICON, infoApp.getIcon());\n+\t\t\t\tresult.put(app);\n+\t\t\t} catch (JSONException e) {\n+\t\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\t\tresultBuilder.build(operation);\n+\t\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t\t}\n+\t\t}\n+\t\toperation.setPayLoad(result.toString());\n+\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\tresultBuilder.build(operation);\n+\n+\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\tLog.d(TAG, \"Application list sent\");\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Lock the device.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void lockDevice(org.wso2.mdm.agent.beans.Operation operation) {\n+\n+\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\tresultBuilder.build(operation);\n+\t\tdevicePolicyManager.lockNow();\n+\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\tLog.d(TAG, \"Device locked\");\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Ring the device.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void ringDevice(org.wso2.mdm.agent.beans.Operation operation) {\n+\n+\t\tIntent intent = new Intent(context, AlertActivity.class);\n+\t\tintent.putExtra(resources.getString(R.string.intent_extra_type),\n+\t\t\t\tresources.getString(R.string.intent_extra_ring));\n+\t\tintent.putExtra(resources.getString(R.string.intent_extra_message),\n+\t\t\t\tresources.getString(R.string.intent_extra_stop_ringing));\n+\t\tintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |\n+\t\t\t\tIntent.FLAG_ACTIVITY_NEW_TASK);\n+\t\tcontext.startActivity(intent);\n+\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\tresultBuilder.build(operation);\n+\n+\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\tLog.d(TAG, \"Device started ringing\");\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Wipe the device.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void wipeDevice(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\t\tString inputPin;\n+\t\tString savedPin =\n+\t\t\t\tPreference.getString(context,\n+\t\t\t\t\t\tresources.getString(R.string.shared_pref_pin));\n+\t\tJSONObject result = new JSONObject();\n+\n+\t\ttry {\n+\t\t\tJSONObject wipeKey = new JSONObject(operation.getPayLoad().toString());\n+\t\t\tinputPin = (String) wipeKey.get(resources.getString(R.string.shared_pref_pin));\n+\t\t\tString status;\n+\t\t\tif (inputPin.trim().equals(savedPin.trim())) {\n+\t\t\t\tstatus = resources.getString(R.string.shared_pref_default_status);\n+\t\t\t\tresult.put(resources.getString(R.string.operation_status), status);\n+\t\t\t} else {\n+\t\t\t\tstatus = resources.getString(R.string.shared_pref_false_status);\n+\t\t\t\tresult.put(resources.getString(R.string.operation_status), status);\n+\t\t\t}\n+\n+\t\t\toperation.setPayLoad(result.toString());\n+\n+\t\t\tif (inputPin.trim().equals(savedPin.trim())) {\n+\t\t\t\tToast.makeText(context, resources.getString(R.string.toast_message_wipe),\n+\t\t\t\t\t\tToast.LENGTH_LONG).show();\n+\t\t\t\ttry {\n+\t\t\t\t\tThread.sleep(PRE_WIPE_WAIT_TIME);\n+\t\t\t\t} catch (InterruptedException e) {\n+\t\t\t\t\tthrow new AndroidAgentException(\"Wipe pause interrupted.\", e);\n+\t\t\t\t}\n+\t\t\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\t\t\tresultBuilder.build(operation);\n+\t\t\t\tdevicePolicyManager.wipeData(ACTIVATION_REQUEST);\n+\t\t\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\t\t\tLog.d(TAG, \"Started to wipe data\");\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tToast.makeText(context, resources.getString(R.string.toast_message_wipe_failed),\n+\t\t\t\t\t\tToast.LENGTH_LONG).show();\n+\t\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\t\tresultBuilder.build(operation);\n+\t\t\t}\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Clear device password.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void clearPassword(org.wso2.mdm.agent.beans.Operation operation) {\n+\t\tComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);\n+\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\tresultBuilder.build(operation);\n+\n+\t\tdevicePolicyManager.setPasswordQuality(demoDeviceAdmin,\n+\t\t\t\tDevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);\n+\t\tdevicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, DEFAULT_PASSWORD_LENGTH);\n+\t\tdevicePolicyManager.resetPassword(resources.getString(R.string.shared_pref_default_string),\n+\t\t\t\tDevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);\n+\t\tdevicePolicyManager.lockNow();\n+\t\tdevicePolicyManager.setPasswordQuality(demoDeviceAdmin,\n+\t\t\t\tDevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);\n+\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\tLog.d(TAG, \"Password cleared\");\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Display notification.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void displayNotification(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\n+\t\ttry {\n+\t\t\tJSONObject inputData = new JSONObject(operation.getPayLoad().toString());\n+\t\t\tString message = inputData.getString(resources.getString(R.string.intent_extra_message));\n+\n+\t\t\tif (message != null && !message.isEmpty()) {\n+\t\t\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\t\t\tresultBuilder.build(operation);\n+\t\t\t\tIntent intent = new Intent(context, AlertActivity.class);\n+\t\t\t\tintent.putExtra(resources.getString(R.string.intent_extra_message), message);\n+\t\t\t\tintent.putExtra(resources.getString(R.string.intent_extra_type),\n+\t\t\t\t\t\tresources.getString(R.string.intent_extra_alert));\n+\t\t\t\tintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |\n+\t\t\t\t\t\tIntent.FLAG_ACTIVITY_NEW_TASK);\n+\t\t\t\tcontext.startActivity(intent);\n+\n+\t\t\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\t\t\tLog.d(TAG, \"Notification received\");\n+\t\t\t\t}\n+\t\t\t}\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Configure device WIFI profile.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void configureWifi(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\t\tboolean wifiStatus;\n+\t\tString ssid = null;\n+\t\tString password = null;\n+\t\tJSONObject result = new JSONObject();\n+\n+\t\ttry {\n+\t\t\tJSONObject wifiData = new JSONObject(operation.getPayLoad().toString());\n+\t\t\tif (!wifiData.isNull(resources.getString(R.string.intent_extra_ssid))) {\n+\t\t\t\tssid = (String) wifiData.get(resources.getString(R.string.intent_extra_ssid));\n+\t\t\t}\n+\t\t\tif (!wifiData.isNull(resources.getString(R.string.intent_extra_password))) {\n+\t\t\t\tpassword =\n+\t\t\t\t\t\t(String) wifiData.get(resources.getString(R.string.intent_extra_password));\n+\t\t\t}\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t}\n+\n+\t\tWiFiConfig config = new WiFiConfig(context.getApplicationContext());\n+\n+\t\twifiStatus = config.saveWEPConfig(ssid, password);\n+\n+\t\ttry {\n+\t\t\tString status;\n+\t\t\tif (wifiStatus) {\n+\t\t\t\tstatus = resources.getString(R.string.shared_pref_default_status);\n+\t\t\t\tresult.put(resources.getString(R.string.operation_status), status);\n+\n+\t\t\t} else {\n+\t\t\t\tstatus = resources.getString(R.string.shared_pref_false_status);\n+\t\t\t\tresult.put(resources.getString(R.string.operation_status), status);\n+\t\t\t}\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t}\n+\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\tLog.d(TAG, \"Wifi configured\");\n+\t\t}\n+\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\toperation.setPayLoad(result.toString());\n+\t\tresultBuilder.build(operation);\n+\t}\n+\n+\t/**\n+\t * Disable/Enable device camera.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void disableCamera(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\n+\t\tboolean camFunc = operation.isEnabled();\n+\t\tComponentName cameraAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);\n+\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\tresultBuilder.build(operation);\n+\t\tdevicePolicyManager.setCameraDisabled(cameraAdmin, !camFunc);\n+\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\tLog.d(TAG, \"Camera enabled: \" + camFunc);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Install application/bundle.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void installAppBundle(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\t\ttry {\n+\n+\t\t\tif (operation.getCode().equals(Constants.Operation.INSTALL_APPLICATION)) {\n+\t\t\t\tJSONObject appData = new JSONObject(operation.getPayLoad().toString());\n+\t\t\t\tinstallApplication(appData, operation);\n+\t\t\t} else if (operation.getCode().equals(Constants.Operation.INSTALL_APPLICATION_BUNDLE)) {\n+\t\t\t\tJSONArray jArray;\n+\t\t\t\tjArray = new JSONArray(operation.getPayLoad().toString());\n+\t\t\t\tfor (int i = 0; i < jArray.length(); i++) {\n+\t\t\t\t\tJSONObject appObj = jArray.getJSONObject(i);\n+\t\t\t\t\tinstallApplication(appObj, operation);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\t\tLog.d(TAG, \"Application bundle installation started\");\n+\t\t\t}\n+\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Uninstall application.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void uninstallApplication(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\t\tString packageName;\n+\t\tString type;\n+\t\ttry {\n+\t\t\tJSONObject appData = new JSONObject(operation.getPayLoad().toString());\n+\n+\t\t\ttype = appData.getString(resources.getString(R.string.app_type));\n+\n+\t\t\tif (resources.getString(R.string.intent_extra_web).equalsIgnoreCase(type)) {\n+\t\t\t\tString appUrl = appData.getString(resources.getString(R.string.app_url));\n+\t\t\t\tString name = appData.getString(resources.getString(R.string.intent_extra_name));\n+\t\t\t\tString operationType = resources.getString(R.string.operation_uninstall);\n+\t\t\t\tJSONObject payload = new JSONObject();\n+\t\t\t\tpayload.put(resources.getString(R.string.intent_extra_identity), appUrl);\n+\t\t\t\tpayload.put(resources.getString(R.string.intent_extra_title), name);\n+\t\t\t\tpayload.put(resources.getString(R.string.operation_type), operationType);\n+\t\t\t\toperation.setPayLoad(payload.toString());\n+\t\t\t\tmanageWebClip(operation);\n+\t\t\t} else {\n+\t\t\t\tpackageName = appData.getString(resources.getString(R.string.app_identifier));\n+\t\t\t\tappList.uninstallApplication(packageName);\n+\t\t\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\t\t\tresultBuilder.build(operation);\n+\t\t\t}\n+\n+\t\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\t\tLog.d(TAG, \"Application started to uninstall\");\n+\t\t\t}\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tthrow new AndroidAgentException(\"Invalid JSON format.\", e);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Encrypt/Decrypt device storage.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tpublic void encryptStorage(org.wso2.mdm.agent.beans.Operation operation) throws AndroidAgentException {\n+\n+\t\tboolean doEncrypt = operation.isEnabled();\n+\t\tJSONObject result = new JSONObject();\n+\t\tComponentName admin = new ComponentName(context, AgentDeviceAdminReceiver.class);\n+\n+\t\tif (doEncrypt &&\n+\t\t\t\tdevicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED &&\n+\t\t\t\t(devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE)) {\n+\n+\t\t\tdevicePolicyManager.setStorageEncryption(admin, doEncrypt);\n+\t\t\tIntent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION);\n+\t\t\tintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n+\t\t\tcontext.startActivity(intent);\n+\n+\t\t} else if (!doEncrypt &&\n+\t\t\t\tdevicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED &&\n+\t\t\t\t(devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE ||\n+\t\t\t\t\t\tdevicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVATING)) {\n+\n+\t\t\tdevicePolicyManager.setStorageEncryption(admin, doEncrypt);\n+\t\t}\n+\n+\t\ttry {\n+\t\t\tString status;\n+\t\t\tif (devicePolicyManager.getStorageEncryptionStatus() !=\n+\t\t\t\t\tDevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {\n+\t\t\t\tstatus = resources.getString(R.string.shared_pref_default_status);\n+\t\t\t\tresult.put(resources.getString(R.string.operation_status), status);\n+\n+\t\t\t} else {\n+\t\t\t\tstatus = resources.getString(R.string.shared_pref_false_status);\n+\t\t\t\tresult.put(resources.getString(R.string.operation_status), status);\n+\t\t\t}\n+\t\t} catch (JSONException e) {\n+\t\t\toperation.setStatus(resources.getString(R.string.operation_value_error));\n+\t\t\tresultBuilder.build(operation);\n+\t\t\tString msg = \"Issue in parsing json\";\n+\t\t\tLog.e(TAG, msg);\n+\t\t\tthrow new AndroidAgentException(msg, e);\n+\t\t}\n+\t\toperation.setPayLoad(result.toString());\n+\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\tresultBuilder.build(operation);\n+\t\tif (Constants.DEBUG_MODE_ENABLED) {\n+\t\t\tLog.d(TAG, \"Encryption process started\");\n+\t\t}\n+\n+\t}\n+\n+\t/**\n+\t * Mute the device.\n+\t *\n+\t * @param operation - Operation object.\n+\t */\n+\tprivate void muteDevice(org.wso2.mdm.agent.beans.Operation operation) {\n+\t\toperation.setStatus(resources.getString(R.string.operation_value_completed));\n+\t\tresultBuilder.build(operation);\n+\n+\t\tAudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);\n+\t\taudioManager.setStreamVolume(AudioManager.STREAM_RING, DEFAULT_VOLUME, DEFAULT_FLAG);\n+\t\tif (Constants.DEBUG_MO","path":"modules/mobile-agents/android/client/src/org/wso2/mdm/agent/services/Operation.java","position":1668,"original_position":1668,"commit_id":"a7a0ada98fa19aa387670f8fedc3f5335c475657","original_commit_id":"a7a0ada98fa19aa387670f8fedc3f5335c475657","user":{"login":"DilanUA","id":8347682,"avatar_url":"https://avatars.githubusercontent.com/u/8347682?v=3","gravatar_id":"","url":"https://api.github.com/users/DilanUA","html_url":"https://github.com/DilanUA","followers_url":"https://api.github.com/users/DilanUA/followers","following_url":"https://api.github.com/users/DilanUA/following{/other_user}","gists_url":"https://api.github.com/users/DilanUA/gists{/gist_id}","starred_url":"https://api.github.com/users/DilanUA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DilanUA/subscriptions","organizations_url":"https://api.github.com/users/DilanUA/orgs","repos_url":"https://api.github.com/users/DilanUA/repos","events_url":"https://api.github.com/users/DilanUA/events{/privacy}","received_events_url":"https://api.github.com/users/DilanUA/received_events","type":"User","site_admin":false},"body":"unnecessary line breaks and spacing","created_at":"2015-09-14T11:19:57Z","updated_at":"2015-09-14T11:19:57Z","html_url":"https://github.com/wso2/product-mdm/pull/53#discussion_r39382961","pull_request_url":"https://api.github.com/repos/wso2/product-mdm/pulls/53","_links":{"self":{"href":"https://api.github.com/repos/wso2/product-mdm/pulls/comments/39382961"},"html":{"href":"https://github.com/wso2/product-mdm/pull/53#discussion_r39382961"},"pull_request":{"href":"https://api.github.com/repos/wso2/product-mdm/pulls/53"}}},"pull_request":{"url":"https://api.github.com/repos/wso2/product-mdm/pulls/53","id":35591290,"html_url":"https://github.com/wso2/product-mdm/pull/53","diff_url":"https://github.com/wso2/product-mdm/pull/53.diff","patch_url":"https://github.com/wso2/product-mdm/pull/53.patch","issue_url":"https://api.github.com/repos/wso2/product-mdm/issues/53","number":53,"state":"closed","locked":false,"title":"Fixed issues in uninstall function of AppM intergration","user":{"login":"milanperera","id":11870191,"avatar_url":"https://avatars.githubusercontent.com/u/11870191?v=3","gravatar_id":"","url":"https://api.github.com/users/milanperera","html_url":"https://github.com/milanperera","followers_url":"https://api.github.com/users/milanperera/followers","following_url":"https://api.github.com/users/milanperera/following{/other_user}","gists_url":"https://api.github.com/users/milanperera/gists{/gist_id}","starred_url":"https://api.github.com/users/milanperera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milanperera/subscriptions","organizations_url":"https://api.github.com/users/milanperera/orgs","repos_url":"https://api.github.com/users/milanperera/repos","events_url":"https://api.github.com/users/milanperera/events{/privacy}","received_events_url":"https://api.github.com/users/milanperera/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-17T18:44:03Z","updated_at":"2015-09-14T11:19:57Z","closed_at":"2015-05-17T18:50:46Z","merged_at":"2015-05-17T18:50:46Z","merge_commit_sha":"ba4334bbef7780cf3c682bd116363c330a5669b7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wso2/product-mdm/pulls/53/commits","review_comments_url":"https://api.github.com/repos/wso2/product-mdm/pulls/53/comments","review_comment_url":"https://api.github.com/repos/wso2/product-mdm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/product-mdm/issues/53/comments","statuses_url":"https://api.github.com/repos/wso2/product-mdm/statuses/a7a0ada98fa19aa387670f8fedc3f5335c475657","head":{"label":"milanperera:master","ref":"master","sha":"a7a0ada98fa19aa387670f8fedc3f5335c475657","user":{"login":"milanperera","id":11870191,"avatar_url":"https://avatars.githubusercontent.com/u/11870191?v=3","gravatar_id":"","url":"https://api.github.com/users/milanperera","html_url":"https://github.com/milanperera","followers_url":"https://api.github.com/users/milanperera/followers","following_url":"https://api.github.com/users/milanperera/following{/other_user}","gists_url":"https://api.github.com/users/milanperera/gists{/gist_id}","starred_url":"https://api.github.com/users/milanperera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milanperera/subscriptions","organizations_url":"https://api.github.com/users/milanperera/orgs","repos_url":"https://api.github.com/users/milanperera/repos","events_url":"https://api.github.com/users/milanperera/events{/privacy}","received_events_url":"https://api.github.com/users/milanperera/received_events","type":"User","site_admin":false},"repo":{"id":34047589,"name":"product-mdm","full_name":"milanperera/product-mdm","owner":{"login":"milanperera","id":11870191,"avatar_url":"https://avatars.githubusercontent.com/u/11870191?v=3","gravatar_id":"","url":"https://api.github.com/users/milanperera","html_url":"https://github.com/milanperera","followers_url":"https://api.github.com/users/milanperera/followers","following_url":"https://api.github.com/users/milanperera/following{/other_user}","gists_url":"https://api.github.com/users/milanperera/gists{/gist_id}","starred_url":"https://api.github.com/users/milanperera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milanperera/subscriptions","organizations_url":"https://api.github.com/users/milanperera/orgs","repos_url":"https://api.github.com/users/milanperera/repos","events_url":"https://api.github.com/users/milanperera/events{/privacy}","received_events_url":"https://api.github.com/users/milanperera/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/milanperera/product-mdm","description":"","fork":true,"url":"https://api.github.com/repos/milanperera/product-mdm","forks_url":"https://api.github.com/repos/milanperera/product-mdm/forks","keys_url":"https://api.github.com/repos/milanperera/product-mdm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/milanperera/product-mdm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/milanperera/product-mdm/teams","hooks_url":"https://api.github.com/repos/milanperera/product-mdm/hooks","issue_events_url":"https://api.github.com/repos/milanperera/product-mdm/issues/events{/number}","events_url":"https://api.github.com/repos/milanperera/product-mdm/events","assignees_url":"https://api.github.com/repos/milanperera/product-mdm/assignees{/user}","branches_url":"https://api.github.com/repos/milanperera/product-mdm/branches{/branch}","tags_url":"https://api.github.com/repos/milanperera/product-mdm/tags","blobs_url":"https://api.github.com/repos/milanperera/product-mdm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/milanperera/product-mdm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/milanperera/product-mdm/git/refs{/sha}","trees_url":"https://api.github.com/repos/milanperera/product-mdm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/milanperera/product-mdm/statuses/{sha}","languages_url":"https://api.github.com/repos/milanperera/product-mdm/languages","stargazers_url":"https://api.github.com/repos/milanperera/product-mdm/stargazers","contributors_url":"https://api.github.com/repos/milanperera/product-mdm/contributors","subscribers_url":"https://api.github.com/repos/milanperera/product-mdm/subscribers","subscription_url":"https://api.github.com/repos/milanperera/product-mdm/subscription","commits_url":"https://api.github.com/repos/milanperera/product-mdm/commits{/sha}","git_commits_url":"https://api.github.com/repos/milanperera/product-mdm/git/commits{/sha}","comments_url":"https://api.github.com/repos/milanperera/product-mdm/comments{/number}","issue_comment_url":"https://api.github.com/repos/milanperera/product-mdm/issues/comments{/number}","contents_url":"https://api.github.com/repos/milanperera/product-mdm/contents/{+path}","compare_url":"https://api.github.com/repos/milanperera/product-mdm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/milanperera/product-mdm/merges","archive_url":"https://api.github.com/repos/milanperera/product-mdm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/milanperera/product-mdm/downloads","issues_url":"https://api.github.com/repos/milanperera/product-mdm/issues{/number}","pulls_url":"https://api.github.com/repos/milanperera/product-mdm/pulls{/number}","milestones_url":"https://api.github.com/repos/milanperera/product-mdm/milestones{/number}","notifications_url":"https://api.github.com/repos/milanperera/product-mdm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/milanperera/product-mdm/labels{/name}","releases_url":"https://api.github.com/repos/milanperera/product-mdm/releases{/id}","created_at":"2015-04-16T09:47:28Z","updated_at":"2015-05-05T09:52:18Z","pushed_at":"2015-09-07T08:58:13Z","git_url":"git://github.com/milanperera/product-mdm.git","ssh_url":"git@github.com:milanperera/product-mdm.git","clone_url":"https://github.com/milanperera/product-mdm.git","svn_url":"https://github.com/milanperera/product-mdm","homepage":null,"size":15789,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"wso2:master","ref":"master","sha":"4f6b0e210032997c9f2b1a6346d440bfb2419726","user":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"repo":{"id":29459213,"name":"product-mdm","full_name":"wso2/product-mdm","owner":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/product-mdm","description":"","fork":false,"url":"https://api.github.com/repos/wso2/product-mdm","forks_url":"https://api.github.com/repos/wso2/product-mdm/forks","keys_url":"https://api.github.com/repos/wso2/product-mdm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/product-mdm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/product-mdm/teams","hooks_url":"https://api.github.com/repos/wso2/product-mdm/hooks","issue_events_url":"https://api.github.com/repos/wso2/product-mdm/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/product-mdm/events","assignees_url":"https://api.github.com/repos/wso2/product-mdm/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/product-mdm/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/product-mdm/tags","blobs_url":"https://api.github.com/repos/wso2/product-mdm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/product-mdm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/product-mdm/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/product-mdm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/product-mdm/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/product-mdm/languages","stargazers_url":"https://api.github.com/repos/wso2/product-mdm/stargazers","contributors_url":"https://api.github.com/repos/wso2/product-mdm/contributors","subscribers_url":"https://api.github.com/repos/wso2/product-mdm/subscribers","subscription_url":"https://api.github.com/repos/wso2/product-mdm/subscription","commits_url":"https://api.github.com/repos/wso2/product-mdm/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/product-mdm/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/product-mdm/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/product-mdm/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/product-mdm/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/product-mdm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/product-mdm/merges","archive_url":"https://api.github.com/repos/wso2/product-mdm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/product-mdm/downloads","issues_url":"https://api.github.com/repos/wso2/product-mdm/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/product-mdm/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/product-mdm/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/product-mdm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/product-mdm/labels{/name}","releases_url":"https://api.github.com/repos/wso2/product-mdm/releases{/id}","created_at":"2015-01-19T07:36:01Z","updated_at":"2015-08-22T02:43:09Z","pushed_at":"2015-09-14T06:59:44Z","git_url":"git://github.com/wso2/product-mdm.git","ssh_url":"git@github.com:wso2/product-mdm.git","clone_url":"https://github.com/wso2/product-mdm.git","svn_url":"https://github.com/wso2/product-mdm","homepage":null,"size":19537,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":5,"forks":19,"open_issues":5,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/product-mdm/pulls/53"},"html":{"href":"https://github.com/wso2/product-mdm/pull/53"},"issue":{"href":"https://api.github.com/repos/wso2/product-mdm/issues/53"},"comments":{"href":"https://api.github.com/repos/wso2/product-mdm/issues/53/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/product-mdm/pulls/53/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/product-mdm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/product-mdm/pulls/53/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/product-mdm/statuses/a7a0ada98fa19aa387670f8fedc3f5335c475657"}}}}