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

Commit 0bb5c850 authored by yomna's avatar yomna
Browse files

Add implementation and flags for new transparency callback APIs

Add implementation to pass information from the modem about identifier
disclosures and security algorithm updates to notify listeners.

Bug: 355062720
Test: atest CtsTelephonyTestCases:TelephonyCallbackTest
Test: atest DefaultPhoneNotifierTest TelephonyRegistryTest
Test: atest CellularIdentifierDisclosureTest SecurityAlgorithmUpdateTest
Flag: com.android.internal.telephony.flags.security_algorithms_update_indications
Flag: com.android.internal.telephony.flags.cellular_identifier_disclosure_indications

Change-Id: I1ad4ffd2aaad56ec8bfaadb272cad99c74700db8
parent d9bc9f0e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -93,3 +93,20 @@ flag {
    }
}

# OWNER=yomna TARGET=25Q2
flag {
  name: "security_algorithms_update_indications"
  is_exported: true
  namespace: "telephony"
  description: "guard system API onSecurityAlgorithmsChanged"
  bug: "355062720"
}

# OWNER=yomna TARGET=25Q2
flag {
  name: "cellular_identifier_disclosure_indications"
  is_exported: true
  namespace: "telephony"
  description: "guard system API onCellularIdentifierDisclosedChanged"
  bug: "355062720"
}
+19 −0
Original line number Diff line number Diff line
@@ -25,12 +25,14 @@ import android.telephony.BarringInfo;
import android.telephony.CallQuality;
import android.telephony.CellIdentity;
import android.telephony.CellInfo;
import android.telephony.CellularIdentifierDisclosure;
import android.telephony.LinkCapacityEstimate;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneCapability;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PreciseCallState;
import android.telephony.PreciseDataConnectionState;
import android.telephony.SecurityAlgorithmUpdate;
import android.telephony.ServiceState;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager.DataEnabledReason;
@@ -356,6 +358,23 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
                sender.getSubId(), ntnSignalStrength);
    }

    @Override
    public void notifySecurityAlgorithmsChanged(Phone sender, SecurityAlgorithmUpdate update) {
        if (!mFeatureFlags.securityAlgorithmsUpdateIndications()) return;

        mTelephonyRegistryMgr.notifySecurityAlgorithmsChanged(sender.getPhoneId(),
                sender.getSubId(), update);
    }

    @Override
    public void notifyCellularIdentifierDisclosedChanged(Phone sender,
            CellularIdentifierDisclosure disclosure) {
        if (!mFeatureFlags.cellularIdentifierDisclosureIndications()) return;

        mTelephonyRegistryMgr.notifyCellularIdentifierDisclosedChanged(sender.getPhoneId(),
                sender.getSubId(), disclosure);
    }

    /**
     * Convert the {@link Call.State} enum into the PreciseCallState.PRECISE_CALL_STATE_* constants
     * for the public API.
+9 −0
Original line number Diff line number Diff line
@@ -25,11 +25,13 @@ import android.telephony.BarringInfo;
import android.telephony.CallQuality;
import android.telephony.CellIdentity;
import android.telephony.CellInfo;
import android.telephony.CellularIdentifierDisclosure;
import android.telephony.LinkCapacityEstimate;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneCapability;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PreciseDataConnectionState;
import android.telephony.SecurityAlgorithmUpdate;
import android.telephony.ServiceState;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager.DataEnabledReason;
@@ -174,4 +176,11 @@ public interface PhoneNotifier {
    /** Notify carrier roaming non-terrestrial network signal strength changed. */
    void notifyCarrierRoamingNtnSignalStrengthChanged(Phone sender,
            @NonNull NtnSignalStrength ntnSignalStrength);

    /** Notify of a cellular identifier disclosure change. */
    void notifyCellularIdentifierDisclosedChanged(Phone sender,
            CellularIdentifierDisclosure disclosure);

    /** Notify of a security algorithm update change. */
    void notifySecurityAlgorithmsChanged(Phone sender, SecurityAlgorithmUpdate update);
}
+39 −0
Original line number Diff line number Diff line
@@ -15,6 +15,12 @@
 */
package com.android.internal.telephony;

