Skip to content

Commit

Permalink
Merge pull request #120 from charithag/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamidu Sachith Punchihewa authored Nov 29, 2017
2 parents a6dedde + 37025bd commit f26c40c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,60 @@ public void getApplicationList(org.wso2.iot.agent.beans.Operation operation) thr
}
}

@Override
public void wipeDevice(Operation operation) throws AndroidAgentException {
String inputPin = null;
String savedPin = Preference.getString(getContext(), getContextResources().getString(R.string.shared_pref_pin));
JSONObject result = new JSONObject();
String ownershipType = Preference.getString(getContext(), Constants.DEVICE_TYPE);
if (Constants.DEFAULT_OWNERSHIP != null) {
ownershipType = Constants.DEFAULT_OWNERSHIP;
}
try {
JSONObject wipeKey;
String status;
if (operation.getPayLoad() != null) {
wipeKey = new JSONObject(operation.getPayLoad().toString());
if (!wipeKey.isNull(getContextResources().getString(R.string.shared_pref_pin))) {
inputPin = (String) wipeKey.get(getContextResources().getString(R.string.shared_pref_pin));
}
}

if (Constants.OWNERSHIP_COPE.equals(ownershipType.trim())) {
status = getContextResources().getString(R.string.shared_pref_default_status);
result.put(getContextResources().getString(R.string.operation_status), status);
} else if (inputPin != null && savedPin != null && inputPin.trim().equals(savedPin.trim())) {
status = getContextResources().getString(R.string.shared_pref_default_status);
result.put(getContextResources().getString(R.string.operation_status), status);
} else {
status = getContextResources().getString(R.string.shared_pref_false_status);
result.put(getContextResources().getString(R.string.operation_status), status);
}

operation.setPayLoad(result.toString());

if (status.equals(getContextResources().getString(R.string.shared_pref_default_status))) {
operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
getResultBuilder().build(operation);
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "Starting wipe data");
}
} else {
operation.setStatus(getContextResources().getString(R.string.operation_value_error));
operation.setOperationResponse("Invalid PIN code entered.");
getResultBuilder().build(operation);
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "Invalid PIN code!");
}
}
} catch (JSONException e) {
operation.setStatus(getContextResources().getString(R.string.operation_value_error));
operation.setOperationResponse("Error in parsing WIPE payload.");
getResultBuilder().build(operation);
throw new AndroidAgentException("Invalid JSON format.", e);
}
}

/**
* Ring the device.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.iot.agent.AlertActivity;
import org.wso2.iot.agent.AndroidAgentException;
import org.wso2.iot.agent.R;
import org.wso2.iot.agent.activities.ServerConfigsActivity;
import org.wso2.iot.agent.api.WiFiConfig;
import org.wso2.iot.agent.beans.AppRestriction;
import org.wso2.iot.agent.beans.ComplianceFeature;
import org.wso2.iot.agent.beans.DeviceAppInfo;
Expand All @@ -55,7 +52,6 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -130,63 +126,6 @@ public void uploadFile(Operation operation) throws AndroidAgentException {
}
}

@Override
public void wipeDevice(Operation operation) throws AndroidAgentException {
String inputPin = null;
String savedPin = Preference.getString(getContext(), getContextResources().getString(R.string.shared_pref_pin));
JSONObject result = new JSONObject();
String ownershipType = Preference.getString(getContext(), Constants.DEVICE_TYPE);
if (Constants.DEFAULT_OWNERSHIP != null) {
ownershipType = Constants.DEFAULT_OWNERSHIP;
}
try {
JSONObject wipeKey;
String status;
if (operation.getPayLoad() != null) {
wipeKey = new JSONObject(operation.getPayLoad().toString());
if (!wipeKey.isNull(getContextResources().getString(R.string.shared_pref_pin))) {
inputPin = (String) wipeKey.get(getContextResources().getString(R.string.shared_pref_pin));
}
}

if (Constants.OWNERSHIP_COPE.equals(ownershipType.trim())) {
status = getContextResources().getString(R.string.shared_pref_default_status);
result.put(getContextResources().getString(R.string.operation_status), status);
} else if (Constants.OWNERSHIP_BYOD.equals(ownershipType.trim()) ||
(inputPin != null && savedPin != null && inputPin.trim().equals(savedPin.trim()))) {
status = getContextResources().getString(R.string.shared_pref_default_status);
result.put(getContextResources().getString(R.string.operation_status), status);
} else {
status = getContextResources().getString(R.string.shared_pref_false_status);
result.put(getContextResources().getString(R.string.operation_status), status);
}

operation.setPayLoad(result.toString());

if (status.equals(getContextResources().getString(R.string.shared_pref_default_status))) {
/*Toast.makeText(getContext(), getContextResources().getString(R.string.toast_message_wipe),
Toast.LENGTH_LONG).show();*/
operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
getResultBuilder().build(operation);

if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "Started to wipe data");
}
} else {
/*Toast.makeText(getContext(), getContextResources().getString(R.string.toast_message_wipe_failed),
Toast.LENGTH_LONG).show();*/
operation.setStatus(getContextResources().getString(R.string.operation_value_error));
operation.setOperationResponse("Invalid PIN code entered.");
getResultBuilder().build(operation);
}
} catch (JSONException e) {
operation.setStatus(getContextResources().getString(R.string.operation_value_error));
operation.setOperationResponse("Error in parsing WIPE payload.");
getResultBuilder().build(operation);
throw new AndroidAgentException("Invalid JSON format.", e);
}
}

@Override
public void displayNotification(Operation operation) throws AndroidAgentException {
try {
Expand Down
Loading

0 comments on commit f26c40c

Please sign in to comment.