Skip to content

Commit

Permalink
telephony: replace hidden `OnSubscriptionsChangedListener.getHandlerE…
Browse files Browse the repository at this point in the history
…xecutor()` API with `Context.getMainExecutor()`

Signed-off-by: iusmac <[email protected]>
  • Loading branch information
iusmac committed Apr 10, 2024
1 parent 33b6122 commit 5fae4a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/com/github/iusmac/sevensim/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class Utils {
public static final boolean IS_AT_LEAST_S = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S;
public static final boolean IS_AT_LEAST_T =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
public static final boolean IS_OLDER_THAN_R = Build.VERSION.SDK_INT < Build.VERSION_CODES.R;

/**
* This a backport of the {@code #BundleCompat.getParcelable} from <b>AndroidX Core v1.10.0</b>
Expand Down
22 changes: 17 additions & 5 deletions src/com/github/iusmac/sevensim/telephony/Subscriptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,26 @@ public Subscriptions(final @ApplicationContext Context context,
mUsableSubIdsSysProp = usableSimSubIdsSysProp;
mSubscriptionsDao = appDatabase.subscriptionsDao();

mSubscriptionManagerListener =
new SubscriptionManager.OnSubscriptionsChangedListener(mContext.getMainLooper()) {
// We use hidden API to create listener with a custom looper before Android 11.0 (R), on
// newer versions, we can register the listener with a custom executor via
// SubscriptionsImpl#addOnSubscriptionsChangedListener()
if (Utils.IS_OLDER_THAN_R) {
mSubscriptionManagerListener =
new SubscriptionManager.OnSubscriptionsChangedListener(mContext.getMainLooper()) {
@Override
public void onSubscriptionsChanged() {
dispatchOnSubscriptionInfoRecordsChanged();
}
};
} else {
mSubscriptionManagerListener =
new SubscriptionManager.OnSubscriptionsChangedListener() {
@Override
public void onSubscriptionsChanged() {
dispatchOnSubscriptionInfoRecordsChanged();
}
};
}
}

/**
Expand Down Expand Up @@ -360,9 +373,8 @@ public void syncSubscriptions(final LocalDateTime dateTime) {
private void registerSubscriptionManagerListener() {
mLogger.v("registerSubscriptionManagerListener().");

if (Utils.IS_AT_LEAST_S) {
mSubscriptionManager.addOnSubscriptionsChangedListener(
mSubscriptionManagerListener.getHandlerExecutor(),
if (Utils.IS_AT_LEAST_R) {
mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(),
mSubscriptionManagerListener);
} else {
ApiDeprecated.addOnSubscriptionsChangedListener(mSubscriptionManager,
Expand Down

0 comments on commit 5fae4a2

Please sign in to comment.