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

Commit 2037f906 authored by Chiachang Wang's avatar Chiachang Wang Committed by Gerrit Code Review
Browse files

Merge "Move getMobileProvisioningUrl parsing to telephony"

parents 5f2b7a9c fe61222d
Loading
Loading
Loading
Loading
+102 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.LinkProperties;
import android.net.LinkProperties;
import android.net.NetworkCapabilities;
import android.net.NetworkCapabilities;
import android.net.Uri;
import android.net.Uri;
@@ -66,6 +67,7 @@ import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.LocalLog;
import android.util.LocalLog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.Xml;


import com.android.ims.ImsCall;
import com.android.ims.ImsCall;
import com.android.ims.ImsConfig;
import com.android.ims.ImsConfig;
@@ -90,9 +92,17 @@ import com.android.internal.telephony.uicc.UiccCardApplication;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UsimServiceTable;
import com.android.internal.telephony.uicc.UsimServiceTable;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.internal.util.XmlUtils;
import com.android.telephony.Rlog;
import com.android.telephony.Rlog;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
@@ -3386,6 +3396,98 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        return activeApnTypes.toArray(new String[activeApnTypes.size()]);
        return activeApnTypes.toArray(new String[activeApnTypes.size()]);
    }
    }



    /**
     *  Location to an updatable file listing carrier provisioning urls.
     *  An example:
     *
     * <?xml version="1.0" encoding="utf-8"?>
     *  <provisioningUrls>
     *   <provisioningUrl mcc="310" mnc="4">http://myserver.com/foo?mdn=%3$s&amp;iccid=%1$s&amp;imei=%2$s</provisioningUrl>
     *  </provisioningUrls>
     */
    private static final String PROVISIONING_URL_PATH =
            "/data/misc/radio/provisioning_urls.xml";
    private final File mProvisioningUrlFile = new File(PROVISIONING_URL_PATH);

    /** XML tag for root element. */
    private static final String TAG_PROVISIONING_URLS = "provisioningUrls";
    /** XML tag for individual url */
    private static final String TAG_PROVISIONING_URL = "provisioningUrl";
    /** XML attribute for mcc */
    private static final String ATTR_MCC = "mcc";
    /** XML attribute for mnc */
    private static final String ATTR_MNC = "mnc";

    private String getProvisioningUrlBaseFromFile() {
        XmlPullParser parser;
        final Configuration config = mContext.getResources().getConfiguration();

        try (FileReader fileReader = new FileReader(mProvisioningUrlFile)) {
            parser = Xml.newPullParser();
            parser.setInput(fileReader);
            XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS);

            while (true) {
                XmlUtils.nextElement(parser);

                final String element = parser.getName();
                if (element == null) break;

                if (element.equals(TAG_PROVISIONING_URL)) {
                    String mcc = parser.getAttributeValue(null, ATTR_MCC);
                    try {
                        if (mcc != null && Integer.parseInt(mcc) == config.mcc) {
                            String mnc = parser.getAttributeValue(null, ATTR_MNC);
                            if (mnc != null && Integer.parseInt(mnc) == config.mnc) {
                                parser.next();
                                if (parser.getEventType() == XmlPullParser.TEXT) {
                                    return parser.getText();
                                }
                            }
                        }
                    } catch (NumberFormatException e) {
                        Rlog.e(LOG_TAG, "Exception in getProvisioningUrlBaseFromFile: " + e);
                    }
                }
            }
            return null;
        } catch (FileNotFoundException e) {
            Rlog.e(LOG_TAG, "Carrier Provisioning Urls file not found");
        } catch (XmlPullParserException e) {
            Rlog.e(LOG_TAG, "Xml parser exception reading Carrier Provisioning Urls file: " + e);
        } catch (IOException e) {
            Rlog.e(LOG_TAG, "I/O exception reading Carrier Provisioning Urls file: " + e);
        }
        return null;
    }

    /**
     * Get the mobile provisioning url.
     */
    public String getMobileProvisioningUrl() {
        String url = getProvisioningUrlBaseFromFile();
        if (TextUtils.isEmpty(url)) {
            url = mContext.getResources().getString(R.string.mobile_provisioning_url);
            Rlog.d(LOG_TAG, "getMobileProvisioningUrl: url from resource =" + url);
        } else {
            Rlog.d(LOG_TAG, "getMobileProvisioningUrl: url from File =" + url);
        }
        // Populate the iccid, imei and phone number in the provisioning url.
        if (!TextUtils.isEmpty(url)) {
            String phoneNumber = getLine1Number();
            if (TextUtils.isEmpty(phoneNumber)) {
                phoneNumber = "0000000000";
            }
            url = String.format(url,
                    getIccSerialNumber() /* ICCID */,
                    getDeviceId() /* IMEI */,
                    phoneNumber /* Phone number */);
        }

        return url;
    }

    /**
    /**
     * Check if there are matching tethering (i.e DUN) for the carrier.
     * Check if there are matching tethering (i.e DUN) for the carrier.
     * @return true if there is a matching DUN APN.
     * @return true if there is a matching DUN APN.
+6 −0
Original line number Original line Diff line number Diff line
@@ -1057,4 +1057,10 @@ public interface PhoneInternalInterface {
     * Resets the Carrier Keys, by deleting them from the database and sending a download intent.
     * Resets the Carrier Keys, by deleting them from the database and sending a download intent.
     */
     */
    public void resetCarrierKeysForImsiEncryption();
    public void resetCarrierKeysForImsiEncryption();

    /**
     *  Return the mobile provisioning url that is used to launch a browser to allow users to manage
     *  their mobile plan.
     */
    String getMobileProvisioningUrl();
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -2954,7 +2954,7 @@ public class DcTracker extends Handler {
                    // While radio is up, grab provisioning URL.  The URL contains ICCID which
                    // While radio is up, grab provisioning URL.  The URL contains ICCID which
                    // disappears when radio is off.
                    // disappears when radio is off.
                    mProvisionBroadcastReceiver = new ProvisionNotificationBroadcastReceiver(
                    mProvisionBroadcastReceiver = new ProvisionNotificationBroadcastReceiver(
                            cm.getMobileProvisioningUrl(),
                            mPhone.getMobileProvisioningUrl(),
                            mTelephonyManager.getNetworkOperatorName());
                            mTelephonyManager.getNetworkOperatorName());
                    mPhone.getContext().registerReceiver(mProvisionBroadcastReceiver,
                    mPhone.getContext().registerReceiver(mProvisionBroadcastReceiver,
                            new IntentFilter(INTENT_PROVISION));
                            new IntentFilter(INTENT_PROVISION));