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

Commit 1f6c2596 authored by Sooraj Sasindran's avatar Sooraj Sasindran
Browse files

API to switch preferred data

Provide API to switch preferred data between default subscription
and opportunistic subscription.

Bug: 118491136
Test: make and called the APIs using setting app
Change-Id: Ic4f7a0aac6f7e1234c30aaee2fed177dbd5e53cd
parent 2e96a44f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -43357,6 +43357,7 @@ package android.telephony {
    method public int getNetworkType();
    method public int getPhoneCount();
    method public int getPhoneType();
    method public int getPreferredOpportunisticDataSubscription();
    method public android.telephony.ServiceState getServiceState();
    method public android.telephony.SignalStrength getSignalStrength();
    method public int getSimCarrierId();
@@ -43406,6 +43407,7 @@ package android.telephony {
    method public boolean setNetworkSelectionModeManual(java.lang.String, boolean);
    method public boolean setOperatorBrandOverride(java.lang.String);
    method public boolean setPreferredNetworkTypeToGlobal();
    method public boolean setPreferredOpportunisticDataSubscription(int);
    method public void setVisualVoicemailSmsFilterSettings(android.telephony.VisualVoicemailSmsFilterSettings);
    method public boolean setVoiceMailNumber(java.lang.String, java.lang.String);
    method public deprecated void setVoicemailRingtoneUri(android.telecom.PhoneAccountHandle, android.net.Uri);
+51 −0
Original line number Diff line number Diff line
@@ -9165,4 +9165,55 @@ public class TelephonyManager {
        }
        return false;
    }

    /**
     * Set preferred opportunistic data subscription id.
     *
     * <p>Requires that the calling app has carrier privileges on both primary and
     * secondary subscriptions (see
     * {@link #hasCarrierPrivileges}), or has permission
     * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
     *
     * @param subId which opportunistic subscription
     * {@link SubscriptionManager#getOpportunisticSubscriptions} is preferred for cellular data.
     * Pass {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} to unset the preference
     * @return true if request is accepted, else false.
     *
     */
    public boolean setPreferredOpportunisticDataSubscription(int subId) {
        String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>";
        try {
            IAns iAlternativeNetworkService = getIAns();
            if (iAlternativeNetworkService != null) {
                return iAlternativeNetworkService.setPreferredData(subId, pkgForDebug);
            }
        } catch (RemoteException ex) {
            Rlog.e(TAG, "setPreferredData RemoteException", ex);
        }
        return false;
    }

    /**
     * Get preferred opportunistic data subscription Id
     *
     * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}),
     * or has permission {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}.
     * @return subId preferred opportunistic subscription id or
     * {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} if there are no preferred
     * subscription id
     *
     */
    public int getPreferredOpportunisticDataSubscription() {
        String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>";
        int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        try {
            IAns iAlternativeNetworkService = getIAns();
            if (iAlternativeNetworkService != null) {
                subId = iAlternativeNetworkService.getPreferredData(pkgForDebug);
            }
        } catch (RemoteException ex) {
            Rlog.e(TAG, "getPreferredData RemoteException", ex);
        }
        return subId;
    }
}
+29 −0
Original line number Diff line number Diff line
@@ -49,4 +49,33 @@ interface IAns {
    * @param callingPackage caller's package name
    */
    boolean isEnabled(String callingPackage);

    /**
     * Set preferred opportunistic data subscription id.
     *
     * <p>Requires that the calling app has carrier privileges on both primary and
     * secondary subscriptions (see
     * {@link #hasCarrierPrivileges}), or has permission
     * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
     *
     * @param subId which opportunistic subscription
     * {@link SubscriptionManager#getOpportunisticSubscriptions} is preferred for cellular data.
     * Pass {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} to unset the preference
     * @param callingPackage caller's package name
     * @return true if request is accepted, else false.
     *
     */
    boolean setPreferredData(int subId, String callingPackage);

    /**
     * Get preferred opportunistic data subscription Id
     *
     * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}),
     * or has permission {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}.
     * @return subId preferred opportunistic subscription id or
     * {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} if there are no preferred
     * subscription id
     *
     */
    int getPreferredData(String callingPackage);
}