andoid8.0 apn增加一个类型

 

客户需求是增加一个默认apn,type是自定义的,如下:

 

在/alps/device/mediatek/config/apns-conf.xml里面增加,系统里面需要识别ptt这个类型,在应用上用如下代码能切换apn。

ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkRequest.Builder builder = new NetworkRequest.Builder();
                builder.addCapability(29);
                builder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
                NetworkRequest build = builder.build();
                connectivityManager.requestNetwork(build, new ConnectivityManager.NetworkCallback() {
                    @Override
                    public void onAvailable(Network network) {
                        super.onAvailable(network);
                        if(DEBUG)Log.e("chenshichun"," "+this.getClass().getCanonicalName()+" ::::::onAvailable:::");
                        Toast.makeText(getApplicationContext(),"onAvailable",Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onLost(Network network) {
                        super.onLost(network);
                        if(DEBUG)Log.e("chenshichun"," "+this.getClass().getCanonicalName()+" ::::::onLost:::");

                        Toast.makeText(getApplicationContext(),"onLost",Toast.LENGTH_SHORT).show();
                    }

记录如下:

M       vendor/mediatek/proprietary/frameworks/opt/telephony-base/java/com/mediatek/internal/telephony/MtkDctConstants.java


  public static final int APN_DM_ID = 10;
    public static final int APN_WAP_ID = 11;
    public static final int APN_NET_ID = 12;
    public static final int APN_CMMAIL_ID = 13;
    public static final int APN_RCSE_ID = 14;
    public static final int APN_XCAP_ID = 15;
    public static final int APN_RCS_ID = 16;
    public static final int APN_BIP_ID = 17;
    public static final int APN_VSIM_ID = 18;
    public static final int APN_PREEMPT_ID = 19;
    public static final int APN_PTT_ID = 20;// add by csc
    public static final int APN_NUM_TYPES = APN_PTT_ID + 1;// mod from APN_PREEMPT_ID





M       vendor/mediatek/proprietary/frameworks/opt/telephony-base/java/com/mediatek/internal/telephony/MtkPhoneConstants.java


    public static final String APN_TYPE_CMMAIL = "cmmail";
    /** M: APN type for dedicate tethering apn */
    public static final String APN_TYPE_TETHERING = "tethering";
    /** M: APN type for RCSE */
    public static final String APN_TYPE_RCSE = "rcse";
    /** M: APN type for XCAP */
    public static final String APN_TYPE_XCAP = "xcap";
    /** M: APN type for RCS */
    public static final String APN_TYPE_RCS = "rcs";
    /** M: APN type for BIP */
    public static final String APN_TYPE_BIP = "bip";
    /** M: APN type for VSIM */
    public static final String APN_TYPE_VSIM = "vsim";
    /** M: APN type for PREEMPT */
    public static final String APN_TYPE_PREEMPT = "preempt";
    /** M: APN type for PTT add by csc*/
    public static final String APN_TYPE_PTT = "ptt";
    /** Array of all APN types */








M       device/mediatek/common/overlay/telephony/frameworks/base/core/res/res/values/config.xml


   
        "wifi,1,1,1,-1,true"
        "mobile,0,0,0,-1,true"
        "mobile_mms,2,0,2,60000,true"
        "mobile_supl,3,0,2,60000,true"
        "mobile_dun,4,0,2,60000,true"
        "mobile_hipri,5,0,3,60000,true"
        "mobile_fota,10,0,2,60000,true"
        "mobile_ims,11,0,-1,-1,true"
        "mobile_cbs,12,0,2,60000,true"
        "mobile_ia,14,0,2,-1,true"
        "mobile_emergency,15,0,2,-1,true"
        "mobile_wap,21,0,3,60000,true"
        "mobile_xcap,25,0,3,60000,true"
        "mobile_rcs,26,0,3,60000,true"
        "mobile_bip,27,0,3,60000,true"
        "mobile_vsim,28,0,-1,60000,true"
        "mobile_preempt,29,0,9,60000,true"
	"mobile_ptt,30,0,9,60000,true"
    







/media/work2/L618_user_1106/RQ_6762_O1_S8/alps/frameworks/base/core/java/android/net/NetworkCapabilities


    public static final int NET_CAPABILITY_BIP = 27;
    /** {@hide} */
    public static final int NET_CAPABILITY_PREEMPT = 28;
    /** M: end */
    public static final int NET_CAPABILITY_PTT = 29;// add by csc for ptt apn
    private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS;
    /** M: modify MAX_NET_CAPABILITY to NET_CAPABILITY_PREEMPT */
    private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_PTT;


 public static String capabilityNameOf(int capability) {
        switch (capability) {
            ---
            case NET_CAPABILITY_VSIM:           return "VSIM";
            case NET_CAPABILITY_BIP:            return "BIP";
            case NET_CAPABILITY_PREEMPT:        return "PREEMPTIVE";
	    case NET_CAPABILITY_PTT:            return "PTT";// add by csc for ptt apn
            /** M: end */
            default:                            return Integer.toString(capability);
        }








vendor/mediatek/proprietary/frameworks/opt/telephony/src/java/com/mediatek/internal/telephony/MtkPhoneSwitcher.java

    @Override
    protected NetworkCapabilities makeNetworkFilter() {
        android.util.Log.e("chenshichun"," "+"MTKphoneSwitcher ::::::makeNetworkFilter:::");

        NetworkCapabilities netCap = super.makeNetworkFilter();
        netCap.addCapability(NetworkCapabilities.NET_CAPABILITY_BIP);
        netCap.addCapability(NetworkCapabilities.NET_CAPABILITY_PREEMPT);
	 netCap.addCapability(NetworkCapabilities.NET_CAPABILITY_PTT);	// add by csc for apn
        return netCap;
    }









M       vendor/mediatek/proprietary/frameworks/opt/telephony/src/java/com/mediatek/internal/telephony/dataconnection/MtkApnContext.java

private static int apnIdForTypeEx(int networkType) {
        switch (networkType) {
        ------
        case ConnectivityManager.TYPE_MOBILE_PREEMPT:
            return MtkDctConstants.APN_PREEMPT_ID;
	case ConnectivityManager.TYPE_MOBILE_PTT:// add by csc for ptt apn
	Log.e("chenshichun"," MtkApnContext::::MtkDctConstants.APN_PTT_ID:::::"+MtkDctConstants.APN_PTT_ID);
            return MtkDctConstants.APN_PTT_ID;
        default:
            return DctConstants.APN_INVALID_ID;
        }
    }



 // reflection for ApnContext.apnIdForNetworkRequest
    private static Bundle apnIdForNetworkRequestEx(NetworkCapabilities nc, int apnId,
            boolean error) {
       	--------
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_PREEMPT)) {
            if (apnId != MtkDctConstants.APN_INVALID_ID) error = true;
            apnId = MtkDctConstants.APN_PREEMPT_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_PTT)) {// add by csc
            if (apnId != MtkDctConstants.APN_INVALID_ID) error = true;
            apnId = MtkDctConstants.APN_PTT_ID;
	     Log.e("chenshichun"," MtkApnContext::::apnId:::::"+apnId);
        }
        Bundle b = new Bundle();
        b.putInt("apnId", apnId);
        b.putBoolean("error", error);
        return b;
    }


 private static int apnIdForApnNameEx(String type) {
        switch (type) {
          	--------
            case MtkPhoneConstants.APN_TYPE_PREEMPT:
                return MtkDctConstants.APN_PREEMPT_ID;
	        case MtkPhoneConstants.APN_TYPE_PTT:// add by csc for ptt apn
                return MtkDctConstants.APN_PTT_ID;
            default:
                return DctConstants.APN_INVALID_ID;
        }
    }

    private boolean needNotifyType(String apnTypes) {
        if (apnTypes.equals(MtkPhoneConstants.APN_TYPE_DM)
               -----
                || apnTypes.equals(MtkPhoneConstants.APN_TYPE_BIP)
                || apnTypes.equals(MtkPhoneConstants.APN_TYPE_VSIM)
                || apnTypes.equals(MtkPhoneConstants.APN_TYPE_PTT)// add by csc for ptt apn
                ) {
            return false;
        }
        return true;
    }















M       vendor/mediatek/proprietary/frameworks/opt/telephony/src/java/com/mediatek/internal/telephony/dataconnection/MtkApnSetting.java

 public static int getApnBitmaskEx(String apn) {
        switch (apn) {
        	-----
            case MtkPhoneConstants.APN_TYPE_RCS: return MtkApnTypes.RCS;
            case MtkPhoneConstants.APN_TYPE_BIP: return MtkApnTypes.BIP;
            case MtkPhoneConstants.APN_TYPE_VSIM: return MtkApnTypes.VSIM;
	        case MtkPhoneConstants.APN_TYPE_PTT: return ApnTypes.DEFAULT;	// add by csc for ptt apn
            case PhoneConstants.APN_TYPE_ALL: return MtkApnTypes.MTKALL;
            default: return ApnTypes.NONE;
        }

M       vendor/mediatek/proprietary/frameworks/opt/telephony/src/java/com/mediatek/internal/telephony/dataconnection/MtkDataConnection.java


@Override
    protected NetworkCapabilities getNetworkCapabilities() {
        ---
                switch (type) {
                    case PhoneConstants.APN_TYPE_ALL: {
                      ---
                        result.addCapability(NetworkCapabilities.NET_CAPABILITY_RCSE);
                        result.addCapability(NetworkCapabilities.NET_CAPABILITY_XCAP);
                        result.addCapability(NetworkCapabilities.NET_CAPABILITY_RCS);
                        result.addCapability(NetworkCapabilities.NET_CAPABILITY_BIP);
                        result.addCapability(NetworkCapabilities.NET_CAPABILITY_VSIM);
			   result.addCapability(NetworkCapabilities.NET_CAPABILITY_PTT);	// add by csc for ptt apn		
                        /// @}
                        break;
                    }
                    ---
                    case MtkPhoneConstants.APN_TYPE_VSIM: {
                        result.addCapability(NetworkCapabilities.NET_CAPABILITY_VSIM);
                        break;
                    }
                    case MtkPhoneConstants.APN_TYPE_PREEMPT: {
                        for (ApnContext apnContext : mApnContexts.keySet()) {
                            if (TextUtils.equals(MtkPhoneConstants.APN_TYPE_PREEMPT,
                                    apnContext.getApnType())) {
                                result.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
                                break;
                            }
                        }
                        break;
                    }
		     case MtkPhoneConstants.APN_TYPE_PTT: {// add by csc for ptt apn
		     	android.util.Log.e("chenshichun","MtkDataConnection "+" ::::::APN_TYPE_PTT:::");
                        result.addCapability(NetworkCapabilities.NET_CAPABILITY_PTT);
                        break;
                    }
                    /// @}
                    default:
                }
            }

       ----
        }
	











M       vendor/mediatek/proprietary/frameworks/opt/telephony/src/java/com/mediatek/internal/telephony/dataconnection/MtkDcRequest.java

@Override
    protected int apnIdForNetworkRequest(NetworkRequest nr) {
        NetworkCapabilities nc = nr.networkCapabilities;
        // For now, ignore the bandwidth stuff
        if (nc.getTransportTypes().length > 0 &&
                nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) == false) {
            return APN_INVALID_ID;
        }

        // in the near term just do 1-1 matches.
        // TODO - actually try to match the set of capabilities
        int apnId = super.apnIdForNetworkRequest(nr);

        boolean error = false;
       ---
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_PREEMPT)) {
            if (apnId != APN_INVALID_ID) error = true;
            apnId = APN_PREEMPT_ID;
        }
	if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_PTT)) {// add by csc
            if (apnId != APN_INVALID_ID) error = true;
            apnId = APN_PTT_ID;
        }
        if (error) {
            // TODO: If this error condition is removed, the framework's handling of
            // NET_CAPABILITY_NOT_RESTRICTED will need to be updated so requests for
            // say FOTA and INTERNET are marked as restricted.  This is not how
            // NetworkCapabilities.maybeMarkCapabilitiesRestricted currently works.
            loge("Multiple apn types specified in request - result is unspecified!");
        }
        if (apnId == APN_INVALID_ID) {
            loge("Unsupported NetworkRequest in Telephony: nr=" + nr);
        }
	Log.e("chenshichun","MtkDcRequest===============apnId============="+apnId);	
        return apnId;
    }














