Example #1
0
  /**
   * Add a sample to the database.
   *
   * @return rowId or -1 if failed
   */
  private long addSample(Sample s) {
    if (Constants.DEBUG)
      Log.d("CaratSampleDB.addSample()", "The sample's battery level=" + s.getBatteryLevel());

    ContentValues initialValues = new ContentValues();
    initialValues.put(COLUMN_TIMESTAMP, s.timestamp);
    // Write the sample hashmap as a blob
    if (s != null) {
      try {
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream oo = new ObjectOutputStream(bo);
        oo.writeObject(SampleReader.writeSample(s));
        initialValues.put(COLUMN_SAMPLE, bo.toByteArray());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    return db.insert(SAMPLES_VIRTUAL_TABLE, null, initialValues);
  }
Example #2
0
  /**
   * Store the sample into the database
   *
   * @param s the sample to be saved
   * @return positive int if the operation is successful, otherwise zero
   */
  public long putSample(Sample s) {
    long id = 0;
    try {
      synchronized (dbLock) {
        if (db == null || !db.isOpen()) {
          db = helper.getWritableDatabase();
        }
        if (Constants.DEBUG)
          Log.d(
              TAG,
              "CaratSampleDB.putSample(). About to save a sample to the DB. "
                  + "uuid="
                  + s.uuId
                  + ", timestamp="
                  + s.timestamp
                  + ", timezone="
                  + s.timeZone
                  + ", batteryLevel="
                  + s.batteryLevel
                  + ", batteryState="
                  + s.batteryState
                  + ", developerMode="
                  + s.developerMode
                  + ", distanceTraveled="
                  + s.distanceTraveled
                  + ", memoryActive="
                  + s.memoryActive
                  + ", memoryFree="
                  + s.memoryFree
                  + ", memoryInactive="
                  + s.memoryInactive
                  + ", memoryWired="
                  + s.memoryWired
                  + ", screenBrightness="
                  + s.screenBrightness
                  + ", networkStatus="
                  + s.networkStatus
                  + ", screenOn="
                  + s.screenOn
                  + ", unknownSources="
                  + s.unknownSources
                  + ", batteryCapacity="
                  + s.batteryDetails.batteryCapacity
                  + ", batteryCharger="
                  + s.batteryDetails.batteryCharger
                  + ", batteryHealth="
                  + s.batteryDetails.batteryHealth
                  + ", batteryTechnology="
                  + s.batteryDetails.batteryTechnology
                  + ", batteryVoltage="
                  + s.batteryDetails.batteryVoltage
                  //                		+ ", callStatus=" + s.callInfo.callStatus
                  //                		+ ", incomingCallTime=" + s.callInfo.incomingCallTime
                  //                		+ ", nonCallTime=" + s.callInfo.nonCallTime
                  //                		+ ", outgoingCallTime=" + s.callInfo.outgoingCallTime
                  + ", cpuStatus="
                  + s.cpuStatus
                  + ", mobileDataActivity="
                  + s.getNetworkDetails().mobileDataActivity
                  + ", mobileDataStatus="
                  + s.getNetworkDetails().mobileDataStatus
                  + ", mobileNetworkType="
                  + s.getNetworkDetails().mobileNetworkType
                  + ", networkType="
                  + s.getNetworkDetails().networkType
                  + ", wifiLinkSpeed="
                  + s.getNetworkDetails().wifiLinkSpeed
                  + ", wifiSignalStrength="
                  + s.getNetworkDetails().wifiSignalStrength
                  + ", wifiStatus="
                  + s.getNetworkDetails().wifiStatus
                  + ", PiListSize="
                  + s.getPiListSize());

        // force init
        id = addSample(s);
        if (id >= 0) {
          lastSample = SampleReader.readSample(s);
        }
        if (db != null && db.isOpen()) {
          db.close();
        }
      }
    } catch (Throwable th) {
      Log.e(TAG, "Failed to add a sample!", th);
    }
    return id;
  }