am f9610b38: Merge "Make the DUN apn data secure." into froyo

Merge commit 'f9610b3842e030138c1dc327a3a467aaea02c227' into kraken

* commit 'f9610b3842e030138c1dc327a3a467aaea02c227':
  Make the DUN apn data secure.
This commit is contained in:
Robert Greenwalt
2010-06-06 12:10:00 -07:00
committed by Android Git Automerger
5 changed files with 90 additions and 5 deletions

View File

@@ -2367,6 +2367,24 @@ public final class Settings {
*/ */
public static final String TETHER_SUPPORTED = "tether_supported"; public static final String TETHER_SUPPORTED = "tether_supported";
/**
* Used to require DUN APN on the device or not - defaults to a build config value
* which defaults to false
* @hide
*/
public static final String TETHER_DUN_REQUIRED = "tether_dun_required";
/**
* Used to hold a gservices-provisioned apn value for DUN. If set, or the
* corresponding build config values are set it will override the APN DB
* values.
* Consists of a comma seperated list of strings:
* "name,apn,proxy,port,username,password,server,mmsc,mmsproxy,mmsport,mcc,mnc,auth,type"
* note that empty fields can be ommitted: "name,apn,,,,,,,,,310,260,,DUN"
* @hide
*/
public static final String TETHER_DUN_APN = "tether_dun_apn";
/** /**
* No longer supported. * No longer supported.
*/ */

View File

@@ -91,8 +91,18 @@
<string-array translatable="false" name="config_tether_upstream_regexs"> <string-array translatable="false" name="config_tether_upstream_regexs">
</string-array> </string-array>
<!-- Boolean indicating if we require the use of DUN on mobile for tethering --> <!-- Boolean indicating if we require the use of DUN on mobile for tethering.
<bool translatable="false" name="config_tether_dun_required">true</bool> Note that this defaults to false so that if you move to a carrier that
hasn't configured anything tethering will still work. If you'd rather
make the device untetherable on unconfigured devices, set to true -->
<bool translatable="false" name="config_tether_dun_required">false</bool>
<!-- String containing the apn value for tethering. May be overriden by secure settings
TETHER_DUN_APN. Value is a comma separated series of strings:
"name,apn,proxy,port,username,password,server,mmsc,mmsproxy,mmsport,mcc,mnc,auth,type"
note that empty fields can be ommitted: "name,apn,,,,,,,,,310,260,,DUN" -->
<string translatable="false" name="config_tether_apndata"></string>
<!-- Flag indicating whether the keyguard should be bypassed when <!-- Flag indicating whether the keyguard should be bypassed when
the slider is open. This can be set or unset depending how easily the slider is open. This can be set or unset depending how easily

View File

@@ -98,6 +98,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
private static final String DNS_DEFAULT_SERVER1 = "8.8.8.8"; private static final String DNS_DEFAULT_SERVER1 = "8.8.8.8";
private static final String DNS_DEFAULT_SERVER2 = "4.2.2.2"; private static final String DNS_DEFAULT_SERVER2 = "4.2.2.2";
// resampled each time we turn on tethering - used as cache for settings/config-val
private boolean mDunRequired; // configuration info - must use DUN apn on 3g private boolean mDunRequired; // configuration info - must use DUN apn on 3g
private HierarchicalStateMachine mTetherMasterSM; private HierarchicalStateMachine mTetherMasterSM;
@@ -157,8 +158,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
mDhcpRange[2] = DHCP_DEFAULT_RANGE2_START; mDhcpRange[2] = DHCP_DEFAULT_RANGE2_START;
mDhcpRange[3] = DHCP_DEFAULT_RANGE2_STOP; mDhcpRange[3] = DHCP_DEFAULT_RANGE2_STOP;
} }
mDunRequired = context.getResources().getBoolean( mDunRequired = false; // resample when we turn on
com.android.internal.R.bool.config_tether_dun_required);
mTetherableUsbRegexs = context.getResources().getStringArray( mTetherableUsbRegexs = context.getResources().getStringArray(
com.android.internal.R.array.config_tether_usb_regexs); com.android.internal.R.array.config_tether_usb_regexs);
@@ -555,7 +555,11 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
} }
public boolean isDunRequired() { public boolean isDunRequired() {
return mDunRequired; boolean defaultVal = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_tether_dun_required);
boolean result = (Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.TETHER_DUN_REQUIRED, (defaultVal ? 1 : 0)) == 1);
return result;
} }
public String[] getTetheredIfaces() { public String[] getTetheredIfaces() {
@@ -1263,6 +1267,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
boolean retValue = true; boolean retValue = true;
switch (message.what) { switch (message.what) {
case CMD_TETHER_MODE_REQUESTED: case CMD_TETHER_MODE_REQUESTED:
mDunRequired = isDunRequired();
TetherInterfaceSM who = (TetherInterfaceSM)message.obj; TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
Log.d(TAG, "Tether Mode requested by " + who.toString()); Log.d(TAG, "Tether Mode requested by " + who.toString());
mNotifyList.add(who); mNotifyList.add(who);

View File

@@ -55,6 +55,35 @@ public class ApnSetting {
this.types = types; this.types = types;
} }
// data[0] = name
// data[1] = apn
// data[2] = proxy
// data[3] = port
// data[4] = username
// data[5] = password
// data[6] = server
// data[7] = mmsc
// data[8] = mmsproxy
// data[9] = mmsport
// data[10] = mcc
// data[11] = mnc
// data[12] = auth
// data[13] = first type...
public static ApnSetting fromString(String data) {
if (data == null) return null;
String[] a = data.split("\\s*,\\s*");
if (a.length < 14) return null;
int authType = 0;
try {
authType = Integer.parseInt(a[12]);
} catch (Exception e) {
}
String[] typeArray = new String[a.length - 13];
System.arraycopy(a, 13, typeArray, 0, a.length - 13);
return new ApnSetting(-1,a[10]+a[11],a[0],a[1],a[2],a[3],a[7],a[8],
a[9],a[4],a[5],authType,typeArray);
}
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(carrier) sb.append(carrier)

View File

@@ -48,6 +48,7 @@ import android.telephony.gsm.GsmCellLocation;
import android.util.EventLog; import android.util.EventLog;
import android.util.Log; import android.util.Log;
import com.android.internal.R;
import com.android.internal.telephony.DataCallState; import com.android.internal.telephony.DataCallState;
import com.android.internal.telephony.DataConnection; import com.android.internal.telephony.DataConnection;
import com.android.internal.telephony.DataConnectionTracker; import com.android.internal.telephony.DataConnectionTracker;
@@ -365,6 +366,10 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
@Override @Override
protected boolean isApnTypeAvailable(String type) { protected boolean isApnTypeAvailable(String type) {
if (type.equals(Phone.APN_TYPE_DUN)) {
return (fetchDunApn() != null);
}
if (allApns != null) { if (allApns != null) {
for (ApnSetting apn : allApns) { for (ApnSetting apn : allApns) {
if (apn.canHandleType(type)) { if (apn.canHandleType(type)) {
@@ -1302,6 +1307,17 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
} }
} }
private ApnSetting fetchDunApn() {
Context c = phone.getContext();
String apnData = Settings.Secure.getString(c.getContentResolver(),
Settings.Secure.TETHER_DUN_APN);
ApnSetting dunSetting = ApnSetting.fromString(apnData);
if (dunSetting != null) return dunSetting;
apnData = c.getResources().getString(R.string.config_tether_apndata);
return ApnSetting.fromString(apnData);
}
/** /**
* *
* @return waitingApns list to be used to create PDP * @return waitingApns list to be used to create PDP
@@ -1309,6 +1325,13 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
*/ */
private ArrayList<ApnSetting> buildWaitingApns() { private ArrayList<ApnSetting> buildWaitingApns() {
ArrayList<ApnSetting> apnList = new ArrayList<ApnSetting>(); ArrayList<ApnSetting> apnList = new ArrayList<ApnSetting>();
if (mRequestedApnType.equals(Phone.APN_TYPE_DUN)) {
ApnSetting dun = fetchDunApn();
if (dun != null) apnList.add(dun);
return apnList;
}
String operator = mGsmPhone.mSIMRecords.getSIMOperatorNumeric(); String operator = mGsmPhone.mSIMRecords.getSIMOperatorNumeric();
if (mRequestedApnType.equals(Phone.APN_TYPE_DEFAULT)) { if (mRequestedApnType.equals(Phone.APN_TYPE_DEFAULT)) {