Skip to content

Commit 75fbe4b

Browse files
committed
fix: ignore carrier config changes during early boot before syncing SIM cards
* During boot up process we get carrier config changes event for each SIM card once loaded. But, sometimes we get intermediate carrier config changes per SIM card during early boot since SIM cards are loaded into the system asynchronously. This forces us to synchronize all SIM cards again, and during this phase a SIM subscription present a moment ago may disappear again. Unfortunately, for our app this is SIM card removal, so we end up resetting the last activated / deactivated time fields, which are needed to properly initialize the user SIM card enabled state preference after a reboot. * This patch aims to resolve this SIM card load race by ignoring all carrier config changes during early boot in order to allow all SIM subscriptions to fully settle up. Signed-off-by: iusmac <iusico.maxim@libero.it>
1 parent 5b414e9 commit 75fbe4b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/com/github/iusmac/sevensim/DirectBootAwareBroadcastReceiver.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import dagger.hilt.android.AndroidEntryPoint;
1111

1212
import java.time.LocalDateTime;
13+
import java.util.Optional;
1314

1415
import javax.inject.Inject;
16+
import javax.inject.Named;
1517

1618
/**
1719
* <p>This static broadcast receiver is marked as being {@link ComponentInfo#directBootAware}, and
@@ -25,6 +27,10 @@ public final class DirectBootAwareBroadcastReceiver extends Hilt_DirectBootAware
2527
@Inject
2628
Logger.Factory mLoggerFactory;
2729

30+
@Inject
31+
@Named("LockedBootCompleted")
32+
SysProp mLockedBootCompletedSysProp;
33+
2834
private Logger mLogger;
2935

3036
@Override
@@ -39,6 +45,8 @@ public void onReceive(final Context context, final Intent intent) {
3945
final String action = intent.getAction() != null ? intent.getAction() : "";
4046
switch (action) {
4147
case Intent.ACTION_LOCKED_BOOT_COMPLETED:
48+
mLockedBootCompletedSysProp.set(Optional.of("1"));
49+
4250
// Need to sync the enabled state of all SIM subscriptions available on the device
4351
// with their existing weekly repeat schedules after the device has finished booting
4452
ForegroundService.syncAllSubscriptionsEnabledState(context, now,
@@ -52,6 +60,13 @@ public void onReceive(final Context context, final Intent intent) {
5260
break;
5361

5462
case CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED:
63+
// Ignore carrier config changes during early boot to allow all SIM subscriptions to
64+
// fully settle up
65+
if (!mLockedBootCompletedSysProp.isTrue()) {
66+
mLogger.d("onReceive() : Ignoring early boot carrier config changes.");
67+
break;
68+
}
69+
5570
// Avoid rebroadcast after unlocking the device as we're direct boot aware
5671
if (Utils.IS_AT_LEAST_R && intent.getBooleanExtra(CarrierConfigManager
5772
.EXTRA_REBROADCAST_ON_UNLOCK, false)) {

src/com/github/iusmac/sevensim/inject/SevenSimModule.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ static DevicePolicyManager provideDevicePolicyManager(
158158
return ContextCompat.getSystemService(context, DevicePolicyManager.class);
159159
}
160160

161+
@Named("LockedBootCompleted")
162+
@Singleton
163+
@Provides
164+
static SysProp provideLockedBootCompletedSysProp() {
165+
return new SysProp("locked_boot_completed", /*isPersistent=*/ false);
166+
}
167+
161168
/** Do not initialize. */
162169
private SevenSimModule() {}
163170
}

0 commit comments

Comments
 (0)