private String getInsertSQL(ContentValues next) {
   return "INSERT INTO devices ("
       + Devices.NAME
       + ", "
       + Devices.LOCATION
       + ", "
       + Devices.DEVICE_TYPE
       + ", "
       + Devices.POWER
       + ", "
       + Devices.REST_ID
       + ", "
       + Devices.CREATED_AT
       + ", "
       + Devices.UPDATED_AT
       + ") "
       + "values ('"
       + next.getAsString(Devices.NAME)
       + "', '"
       + next.getAsString(Devices.LOCATION)
       + "', '"
       + next.getAsString(Devices.DEVICE_TYPE)
       + "', '"
       + next.getAsBoolean(Devices.POWER)
       + "', '"
       + next.getAsInteger(Devices.REST_ID)
       + "', '"
       + next.get(Devices.CREATED_AT)
       + "', '"
       + next.get(Devices.UPDATED_AT)
       + "'"
       + ")";
 }
예제 #2
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    if (sUriMatcher.match(uri) == TYPE_RESTRICTION) {
      // Check access
      enforcePermission();

      // Get arguments
      String restrictionName = selection;
      int uid = values.getAsInteger(COL_UID);
      String methodName = values.getAsString(COL_METHOD);
      boolean allowed = !Boolean.parseBoolean(values.getAsString(COL_RESTRICTED));

      // Update
      updateRestriction(uid, restrictionName, methodName, allowed);

      return 1; // rows
    } else if (sUriMatcher.match(uri) == TYPE_USAGE) {
      Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

      // Get arguments
      int uid = values.getAsInteger(COL_UID);
      String restrictionName = values.getAsString(PrivacyProvider.COL_RESTRICTION);
      String methodName = values.getAsString(COL_METHOD);
      boolean restricted = false;
      if (values.containsKey(PrivacyProvider.COL_RESTRICTED))
        restricted = values.getAsBoolean(PrivacyProvider.COL_RESTRICTED);
      long timeStamp = values.getAsLong(PrivacyProvider.COL_USED);
      Util.log(
          null,
          Log.INFO,
          String.format(
              "Update usage data %d/%s/%s=%b", uid, restrictionName, methodName, restricted));

      // Update usage data
      if (methodName != null) updateUsage(uid, restrictionName, methodName, restricted, timeStamp);

      return 1;
    } else if (sUriMatcher.match(uri) == TYPE_SETTING) {
      // Check access
      enforcePermission();

      // Get arguments
      String settingName = selection;

      // Update setting
      SharedPreferences prefs =
          getContext().getSharedPreferences(PREF_SETTINGS, Context.MODE_WORLD_READABLE);
      SharedPreferences.Editor editor = prefs.edit();
      editor.putString(getSettingPref(settingName), values.getAsString(COL_VALUE));
      editor.apply();
      setPrefFileReadable(PREF_SETTINGS);

      return 1;
    }

    throw new IllegalArgumentException(uri.toString());
  }
예제 #3
0
  public final void createFromContentValue(ContentValues args) {
    Integer tmp_i;
    String tmp_s;
    Long tmp_l;
    Boolean tmp_b;

    tmp_s = args.getAsString(FIELD_FROM);
    if (tmp_s != null) {
      from = tmp_s;
    }
    tmp_s = args.getAsString(FIELD_TO);
    if (tmp_s != null) {
      to = tmp_s;
    }
    tmp_s = args.getAsString(FIELD_CONTACT);
    if (tmp_s != null) {
      contact = tmp_s;
    }
    tmp_s = args.getAsString(FIELD_BODY);
    if (tmp_s != null) {
      body = tmp_s;
    }
    tmp_s = args.getAsString(FIELD_MIME_TYPE);
    if (tmp_s != null) {
      mimeType = tmp_s;
    }
    tmp_l = args.getAsLong(FIELD_DATE);
    if (tmp_l != null) {
      date = tmp_l;
    }
    tmp_i = args.getAsInteger(FIELD_TYPE);
    if (tmp_i != null) {
      type = tmp_i;
    }
    tmp_i = args.getAsInteger(FIELD_STATUS);
    if (tmp_i != null) {
      status = tmp_i;
    }
    tmp_b = args.getAsBoolean(FIELD_READ);
    if (tmp_b != null) {
      read = tmp_b;
    }

    tmp_s = args.getAsString(FIELD_FROM_FULL);
    if (tmp_s != null) {
      fullFrom = tmp_s;
    }

    tmp_i = args.getAsInteger(FIELD_DATA_DOWNLOADED);
    if (tmp_i != null) {
      data_downloaded = tmp_i;
    }
  }
 @Override
 public Uri insert(Uri uri, ContentValues values) {
   // TODO Auto-generated method stub
   int rowID =
       mManager.addDream(
           new Date(values.getAsString(Dreams.TIME)),
           values.getAsInteger(Dreams.PART),
           values.getAsString(Dreams.TITLE),
           values.getAsString(Dreams.DESCRIPTION),
           values.getAsString(Dreams.TAGS),
           values.getAsBoolean(Dreams.EROTIC));
   return ContentUris.withAppendedId(uri, rowID);
 }
