[Settings] Code refactor for performance

Perform query in the background thread to reduce the time required for
rendering UI.

Bug: 260540995
Test: local
Change-Id: I4286553b44b51752ae64a9bb2ce5656fe7e9b4e8
This commit is contained in:
Bonian Chen
2022-12-06 10:41:00 +00:00
parent 14f145181f
commit 854eb4947a
3 changed files with 62 additions and 14 deletions

View File

@@ -33,6 +33,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@RunWith(AndroidJUnit4.class)
public class SlotSimStatusTest {
@@ -58,6 +61,16 @@ public class SlotSimStatusTest {
assertEquals(new Integer(target.size()), new Integer(2));
}
@Test
public void size_returnNumberOfPhone_whenQueryInBackgroundThread() {
doReturn(2).when(mTelephonyManager).getPhoneCount();
ExecutorService executor = Executors.newSingleThreadExecutor();
SlotSimStatus target = new SlotSimStatus(mContext, executor);
assertEquals(new Integer(target.size()), new Integer(2));
}
@Test
public void getPreferenceOrdering_returnOrdering_whenQuery() {
doReturn(2).when(mTelephonyManager).getPhoneCount();