Skip to content

Commit c645a52

Browse files
authored
test(SubscriptionsComponentTest): fix failing instrumentation tests before Android 14-QPR2 (#67)
The instrumentation tests fail on Android 13, because we migrated to the newer API to create the listener too early. Only after the Android 14-QPR2 update the behavior was changed. As of docs for SubscriptionManager.OnSubscriptionsChangedListener constructor, we should continue to use the deprecated hidden API to create the listener on versions prior to Android 15: > On OS versions prior to {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} callers should > assume that this call will fail if invoked on a thread that does not already have a > prepared looper. --- > Task :connectedDebugAndroidTest com.github.iusmac.sevensim.telephony.SubscriptionsComponentTest > test_shouldReturnTheSameVisibleSubscriptionInfoListWhenQueriedBySubId[SM-A105FN - 13] FAILED java.lang.RuntimeException: Can't create handler inside thread Thread[Instr: com.github.iusmac.sevensim.HiltTestRunner,5,main] that has not called Looper.prepare() at android.os.Handler.<init>(Handler.java:227) com.github.iusmac.sevensim.telephony.SubscriptionsComponentTest > test_shouldReturnTheSameVisibleSubscriptionInfoListWhenQueriedBySimSlotIndex_SinceR[SM-A105FN - 13] FAILED java.lang.RuntimeException: Can't create handler inside thread Thread[Instr: com.github.iusmac.sevensim.HiltTestRunner,5,main] that has not called Looper.prepare() at android.os.Handler.<init>(Handler.java:227) Signed-off-by: iusmac <iusico.maxim@libero.it>
1 parent 7a3b018 commit c645a52

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/com/github/iusmac/sevensim/telephony/Subscriptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ public void onReceive(final Context context, final Intent intent) {
130130
mUsableSubIdsSysProp = usableSimSubIdsSysProp;
131131
mSubscriptionsDao = appDatabase.subscriptionsDao();
132132

133-
// We use hidden API to create listener with a custom looper before Android 11.0 (R), on
133+
// We use hidden API to create listener with a custom looper before Android 15.0 (V), on
134134
// newer versions, we can register the listener with a custom executor via
135135
// SubscriptionsImpl#addOnSubscriptionsChangedListener()
136-
if (Utils.IS_AT_LEAST_R) {
136+
if (Utils.IS_AT_LEAST_V) {
137137
mSubscriptionManagerListener =
138138
new SubscriptionManager.OnSubscriptionsChangedListener() {
139139
@Override
@@ -391,7 +391,7 @@ public void syncSubscriptions(final LocalDateTime dateTime) {
391391
private void registerSubscriptionManagerListener() {
392392
mLogger.v("registerSubscriptionManagerListener().");
393393

394-
if (Utils.IS_AT_LEAST_R) {
394+
if (Utils.IS_AT_LEAST_V) {
395395
mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(),
396396
mSubscriptionManagerListener);
397397
} else {

0 commit comments

Comments
 (0)