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

Commit 0e818a5f authored by talreja's avatar talreja
Browse files

Added the logic to show specific identifier in identifier disclosure notification.

Bug: 417307656
Test: m & atest CellularNetworkSecuritySafetySourceTest CellularIdentifierDisclosureNotifierTest
Flag: EXEMPT bugfix
Change-Id: Ib0389b6030e273792e5cc51f5e91fdf1b0495a7e
parent d8208540
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public class CellularIdentifierDisclosureNotifier {
            // because we know that any actions taken on disabled will be scheduled after this
            // incrementAndNotify call.
            try {
                mSerializedWorkQueue.execute(incrementAndNotify(context, subId));
                mSerializedWorkQueue.execute(incrementAndNotify(context, subId, disclosure));
            } catch (RejectedExecutionException e) {
                Rlog.e(TAG, "Failed to schedule incrementAndNotify: " + e.getMessage());
            }
@@ -212,7 +212,8 @@ public class CellularIdentifierDisclosureNotifier {
        return sInstance;
    }

    private Runnable incrementAndNotify(Context context, int subId) {
    private Runnable incrementAndNotify(Context context, int subId,
                                        CellularIdentifierDisclosure disclosure) {
        return () -> {
            DisclosureWindow window = mWindows.get(subId);
            if (window == null) {
@@ -234,6 +235,7 @@ public class CellularIdentifierDisclosureNotifier {
            mSafetySource.setIdentifierDisclosure(
                    context,
                    subId,
                    disclosure,
                    disclosureCount,
                    window.getFirstOpen(),
                    window.getCurrentEnd());
+47 −15
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUEST
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED;
import static android.safetycenter.SafetySourceData.SEVERITY_LEVEL_INFORMATION;
import static android.safetycenter.SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION;
import static android.telephony.CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_IMEI;
import static android.telephony.CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_IMSI;
import static android.telephony.CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_SUCI;

import android.annotation.IntDef;
import android.app.PendingIntent;
@@ -32,6 +35,9 @@ import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceIssue;
import android.safetycenter.SafetySourceStatus;
import android.telephony.CellularIdentifierDisclosure;
import android.telephony.CellularIdentifierDisclosure.CellularIdentifier;
import android.text.TextUtils;
import android.text.format.DateFormat;

import com.android.internal.R;
@@ -145,9 +151,11 @@ public class CellularNetworkSecuritySafetySource {

    /** Sets the identifier disclosure issue state for the identifier subscription. */
    public synchronized void setIdentifierDisclosure(
            Context context, int subId, int count, Instant start, Instant end) {
        IdentifierDisclosure disclosure = new IdentifierDisclosure(count, start, end);
        mIdentifierDisclosures.put(subId, disclosure);
            Context context, int subId, CellularIdentifierDisclosure disclosure, int count,
            Instant start, Instant end) {
        IdentifierDisclosure identifierDisclosure =
                new IdentifierDisclosure(count, start, end, disclosure);
        mIdentifierDisclosures.put(subId, identifierDisclosure);
        updateSafetyCenter(context);
    }

@@ -299,23 +307,33 @@ public class CellularNetworkSecuritySafetySource {

        SubscriptionInfoInternal subInfo =
                mSubscriptionManagerService.getSubscriptionInfoInternal(subId);

        String cellularIdentifier =
                getCellularIdentifier(context, disclosure.mDisclosure.getCellularIdentifier());
        String issueSummaryNotification;
        String issueSummary;
        if (TextUtils.isEmpty(cellularIdentifier)) {
            issueSummaryNotification =
                    context.getString(R.string.scIdentifierDisclosureIssueSummaryNotification,
                            getCurrentTime(context), subInfo.getDisplayName());
            issueSummary = context.getString(R.string.scIdentifierDisclosureIssueSummary,
                    getCurrentTime(context), subInfo.getDisplayName());
        } else {
            issueSummaryNotification =
                    context.getString(R.string.scIDIssueSummaryNotificationWithCellularID,
                            getCurrentTime(context), cellularIdentifier, subInfo.getDisplayName());
            issueSummary = context.getString(R.string.scIDIssueSummaryWithCellularID,
                    getCurrentTime(context), cellularIdentifier, subInfo.getDisplayName());
        }
        // Notifications have no buttons
        final SafetySourceIssue.Notification customNotification =
                new SafetySourceIssue.Notification.Builder(
                        context.getString(R.string.scIdentifierDisclosureIssueTitle),
                        context.getString(
                                R.string.scIdentifierDisclosureIssueSummaryNotification,
                                getCurrentTime(context),
                                subInfo.getDisplayName())).build();
                        issueSummaryNotification).build();
        SafetySourceIssue.Builder builder =
                new SafetySourceIssue.Builder(
                        IDENTIFIER_DISCLOSURE_ISSUE_ID + "_" + subId,
                        context.getString(R.string.scIdentifierDisclosureIssueTitle),
                        context.getString(
                                R.string.scIdentifierDisclosureIssueSummary,
                                getCurrentTime(context),
                                subInfo.getDisplayName()),
                        issueSummary,
                        SEVERITY_LEVEL_RECOMMENDATION,
                        IDENTIFIER_DISCLOSURE_ISSUE_ID)
                        .setNotificationBehavior(
@@ -351,6 +369,16 @@ public class CellularNetworkSecuritySafetySource {
        return DateFormat.getTimeFormat(context).format(today);
    }

    private String getCellularIdentifier(Context context,
                                         @CellularIdentifier int cellularIdentifier) {
        return switch (cellularIdentifier) {
            case CELLULAR_IDENTIFIER_IMSI -> context.getString(R.string.cellular_identifier_imsi);
            case CELLULAR_IDENTIFIER_IMEI -> context.getString(R.string.cellular_identifier_imei);
            case CELLULAR_IDENTIFIER_SUCI -> context.getString(R.string.cellular_identifier_suci);
            default -> "";
        };
    }

    /**
     * Return Intent for learn more action, or null if resource associated with the Intent
     * uri is
@@ -409,11 +437,14 @@ public class CellularNetworkSecuritySafetySource {
        private final int mDisclosureCount;
        private final Instant mWindowStart;
        private final Instant mWindowEnd;
        private final CellularIdentifierDisclosure mDisclosure;

        private IdentifierDisclosure(int count, Instant start, Instant end) {
        private IdentifierDisclosure(int count, Instant start, Instant end,
                                     CellularIdentifierDisclosure disclosure) {
            mDisclosureCount = count;
            mWindowStart = start;
            mWindowEnd = end;
            mDisclosure = disclosure;
        }

        private int getDisclosureCount() {
@@ -436,12 +467,13 @@ public class CellularNetworkSecuritySafetySource {
            IdentifierDisclosure other = (IdentifierDisclosure) o;
            return mDisclosureCount == other.mDisclosureCount
                    && Objects.equals(mWindowStart, other.mWindowStart)
                    && Objects.equals(mWindowEnd, other.mWindowEnd);
                    && Objects.equals(mWindowEnd, other.mWindowEnd)
                    && Objects.equals(mDisclosure, other.mDisclosure);
        }

        @Override
        public int hashCode() {
            return Objects.hash(mDisclosureCount, mWindowStart, mWindowEnd);
            return Objects.hash(mDisclosureCount, mWindowStart, mWindowEnd, mDisclosure);
        }
    }
}
+21 −21
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public class CellularIdentifierDisclosureNotifierTest {
        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
        assertEquals(0, notifier.getCurrentDisclosureCount(SUB_ID_1));
        verify(mSafetySource, never())
                .setIdentifierDisclosure(any(), anyInt(), anyInt(), any(), any());
                .setIdentifierDisclosure(any(), anyInt(), any(), anyInt(), any(), any());
    }

    @Test
@@ -112,7 +112,7 @@ public class CellularIdentifierDisclosureNotifierTest {

        assertEquals(0, notifier.getCurrentDisclosureCount(SUB_ID_1));
        verify(mSafetySource, never())
                .setIdentifierDisclosure(any(), anyInt(), anyInt(), any(), any());
                .setIdentifierDisclosure(any(), anyInt(), any(), anyInt(), any(), any());
    }

    @Test
@@ -131,7 +131,7 @@ public class CellularIdentifierDisclosureNotifierTest {

        assertEquals(0, notifier.getCurrentDisclosureCount(SUB_ID_1));
        verify(mSafetySource, never())
                .setIdentifierDisclosure(any(), anyInt(), anyInt(), any(), any());
                .setIdentifierDisclosure(any(), anyInt(), any(), anyInt(), any(), any());
    }

    @Test
@@ -150,7 +150,7 @@ public class CellularIdentifierDisclosureNotifierTest {

        assertEquals(1, notifier.getCurrentDisclosureCount(SUB_ID_1));
        verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(1), any(), any());
    }

    @Test
@@ -164,11 +164,11 @@ public class CellularIdentifierDisclosureNotifierTest {

        assertEquals(3, notifier.getCurrentDisclosureCount(SUB_ID_1));
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(1), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(2), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(2), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(3), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(3), any(), any());
    }

    @Test
@@ -181,7 +181,7 @@ public class CellularIdentifierDisclosureNotifierTest {
        assertEquals(1, notifier.getCurrentDisclosureCount(SUB_ID_1));
        Assert.assertEquals(notifier.getFirstOpen(SUB_ID_1), notifier.getCurrentEnd(SUB_ID_1));
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(1), any(), any());
    }

    @Test
@@ -200,7 +200,7 @@ public class CellularIdentifierDisclosureNotifierTest {
        assertEquals(2, notifier.getCurrentDisclosureCount(SUB_ID_1));
        assertTrue(notifier.getFirstOpen(SUB_ID_1).isBefore(notifier.getCurrentEnd(SUB_ID_1)));
        verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(1), any(), any());
    }

    @Test
@@ -213,9 +213,9 @@ public class CellularIdentifierDisclosureNotifierTest {
        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
        assertEquals(2, notifier.getCurrentDisclosureCount(SUB_ID_1));
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(1), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(2), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(2), any(), any());

        // Window close should reset the counter
        mExecutor.advanceTime(WINDOW_CLOSE_ADVANCE_MILLIS);
@@ -225,7 +225,7 @@ public class CellularIdentifierDisclosureNotifierTest {
        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
        assertEquals(1, notifier.getCurrentDisclosureCount(SUB_ID_1));
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(1), any(), any());
    }

    @Test
@@ -238,9 +238,9 @@ public class CellularIdentifierDisclosureNotifierTest {
        notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
        assertEquals(2, notifier.getCurrentDisclosureCount(SUB_ID_1));
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(1), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(2), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(2), any(), any());

        notifier.disable(mContext);
        assertFalse(notifier.isEnabled());
@@ -262,23 +262,23 @@ public class CellularIdentifierDisclosureNotifierTest {
            notifier.addDisclosure(mContext, SUB_ID_1, mDislosure);
        }
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(1), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(2), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(2), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), eq(3), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_1), any(), eq(3), any(), any());

        for (int i = 0; i < 4; i++) {
            notifier.addDisclosure(mContext, SUB_ID_2, mDislosure);
        }
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_2), eq(1), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_2), any(), eq(1), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_2), eq(2), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_2), any(), eq(2), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_2), eq(3), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_2), any(), eq(3), any(), any());
        mInOrder.verify(mSafetySource, times(1))
                .setIdentifierDisclosure(any(), eq(SUB_ID_2), eq(4), any(), any());
                .setIdentifierDisclosure(any(), eq(SUB_ID_2), any(), eq(4), any(), any());

        assertEquals(3, notifier.getCurrentDisclosureCount(SUB_ID_1));
        assertEquals(4, notifier.getCurrentDisclosureCount(SUB_ID_2));
+31 −6
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package com.android.internal.telephony.security;

import static android.telephony.CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_IMSI;
import static android.telephony.CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_IMEI;
import static android.telephony.CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_SUCI;
import static android.telephony.CellularIdentifierDisclosure.NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST;

import static com.android.internal.telephony.security.CellularNetworkSecuritySafetySource.NULL_CIPHER_STATE_ENCRYPTED;
import static com.android.internal.telephony.security.CellularNetworkSecuritySafetySource.NULL_CIPHER_STATE_NOTIFY_ENCRYPTED;
import static com.android.internal.telephony.security.CellularNetworkSecuritySafetySource.NULL_CIPHER_STATE_NOTIFY_NON_ENCRYPTED;
@@ -36,6 +41,8 @@ import android.content.Context;
import android.content.Intent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceIssue;
import android.telephony.CellularIdentifierDisclosure;
import android.telephony.CellularIdentifierDisclosure.CellularIdentifier;

import com.android.internal.R;
import com.android.internal.telephony.TelephonyTest;
@@ -85,6 +92,9 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest
        mContextFixture.putResource(R.string.scIdentifierDisclosureIssueTitle, "fake");
        mContextFixture.putResource(R.string.scIdentifierDisclosureIssueSummaryNotification,
                "fake %1$s %2$s");
        mContextFixture.putResource(R.string.scIDIssueSummaryNotificationWithCellularID,
                "fake %1$s %2$s");
        mContextFixture.putResource(R.string.scIDIssueSummaryWithCellularID, "fake %1$s %2$s");
        mContextFixture.putResource(
                R.string.scIdentifierDisclosureIssueSummary, "fake %1$s %2$s");
        mContextFixture.putResource(R.string.scNullCipherIssueActionSettings, "fake");
@@ -209,7 +219,8 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest
    public void enableIdentifierDisclosureIssue_enableTwice() {
        ArgumentCaptor<SafetySourceData> data = ArgumentCaptor.forClass(SafetySourceData.class);
        mSafetySource.setIdentifierDisclosureIssueEnabled(mContext, true);
        mSafetySource.setIdentifierDisclosure(mContext, 0, 12, Instant.now(), Instant.now());
        mSafetySource.setIdentifierDisclosure(mContext, 0, getCellularIdentifierDisclosure(
                CELLULAR_IDENTIFIER_IMSI), 12, Instant.now(), Instant.now());
        mSafetySource.setIdentifierDisclosureIssueEnabled(mContext, true);

        // Two invocations because the initial enablement and the subsequent disclosure result in
@@ -236,7 +247,8 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest
        ArgumentCaptor<SafetySourceData> data = ArgumentCaptor.forClass(SafetySourceData.class);

        mSafetySource.setIdentifierDisclosureIssueEnabled(mContext, true);
        mSafetySource.setIdentifierDisclosure(mContext, 0, 12, Instant.now(), Instant.now());
        mSafetySource.setIdentifierDisclosure(mContext, 0, getCellularIdentifierDisclosure(
                CELLULAR_IDENTIFIER_IMSI), 12, Instant.now(), Instant.now());

        verify(mSafetyCenterManagerWrapper, times(2)).setSafetySourceData(data.capture());
        assertThat(data.getAllValues().get(1).getStatus()).isNotNull();
@@ -248,8 +260,10 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest
        ArgumentCaptor<SafetySourceData> data = ArgumentCaptor.forClass(SafetySourceData.class);

        mSafetySource.setIdentifierDisclosureIssueEnabled(mContext, true);
        mSafetySource.setIdentifierDisclosure(mContext, 0, 12, Instant.now(), Instant.now());
        mSafetySource.setIdentifierDisclosure(mContext, 1, 3, Instant.now(), Instant.now());
        mSafetySource.setIdentifierDisclosure(mContext, 0, getCellularIdentifierDisclosure(
                CELLULAR_IDENTIFIER_IMEI), 12, Instant.now(), Instant.now());
        mSafetySource.setIdentifierDisclosure(mContext, 1, getCellularIdentifierDisclosure(
                CELLULAR_IDENTIFIER_IMEI), 3, Instant.now(), Instant.now());

        verify(mSafetyCenterManagerWrapper, times(3)).setSafetySourceData(data.capture());
        assertThat(data.getAllValues().get(2).getStatus()).isNotNull();
@@ -263,7 +277,8 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest
        mSafetySource.setNullCipherIssueEnabled(mContext, true);
        mSafetySource.setNullCipherState(mContext, 0, NULL_CIPHER_STATE_NOTIFY_NON_ENCRYPTED);
        mSafetySource.setIdentifierDisclosureIssueEnabled(mContext, true);
        mSafetySource.setIdentifierDisclosure(mContext, 0, 12, Instant.now(), Instant.now());
        mSafetySource.setIdentifierDisclosure(mContext, 0, getCellularIdentifierDisclosure(
                CELLULAR_IDENTIFIER_SUCI), 12, Instant.now(), Instant.now());

        verify(mSafetyCenterManagerWrapper, times(4)).setSafetySourceData(data.capture());
        assertThat(data.getAllValues().get(3).getStatus()).isNotNull();
@@ -279,7 +294,8 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest
        mSafetySource.setNullCipherIssueEnabled(mContext, true);
        mSafetySource.setNullCipherState(mContext, 0, NULL_CIPHER_STATE_NOTIFY_NON_ENCRYPTED);
        mSafetySource.setIdentifierDisclosureIssueEnabled(mContext, true);
        mSafetySource.setIdentifierDisclosure(mContext, 0, 12, Instant.now(), Instant.now());
        mSafetySource.setIdentifierDisclosure(mContext, 0, getCellularIdentifierDisclosure(
                CELLULAR_IDENTIFIER_SUCI), 12, Instant.now(), Instant.now());

        verify(mSafetyCenterManagerWrapper, times(4)).setSafetySourceData(data.capture());
        List<SafetySourceIssue.Action> actions = data.getAllValues().get(
@@ -289,4 +305,13 @@ public final class CellularNetworkSecuritySafetySourceTest extends TelephonyTest
        assertThat(actions).hasSize(1);
        assertThat(actions.getFirst().getId()).isEqualTo("cellular_security_settings");
    }

    private CellularIdentifierDisclosure getCellularIdentifierDisclosure(
            @CellularIdentifier int cellularIdentifier) {
        return new CellularIdentifierDisclosure(
                NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST,
                cellularIdentifier,
                "001001",
                false);
    }
}
 No newline at end of file