Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a43ccfaa authored by kai's avatar kai
Browse files

Bluetooth PbapParserTest

Get time zone and adjust date according to the device's time zone.

Bug: 65554571
Test: 1 Select time zone in car kit, runtest bluetooth
      2 Change time zone in car kit, runtest bluetooth

Change-Id: Ibc5a1a7ab115ea5d397faa93b830f3439d7bc8c0
(cherry picked from commit d049ead3ae5125093d1b1403d4cdfaf6503ae787)
parent 0cff9baf
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.test.AndroidTestCase;

import java.io.IOException;
import java.io.InputStream;
import java.util.TimeZone;

import org.junit.Before;
import org.junit.Test;
@@ -81,11 +82,10 @@ public class PbapParserTest extends AndroidTestCase {
        processor.setResults(pbapVCardList.getList());

        // Verify that these entries aren't in the call log to start.
        // EST is default Time Zone
        assertFalse(verifyCallLog("555-0002", "1483250460000", "3"));
        assertFalse(verifyCallLog("555-0002", "1483232460000", "3"));
        // Finish processing the data and verify entries were added to the call log.
        processor.onPullComplete();
        assertTrue(verifyCallLog("555-0002", "1483250460000", "3"));
        assertTrue(verifyCallLog("555-0002", "1483232460000", "3"));
    }

    // testUnknownCall should parse two calls with no phone number.
@@ -102,14 +102,13 @@ public class PbapParserTest extends AndroidTestCase {
        processor.setResults(pbapVCardList.getList());

        // Verify that these entries aren't in the call log to start.
        // EST is default Time Zone
        assertFalse(verifyCallLog("", "1483250520000", "3"));
        assertFalse(verifyCallLog("", "1483250580000", "3"));
        assertFalse(verifyCallLog("", "1483232520000", "3"));
        assertFalse(verifyCallLog("", "1483232580000", "3"));

        // Finish processing the data and verify entries were added to the call log.
        processor.onPullComplete();
        assertTrue(verifyCallLog("", "1483250520000", "3"));
        assertTrue(verifyCallLog("", "1483250580000", "3"));
        assertTrue(verifyCallLog("", "1483232520000", "3"));
        assertTrue(verifyCallLog("", "1483232580000", "3"));
    }

    // Find Entries in call log with type matching number and date.
@@ -118,6 +117,9 @@ public class PbapParserTest extends AndroidTestCase {
        String[] query = new String[] {Calls.NUMBER, Calls.DATE, Calls.TYPE};
        Cursor cursor = mContext.getContentResolver().query(Calls.CONTENT_URI, query,
                Calls.TYPE + "= " + type, null, Calls.DATE + ", " + Calls.NUMBER);
        if (date != null) {
            date = adjDate(date);
        }
        if (cursor != null) {
            while (cursor.moveToNext()) {
                String foundNumber = cursor.getString(cursor.getColumnIndex(Calls.NUMBER));
@@ -131,4 +133,11 @@ public class PbapParserTest extends AndroidTestCase {
        }
        return false;
    }

    // Get time zone from device and adjust date to the device's time zone.
    String adjDate(String date) {
        TimeZone tz = TimeZone.getDefault();
        long dt = Long.valueOf(date) - tz.getRawOffset();
        return Long.toString(dt);
    }
}