docs: public static File fileFromKey(SQLDatabase db, byte[] key, String attachmentsDir,
                              boolean allowCreateName)
              throws AttachmentException {
  
          String keyString = keyToString(key);
          String filename = null;
  
          db.beginTransaction();
          Cursor c = null;
          try {
              c = db.rawQuery(SQL_FILENAME_LOOKUP_QUERY, new String[]{ keyString });
              if (c.moveToFirst()) {
                  filename = c.getString(0);
                  logger.finest(String.format("Found filename %s for key %s", filename, keyString));
              } else if (allowCreateName) {
                  filename = generateFilenameForKey(db, keyString);
                  logger.finest(String.format("Added filename %s for key %s", filename, keyString));
              }
              db.setTransactionSuccessful();
          } catch (SQLException e) {
              logger.log(Level.WARNING, "Couldn't read key,filename mapping database", e);
              filename = null;
          } finally {
              DatabaseUtils.closeCursorQuietly(c);
              db.endTransaction();
          }
  
          if (filename != null) {
              return new File(attachmentsDir, filename);
          } else {
              // generateFilenameForKey throws an exception if we couldn't generate, this
              // means we couldn't get one from the database.
              throw new AttachmentException("Couldn't retrieve filename for attachment");
          }
      }