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

Commit d9b5dda4 authored by Nathan Harold's avatar Nathan Harold
Browse files

Expose PreciseDataConnectionState to Public API

1) Remove Unused Parameters for onDataConnectionState:
The data connection state broadcast includes a number of
parameters that are never used anywhere. To prepare for
updated code that relies on PreciseDataConnectionState,
remove the unused parameters that were internal-only and
included in the broadcast.

-LinkProperties
-NetworkCapabilities
-DataRoaming
-DataAllowed
-Interface name

2) Add Disconnecting State for Data Connections

Add a disconnecting state to correct a mismatch
between the internal and externally visible enums.

This will allow apps to know when connections are
in the process of being torn down, which in the case
of radio link issues could be as much as 15 seconds.

3) Expose PreciseDataConnection for Carrier Apps

Exposes the PSL for PreciseDataConnectionState along
with existing fields in the PreciseDataConnectionState
class.

-Make PreciseDataConnectionState public along with some
 of its fields.
-Expose onPreciseDataConnectionStateChanged.
-Add onPreciseDataConnectionStatesChanged to provide PDCS
 for all APNs in one cohesive batch.

4) Cache PreciseDataConnectionState by APN Type

In telephony registry, multiple different APN types
are all piped through the same cache entry, so every
time any APN changes relative to the previous type,
it triggers an update. This also means that when
a registrant requests the data connection state, only
the most recent type's state is updated.

This change caches entries in TelephonyRegistry based
on the APN's type (specifically the type among types
which triggered the change).

Bug: 143083105
Test: make update-api && make offline-sdk-docs
      (no functional change in this CL).
Test: atest FrameworksTelephonyTests

