Exemplo n.º 1
0
  @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();
  }
Exemplo n.º 2
0
 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
 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);
 }
 @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);
   }
 }
 @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);
 }
 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");
 }