Loading src/java/com/android/internal/telephony/Phone.java +3 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; Loading Loading @@ -5374,6 +5375,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { */ public void notifyCarrierRoamingNtnAvailableServicesChanged( @NetworkRegistrationInfo.ServiceType int[] availableServices) { logd("notifyCarrierRoamingNtnAvailableServicesChanged availableServices:" + Arrays.toString(availableServices)); mNotifier.notifyCarrierRoamingNtnAvailableServicesChanged(this, availableServices); } Loading src/java/com/android/internal/telephony/satellite/SatelliteController.java +85 −31 Original line number Diff line number Diff line Loading @@ -596,6 +596,8 @@ public class SatelliteController extends Handler { private static final String ACTION_NOTIFICATION_CLICK = "action_notification_click"; private static final String ACTION_NOTIFICATION_DISMISS = "action_notification_dismiss"; private AtomicBoolean mOverrideNtnEligibility; private String mDefaultSmsPackageName = ""; private String mSatelliteGatewayServicePackageName = ""; private BroadcastReceiver mDefaultSmsSubscriptionChangedBroadcastReceiver = new BroadcastReceiver() { @Override Loading @@ -608,6 +610,32 @@ public class SatelliteController extends Handler { } }; private BroadcastReceiver mPackageStateChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mDefaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(mContext); mSatelliteGatewayServicePackageName = getConfigSatelliteGatewayServicePackage(); String schemeSpecificPart = intent.getData().getSchemeSpecificPart(); plogd("packageStateChanged: " + intent.getData().toString() + " DefaultSmsPackageName:" + mDefaultSmsPackageName); if (!schemeSpecificPart.equals(mSatelliteGatewayServicePackageName) && !schemeSpecificPart.equals(mDefaultSmsPackageName)) { plogv("Neither SMS or SatelliteGateway package"); return; } int[] activeSubIds = mSubscriptionManagerService.getActiveSubIdList(true); if (activeSubIds != null) { for (int activeSubId : activeSubIds) { plogd("mPackageStateChangedReceiver: activeSubId= " + activeSubId); handleCarrierRoamingNtnAvailableServicesChanged(activeSubId); } } else { ploge("mPackageStateChangedReceiver: activeSubIds is null"); } } }; // List of device states returned from DeviceStateManager to determine if running on a foldable // device. private List<DeviceState> mDeviceStates = new ArrayList(); Loading Loading @@ -716,6 +744,7 @@ public class SatelliteController extends Handler { } mSatellitePlmnListFromOverlayConfig = readSatellitePlmnsFromOverlayConfig(); registerApplicationStateChanged(); updateSupportedSatelliteServicesForActiveSubscriptions(); mCarrierConfigChangeListener = (slotIndex, subId, carrierId, specificCarrierId) -> Loading Loading @@ -6293,6 +6322,13 @@ public class SatelliteController extends Handler { } } private void plogv(@NonNull String log) { Rlog.v(TAG, log); if (mPersistentLogger != null) { mPersistentLogger.debug(TAG, log); } } private void handlePersistentLoggingOnSessionStart(RequestSatelliteEnabledArgument argument) { if (mPersistentLogger == null) { return; Loading Loading @@ -7114,7 +7150,8 @@ public class SatelliteController extends Handler { } } private void handleCarrierRoamingNtnAvailableServicesChanged(int subId) { @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) protected void handleCarrierRoamingNtnAvailableServicesChanged(int subId) { if (!mFeatureFlags.carrierRoamingNbIotNtn()) { plogd("handleCarrierRoamingNtnAvailableServicesChanged: " + "carrierRoamingNbIotNtn flag is disabled"); Loading @@ -7128,48 +7165,46 @@ public class SatelliteController extends Handler { plogd("notifyNtnAvailableServices: carrierRoamingNbIotNtn flag is disabled"); return; } synchronized (mSatellitePhoneLock) { if (mSatellitePhone == null) { plogd("updateLastNotifiedNtnAvailableServicesAndNotify: phone is null"); Phone phone = SatelliteServiceUtils.getPhone(subId); if (phone == null) { plogd("notifyNtnAvailableServices: phone is null."); return; } plogd("updateLastNotifiedNtnAvailableServicesAndNotify: phoneId= " + phone.getPhoneId()); if (isSatelliteSupportedViaCarrier(subId)) { // TODO: Invoke SatelliteManager#getSatelliteDisallowedReasons() NOT EMPTY. int[] services = getSupportedSatelliteServicesForCarrier(subId); if (isP2PSmsDisallowedOnCarrierRoamingNtn(mSatellitePhone)) { if (isP2PSmsDisallowedOnCarrierRoamingNtn(subId)) { services = Arrays.stream(services).filter( value -> value != NetworkRegistrationInfo.SERVICE_TYPE_SMS).toArray(); } mSatellitePhone.notifyCarrierRoamingNtnAvailableServicesChanged(services); phone.notifyCarrierRoamingNtnAvailableServicesChanged(services); } else { mSatellitePhone.notifyCarrierRoamingNtnAvailableServicesChanged(new int[0]); } phone.notifyCarrierRoamingNtnAvailableServicesChanged(new int[0]); } } /** * Whether the P2P SMS over carrier roaming satellite is disallowed or not. * * @param phone phone object * @param subId Associated subscription ID * return {@code true} when the phone does not support P2P SMS over carrier roaming satellite * {@code false} otherwise */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) public boolean isP2PSmsDisallowedOnCarrierRoamingNtn(@NonNull Phone phone) { int subId = phone.getSubId(); public boolean isP2PSmsDisallowedOnCarrierRoamingNtn(int subId) { int carrierRoamingNtnConnectType = getCarrierRoamingNtnConnectType(subId); if (carrierRoamingNtnConnectType == CARRIER_ROAMING_NTN_CONNECT_MANUAL) { // Manual Connected plogd("isP2PSmsDisallowedOnCarrierRoamingNtn: manual connect"); String msgPackageName = Telephony.Sms.getDefaultSmsPackage(mContext); String sgPackageName = getConfigSatelliteGatewayServicePackage(); if (!isApplicationSupportsP2P(msgPackageName) || !isApplicationSupportsP2P(sgPackageName)) { plogd("isP2PSmsSupportedOnCarrierRoamingNtn APKs do not supports P2P"); if (!isApplicationSupportsP2P(mDefaultSmsPackageName) || !isApplicationSupportsP2P(mSatelliteGatewayServicePackageName)) { plogd("isP2PSmsDisallowedOnCarrierRoamingNtn: APKs do not supports P2P"); return true; } } plogd("isP2PSmsDisallowedOnCarrierRoamingNtn [phoneId=" + phone.getPhoneId() + "]: P2P is supported"); plogd("isP2PSmsDisallowedOnCarrierRoamingNtn: P2P is supported"); return false; } Loading @@ -7188,7 +7223,8 @@ public class SatelliteController extends Handler { } /** * Whether application supports the P2P SMS to connect to carrier roaming non-terrestrial network. * Whether application supports the P2P SMS to connect to carrier roaming non-terrestrial * network. * * @param packageName application's default package name * return {@code true} when the application supports P2P SMS over the roaming satellite Loading @@ -7201,6 +7237,7 @@ public class SatelliteController extends Handler { applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { logd("isApplicationSupportsP2P pkgName: " + packageName + " is not installed."); return false; } if (applicationInfo == null || applicationInfo.metaData == null) { logd("isApplicationSupportsP2P pkgName: " + packageName + " meta-data info is empty."); Loading @@ -7209,4 +7246,21 @@ public class SatelliteController extends Handler { return applicationInfo.metaData.getBoolean( SatelliteManager.METADATA_SATELLITE_MANUAL_CONNECT_P2P_SUPPORT); } /** * Registers for the applications state changed. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) public void registerApplicationStateChanged() { mDefaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(mContext); mSatelliteGatewayServicePackageName = getConfigSatelliteGatewayServicePackage(); IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Telephony.Sms.Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED); packageFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED); packageFilter.addDataScheme("package"); mContext.registerReceiver(mPackageStateChangedReceiver, packageFilter, mContext.RECEIVER_EXPORTED); } } tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +92 −3 Original line number Diff line number Diff line Loading @@ -113,13 +113,16 @@ import static org.mockito.Mockito.when; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; import android.hardware.devicestate.DeviceState; import android.net.Uri; import android.os.AsyncResult; import android.os.Bundle; import android.os.CancellationSignal; Loading Loading @@ -198,6 +201,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; Loading Loading @@ -4831,7 +4835,7 @@ public class SatelliteControllerTest extends TelephonyTest { logd("NameNotFoundException"); } assertTrue(mSatelliteControllerUT .isP2PSmsDisallowedOnCarrierRoamingNtn(mPhone)); .isP2PSmsDisallowedOnCarrierRoamingNtn(/*subId*/ SUB_ID)); } @Test Loading @@ -4853,7 +4857,7 @@ public class SatelliteControllerTest extends TelephonyTest { } // If it is automatic connection case, it is not support the callback. assertFalse(mSatelliteControllerUT .isP2PSmsDisallowedOnCarrierRoamingNtn(mPhone)); .isP2PSmsDisallowedOnCarrierRoamingNtn(/*subId*/ SUB_ID)); } ApplicationInfo getApplicationInfo() { Loading @@ -4863,6 +4867,84 @@ public class SatelliteControllerTest extends TelephonyTest { METADATA_SATELLITE_MANUAL_CONNECT_P2P_SUPPORT, true); return applicationInfo; } @Test public void testRegisterApplicationStateChanged() { when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, false); when(mMockSubscriptionManagerService.getActiveSubIdList(true)) .thenReturn(new int[]{SUB_ID1}); ArgumentCaptor<IntentFilter> intentFilterCaptor = ArgumentCaptor.forClass(IntentFilter.class); ArgumentCaptor<BroadcastReceiver> receiverCaptor = ArgumentCaptor.forClass(BroadcastReceiver.class); verify(mContext).registerReceiver(receiverCaptor.capture(), intentFilterCaptor.capture(), anyInt()); BroadcastReceiver receiver = receiverCaptor.getValue(); mSatelliteControllerUT = new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); assertFalse(mSatelliteControllerUT.isApplicationUpdated); Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED); intent.setData(Uri.parse("com.example.app")); receiver.onReceive(mContext, intent); CountDownLatch latch1 = new CountDownLatch(1); new Handler(Looper.getMainLooper()).postDelayed(() -> { latch1.countDown(); }, 100); try { latch1.await(); } catch (InterruptedException e) { } assertTrue(mSatelliteControllerUT.isApplicationUpdated); mSatelliteControllerUT = new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); assertFalse(mSatelliteControllerUT.isApplicationUpdated); intent = new Intent(Intent.ACTION_PACKAGE_REPLACED); intent.setData(Uri.parse("com.example.app")); receiver.onReceive(mContext, intent); CountDownLatch latch2 = new CountDownLatch(1); new Handler(Looper.getMainLooper()).postDelayed(() -> { latch2.countDown(); }, 100); try { latch2.await(); } catch (InterruptedException e) { } assertTrue(mSatelliteControllerUT.isApplicationUpdated); mSatelliteControllerUT = new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); assertFalse(mSatelliteControllerUT.isApplicationUpdated); intent = new Intent(Intent.ACTION_PACKAGE_REMOVED); intent.setData(Uri.parse("com.example.app")); receiver.onReceive(mContext, intent); CountDownLatch latch3 = new CountDownLatch(1); new Handler(Looper.getMainLooper()).postDelayed(() -> { latch3.countDown(); }, 100); try { latch3.await(); } catch (InterruptedException e) { } assertTrue(mSatelliteControllerUT.isApplicationUpdated); mSatelliteControllerUT = new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); assertFalse(mSatelliteControllerUT.isApplicationUpdated); intent = new Intent(Intent.ACTION_PACKAGE_ADDED); intent.setData(Uri.parse("com.example.different")); receiver.onReceive(mContext, intent); CountDownLatch latch4 = new CountDownLatch(1); new Handler(Looper.getMainLooper()).postDelayed(() -> { latch4.countDown(); }, 100); try { latch4.await(); } catch (InterruptedException e) { } assertFalse(mSatelliteControllerUT.isApplicationUpdated); } private void verifyProvisionStatusPerSubscriberIdGetFromDb(boolean provision) { doReturn(provision).when( mMockSubscriptionManagerService).isSatelliteProvisionedForNonIpDatagram(anyInt()); Loading Loading @@ -5620,12 +5702,13 @@ public class SatelliteControllerTest extends TelephonyTest { public int satelliteModeSettingValue = SATELLITE_MODE_ENABLED_FALSE; public boolean setSettingsKeyToAllowDeviceRotationCalled = false; public OutcomeReceiver<Boolean, SatelliteException> isSatelliteAllowedCallback = null; public String packageName = "com.example.app"; public static boolean isApplicationUpdated; TestSatelliteController( Context context, Looper looper, @NonNull FeatureFlags featureFlags) { super(context, looper, featureFlags); logd("Constructing TestSatelliteController"); isApplicationUpdated = false; } @Override Loading Loading @@ -5702,9 +5785,15 @@ public class SatelliteControllerTest extends TelephonyTest { @Override protected String getConfigSatelliteGatewayServicePackage() { String packageName = "com.example.app"; return packageName; } @Override protected void handleCarrierRoamingNtnAvailableServicesChanged(int subId) { isApplicationUpdated = true; } void setSatelliteProvisioned(@Nullable Boolean isProvisioned) { synchronized (mSatelliteViaOemProvisionLock) { mIsSatelliteViaOemProvisioned = isProvisioned; Loading Loading
src/java/com/android/internal/telephony/Phone.java +3 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; Loading Loading @@ -5374,6 +5375,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { */ public void notifyCarrierRoamingNtnAvailableServicesChanged( @NetworkRegistrationInfo.ServiceType int[] availableServices) { logd("notifyCarrierRoamingNtnAvailableServicesChanged availableServices:" + Arrays.toString(availableServices)); mNotifier.notifyCarrierRoamingNtnAvailableServicesChanged(this, availableServices); } Loading
src/java/com/android/internal/telephony/satellite/SatelliteController.java +85 −31 Original line number Diff line number Diff line Loading @@ -596,6 +596,8 @@ public class SatelliteController extends Handler { private static final String ACTION_NOTIFICATION_CLICK = "action_notification_click"; private static final String ACTION_NOTIFICATION_DISMISS = "action_notification_dismiss"; private AtomicBoolean mOverrideNtnEligibility; private String mDefaultSmsPackageName = ""; private String mSatelliteGatewayServicePackageName = ""; private BroadcastReceiver mDefaultSmsSubscriptionChangedBroadcastReceiver = new BroadcastReceiver() { @Override Loading @@ -608,6 +610,32 @@ public class SatelliteController extends Handler { } }; private BroadcastReceiver mPackageStateChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mDefaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(mContext); mSatelliteGatewayServicePackageName = getConfigSatelliteGatewayServicePackage(); String schemeSpecificPart = intent.getData().getSchemeSpecificPart(); plogd("packageStateChanged: " + intent.getData().toString() + " DefaultSmsPackageName:" + mDefaultSmsPackageName); if (!schemeSpecificPart.equals(mSatelliteGatewayServicePackageName) && !schemeSpecificPart.equals(mDefaultSmsPackageName)) { plogv("Neither SMS or SatelliteGateway package"); return; } int[] activeSubIds = mSubscriptionManagerService.getActiveSubIdList(true); if (activeSubIds != null) { for (int activeSubId : activeSubIds) { plogd("mPackageStateChangedReceiver: activeSubId= " + activeSubId); handleCarrierRoamingNtnAvailableServicesChanged(activeSubId); } } else { ploge("mPackageStateChangedReceiver: activeSubIds is null"); } } }; // List of device states returned from DeviceStateManager to determine if running on a foldable // device. private List<DeviceState> mDeviceStates = new ArrayList(); Loading Loading @@ -716,6 +744,7 @@ public class SatelliteController extends Handler { } mSatellitePlmnListFromOverlayConfig = readSatellitePlmnsFromOverlayConfig(); registerApplicationStateChanged(); updateSupportedSatelliteServicesForActiveSubscriptions(); mCarrierConfigChangeListener = (slotIndex, subId, carrierId, specificCarrierId) -> Loading Loading @@ -6293,6 +6322,13 @@ public class SatelliteController extends Handler { } } private void plogv(@NonNull String log) { Rlog.v(TAG, log); if (mPersistentLogger != null) { mPersistentLogger.debug(TAG, log); } } private void handlePersistentLoggingOnSessionStart(RequestSatelliteEnabledArgument argument) { if (mPersistentLogger == null) { return; Loading Loading @@ -7114,7 +7150,8 @@ public class SatelliteController extends Handler { } } private void handleCarrierRoamingNtnAvailableServicesChanged(int subId) { @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) protected void handleCarrierRoamingNtnAvailableServicesChanged(int subId) { if (!mFeatureFlags.carrierRoamingNbIotNtn()) { plogd("handleCarrierRoamingNtnAvailableServicesChanged: " + "carrierRoamingNbIotNtn flag is disabled"); Loading @@ -7128,48 +7165,46 @@ public class SatelliteController extends Handler { plogd("notifyNtnAvailableServices: carrierRoamingNbIotNtn flag is disabled"); return; } synchronized (mSatellitePhoneLock) { if (mSatellitePhone == null) { plogd("updateLastNotifiedNtnAvailableServicesAndNotify: phone is null"); Phone phone = SatelliteServiceUtils.getPhone(subId); if (phone == null) { plogd("notifyNtnAvailableServices: phone is null."); return; } plogd("updateLastNotifiedNtnAvailableServicesAndNotify: phoneId= " + phone.getPhoneId()); if (isSatelliteSupportedViaCarrier(subId)) { // TODO: Invoke SatelliteManager#getSatelliteDisallowedReasons() NOT EMPTY. int[] services = getSupportedSatelliteServicesForCarrier(subId); if (isP2PSmsDisallowedOnCarrierRoamingNtn(mSatellitePhone)) { if (isP2PSmsDisallowedOnCarrierRoamingNtn(subId)) { services = Arrays.stream(services).filter( value -> value != NetworkRegistrationInfo.SERVICE_TYPE_SMS).toArray(); } mSatellitePhone.notifyCarrierRoamingNtnAvailableServicesChanged(services); phone.notifyCarrierRoamingNtnAvailableServicesChanged(services); } else { mSatellitePhone.notifyCarrierRoamingNtnAvailableServicesChanged(new int[0]); } phone.notifyCarrierRoamingNtnAvailableServicesChanged(new int[0]); } } /** * Whether the P2P SMS over carrier roaming satellite is disallowed or not. * * @param phone phone object * @param subId Associated subscription ID * return {@code true} when the phone does not support P2P SMS over carrier roaming satellite * {@code false} otherwise */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) public boolean isP2PSmsDisallowedOnCarrierRoamingNtn(@NonNull Phone phone) { int subId = phone.getSubId(); public boolean isP2PSmsDisallowedOnCarrierRoamingNtn(int subId) { int carrierRoamingNtnConnectType = getCarrierRoamingNtnConnectType(subId); if (carrierRoamingNtnConnectType == CARRIER_ROAMING_NTN_CONNECT_MANUAL) { // Manual Connected plogd("isP2PSmsDisallowedOnCarrierRoamingNtn: manual connect"); String msgPackageName = Telephony.Sms.getDefaultSmsPackage(mContext); String sgPackageName = getConfigSatelliteGatewayServicePackage(); if (!isApplicationSupportsP2P(msgPackageName) || !isApplicationSupportsP2P(sgPackageName)) { plogd("isP2PSmsSupportedOnCarrierRoamingNtn APKs do not supports P2P"); if (!isApplicationSupportsP2P(mDefaultSmsPackageName) || !isApplicationSupportsP2P(mSatelliteGatewayServicePackageName)) { plogd("isP2PSmsDisallowedOnCarrierRoamingNtn: APKs do not supports P2P"); return true; } } plogd("isP2PSmsDisallowedOnCarrierRoamingNtn [phoneId=" + phone.getPhoneId() + "]: P2P is supported"); plogd("isP2PSmsDisallowedOnCarrierRoamingNtn: P2P is supported"); return false; } Loading @@ -7188,7 +7223,8 @@ public class SatelliteController extends Handler { } /** * Whether application supports the P2P SMS to connect to carrier roaming non-terrestrial network. * Whether application supports the P2P SMS to connect to carrier roaming non-terrestrial * network. * * @param packageName application's default package name * return {@code true} when the application supports P2P SMS over the roaming satellite Loading @@ -7201,6 +7237,7 @@ public class SatelliteController extends Handler { applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { logd("isApplicationSupportsP2P pkgName: " + packageName + " is not installed."); return false; } if (applicationInfo == null || applicationInfo.metaData == null) { logd("isApplicationSupportsP2P pkgName: " + packageName + " meta-data info is empty."); Loading @@ -7209,4 +7246,21 @@ public class SatelliteController extends Handler { return applicationInfo.metaData.getBoolean( SatelliteManager.METADATA_SATELLITE_MANUAL_CONNECT_P2P_SUPPORT); } /** * Registers for the applications state changed. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) public void registerApplicationStateChanged() { mDefaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(mContext); mSatelliteGatewayServicePackageName = getConfigSatelliteGatewayServicePackage(); IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Telephony.Sms.Intents.ACTION_DEFAULT_SMS_PACKAGE_CHANGED); packageFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED); packageFilter.addDataScheme("package"); mContext.registerReceiver(mPackageStateChangedReceiver, packageFilter, mContext.RECEIVER_EXPORTED); } }
tests/telephonytests/src/com/android/internal/telephony/satellite/SatelliteControllerTest.java +92 −3 Original line number Diff line number Diff line Loading @@ -113,13 +113,16 @@ import static org.mockito.Mockito.when; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; import android.hardware.devicestate.DeviceState; import android.net.Uri; import android.os.AsyncResult; import android.os.Bundle; import android.os.CancellationSignal; Loading Loading @@ -198,6 +201,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; Loading Loading @@ -4831,7 +4835,7 @@ public class SatelliteControllerTest extends TelephonyTest { logd("NameNotFoundException"); } assertTrue(mSatelliteControllerUT .isP2PSmsDisallowedOnCarrierRoamingNtn(mPhone)); .isP2PSmsDisallowedOnCarrierRoamingNtn(/*subId*/ SUB_ID)); } @Test Loading @@ -4853,7 +4857,7 @@ public class SatelliteControllerTest extends TelephonyTest { } // If it is automatic connection case, it is not support the callback. assertFalse(mSatelliteControllerUT .isP2PSmsDisallowedOnCarrierRoamingNtn(mPhone)); .isP2PSmsDisallowedOnCarrierRoamingNtn(/*subId*/ SUB_ID)); } ApplicationInfo getApplicationInfo() { Loading @@ -4863,6 +4867,84 @@ public class SatelliteControllerTest extends TelephonyTest { METADATA_SATELLITE_MANUAL_CONNECT_P2P_SUPPORT, true); return applicationInfo; } @Test public void testRegisterApplicationStateChanged() { when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true); mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, false); when(mMockSubscriptionManagerService.getActiveSubIdList(true)) .thenReturn(new int[]{SUB_ID1}); ArgumentCaptor<IntentFilter> intentFilterCaptor = ArgumentCaptor.forClass(IntentFilter.class); ArgumentCaptor<BroadcastReceiver> receiverCaptor = ArgumentCaptor.forClass(BroadcastReceiver.class); verify(mContext).registerReceiver(receiverCaptor.capture(), intentFilterCaptor.capture(), anyInt()); BroadcastReceiver receiver = receiverCaptor.getValue(); mSatelliteControllerUT = new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); assertFalse(mSatelliteControllerUT.isApplicationUpdated); Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED); intent.setData(Uri.parse("com.example.app")); receiver.onReceive(mContext, intent); CountDownLatch latch1 = new CountDownLatch(1); new Handler(Looper.getMainLooper()).postDelayed(() -> { latch1.countDown(); }, 100); try { latch1.await(); } catch (InterruptedException e) { } assertTrue(mSatelliteControllerUT.isApplicationUpdated); mSatelliteControllerUT = new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); assertFalse(mSatelliteControllerUT.isApplicationUpdated); intent = new Intent(Intent.ACTION_PACKAGE_REPLACED); intent.setData(Uri.parse("com.example.app")); receiver.onReceive(mContext, intent); CountDownLatch latch2 = new CountDownLatch(1); new Handler(Looper.getMainLooper()).postDelayed(() -> { latch2.countDown(); }, 100); try { latch2.await(); } catch (InterruptedException e) { } assertTrue(mSatelliteControllerUT.isApplicationUpdated); mSatelliteControllerUT = new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); assertFalse(mSatelliteControllerUT.isApplicationUpdated); intent = new Intent(Intent.ACTION_PACKAGE_REMOVED); intent.setData(Uri.parse("com.example.app")); receiver.onReceive(mContext, intent); CountDownLatch latch3 = new CountDownLatch(1); new Handler(Looper.getMainLooper()).postDelayed(() -> { latch3.countDown(); }, 100); try { latch3.await(); } catch (InterruptedException e) { } assertTrue(mSatelliteControllerUT.isApplicationUpdated); mSatelliteControllerUT = new TestSatelliteController(mContext, Looper.myLooper(), mFeatureFlags); assertFalse(mSatelliteControllerUT.isApplicationUpdated); intent = new Intent(Intent.ACTION_PACKAGE_ADDED); intent.setData(Uri.parse("com.example.different")); receiver.onReceive(mContext, intent); CountDownLatch latch4 = new CountDownLatch(1); new Handler(Looper.getMainLooper()).postDelayed(() -> { latch4.countDown(); }, 100); try { latch4.await(); } catch (InterruptedException e) { } assertFalse(mSatelliteControllerUT.isApplicationUpdated); } private void verifyProvisionStatusPerSubscriberIdGetFromDb(boolean provision) { doReturn(provision).when( mMockSubscriptionManagerService).isSatelliteProvisionedForNonIpDatagram(anyInt()); Loading Loading @@ -5620,12 +5702,13 @@ public class SatelliteControllerTest extends TelephonyTest { public int satelliteModeSettingValue = SATELLITE_MODE_ENABLED_FALSE; public boolean setSettingsKeyToAllowDeviceRotationCalled = false; public OutcomeReceiver<Boolean, SatelliteException> isSatelliteAllowedCallback = null; public String packageName = "com.example.app"; public static boolean isApplicationUpdated; TestSatelliteController( Context context, Looper looper, @NonNull FeatureFlags featureFlags) { super(context, looper, featureFlags); logd("Constructing TestSatelliteController"); isApplicationUpdated = false; } @Override Loading Loading @@ -5702,9 +5785,15 @@ public class SatelliteControllerTest extends TelephonyTest { @Override protected String getConfigSatelliteGatewayServicePackage() { String packageName = "com.example.app"; return packageName; } @Override protected void handleCarrierRoamingNtnAvailableServicesChanged(int subId) { isApplicationUpdated = true; } void setSatelliteProvisioned(@Nullable Boolean isProvisioned) { synchronized (mSatelliteViaOemProvisionLock) { mIsSatelliteViaOemProvisioned = isProvisioned; Loading