微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > Mobile Data Connection API

Mobile Data Connection API

时间:10-02 整理:3721RD 点击:

[DESCRIPTION]

Mobile Data Connection API

[SOLUTION]

App can use the APIs in ConnectivityManager to operate data service. We
can use ConnectivityService by the following example.
ConnectivityManager cm = (ConnectivityManager)context.getSystEMService(
Context.CONNECTIVITY_SERVICE);
Because the dual SIM cards dual stay, we use methods which have postfix
–Gemini is to access different card. We can use following code to get
which card (slot id) is set in settings.
int GPRSDefaultSlot = Settings.System.getInt(contentResolver,
Settings.System.GPRS_CONNECTION_SETTING,
Settings.System.GPRS_CONNECTION_SETTING_DEFAULT) - 1;
Following we will introduce several data service operations.
1.1How to start to use Mobile Data Service?
Generally we want to use mobile data service that must turn on the mobile
data by Settings/SIM Manager/Status bar.
public boolean getMobileDataEnabled()
Gets the value of the setting for enabling Mobile data. This method return
the data service is enabled or disabled.
public boolean getMobileDataEnabledGemini(int slotId)
– This method Gets the value of the setting for enabling Mobile data.
It’s the same with getMobileDataEnabled(), but passes the slot id to
access the corresponding cards.
– Parameters:
slotId: PhoneConstants.GEMINI_SIM_1~4 (for Gemini+)
public void setMobileDataEnabled(boolean enabled)
– This method decides the phone can use data service or not. Sets the
persisted value for enabling/disabling Mobile data.
– Parameters:
enabled: Whether the mobile data connection should be used or not
public boolean setMobileDataEnabledGemini(int slotId)
– This method decides the phone can use data service or not. Sets the
persisted value for enabling/disabling Mobile data. It’s the same with
setMobileDataEnabled(), but passes the slot id to access the corresponding
cards
– Parameters:
slotId: PhoneConstants.GEMINI_SIM_1~4 (for Gemini+)
In GEMINI_SUPPORT, to turn on data service using
setMobileDataEnabledGemini(slotId) and to turn off via
setMobileDataEnabled(false).
1.2On-Demand Data Connection
If an application calls “startUsingNetworkFeature” to request a data
connection, it must calls “stopUsingNetworkFeature” when the data
connection is no longer needed (No matter the data connection is existed
or not). When we got failure response fROM “startUsingNetworkFeature”,
call to “stopUsingNetworkFeature” before retrying.
There is an expire time of “startUsingNetworkFeature”. Call
“startUsingNetworkFeature” every 250 seconds (or less) if the data
connection needs to be existed for a long time (Currently the expire timer
is 300 seconds).
ConnectivityManager.startUsingNetworkFeature(int networkType, String
feature, IBinder binder)
– Tells the underlying networking system that the caller wants to begin
using the named feature
– This method requires the caller to hold the permission
android.Manifest.permission.CHANGE_NETWORK_STATE
– Parameter
networkType: which network the request pertains to
feature: the name of the feature to be used
binder: the binder from the caller
– Return an integer value representing the outcome of the request
-1 means failure
startUsingNetworkFeatureGemini (int networkType, String feature, int
radioNum)
– startUsingNetworkFeature in Gemini
– Parameter
radioNum: which slot we will use.
ConnectivityManager.stopUsingNetworkFeature
– Tells the underlying networking system that the caller is finished
using the named feature
– This method requires the caller to hold the permission
android.Manifest.permission.CHANGE_NETWORK_STATE
– Parameter
networkType: which network the request pertains to
feature: the name of the feature that is no long`er needed
– Return an integer value representing the outcome of the request
-1 means failure
stopUsingNetworkFeatureGemini (int networkType, String feature, int
radioNum)
– startUsingNetworkFeature in Gemini
– Parameter
radioNum: which slot we will use.
The Possible Values of the Parameters Used to Start/Stop Network Feature:
int networkType
– ConnectivityManager.TYPE_MOBILE
String feature
– Phone.FEATURE_ENABLE_MMS
– Phone.FEATURE_ENABLE_SUPL
– Phone.FEATURE_ENABLE_DUN
– Phone.FEATURE_ENABLE_HIPRI
– Phone.FEATURE_ENABLE_DUN_ALWAYS
– Phone.FEATURE_ENABLE_FOTA
– Phone.FEATURE_ENABLE_IMS
– Phone.FEATURE_ENABLE_CBS
– Phone.FEATURE_ENABLE_DM
– Phone.FEATURE_ENABLE_WAP
– Phone.FEATURE_ENABLE_NET
– Phone.FEATURE_ENABLE_CMMAIL
– Phone.FEATURE_ENABLE_RCSE
1.3Data State Changed Notification
Use broADCastReceiver can track the data state change by
CONNECTIVITY_ACTION. When receiving data state changed notification, use
ConnectivityManager.getNetworkInfo to query current state
Intent action
– ConnectivityManager.CONNECTIVITY_ACTION

http://developer.android.com/reference/android/net/ConnectivityManager.htm
l#CONNECTIVITY_ACTION
Keys of the extra fields
– ConnectivityManager.EXTRA_SIM_ID
The SIM slot ID that the data connection based on
Possible values (int)
PhoneConstants.GEMINI_SIM_1
PhoneConstants.GEMINI_SIM_2
PhoneConstants.GEMINI_SIM_3
PhoneConstants.GEMINI_SIM_4
– ConnectivityManager.EXTRA_NETWORK_TYPE
The network type of the data connection
http://developer.android.com/reference/android/net/ConnectivityManager.htm
l#EXTRA_NETWORK_TYPE
Possible values (int)
ConnectivityManager.TYPE_MOBILE
ConnectivityManager.TYPE_MOBILE_MMS
ConnectivityManager.TYPE_MOBILE_SUPL
ConnectivityManager.TYPE_MOBILE_DUN
ConnectivityManager.TYPE_MOBILE_HIPRI
ConnectivityManager.TYPE_MOBILE_FOTA
ConnectivityManager.TYPE_MOBILE_IMS
ConnectivityManager.TYPE_MOBILE_CBS
ConnectivityManager.TYPE_MOBILE_DM
ConnectivityManager.TYPE_MOBILE_WAP
ConnectivityManager.TYPE_MOBILE_NET
ConnectivityManager.TYPE_MOBILE_CMMAIL
ConnectivityManager.TYPE_MOBILE_RCSE
– ConnectivityManager.EXTRA_NO_CONNECTIVITY
If there is any active network info
http://developer.android.com/reference/android/net/ConnectivityManager.htm
l#EXTRA_NO_CONNECTIVITY
– ConnectivityManager.EXTRA_REASON
The reason why the state is changed
http://developer.android.com/reference/android/net/ConnectivityManager.htm
l#EXTRA_REASON
Possible values (String)
PhoneConstants.REASON_LINK_PROPERTIES_CHANGED
PhoneConstants.REASON_GPRS_ATTACHED_TIMEOUT
PhoneConstants.REASON_ON_RADIO_AVAILABLE
PhoneConstants.REASON_ON_RECORDS_LOADED
PhoneConstants.REASON_POLL_STATE_DONE
PhoneConstants.REASON_NO_SUCH_PDP
PhoneConstants.REASON_PDP_NOT_ACTIVE
1.4 Others
NetworkInfo
http://developer.android.com/reference/android/net/NetworkInfo.html
The other Google original api in ConnectivityManager can be referred to:
http://developer.android.com/reference/android/net/ConnectivityManager.htm
l
Retry Mechanism Suggestion
– Start to retry if receiving failure response from
“startUsingNetworkFeature”/”startUsingNetworkFeatureGemini”
– Start to retry if receiving unexpected disconnected state of the
specified APN type from “CONNECTIVITY_ACTION”
For example, after “startUsingNetworkFeature” is called, we expected
receiving connected state changed event but received disconnected state
changed event
– Use an increasing timer to arrange the next retry
For example, the first 3 retries are arranged in 30 seconds after
receiving fail or expected disconnected state.
– The next 3 retries are arranged in 60 seconds after receiving fail or
expected disconnected state. And so on…depends on the requirement of the
application

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top