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); } }
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; }
@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); }