import static android.telephony.CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_IMSI;
import static android.telephony.CellularIdentifierDisclosure.NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST;
import static android.telephony.SecurityAlgorithmUpdate.CONNECTION_EVENT_VOLTE_SIP;
import static android.telephony.SecurityAlgorithmUpdate.SECURITY_ALGORITHM_EEA2;
import static android.telephony.SecurityAlgorithmUpdate.SECURITY_ALGORITHM_HMAC_SHA1_96;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.eq;
@@ -26,9 +32,11 @@ import static org.mockito.Mockito.verify;

import android.telephony.CellIdentityGsm;
import android.telephony.CellInfo;
import android.telephony.CellularIdentifierDisclosure;
import android.telephony.DisconnectCause;
import android.telephony.PreciseCallState;
import android.telephony.PreciseDisconnectCause;
import android.telephony.SecurityAlgorithmUpdate;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsCallProfile;
@@ -449,4 +457,35 @@ public class DefaultPhoneNotifierTest extends TelephonyTest {
        verify(mTelephonyRegistryManager).notifyCarrierRoamingNtnAvailableServicesChanged(
                eq(subId), eq(testServices));
    }

    @Test
    @SmallTest
    public void testSecurityAlgorithmsChanged() {
        doReturn(true).when(mFeatureFlags).securityAlgorithmsUpdateIndications();
        int phoneId = mPhone.getPhoneId();
        int subId = mPhone.getSubId();
        SecurityAlgorithmUpdate update =
                new SecurityAlgorithmUpdate(
                        CONNECTION_EVENT_VOLTE_SIP, SECURITY_ALGORITHM_EEA2,
                        SECURITY_ALGORITHM_HMAC_SHA1_96, false);
        mDefaultPhoneNotifierUT.notifySecurityAlgorithmsChanged(mPhone, update);
        verify(mTelephonyRegistryManager).notifySecurityAlgorithmsChanged(
                eq(phoneId), eq(subId), eq(update));
    }

    @Test
    @SmallTest
    public void testCellularIdentifierDisclosedChanged() {
        doReturn(true).when(mFeatureFlags).cellularIdentifierDisclosureIndications();
        int phoneId = mPhone.getPhoneId();
        int subId = mPhone.getSubId();
        CellularIdentifierDisclosure disclosure =
                new CellularIdentifierDisclosure(NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST,
                        CELLULAR_IDENTIFIER_IMSI,
                        "001001",
                        false);
        mDefaultPhoneNotifierUT.notifyCellularIdentifierDisclosedChanged(mPhone, disclosure);
        verify(mTelephonyRegistryManager).notifyCellularIdentifierDisclosedChanged(
                eq(phoneId), eq(subId), eq(disclosure));
    }
}
+69 −1
Original line number Diff line number Diff line
@@ -15,7 +15,12 @@
 */
package com.android.internal.telephony;

import static android.telephony.CellularIdentifierDisclosure.CELLULAR_IDENTIFIER_IMSI;
import static android.telephony.CellularIdentifierDisclosure.NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST;
import static android.telephony.PhysicalChannelConfig.PHYSICAL_CELL_ID_UNKNOWN;
import static android.telephony.SecurityAlgorithmUpdate.CONNECTION_EVENT_VOLTE_SIP;
import static android.telephony.SecurityAlgorithmUpdate.SECURITY_ALGORITHM_EEA2;
import static android.telephony.SecurityAlgorithmUpdate.SECURITY_ALGORITHM_HMAC_SHA1_96;
import static android.telephony.ServiceState.FREQUENCY_RANGE_LOW;
import static android.telephony.SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
@@ -57,11 +62,13 @@ import android.telephony.CellIdentityLte;
import android.telephony.CellInfo;
import android.telephony.CellInfoLte;
import android.telephony.CellLocation;
import android.telephony.CellularIdentifierDisclosure;
import android.telephony.LinkCapacityEstimate;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneCapability;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PreciseDataConnectionState;
import android.telephony.SecurityAlgorithmUpdate;
import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
@@ -181,6 +188,10 @@ public class TelephonyRegistryTest extends TelephonyTest {
                TelephonyCallback.EVENT_EMERGENCY_CALLBACK_MODE_CHANGED);
        READ_PRIVILEGED_PHONE_STATE_EVENTS.add(
                TelephonyCallback.EVENT_SIMULTANEOUS_CELLULAR_CALLING_SUBSCRIPTIONS_CHANGED);
        READ_PRIVILEGED_PHONE_STATE_EVENTS.add(
                TelephonyCallback.EVENT_CELLULAR_IDENTIFIER_DISCLOSED_CHANGED);
        READ_PRIVILEGED_PHONE_STATE_EVENTS.add(
                TelephonyCallback.EVENT_SECURITY_ALGORITHMS_CHANGED);
    }

    // All events contribute to TelephonyRegistry#isActiveEmergencySessionPermissionRequired
