Merge change 4786 into donut
* changes: gps: Set SUPL server via hostname rather than IP address.
This commit is contained in:
8
core/jni/android_location_GpsLocationProvider.cpp
Normal file → Executable file
8
core/jni/android_location_GpsLocationProvider.cpp
Normal file → Executable file
@@ -336,13 +336,15 @@ static void android_location_GpsLocationProvider_agps_data_conn_failed(JNIEnv* e
|
||||
}
|
||||
|
||||
static void android_location_GpsLocationProvider_set_agps_server(JNIEnv* env, jobject obj,
|
||||
jint type, jint addr, jint port)
|
||||
jint type, jstring hostname, jint port)
|
||||
{
|
||||
if (!sAGpsInterface) {
|
||||
sAGpsInterface = (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
|
||||
}
|
||||
if (sAGpsInterface) {
|
||||
sAGpsInterface->set_server(type, addr, port);
|
||||
const char *c_hostname = env->GetStringUTFChars(hostname, NULL);
|
||||
sAGpsInterface->set_server(type, c_hostname, port);
|
||||
env->ReleaseStringUTFChars(hostname, c_hostname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +367,7 @@ static JNINativeMethod sMethods[] = {
|
||||
{"native_agps_data_conn_open", "(Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_agps_data_conn_open},
|
||||
{"native_agps_data_conn_closed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_closed},
|
||||
{"native_agps_data_conn_failed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_failed},
|
||||
{"native_set_agps_server", "(III)V", (void*)android_location_GpsLocationProvider_set_agps_server},
|
||||
{"native_set_agps_server", "(ILjava/lang/String;I)V", (void*)android_location_GpsLocationProvider_set_agps_server},
|
||||
};
|
||||
|
||||
int register_android_location_GpsLocationProvider(JNIEnv* env)
|
||||
|
||||
70
location/java/com/android/internal/location/GpsLocationProvider.java
Normal file → Executable file
70
location/java/com/android/internal/location/GpsLocationProvider.java
Normal file → Executable file
@@ -208,12 +208,6 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
private GpsNetworkThread mNetworkThread;
|
||||
private Object mNetworkThreadLock = new Object();
|
||||
|
||||
private String mSuplHost;
|
||||
private int mSuplPort;
|
||||
private String mC2KHost;
|
||||
private int mC2KPort;
|
||||
private boolean mSetSuplServer;
|
||||
private boolean mSetC2KServer;
|
||||
private String mAGpsApn;
|
||||
private int mAGpsDataConnectionState;
|
||||
private final ConnectivityManager mConnMgr;
|
||||
@@ -355,23 +349,27 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
stream.close();
|
||||
mNtpServer = mProperties.getProperty("NTP_SERVER", null);
|
||||
|
||||
mSuplHost = mProperties.getProperty("SUPL_HOST");
|
||||
String host = mProperties.getProperty("SUPL_HOST");
|
||||
String portString = mProperties.getProperty("SUPL_PORT");
|
||||
if (mSuplHost != null && portString != null) {
|
||||
if (host != null && portString != null) {
|
||||
try {
|
||||
mSuplPort = Integer.parseInt(portString);
|
||||
mSetSuplServer = true;
|
||||
int port = Integer.parseInt(portString);
|
||||
native_set_agps_server(AGPS_TYPE_SUPL, host, port);
|
||||
// use MS-Based position mode if SUPL support is enabled
|
||||
mPositionMode = GPS_POSITION_MODE_MS_BASED;
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
|
||||
}
|
||||
}
|
||||
|
||||
mC2KHost = mProperties.getProperty("C2K_HOST");
|
||||
host = mProperties.getProperty("C2K_HOST");
|
||||
portString = mProperties.getProperty("C2K_PORT");
|
||||
if (mC2KHost != null && portString != null) {
|
||||
if (host != null && portString != null) {
|
||||
try {
|
||||
mC2KPort = Integer.parseInt(portString);
|
||||
mSetC2KServer = true;
|
||||
int port = Integer.parseInt(portString);
|
||||
native_set_agps_server(AGPS_TYPE_C2K, host, port);
|
||||
// use MS-Based position mode if SUPL support is enabled
|
||||
mPositionMode = GPS_POSITION_MODE_MS_BASED;
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "unable to parse C2K_PORT: " + portString);
|
||||
}
|
||||
@@ -386,10 +384,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
* data network (e.g., the Internet), false otherwise.
|
||||
*/
|
||||
public boolean requiresNetwork() {
|
||||
// We want updateNetworkState() to get called when the network state changes
|
||||
// for XTRA and NTP time injection support.
|
||||
return (mNtpServer != null || native_supports_xtra() ||
|
||||
mSuplHost != null || mC2KHost != null);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateNetworkState(int state) {
|
||||
@@ -989,29 +984,6 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setAGpsServer(int type, String host, int port) {
|
||||
try {
|
||||
InetAddress inetAddress = InetAddress.getByName(host);
|
||||
if (inetAddress != null) {
|
||||
byte[] addrBytes = inetAddress.getAddress();
|
||||
long addr = 0;
|
||||
for (int i = 0; i < addrBytes.length; i++) {
|
||||
int temp = addrBytes[i];
|
||||
// signed -> unsigned
|
||||
if (temp < 0) temp = 256 + temp;
|
||||
addr = addr * 256 + temp;
|
||||
}
|
||||
// use MS-Based position mode if SUPL support is enabled
|
||||
mPositionMode = GPS_POSITION_MODE_MS_BASED;
|
||||
native_set_agps_server(type, (int)addr, port);
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
Log.e(TAG, "unknown host for server " + host);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private class GpsEventThread extends Thread {
|
||||
|
||||
public GpsEventThread() {
|
||||
@@ -1085,7 +1057,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
}
|
||||
waitTime = getWaitTime();
|
||||
} while (!mDone && ((!mXtraDownloadRequested &&
|
||||
!mTimeInjectRequested && !mSetSuplServer && !mSetC2KServer && waitTime > 0)
|
||||
!mTimeInjectRequested && waitTime > 0)
|
||||
|| !mNetworkAvailable));
|
||||
if (Config.LOGD) Log.d(TAG, "NetworkThread out of wake loop");
|
||||
|
||||
@@ -1113,18 +1085,6 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
// Set the AGPS server addresses if we have not yet
|
||||
if (mSetSuplServer) {
|
||||
if (setAGpsServer(AGPS_TYPE_SUPL, mSuplHost, mSuplPort)) {
|
||||
mSetSuplServer = false;
|
||||
}
|
||||
}
|
||||
if (mSetC2KServer) {
|
||||
if (setAGpsServer(AGPS_TYPE_C2K, mC2KHost, mC2KPort)) {
|
||||
mSetC2KServer = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((mXtraDownloadRequested ||
|
||||
(mNextXtraTime > 0 && mNextXtraTime <= System.currentTimeMillis()))
|
||||
&& xtraDownloader != null) {
|
||||
@@ -1225,5 +1185,5 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
private native void native_agps_data_conn_open(String apn);
|
||||
private native void native_agps_data_conn_closed();
|
||||
private native void native_agps_data_conn_failed();
|
||||
private native void native_set_agps_server(int type, int addr, int port);
|
||||
private native void native_set_agps_server(int type, String hostname, int port);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user