Merged-In: Ib6a769f5a0cae923ca47a842733bd28755a90ed5
Change-Id: Ib6a769f5a0cae923ca47a842733bd28755a90ed5
(cherry picked from commit 4d340f12)
(cherry picked from commit c95b4e54)
parent 6a1d13f5
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -44752,6 +44752,7 @@ package android.telephony {
    method public void onDataConnectionStateChanged(int);
    method public void onDataConnectionStateChanged(int, int);
    method public void onMessageWaitingIndicatorChanged(boolean);
    method @RequiresPermission("android.permission.MODIFY_PHONE_STATE") public void onPreciseDataConnectionStateChanged(@NonNull android.telephony.PreciseDataConnectionState);
    method public void onServiceStateChanged(android.telephony.ServiceState);
    method @Deprecated public void onSignalStrengthChanged(int);
    method public void onSignalStrengthsChanged(android.telephony.SignalStrength);
@@ -44766,12 +44767,23 @@ package android.telephony {
    field public static final int LISTEN_EMERGENCY_NUMBER_LIST = 16777216; // 0x1000000
    field public static final int LISTEN_MESSAGE_WAITING_INDICATOR = 4; // 0x4
    field public static final int LISTEN_NONE = 0; // 0x0
    field @RequiresPermission("android.permission.MODIFY_PHONE_STATE") public static final int LISTEN_PRECISE_DATA_CONNECTION_STATE = 4096; // 0x1000
    field public static final int LISTEN_SERVICE_STATE = 1; // 0x1
    field @Deprecated public static final int LISTEN_SIGNAL_STRENGTH = 2; // 0x2
    field public static final int LISTEN_SIGNAL_STRENGTHS = 256; // 0x100
    field public static final int LISTEN_USER_MOBILE_DATA_STATE = 524288; // 0x80000
  }
  public final class PreciseDataConnectionState implements android.os.Parcelable {
    method public int describeContents();
    method public int getLastCauseCode();
    method @Nullable public android.net.LinkProperties getLinkProperties();
    method public int getNetworkType();
    method public int getState();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.telephony.PreciseDataConnectionState> CREATOR;
  }
  public final class RadioAccessSpecifier implements android.os.Parcelable {
    ctor public RadioAccessSpecifier(int, int[], int[]);
    method public int describeContents();
@@ -45274,6 +45286,7 @@ package android.telephony {
    field public static final int DATA_CONNECTED = 2; // 0x2
    field public static final int DATA_CONNECTING = 1; // 0x1
    field public static final int DATA_DISCONNECTED = 0; // 0x0
    field public static final int DATA_DISCONNECTING = 4; // 0x4
    field public static final int DATA_SUSPENDED = 3; // 0x3
    field public static final int DATA_UNKNOWN = -1; // 0xffffffff
    field public static final String EXTRA_CALL_VOICEMAIL_INTENT = "android.telephony.extra.CALL_VOICEMAIL_INTENT";
+6 −9
Original line number Diff line number Diff line
@@ -8505,7 +8505,6 @@ package android.telephony {
    method public void onOutgoingEmergencyCall(@NonNull android.telephony.emergency.EmergencyNumber);
    method public void onOutgoingEmergencySms(@NonNull android.telephony.emergency.EmergencyNumber);
    method @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public void onPreciseCallStateChanged(@NonNull android.telephony.PreciseCallState);
    method @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public void onPreciseDataConnectionStateChanged(@NonNull android.telephony.PreciseDataConnectionState);
    method public void onRadioPowerStateChanged(int);
    method public void onSrvccStateChanged(int);
    method public void onVoiceActivationStateChanged(int);
@@ -8515,7 +8514,6 @@ package android.telephony {
    field @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int LISTEN_OUTGOING_EMERGENCY_CALL = 268435456; // 0x10000000
    field @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int LISTEN_OUTGOING_EMERGENCY_SMS = 536870912; // 0x20000000
    field @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public static final int LISTEN_PRECISE_CALL_STATE = 2048; // 0x800
    field @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public static final int LISTEN_PRECISE_DATA_CONNECTION_STATE = 4096; // 0x1000
    field public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 8388608; // 0x800000
    field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_SRVCC_STATE_CHANGED = 16384; // 0x4000
    field public static final int LISTEN_VOICE_ACTIVATION_STATE = 131072; // 0x20000
@@ -8541,13 +8539,12 @@ package android.telephony {
  }
  public final class PreciseDataConnectionState implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getDataConnectionApn();
    method public int getDataConnectionApnTypeBitMask();
    method public int getDataConnectionFailCause();
    method public int getDataConnectionState();
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.telephony.PreciseDataConnectionState> CREATOR;
    method @Deprecated @NonNull public String getDataConnectionApn();
    method @Deprecated public int getDataConnectionApnTypeBitMask();
    method @Deprecated public int getDataConnectionFailCause();
    method @Deprecated @Nullable public android.net.LinkProperties getDataConnectionLinkProperties();
    method @Deprecated public int getDataConnectionNetworkType();
    method @Deprecated public int getDataConnectionState();
  }
  public final class PreciseDisconnectCause {
+4 −0
Original line number Diff line number Diff line
@@ -3004,6 +3004,10 @@ package android.telephony {
    field @RequiresPermission("android.permission.READ_ACTIVE_EMERGENCY_SESSION") public static final int LISTEN_OUTGOING_EMERGENCY_SMS = 536870912; // 0x20000000
  }

  public final class PreciseDataConnectionState implements android.os.Parcelable {
    ctor @Deprecated public PreciseDataConnectionState(int, int, int, @NonNull String, @Nullable android.net.LinkProperties, int);
  }

  public class ServiceState implements android.os.Parcelable {
    method public void addNetworkRegistrationInfo(android.telephony.NetworkRegistrationInfo);
    method public void setCdmaSystemAndNetworkId(int, int);
+29 −16
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ import android.telephony.Annotation.SrvccState;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.ims.ImsReasonInfo;

import com.android.internal.telephony.IPhoneStateListener;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.IPhoneStateListener;

import dalvik.system.VMRuntime;

@@ -196,12 +196,13 @@ public class PhoneStateListener {
    /**
     * Listen for {@link PreciseDataConnectionState} on the data connection (cellular).
     *
     * @see #onPreciseDataConnectionStateChanged
     * <p>Requires permission {@link android.Manifest.permission#MODIFY_PHONE_STATE}
     * or the calling app has carrier privileges
     * (see {@link TelephonyManager#hasCarrierPrivileges}).
     *
     * @hide
     * @see #onPreciseDataConnectionStateChanged
     */
    @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
    @SystemApi
    @RequiresPermission((android.Manifest.permission.MODIFY_PHONE_STATE))
    public static final int LISTEN_PRECISE_DATA_CONNECTION_STATE            = 0x00001000;

    /**
@@ -719,8 +720,9 @@ public class PhoneStateListener {
    }

    /**
     * Callback invoked when data connection state changes with precise information
     * on the registered subscription.
     * Callback providing update about the default/internet data connection on the registered
     * subscription.
     *
     * Note, the registration subId comes from {@link TelephonyManager} object which registers
     * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
     * If this TelephonyManager object was created with
@@ -728,12 +730,13 @@ public class PhoneStateListener {
     * subId. Otherwise, this callback applies to
     * {@link SubscriptionManager#getDefaultSubscriptionId()}.
     *
     * @param dataConnectionState {@link PreciseDataConnectionState}
     * <p>Requires permission {@link android.Manifest.permission#MODIFY_PHONE_STATE}
     * or the calling app has carrier privileges
     * (see {@link TelephonyManager#hasCarrierPrivileges}).
     *
     * @hide
     * @param dataConnectionState {@link PreciseDataConnectionState}
     */
    @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
    @SystemApi
    @RequiresPermission((android.Manifest.permission.MODIFY_PHONE_STATE))
    public void onPreciseDataConnectionStateChanged(
            @NonNull PreciseDataConnectionState dataConnectionState) {
        // default implementation empty
@@ -1042,12 +1045,22 @@ public class PhoneStateListener {
            PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
            if (psl == null) return;

            if (state == TelephonyManager.DATA_DISCONNECTING
                    && VMRuntime.getRuntime().getTargetSdkVersion() < Build.VERSION_CODES.R) {
                Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                        () -> {
                            psl.onDataConnectionStateChanged(
                                    TelephonyManager.DATA_CONNECTED, networkType);
                            psl.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED);
                        }));
            } else {
                Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                        () -> {
                            psl.onDataConnectionStateChanged(state, networkType);
                            psl.onDataConnectionStateChanged(state);
                        }));
            }
        }

        public void onDataActivity(int direction) {
            PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
+8 −40
Original line number Diff line number Diff line
@@ -21,17 +21,13 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.content.Context;
import android.net.LinkProperties;
import android.net.NetworkCapabilities;
import android.os.Binder;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.Annotation.ApnType;
import android.telephony.Annotation.CallState;
import android.telephony.Annotation.DataActivityType;
import android.telephony.Annotation.DataFailureCause;
import android.telephony.Annotation.DataState;
import android.telephony.Annotation.NetworkType;
import android.telephony.Annotation.PreciseCallStates;
import android.telephony.Annotation.RadioPowerState;
@@ -363,27 +359,18 @@ public class TelephonyRegistryManager {
     * @param subId for which data connection state changed.
     * @param slotIndex for which data connections state changed. Can be derived from subId except
     * when subId is invalid.
     * @param state latest data connection state, e.g,
     * @param isDataConnectivityPossible indicates if data is allowed
     * @param apn the APN {@link ApnSetting#getApnName()} of this data connection.
     * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN.
     * @param linkProperties {@link LinkProperties} associated with this data connection.
     * @param networkCapabilities {@link NetworkCapabilities} associated with this data connection.
     * @param networkType associated with this data connection.
     * @param roaming {@code true} indicates in roaming, {@false} otherwise.
     * @see TelephonyManager#DATA_DISCONNECTED
     * @see TelephonyManager#isDataConnectivityPossible()
     * @param apnType the APN type that triggered this update
     * @param preciseState the PreciseDataConnectionState
     *
     * @see android.telephony.PreciseDataConnection
     * @see TelephonyManager#DATA_DISCONNECTED
     * @hide
     */
    public void notifyDataConnectionForSubscriber(int slotIndex, int subId, @DataState int state,
        boolean isDataConnectivityPossible,
        @ApnType String apn, String apnType, LinkProperties linkProperties,
        NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
    public void notifyDataConnectionForSubscriber(int slotIndex, int subId,
            String apnType, PreciseDataConnectionState preciseState) {
        try {
            sRegistry.notifyDataConnectionForSubscriber(slotIndex, subId, state,
                isDataConnectivityPossible,
                apn, apnType, linkProperties, networkCapabilities, networkType, roaming);
            sRegistry.notifyDataConnectionForSubscriber(
                    slotIndex, subId, apnType, preciseState);
        } catch (RemoteException ex) {
            // system process is dead
        }
@@ -667,25 +654,6 @@ public class TelephonyRegistryManager {
        }
    }

    /**
     * Notify data connection failed on certain subscription.
     *
     * @param subId for which data connection failed.
     * @param slotIndex for which data conenction faled. Can be derived from subId except when subId
     * is invalid.
     * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN. Note each data
     * connection can support multiple anyTypes.
     *
     * @hide
     */
    public void notifyDataConnectionFailed(int subId, int slotIndex, String apnType) {
        try {
            sRegistry.notifyDataConnectionFailedForSubscriber(slotIndex, subId, apnType);
        } catch (RemoteException ex) {
            // system process is dead
        }
    }

    /**
     * TODO change from bundle to CellLocation?
     * @hide
Loading