예제 #5
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {

    if (LOGD) Log.d(TAG, "update");

    switch (URI_MATCHER.match(uri)) {
      case URI_TASKS:
        Task task = new Task();

        // map values
        if (values.containsKey(NAME)) task.setValue(Task.TITLE, values.getAsString(NAME));
        if (values.containsKey(PREFERRED_DUE_DATE))
          task.setValue(Task.DUE_DATE, values.getAsLong(PREFERRED_DUE_DATE));
        if (values.containsKey(DEFINITE_DUE_DATE))
          task.setValue(Task.DUE_DATE, values.getAsLong(DEFINITE_DUE_DATE));
        if (values.containsKey(IMPORTANCE))
          task.setValue(Task.IMPORTANCE, values.getAsInteger(IMPORTANCE));
        if (values.containsKey(COMPLETED))
          task.setValue(
              Task.COMPLETION_DATE, values.getAsBoolean(COMPLETED) ? DateUtilities.now() : 0);

        // map selection criteria
        String criteria =
            selection
                .replace(NAME, Task.TITLE.name)
                .replace(PREFERRED_DUE_DATE, Task.DUE_DATE.name)
                .replace(DEFINITE_DUE_DATE, Task.DUE_DATE.name)
                .replace(IDENTIFIER, Task.ID.name)
                .replace(ID, Task.ID.name)
                .replace(IMPORTANCE, Task.IMPORTANCE.name);

        return taskService.updateBySelection(criteria, selectionArgs, task);

      case URI_TAGS:
        throw new UnsupportedOperationException("tags updating: not yet");

      default:
        throw new IllegalStateException("Unrecognized URI:" + uri);
    }
  }
