diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 2c62ebd684c..177e750c892 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -132,6 +132,7 @@
+
diff --git a/src/com/android/settings/network/CellularSecurityPreferenceController.java b/src/com/android/settings/network/CellularSecurityPreferenceController.java
index a184553c0f3..f02e82458db 100644
--- a/src/com/android/settings/network/CellularSecurityPreferenceController.java
+++ b/src/com/android/settings/network/CellularSecurityPreferenceController.java
@@ -23,6 +23,7 @@ import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.safetycenter.SafetyCenterManager;
+import android.safetycenter.SafetySourceData;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
@@ -48,6 +49,7 @@ import java.util.List;
public class CellularSecurityPreferenceController extends BasePreferenceController {
private static final String LOG_TAG = "CellularSecurityPreferenceController";
+ private static final String SAFETY_SOURCE_ID = "AndroidCellularNetworkSecurity";
private @Nullable TelephonyManager mTelephonyManager;
@@ -134,13 +136,30 @@ public class CellularSecurityPreferenceController extends BasePreferenceControll
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
return super.handlePreferenceTreeClick(preference);
}
- boolean isSafetyCenterSupported = isSafetyCenterSupported();
- if (isSafetyCenterSupported && areNotificationsEnabled()) {
+ if (!isSafetyCenterSupported()) {
+ // Realistically, it's unlikely to end up in handlePreferenceTreeClick with SafetyCenter
+ // being not supported on the device.
+ return false;
+ }
+ // Need to check that both Safety Center is available on device, and also that the HALs are
+ // enabled before showing the Safety Center UI. Otherwise, we need to take them to the page
+ // where the HALs can be enabled.
+ SafetyCenterManager safetyCenterManager = mContext.getSystemService(
+ SafetyCenterManager.class);
+ SafetySourceData data = null;
+ if (safetyCenterManager.isSafetyCenterEnabled()) {
+ data = safetyCenterManager.getSafetySourceData(SAFETY_SOURCE_ID);
+ }
+ // Can only redirect to SafetyCenter if it has received data via the SafetySource, as
+ // SafetyCenter doesn't support redirecting to a specific page associated with a source
+ // if it hasn't received data from that source. See b/373942609 for details.
+ if (data != null && areNotificationsEnabled()) {
Intent safetyCenterIntent = new Intent(Intent.ACTION_SAFETY_CENTER);
safetyCenterIntent.putExtra(SafetyCenterManager.EXTRA_SAFETY_SOURCES_GROUP_ID,
"AndroidCellularNetworkSecuritySources");
mContext.startActivity(safetyCenterIntent);
} else {
+ Log.v(LOG_TAG, "Hardware APIs not enabled, or data source is null.");
final Bundle bundle = new Bundle();
bundle.putString(CellularSecuritySettingsFragment.KEY_CELLULAR_SECURITY_PREFERENCE, "");
diff --git a/tests/unit/src/com/android/settings/network/CellularSecurityPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/CellularSecurityPreferenceControllerTest.java
index 7f05913cd82..359019db8e5 100644
--- a/tests/unit/src/com/android/settings/network/CellularSecurityPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/CellularSecurityPreferenceControllerTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -50,7 +49,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -148,21 +146,6 @@ public final class CellularSecurityPreferenceControllerTest {
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
- @Test
- public void handlePreferenceTreeClick_safetyCenterSupported_shouldRedirectToSafetyCenter() {
- final ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class);
-
- doReturn(true).when(mTelephonyManager).isNullCipherNotificationsEnabled();
- doReturn(true).when(mTelephonyManager)
- .isCellularIdentifierDisclosureNotificationsEnabled();
- doReturn(true).when(mTelephonyManager).isNullCipherAndIntegrityPreferenceEnabled();
- boolean prefHandled = mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(prefHandled).isTrue();
- verify(mContext).startActivity(intentCaptor.capture());
- assertThat(intentCaptor.getValue().getAction()).isEqualTo(Intent.ACTION_SAFETY_CENTER);
- }
-
private void enableFlags(boolean enabled) {
if (enabled) {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_MODEM_CIPHER_TRANSPARENCY_UNSOL_EVENTS);