Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aea18e40 authored by Yomna N's avatar Yomna N Committed by Android (Google) Code Review
Browse files

Merge "Fix broken Safety Center redirect when SafetySourceData is null" into main

parents 99ff9245 d4dc1fed
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.READ_APP_SPECIFIC_LOCALES" />
    <uses-permission android:name="android.permission.QUERY_ADMIN_POLICY" />
    <uses-permission android:name="android.permission.MANAGE_SAFETY_CENTER" />
    <uses-permission android:name="android.permission.READ_SAFETY_CENTER_STATUS" />
    <uses-permission android:name="android.permission.SEND_SAFETY_CENTER_UPDATE" />
    <uses-permission android:name="android.permission.START_VIEW_APP_FEATURES" />
+21 −2
Original line number Diff line number Diff line
@@ -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;

@@ -133,13 +135,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, "");

+0 −17
Original line number Diff line number Diff line
@@ -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<Intent> 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);