简要说明Java 中.class文件的内部结构(一)

2014-11-24 01:22:40 · 作者: · 浏览: 0

3.0之前版本code:
Java代码
private void setWifiProxyConfiguration(ProxyConfiguration proxyconfiguration) {

// if isnot SSID ,return out
if (proxyconfiguration.getProxyScope() != ProxyConfiguration.ProxyScope.SSID){
return;
}
mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

// add a WifiConfig
List wifiConfiguredNetworks = mWifiManager
.getConfiguredNetworks();

for (final WifiConfiguration w : wifiConfiguredNetworks){
Log.i(TAG, ""+w.SSID+":"+proxyconfiguration.getNetworkId());

if (w.SSID.equals("""+proxyconfiguration.getNetworkId()+""")){

mLinkProperties.clear();
Log.i(TAG, "w.SSID.equals(proxyconfiguration.getNetworkId()):"
+ wifiConfiguredNetworks.indexOf(w));

mWifiConfiguration = wifiConfiguredNetworks.get(wifiConfiguredNetworks.indexOf(w));
ProxyProperties proxyproperties = new ProxyProperties(
proxyconfiguration.getProxyURL(),
proxyconfiguration.getProxyPort(),
proxyconfiguration.getmUrlExclusionList());
mLinkProperties.setHttpProxy(proxyproperties);
mWifiConfiguration.linkProperties = new LinkProperties(mLinkProperties);
mWifiConfiguration.proxySettings = ProxySettings.STATIC;

Log.i(TAG, "mWifiConfiguration.linkProperties.setHttpProxy(proxyproperties);"+ mWifiConfiguration);

mWifiManager.saveNetwork(mWifiConfiguration);
}
}
}


附3.0 Demo

3.1时源码有所改动加入了async code为:

Java代码
private class WifiServiceHandler extends Handler {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
Log.e(TAG, "Success to establish AsyncChannel connection");
//AsyncChannel in msg.obj
} else {
//AsyncChannel set up failure, ignore
Log.e(TAG, "Failed to establish AsyncChannel connection");
}
break;
default:
//Ignore
break;
}
}

WifiServiceHandler(Looper looper){
super(looper);
}
}
// Standard priority background threads.
final HandlerThread mHandlerThread = new HandlerThread("DivideService",Process.THREAD_PRIORITY_BACKGROUND);
final WifiServiceHandler mHandler;
// run a message loop for a thread.
// Threads do not have a message loop associated with them by default; so create one
mHandlerThread.start();
mHandler = new WifiServiceHandler(mHandlerThread.getLooper());
public void setProxyConfiguration(ProxyConfiguration[] proxyConfigurations) {
if (mContext.checkCallingOrSelfPermission(ENTERPROID_PERMISSION) != PackageManager.PERMISSION_GRANTED) {
if(DEBUG_LOADERS) Log.e(TAG, "setProxyConfiguration() no permission");
return;
}
if (proxyConfigurations != null) {
if(DEBUG_LOADERS) Log.d(TAG, "setProxyConfi