public static void execute(Context ctx, String command, String phoneNumber) { String secretKey = SMSUtil.getSecretKey(command); String email = PreyConfig.getPreyConfig(ctx).getEmail(); boolean isPasswordOk = false; PreyTelephonyManager preyTelephony = PreyTelephonyManager.getInstance(ctx); PreyConnectivityManager preyConnectivity = PreyConnectivityManager.getInstance(ctx); boolean connection = false; int i = 0; try { while (!connection && i < 5) { connection = preyTelephony.isDataConnectivityEnabled() || preyConnectivity.isConnected(); if (!connection) { PreyLogger.d("Phone doesn't have internet connection now. Waiting 10 secs for it"); Thread.sleep(10000); } } } catch (Exception e) { PreyLogger.e("Error, because:" + e.getMessage(), e); } try { isPasswordOk = PreyWebServices.getInstance().checkPassword(ctx, email, secretKey); } catch (Exception e) { PreyLogger.e("Error, because:" + e.getMessage(), e); } try { if (isPasswordOk) { List<JSONObject> jsonList = SMSParser.getJSONListFromText(command, phoneNumber); ActionsController.getInstance(ctx).runActionJson(ctx, jsonList); } } catch (Exception e) { PreyLogger.e("Error, because:" + e.getMessage(), e); } }
@Override protected void onHandleIntent(Intent intent) { JSONArray jsonArray = new JSONArray(); List<String> listExclude = new ArrayList<String>(); PreyLogger.i("start report"); List<HttpDataService> listData = new ArrayList<HttpDataService>(); Context ctx = this; jsonArray = new JSONArray(); if (!listExclude.contains("picture")) jsonArray.put(new String("picture")); if (!listExclude.contains("location")) jsonArray.put(new String("location")); if (!listExclude.contains("access_points_list")) jsonArray.put(new String("access_points_list")); try { List<ActionResult> lista = new ArrayList<ActionResult>(); for (int i = 0; i < jsonArray.length(); i++) { String nameAction = jsonArray.getString(i); PreyLogger.d("nameAction:" + nameAction); String methodAction = "report"; JSONObject parametersAction = null; listData = ClassUtil.execute(ctx, lista, nameAction, methodAction, parametersAction, listData); } } catch (Exception e) { } int parms = 0; for (int i = 0; listData != null && i < listData.size(); i++) { HttpDataService httpDataService = listData.get(i); parms = parms + httpDataService.getDataAsParameters().size(); if (httpDataService.getEntityFiles() != null) { for (int j = 0; j < httpDataService.getEntityFiles().size(); j++) { EntityFile entity = httpDataService.getEntityFiles().get(j); if (entity != null && entity.getLength() > 0) { parms = parms + 1; } } } } if (PreyConfig.getPreyConfig(ctx).isConnectionExists()) { if (parms > 0) { PreyHttpResponse response = PreyWebServices.getInstance().sendPreyHttpReport(ctx, listData); if (response != null) { PreyConfig.getPreyConfig(ctx).setLastEvent("report_send"); PreyLogger.d("response.getStatusLine():" + response.getStatusLine()); if (200 != response.getStatusLine().getStatusCode()) { PreyConfig.getPreyConfig(ctx).setMissing(false); PreyConfig.getPreyConfig(ctx).setIntervalReport(""); ReportScheduled.getInstance(ctx).reset(); } } } } stopSelf(); }
@Override public void execute(ActionJob actionJob, Context ctx) throws PreyException { HttpDataService data = LocationUtil.dataLocation(ctx); PreyLogger.d("Ejecuting LocationNotifierAction Action. DONE!"); ActionResult result = new ActionResult(); result.setDataToSend(data); actionJob.finish(result); }
public static void unhide(Context ctx, List<ActionResult> lista, JSONObject options) { PreyLogger.i("started unhide"); PreyWebServices.getInstance() .sendNotifyActionResultPreyHttp( ctx, UtilJson.makeMapParam("stop", "camouflage", "stopped")); PreyConfig.getPreyConfig(ctx).setCamouflageSet(false); ComponentName componentToEnabled = new ComponentName("com.prey", "com.prey.activities.LoginActivity"); PackageManager pm = ctx.getApplicationContext().getPackageManager(); pm.setComponentEnabledSetting( componentToEnabled, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); PreyLogger.i("stopped unhide"); PreyConfig.getPreyConfig(ctx).setLastEvent("camouflage_unhide"); }
@Override public void onReceive(Context context, Intent intent) { PreyLogger.d("Boot finished. Starting Prey Boot Service"); // just make sure we are getting the right intent (better safe than // sorry) if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) { String interval = PreyConfig.getPreyConfig(context).getIntervalReport(); if (interval != null && !"".equals(interval)) { Report.run(context, Integer.parseInt(interval)); } boolean keepOn = PreyConfig.getPreyConfig(context).isKeepOn(); if (keepOn) { context.startService(new Intent(context, PreyKeepOnService.class)); } else { context.stopService(new Intent(context, PreyKeepOnService.class)); } } else PreyLogger.e("Received unexpected intent " + intent.toString(), null); }
@Override public void onReceive(Context context, Intent intent) { PreyLogger.i("Out call Broadcast - Action received: " + intent.getAction()); if (intent.getAction() != null && intent.getAction().equals(ACTION)) { String phoneNumber = getResultData(); if (phoneNumber != null) { // No reformatted number, use the original phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); PreyLogger.i("phoneNumber:" + phoneNumber); if ("#12345*".equals(phoneNumber)) { Camouflage.hide(context, null, null); } if ("#67890*".equals(phoneNumber)) { Camouflage.unhide(context, null, null); } } } }
@Override public void setChecked(boolean checked) { super.setChecked(checked); PreyLogger.i("LocationLowBatteryCheckBoxPreference:" + checked); Context ctx = getContext(); PreyConfig.getPreyConfig(ctx).setLocationLowBattery(checked); if (checked) { PreyConfig.getPreyConfig(ctx).setLocationLowBatteryDate(0); } }
@Override public void onPasswordSucceeded(Context context, Intent intent) { PreyConfig preyConfig = PreyConfig.getPreyConfig(context); if (preyConfig.isLockSet()) { PreyLogger.d("Password was entered successfully"); ArrayList<String> modulesList = new ArrayList<String>(); modulesList.add(LockAction.DATA_ID); PreyWebServices.getInstance().deactivateModules(context, modulesList); preyConfig.setLock(false); FroyoSupport.getInstance(context).changePasswordAndLock("", false); } }
public static void hide(Context ctx, List<ActionResult> lista, JSONObject parameters) { PreyLogger.i("started hide"); String messageId = null; try { messageId = parameters.getString(PreyConfig.MESSAGE_ID); } catch (Exception e) { } PreyWebServices.getInstance() .sendNotifyActionResultPreyHttp( ctx, UtilJson.makeMapParam("start", "camouflage", "started", null)); PreyConfig.getPreyConfig(ctx).setCamouflageSet(true); ComponentName componentToDisabled = new ComponentName("com.prey", "com.prey.activities.LoginActivity"); PackageManager pm = ctx.getPackageManager(); pm.setComponentEnabledSetting( componentToDisabled, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); PreyLogger.i("stopped hide"); PreyConfig.getPreyConfig(ctx).setLastEvent("camouflage_hide"); }
public static HttpDataService dataLocation(Context ctx) { HttpDataService data = new HttpDataService("location"); try { data.setList(true); PreyConfig.getPreyConfig(ctx).setMissing(true); Intent intent = new Intent(ctx, LocationService.class); ctx.startService(intent); boolean validLocation = false; PreyLocation lastLocation; HashMap<String, String> parametersMap = new HashMap<String, String>(); int i = 0; while (!validLocation) { lastLocation = PreyLocationManager.getInstance(ctx).getLastLocation(); if (lastLocation.isValid()) { validLocation = true; parametersMap.put("lat", Double.toString(lastLocation.getLat())); parametersMap.put("lng", Double.toString(lastLocation.getLng())); parametersMap.put("accuracy", Float.toString(lastLocation.getAccuracy())); } else { try { Thread.sleep(5000); } catch (InterruptedException e) { throw new PreyException("Thread was intrrupted. Finishing Location NotifierAction", e); } if (i > 2) { return null; } i++; } } data.addDataListAll(parametersMap); // ArrayList<HttpDataService> dataToBeSent = new ArrayList<HttpDataService>(); // dataToBeSent.add(data); // PreyWebServices.getInstance().sendPreyHttpData(ctx, dataToBeSent); ctx.stopService(intent); PreyConfig.getPreyConfig(ctx).setMissing(false); } catch (Exception e) { PreyLogger.e("Error causa:" + e.getMessage(), e); // PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx, // UtilJson.makeMapParam("get","location","failed",e.getMessage())); } return data; }
public LocationNotifierAction() { PreyLogger.d("Ejecuting LocationNotifierAction Action"); data = new HttpDataService(LocationNotifierAction.DATA_ID); data.setList(true); }
@Override public void onPasswordChanged(Context context, Intent intent) { // TODO Auto-generated method stub PreyLogger.d("Password was changed successfully"); }
@Override public void onDisabled(Context context, Intent intent) { PreyLogger.d("Device Admin disabled"); }