M       vendor/mediatek/proprietary/frameworks/opt/telephony/src/java/com/mediatek/internal/telephony/dataconnection/MtkDcTracker.java

protected void initApnContexts() {
        ---
        for (String networkConfigString : networkConfigStrings) {
            NetworkConfig networkConfig = new NetworkConfig(networkConfigString);
            ApnContext apnContext = null;

            switch (networkConfig.type) {
            ---
            case ConnectivityManager.TYPE_MOBILE_PREEMPT:
                apnContext = addApnContext(MtkPhoneConstants.APN_TYPE_PREEMPT, networkConfig);
                break;
	     case ConnectivityManager.TYPE_MOBILE_PTT:// add by csc
	            Log.e("chenshichun"," MtkDcTracker:::::::TYPE_MOBILE_PTT::");
                apnContext = addApnContext(MtkPhoneConstants.APN_TYPE_PTT, networkConfig);
                break;
            // M @}
            case ConnectivityManager.TYPE_MOBILE_EMERGENCY:
                apnContext = addApnContext(PhoneConstants.APN_TYPE_EMERGENCY, networkConfig);
                break;
            default:
                log("initApnContexts: skipping unknown type=" + networkConfig.type);
                continue;
            }
            log("initApnContexts: apnContext=" + apnContext);
        }
  ---
    }





 

你可能感兴趣的:(android,android,源码)