예제 #6
0
  /** Inserts a row in the database */
  @Override
  public Uri insert(final Uri uri, final ContentValues values) {
    //		checkInsertPermissions(values);
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    // note we disallow inserting into ALL_DOWNLOADS
    int match = sURIMatcher.match(uri);
    if (match != MY_DOWNLOADS) {
      Log.d(Constants.TAG, "calling insert on an unknown/invalid URI: " + uri);
      throw new IllegalArgumentException("Unknown/Invalid URI " + uri);
    }

    ContentValues filteredValues = new ContentValues();

    copyString(Downloads.COLUMN_URI, values, filteredValues);
    copyString(Downloads.COLUMN_APP_DATA, values, filteredValues);
    copyBoolean(Downloads.COLUMN_NO_INTEGRITY, values, filteredValues);
    copyString(Downloads.COLUMN_FILE_NAME_HINT, values, filteredValues);
    copyString(Downloads.COLUMN_MIME_TYPE, values, filteredValues);

    copyBoolean(Downloads.COLUMN_IS_PUBLIC_API, values, filteredValues);
    boolean isPublicApi = values.getAsBoolean(Downloads.COLUMN_IS_PUBLIC_API) == Boolean.TRUE;

    Integer dest = values.getAsInteger(Downloads.COLUMN_DESTINATION);
    if (dest != null) {
      if (dest != Downloads.DESTINATION_EXTERNAL && dest != Downloads.DESTINATION_FILE_URI) {
        throw new SecurityException("unauthorized destination code");
      }
      if (dest == Downloads.DESTINATION_FILE_URI) {
        getContext()
            .enforcePermission(
                android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Binder.getCallingPid(),
                Binder.getCallingUid(),
                "need WRITE_EXTERNAL_STORAGE permission to use DESTINATION_FILE_URI");
        checkFileUriDestination(values);
      }
      filteredValues.put(Downloads.COLUMN_DESTINATION, dest);
    }
    Integer vis = values.getAsInteger(Downloads.COLUMN_VISIBILITY);
    if (vis == null) {
      if (dest == Downloads.DESTINATION_EXTERNAL) {
        filteredValues.put(
            Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      } else {
        filteredValues.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_HIDDEN);
      }
    } else {
      filteredValues.put(Downloads.COLUMN_VISIBILITY, vis);
    }
    copyInteger(Downloads.COLUMN_CONTROL, values, filteredValues);
    filteredValues.put(Downloads.COLUMN_STATUS, Downloads.STATUS_PENDING);
    filteredValues.put(Downloads.COLUMN_LAST_MODIFICATION, mSystemFacade.currentTimeMillis());

    String pckg = values.getAsString(Downloads.COLUMN_NOTIFICATION_PACKAGE);
    String clazz = values.getAsString(Downloads.COLUMN_NOTIFICATION_CLASS);
    if (pckg != null && (clazz != null || isPublicApi)) {
      int uid = Binder.getCallingUid();
      try {
        if (uid == 0 || mSystemFacade.userOwnsPackage(uid, pckg)) {
          filteredValues.put(Downloads.COLUMN_NOTIFICATION_PACKAGE, pckg);
          if (clazz != null) {
            filteredValues.put(Downloads.COLUMN_NOTIFICATION_CLASS, clazz);
          }
        }
      } catch (PackageManager.NameNotFoundException ex) {
        /* ignored for now */
      }
    }
    copyString(Downloads.COLUMN_NOTIFICATION_EXTRAS, values, filteredValues);
    copyString(Downloads.COLUMN_COOKIE_DATA, values, filteredValues);
    copyString(Downloads.COLUMN_USER_AGENT, values, filteredValues);
    copyString(Downloads.COLUMN_REFERER, values, filteredValues);
    if (true /*
              * getContext().checkCallingPermission(
              * Downloads.PERMISSION_ACCESS_ADVANCED) ==
              * PackageManager.PERMISSION_GRANTED
              */) {
      copyInteger(Downloads.COLUMN_OTHER_UID, values, filteredValues);
    }
    filteredValues.put(Constants.UID, Binder.getCallingUid());
    if (Binder.getCallingUid() == 0) {
      copyInteger(Constants.UID, values, filteredValues);
    }
    copyStringWithDefault(Downloads.COLUMN_TITLE, values, filteredValues, "");
    copyStringWithDefault(Downloads.COLUMN_DESCRIPTION, values, filteredValues, "");
    filteredValues.put(Downloads.COLUMN_TOTAL_BYTES, -1);
    filteredValues.put(Downloads.COLUMN_CURRENT_BYTES, 0);

    if (values.containsKey(Downloads.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI)) {
      copyBoolean(Downloads.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI, values, filteredValues);
    } else {
      // by default, make external downloads visible in the UI
      boolean isExternal = (dest == null || dest == Downloads.DESTINATION_EXTERNAL);
      filteredValues.put(Downloads.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI, isExternal);
    }

    if (isPublicApi) {
      copyInteger(Downloads.COLUMN_ALLOWED_NETWORK_TYPES, values, filteredValues);
      copyBoolean(Downloads.COLUMN_ALLOW_ROAMING, values, filteredValues);
    }

    if (Constants.LOGVV) {
      Log.v(
          Constants.TAG,
          "initiating download with UID " + filteredValues.getAsInteger(Constants.UID));
      if (filteredValues.containsKey(Downloads.COLUMN_OTHER_UID)) {
        Log.v(
            Constants.TAG, "other UID " + filteredValues.getAsInteger(Downloads.COLUMN_OTHER_UID));
      }
    }

    Context context = getContext();
    context.startService(new Intent(context, DownloadService.class));

    long rowID = db.insert(DB_TABLE, null, filteredValues);
    if (rowID == -1) {
      Log.d(Constants.TAG, "couldn't insert into downloads database");
      return null;
    }

    insertRequestHeaders(db, rowID, values);
    context.startService(new Intent(context, DownloadService.class));
    notifyContentChanged(uri, match);
    return ContentUris.withAppendedId(Downloads.CONTENT_URI, rowID);
  }
예제 #7
0
 private static final void copyBoolean(String key, ContentValues from, ContentValues to) {
   Boolean b = from.getAsBoolean(key);
   if (b != null) {
     to.put(key, b);
   }
 }
 @Override
 public Boolean getAsBoolean(String key) {
   return contentValues.getAsBoolean(key);
 }
 public Boolean getAsBoolean(String key, Boolean def) {
   return contentValues.containsKey(key) && contentValues.get(key) != null
       ? contentValues.getAsBoolean(key)
       : def;
 }