Loading android/app/src/com/android/bluetooth/pbapclient/CallLogPullRequest.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.provider.ContactsContract; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Pair; import com.android.internal.annotations.VisibleForTesting; import com.android.vcard.VCardEntry; import com.android.vcard.VCardEntry; import com.android.vcard.VCardEntry.PhoneData; import com.android.vcard.VCardEntry.PhoneData; Loading @@ -42,7 +43,8 @@ public class CallLogPullRequest extends PullRequest { private static final boolean DBG = Utils.DBG; private static final boolean DBG = Utils.DBG; private static final boolean VDBG = Utils.VDBG; private static final boolean VDBG = Utils.VDBG; private static final String TAG = "PbapCallLogPullRequest"; private static final String TAG = "PbapCallLogPullRequest"; private static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME"; @VisibleForTesting static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME"; private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss"; private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss"; private final Account mAccount; private final Account mAccount; Loading android/app/src/com/android/bluetooth/pbapclient/PhonebookPullRequest.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -24,12 +24,14 @@ import android.os.RemoteException; import android.provider.ContactsContract; import android.provider.ContactsContract; import android.util.Log; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.vcard.VCardEntry; import com.android.vcard.VCardEntry; import java.util.ArrayList; import java.util.ArrayList; public class PhonebookPullRequest extends PullRequest { public class PhonebookPullRequest extends PullRequest { private static final int MAX_OPS = 250; @VisibleForTesting static final int MAX_OPS = 250; private static final boolean VDBG = Utils.VDBG; private static final boolean VDBG = Utils.VDBG; private static final String TAG = "PbapPbPullRequest"; private static final String TAG = "PbapPbPullRequest"; Loading android/app/tests/unit/src/com/android/bluetooth/pbapclient/CallLogPullRequestTest.java 0 → 100644 +165 −0 Original line number Original line Diff line number Diff line /* * Copyright 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth.pbapclient; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import android.accounts.Account; import android.content.Context; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.vcard.VCardConstants; import com.android.vcard.VCardEntry; import com.android.vcard.VCardProperty; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) public class CallLogPullRequestTest { private final Account mAccount = mock(Account.class); private final HashMap<String, Integer> mCallCounter = new HashMap<>(); private Context mTargetContext; @Before public void setUp() { mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); } @Test public void testToString() { final String path = PbapClientConnectionHandler.ICH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); assertThat(request.toString()).isNotEmpty(); } @Test public void onPullComplete_whenResultsAreNull() { final String path = PbapClientConnectionHandler.ICH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); request.setResults(null); request.onPullComplete(); // No operation has been done. assertThat(mCallCounter.size()).isEqualTo(0); } @Test public void onPullComplete_whenPathIsInvalid() { final String invalidPath = "invalidPath"; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, invalidPath, mCallCounter, mAccount); List<VCardEntry> results = new ArrayList<>(); request.setResults(results); request.onPullComplete(); // No operation has been done. assertThat(mCallCounter.size()).isEqualTo(0); } @Test public void onPullComplete_whenResultsAreEmpty() { final String path = PbapClientConnectionHandler.ICH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); List<VCardEntry> results = new ArrayList<>(); request.setResults(results); request.onPullComplete(); // Call counter should remain same. assertThat(mCallCounter.size()).isEqualTo(0); } @Test public void onPullComplete_whenThereIsNoPhoneProperty() { final String path = PbapClientConnectionHandler.MCH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); // Add some property which is NOT a phone number VCardProperty property = new VCardProperty(); property.setName(VCardConstants.PROPERTY_NOTE); property.setValues("Some random note"); VCardEntry entry = new VCardEntry(); entry.addProperty(property); List<VCardEntry> results = new ArrayList<>(); results.add(entry); request.setResults(results); request.onPullComplete(); // Call counter should remain same. assertThat(mCallCounter.size()).isEqualTo(0); } @Test public void onPullComplete_success() { final String path = PbapClientConnectionHandler.OCH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); List<VCardEntry> results = new ArrayList<>(); final String phoneNum = "tel:0123456789"; VCardEntry entry1 = new VCardEntry(); entry1.addProperty(createProperty(VCardConstants.PROPERTY_TEL, phoneNum)); results.add(entry1); VCardEntry entry2 = new VCardEntry(); entry2.addProperty(createProperty(VCardConstants.PROPERTY_TEL, phoneNum)); entry2.addProperty( createProperty(CallLogPullRequest.TIMESTAMP_PROPERTY, "20220914T143305")); results.add(entry2); request.setResults(results); request.onPullComplete(); assertThat(mCallCounter.size()).isEqualTo(1); for (String key : mCallCounter.keySet()) { assertThat(mCallCounter.get(key)).isEqualTo(2); break; } } private VCardProperty createProperty(String name, String value) { VCardProperty property = new VCardProperty(); property.setName(name); property.setValues(value); return property; } } android/app/tests/unit/src/com/android/bluetooth/pbapclient/PhonebookPullRequestTest.java 0 → 100644 +91 −0 Original line number Original line Diff line number Diff line /* * Copyright 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth.pbapclient; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import android.accounts.Account; import android.content.Context; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.vcard.VCardConstants; import com.android.vcard.VCardEntry; import com.android.vcard.VCardProperty; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) public class PhonebookPullRequestTest { private PhonebookPullRequest mRequest; private Context mTargetContext; @Before public void setUp() { mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); mRequest = new PhonebookPullRequest(mTargetContext, mock(Account.class)); } @Test public void onPullComplete_whenResultsAreNull() { mRequest.setResults(null); mRequest.onPullComplete(); // No operation has been done. assertThat(mRequest.complete).isFalse(); } @Test public void onPullComplete_success() { List<VCardEntry> results = new ArrayList<>(); results.add(createEntry(200)); results.add(createEntry(200)); results.add(createEntry(PhonebookPullRequest.MAX_OPS)); mRequest.setResults(results); mRequest.onPullComplete(); assertThat(mRequest.complete).isTrue(); } private VCardProperty createProperty(String name, String value) { VCardProperty property = new VCardProperty(); property.setName(name); property.setValues(value); return property; } private VCardEntry createEntry(int propertyCount) { VCardEntry entry = new VCardEntry(); for (int i = 0; i < propertyCount; i++) { entry.addProperty(createProperty(VCardConstants.PROPERTY_TEL, Integer.toString(i))); } return entry; } } Loading
android/app/src/com/android/bluetooth/pbapclient/CallLogPullRequest.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.provider.ContactsContract; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Pair; import com.android.internal.annotations.VisibleForTesting; import com.android.vcard.VCardEntry; import com.android.vcard.VCardEntry; import com.android.vcard.VCardEntry.PhoneData; import com.android.vcard.VCardEntry.PhoneData; Loading @@ -42,7 +43,8 @@ public class CallLogPullRequest extends PullRequest { private static final boolean DBG = Utils.DBG; private static final boolean DBG = Utils.DBG; private static final boolean VDBG = Utils.VDBG; private static final boolean VDBG = Utils.VDBG; private static final String TAG = "PbapCallLogPullRequest"; private static final String TAG = "PbapCallLogPullRequest"; private static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME"; @VisibleForTesting static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME"; private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss"; private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss"; private final Account mAccount; private final Account mAccount; Loading
android/app/src/com/android/bluetooth/pbapclient/PhonebookPullRequest.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -24,12 +24,14 @@ import android.os.RemoteException; import android.provider.ContactsContract; import android.provider.ContactsContract; import android.util.Log; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.vcard.VCardEntry; import com.android.vcard.VCardEntry; import java.util.ArrayList; import java.util.ArrayList; public class PhonebookPullRequest extends PullRequest { public class PhonebookPullRequest extends PullRequest { private static final int MAX_OPS = 250; @VisibleForTesting static final int MAX_OPS = 250; private static final boolean VDBG = Utils.VDBG; private static final boolean VDBG = Utils.VDBG; private static final String TAG = "PbapPbPullRequest"; private static final String TAG = "PbapPbPullRequest"; Loading
android/app/tests/unit/src/com/android/bluetooth/pbapclient/CallLogPullRequestTest.java 0 → 100644 +165 −0 Original line number Original line Diff line number Diff line /* * Copyright 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth.pbapclient; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import android.accounts.Account; import android.content.Context; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.vcard.VCardConstants; import com.android.vcard.VCardEntry; import com.android.vcard.VCardProperty; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) public class CallLogPullRequestTest { private final Account mAccount = mock(Account.class); private final HashMap<String, Integer> mCallCounter = new HashMap<>(); private Context mTargetContext; @Before public void setUp() { mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); } @Test public void testToString() { final String path = PbapClientConnectionHandler.ICH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); assertThat(request.toString()).isNotEmpty(); } @Test public void onPullComplete_whenResultsAreNull() { final String path = PbapClientConnectionHandler.ICH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); request.setResults(null); request.onPullComplete(); // No operation has been done. assertThat(mCallCounter.size()).isEqualTo(0); } @Test public void onPullComplete_whenPathIsInvalid() { final String invalidPath = "invalidPath"; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, invalidPath, mCallCounter, mAccount); List<VCardEntry> results = new ArrayList<>(); request.setResults(results); request.onPullComplete(); // No operation has been done. assertThat(mCallCounter.size()).isEqualTo(0); } @Test public void onPullComplete_whenResultsAreEmpty() { final String path = PbapClientConnectionHandler.ICH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); List<VCardEntry> results = new ArrayList<>(); request.setResults(results); request.onPullComplete(); // Call counter should remain same. assertThat(mCallCounter.size()).isEqualTo(0); } @Test public void onPullComplete_whenThereIsNoPhoneProperty() { final String path = PbapClientConnectionHandler.MCH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); // Add some property which is NOT a phone number VCardProperty property = new VCardProperty(); property.setName(VCardConstants.PROPERTY_NOTE); property.setValues("Some random note"); VCardEntry entry = new VCardEntry(); entry.addProperty(property); List<VCardEntry> results = new ArrayList<>(); results.add(entry); request.setResults(results); request.onPullComplete(); // Call counter should remain same. assertThat(mCallCounter.size()).isEqualTo(0); } @Test public void onPullComplete_success() { final String path = PbapClientConnectionHandler.OCH_PATH; final CallLogPullRequest request = new CallLogPullRequest( mTargetContext, path, mCallCounter, mAccount); List<VCardEntry> results = new ArrayList<>(); final String phoneNum = "tel:0123456789"; VCardEntry entry1 = new VCardEntry(); entry1.addProperty(createProperty(VCardConstants.PROPERTY_TEL, phoneNum)); results.add(entry1); VCardEntry entry2 = new VCardEntry(); entry2.addProperty(createProperty(VCardConstants.PROPERTY_TEL, phoneNum)); entry2.addProperty( createProperty(CallLogPullRequest.TIMESTAMP_PROPERTY, "20220914T143305")); results.add(entry2); request.setResults(results); request.onPullComplete(); assertThat(mCallCounter.size()).isEqualTo(1); for (String key : mCallCounter.keySet()) { assertThat(mCallCounter.get(key)).isEqualTo(2); break; } } private VCardProperty createProperty(String name, String value) { VCardProperty property = new VCardProperty(); property.setName(name); property.setValues(value); return property; } }
android/app/tests/unit/src/com/android/bluetooth/pbapclient/PhonebookPullRequestTest.java 0 → 100644 +91 −0 Original line number Original line Diff line number Diff line /* * Copyright 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth.pbapclient; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import android.accounts.Account; import android.content.Context; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.vcard.VCardConstants; import com.android.vcard.VCardEntry; import com.android.vcard.VCardProperty; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) public class PhonebookPullRequestTest { private PhonebookPullRequest mRequest; private Context mTargetContext; @Before public void setUp() { mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); mRequest = new PhonebookPullRequest(mTargetContext, mock(Account.class)); } @Test public void onPullComplete_whenResultsAreNull() { mRequest.setResults(null); mRequest.onPullComplete(); // No operation has been done. assertThat(mRequest.complete).isFalse(); } @Test public void onPullComplete_success() { List<VCardEntry> results = new ArrayList<>(); results.add(createEntry(200)); results.add(createEntry(200)); results.add(createEntry(PhonebookPullRequest.MAX_OPS)); mRequest.setResults(results); mRequest.onPullComplete(); assertThat(mRequest.complete).isTrue(); } private VCardProperty createProperty(String name, String value) { VCardProperty property = new VCardProperty(); property.setName(name); property.setValues(value); return property; } private VCardEntry createEntry(int propertyCount) { VCardEntry entry = new VCardEntry(); for (int i = 0; i < propertyCount; i++) { entry.addProperty(createProperty(VCardConstants.PROPERTY_TEL, Integer.toString(i))); } return entry; } }