@@ -211,7 +222,9 @@ public class TelephonyRegistryTest extends TelephonyTest {
            TelephonyCallback.DataActivityListener,
            TelephonyCallback.SimultaneousCellularCallingSupportListener,
            TelephonyCallback.EmergencyCallbackModeListener,
            TelephonyCallback.CarrierRoamingNtnModeListener {
            TelephonyCallback.CarrierRoamingNtnModeListener,
            TelephonyCallback.SecurityAlgorithmsListener,
            TelephonyCallback.CellularIdentifierDisclosedListener {
        // This class isn't mockable to get invocation counts because the IBinder is null and
        // crashes the TelephonyRegistry. Make a cheesy verify(times()) alternative.
        public AtomicInteger invocationCount = new AtomicInteger(0);
@@ -351,6 +364,16 @@ public class TelephonyRegistryTest extends TelephonyTest {
            invocationCount.incrementAndGet();
            mCarrierRoamingNtnSignalStrength = ntnSignalStrength;
        }

        @Override
        public void onSecurityAlgorithmsChanged(SecurityAlgorithmUpdate update) {
            invocationCount.incrementAndGet();
        }

        @Override
        public void onCellularIdentifierDisclosedChanged(CellularIdentifierDisclosure disclosure) {
            invocationCount.incrementAndGet();
        }
    }

    public class MySatelliteStateChangeListener implements ISatelliteStateChangeListener {
@@ -1838,4 +1861,49 @@ public class TelephonyRegistryTest extends TelephonyTest {
        // We should not receive the new state change after monitoring end
        assertFalse(mIsSatelliteEnabled);
    }


    @Test
    @EnableFlags(Flags.FLAG_SECURITY_ALGORITHMS_UPDATE_INDICATIONS)
    public void testNotifySecurityAlgorithmsChanged() {
        int subId = 1;
        int[] events = {TelephonyCallback.EVENT_SECURITY_ALGORITHMS_CHANGED};

        mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(),
                mContext.getAttributionTag(), mTelephonyCallback.callback, events, false);

        SecurityAlgorithmUpdate update =
                new SecurityAlgorithmUpdate(
                        CONNECTION_EVENT_VOLTE_SIP, SECURITY_ALGORITHM_EEA2,
                        SECURITY_ALGORITHM_HMAC_SHA1_96, false);

        mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(),
                mContext.getAttributionTag(), mTelephonyCallback.callback, events, false);
        int invocationCount = mTelephonyCallback.invocationCount.get();
        mTelephonyRegistry.notifySecurityAlgorithmsChanged(0, 1, update);
        processAllMessages();
        assertEquals(invocationCount + 1, mTelephonyCallback.invocationCount.get());
    }

    @Test
    @EnableFlags(Flags.FLAG_CELLULAR_IDENTIFIER_DISCLOSURE_INDICATIONS)
    public void testNotifyCellularIdentifierDisclosedChanged() {
        int subId = 1;
        int[] events = {TelephonyCallback.EVENT_CELLULAR_IDENTIFIER_DISCLOSED_CHANGED};

        CellularIdentifierDisclosure disclosure =
                new CellularIdentifierDisclosure(NAS_PROTOCOL_MESSAGE_ATTACH_REQUEST,
                        CELLULAR_IDENTIFIER_IMSI,
                        "001001",
                        false);

        mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(),
                mContext.getAttributionTag(), mTelephonyCallback.callback, events, false);
        int invocationCount = mTelephonyCallback.invocationCount.get();
        mTelephonyRegistry.notifyCellularIdentifierDisclosedChanged(0, 1,
                disclosure);
        processAllMessages();
        assertEquals(invocationCount + 1, mTelephonyCallback.invocationCount.get());
    }

}