private Entity setupTestEventEntity(String organizer, String attendee, String title) {
    // Create an Entity for an Event
    ContentValues entityValues = new ContentValues();
    Entity entity = new Entity(entityValues);

    // Set up values for the Event
    String location = "Meeting Location";

    // Fill in times, location, title, and organizer
    entityValues.put(
        "DTSTAMP",
        CalendarUtilities.convertEmailDateTimeToCalendarDateTime("2010-04-05T14:30:51Z"));
    entityValues.put(Events.DTSTART, Utility.parseEmailDateTimeToMillis("2010-04-12T18:30:00Z"));
    entityValues.put(Events.DTEND, Utility.parseEmailDateTimeToMillis("2010-04-12T19:30:00Z"));
    entityValues.put(Events.EVENT_LOCATION, location);
    entityValues.put(Events.TITLE, title);
    entityValues.put(Events.ORGANIZER, organizer);
    entityValues.put(Events._SYNC_DATA, "31415926535");

    // Add the attendee
    ContentValues attendeeValues = new ContentValues();
    attendeeValues.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE);
    attendeeValues.put(Attendees.ATTENDEE_EMAIL, attendee);
    entity.addSubValue(Attendees.CONTENT_URI, attendeeValues);

    // Add the organizer
    ContentValues organizerValues = new ContentValues();
    organizerValues.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ORGANIZER);
    organizerValues.put(Attendees.ATTENDEE_EMAIL, organizer);
    entity.addSubValue(Attendees.CONTENT_URI, organizerValues);
    return entity;
  }
예제 #2
0
 /** @return Device's unique ID if available. null if the device has no unique ID. */
 public static String getConsistentDeviceId(Context context) {
   final String deviceId;
   try {
     TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
     if (tm == null) {
       return null;
     }
     deviceId = tm.getDeviceId();
     if (deviceId == null) {
       return null;
     }
   } catch (Exception e) {
     Log.d(Email.LOG_TAG, "Error in TelephonyManager.getDeviceId(): " + e.getMessage());
     return null;
   }
   final MessageDigest sha;
   try {
     sha = MessageDigest.getInstance("SHA-1");
   } catch (NoSuchAlgorithmException impossible) {
     return null;
   }
   sha.update(Utility.toUtf8(deviceId));
   final int hash = getSmallHashFromSha1(sha.digest());
   return Integer.toString(hash);
 }
 private BlockHash parseIcsContent(byte[] bytes) throws IOException {
   BufferedReader reader = new BufferedReader(new StringReader(Utility.fromUtf8(bytes)));
   String line = reader.readLine();
   if (!line.equals("BEGIN:VCALENDAR")) {
     throw new IllegalArgumentException();
   }
   return new BlockHash("VCALENDAR", reader);
 }
 private Entity setupTestExceptionEntity(String organizer, String attendee, String title) {
   Entity entity = setupTestEventEntity(organizer, attendee, title);
   ContentValues entityValues = entity.getEntityValues();
   entityValues.put(Events.ORIGINAL_EVENT, 69);
   // The exception will be on April 26th
   entityValues.put(
       Events.ORIGINAL_INSTANCE_TIME, Utility.parseEmailDateTimeToMillis("2010-04-26T18:30:00Z"));
   return entity;
 }
 /** Write and clear the buffer */
 private void logRaw(int oneByte) {
   if (oneByte == '\r') {
     // Don't log.
   } else if (oneByte == '\n') {
     flushLog();
   } else if (0x20 <= oneByte && oneByte <= 0x7e) { // Printable ASCII.
     mSb.append((char) oneByte);
   } else {
     // email protocols are supposed to be all 7bits, but there are wrong implementations
     // that do send 8 bit characters...
     mSb.append("\\x" + Utility.byteToHex(oneByte));
   }
 }
 public void testParseDateTimeToMillis(String date) {
   // Format for calendar date strings is 20100223T160000000Z
   String dateString = "20100223T151617000Z";
   long dateTime = Utility.parseDateTimeToMillis(dateString);
   GregorianCalendar cal = new GregorianCalendar();
   cal.setTimeInMillis(dateTime);
   cal.setTimeZone(TimeZone.getTimeZone("GMT"));
   assertEquals(cal.get(Calendar.YEAR), 2010);
   assertEquals(cal.get(Calendar.MONTH), 1); // 0 based
   assertEquals(cal.get(Calendar.DAY_OF_MONTH), 23);
   assertEquals(cal.get(Calendar.HOUR_OF_DAY), 16);
   assertEquals(cal.get(Calendar.MINUTE), 16);
   assertEquals(cal.get(Calendar.SECOND), 17);
 }