huangcm
2025-04-26 552bdb764ece01f57e1f174432a69f0af3b2c141
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
package com.DeviceTest;
 
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.EthernetManager;
import android.net.IpConfiguration;
import android.net.IpConfiguration.IpAssignment;
import android.net.IpConfiguration.ProxySettings;
import android.net.StaticIpConfiguration;
import android.net.NetworkInfo;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
 
import com.DeviceTest.helper.ConfigUtil;
import com.DeviceTest.helper.ControlButtonUtil;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.net.Inet4Address;
import android.net.RouteInfo;
 
import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
 
public class EthernetTestActivity extends Activity {
    private static final String TAG = EthernetTestActivity.class.getSimpleName();
 
    public enum ETHERNET_STATE {
        ETHER_STATE_DISCONNECTED,
        ETHER_STATE_CONNECTING,
        ETHER_STATE_CONNECTED
    }
 
    private static final String HTTP_TEST_URL = "https://www.baidu.com/";
    private static final String nullIpInfo = "0.0.0.0";
    private static final String gettingIpInfo = "gettings...";
    private static final int TEST_GET_INFO_TIMEOUT_DELAY = 5000;
    private static final int TEST_FINISH_DELAY = 1500;
 
    private static final int MSG_GET_ETHERNET_STATE = 1;
    private static final int MSG_GET_ETHERNET_TIMEOUT = 2;
    private static final int MSG_HTTP_TEST = 3;
    private static final int MSG_TEST_FAILED = 4;
    private static final int MSG_TEST_SUCCESS = 5;
 
    private TextView txt_ethInfo;
    private TextView txt_result;
    private ProgressBar progressBar;
    private boolean mReadyToGetEthInfo;
    private boolean mStop;
 
    private ConnectivityManager mConnectivityManager;
    private EthernetManager mEthManager;
    private BroadcastReceiver mReceiver;
    private String mIfaceName;
    private String mEthIpAddress = null;
    private String mEthNetmask = null;
    private String mEthGateway = null;
    private String mEthdns1 = null;
    private String mEthdns2 = null;
 
    protected String mAssignIfaceName;
 
    protected void preData() {
    }
 
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (mStop) {
                return;
            }
            switch (msg.what) {
                case MSG_GET_ETHERNET_STATE:
                    Log.v(TAG, "MSG_GET_ETHERNET_STATE");
                    if (mReadyToGetEthInfo) {
                        handleEtherStateChange((ETHERNET_STATE) msg.obj);
                    }
                    break;
                case MSG_GET_ETHERNET_TIMEOUT:
                    if (mReadyToGetEthInfo) {
                        mReadyToGetEthInfo = false;
                        Log.e(TAG, "MSG_GET_ETHERNET_TIMEOUT");
                        mHandler.removeMessages(MSG_GET_ETHERNET_TIMEOUT);
                        progressBar.setVisibility(View.GONE);
                        txt_result.setText(R.string.EthernetGetInfoTimeoutFail);
                        mHandler.sendEmptyMessageDelayed(MSG_TEST_FAILED, TEST_FINISH_DELAY);
                    }
                    break;
                case MSG_HTTP_TEST:
                    Log.v(TAG, "MSG_HTTP_TEST");
                    txt_result.setText("waiting test connect:\n" + HTTP_TEST_URL);
                    progressBar.setVisibility(View.VISIBLE);
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            mHandler.sendEmptyMessageDelayed(httpUrlTest() ? MSG_TEST_SUCCESS
                                    : MSG_TEST_FAILED, TEST_FINISH_DELAY);
                        }
                    }).start();
                    break;
                case MSG_TEST_SUCCESS:
                    Log.v(TAG, "MSG_TEST_SUCCESS");
                    mHandler.removeMessages(MSG_TEST_SUCCESS);
                    mStop = true;
                    findViewById(R.id.btn_Pass).performClick();
                    break;
                case MSG_TEST_FAILED:
                    Log.v(TAG, "MSG_TEST_FAILED");
                    mHandler.removeMessages(MSG_TEST_FAILED);
                    mStop = true;
                    findViewById(R.id.btn_Fail).performClick();
                    break;
                default:
                    break;
            }
        }
    };
 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(FLAG_FULLSCREEN | FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.ethernettest);
 
        preData();
        txt_ethInfo = (TextView) findViewById(R.id.txt_ethInfo);
        txt_result = (TextView) findViewById(R.id.txt_result);
        progressBar = (ProgressBar) findViewById(R.id.progress);
        ControlButtonUtil.initControlButtonView(this);
        findViewById(R.id.btn_Pass).setVisibility(View.INVISIBLE);
        findViewById(R.id.btn_Fail).setVisibility(View.INVISIBLE);
 
        mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
 
        mEthManager = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE);
        if (null == mEthManager) {
            Log.e(TAG, "get ethernet manager failed");
            txt_result.setText(R.string.EthernetManagerFail);
            mHandler.sendEmptyMessageDelayed(MSG_TEST_FAILED, TEST_FINISH_DELAY);
            return;
        }
        String[] ifaces = new String[]{"eth0"};
        if (Build.VERSION.SDK_INT >= ConfigUtil.ANDROID_SDK_VERSION_P) {
            try {
                Method m = EthernetManager.class.getMethod("getAvailableInterfaces", null);
                ifaces = (String[]) m.invoke(mEthManager, null);
            } catch (Exception e) {
                e.printStackTrace();
                ifaces = null;
            }
        }
        if (ifaces.length > 0) {
            if (ConfigUtil.isSpecialEvb() && TextUtils.isEmpty(mAssignIfaceName)) {
                mAssignIfaceName = "eth0";
            }
            if (TextUtils.isEmpty(mAssignIfaceName)) {
                mIfaceName = ifaces[0];//"eth0";
            } else {
                for (String iface : ifaces) {
                    if (null != iface && iface.equals(mAssignIfaceName)) {
                        mIfaceName = iface;
                        break;
                    }
                }
            }
        }
 
        Log.v(TAG, "mIfaceName=" + mIfaceName);
        if (null == mIfaceName) {
            Log.e(TAG, "get ethernet ifaceName failed");
            txt_result.setText(R.string.EthernetInterfacesFail);
            mHandler.sendEmptyMessageDelayed(MSG_TEST_FAILED, TEST_FINISH_DELAY);
            return;
        }
        mReadyToGetEthInfo = true;
        progressBar.setVisibility(View.VISIBLE);
        mReceiver = new MyBroadcastReceiver();
        mHandler.sendEmptyMessageDelayed(MSG_GET_ETHERNET_TIMEOUT, TEST_GET_INFO_TIMEOUT_DELAY);
    }
 
    protected void onResume() {
        super.onResume();
 
        if (null != mReceiver) {
            IntentFilter localIntentFilter = new IntentFilter();
            localIntentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
            registerReceiver(mReceiver, localIntentFilter);
        }
    }
 
    public void onPause() {
        super.onPause();
 
        if (null != mReceiver) {
            unregisterReceiver(mReceiver);
        }
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mReadyToGetEthInfo = false;
        mStop = false;
        mHandler.removeMessages(MSG_GET_ETHERNET_STATE);
        mHandler.removeMessages(MSG_GET_ETHERNET_TIMEOUT);
        mHandler.removeMessages(MSG_TEST_FAILED);
        mHandler.removeMessages(MSG_TEST_SUCCESS);
    }
 
    private void getEthInfo() throws Exception {
        /*
        mEthHwAddress = mEthManager.getEthernetHwaddr(mEthManager.getEthernetIfaceName());
        if (mEthHwAddress == null) mEthHwAddress = nullIpInfo;
        */
        IpConfiguration ipConfiguration = null;
        if (Build.VERSION.SDK_INT >= ConfigUtil.ANDROID_SDK_VERSION_P) {
            Method m = EthernetManager.class.getMethod("getConfiguration", String.class);
            ipConfiguration = (IpConfiguration) m.invoke(mEthManager, mIfaceName);
        } else {
            Method m = EthernetManager.class.getMethod("getConfiguration", null);
            ipConfiguration = (IpConfiguration) m.invoke(mEthManager, null);
        }
        IpAssignment mode = ipConfiguration.getIpAssignment();
        if (mode == IpAssignment.DHCP || mode == IpAssignment.UNASSIGNED) {
            getEthInfoFromDhcp_V1();
        } else if (mode == IpAssignment.STATIC) {
            getEthInfoFromStaticIp();
        }
    }
 
    public static String intToNetmask(int prefixLength) {
        if (prefixLength < 0 || prefixLength > 32) {
            throw new IllegalArgumentException("Prefix length must be between 0 and 32");
        }
        StringBuilder netmask = new StringBuilder();
        int[] parts = new int[4];
        // 计算每一部分的值
        for (int i = 0; i < 4; i++) {
            if (prefixLength >= 8) {
                parts[i] = 255;
                prefixLength -= 8;
            } else if (prefixLength > 0) {
                parts[i] = 256 - (1 << (8 - prefixLength));
                prefixLength = 0;
            } else {
                parts[i] = 0;
            }
        }
        // 构建点分十进制字符串
        for (int i = 0; i < 4; i++) {
            netmask.append(parts[i]);
            if (i < 3) {
                netmask.append(".");
            }
        }
        return netmask.toString();
    }
 
    private void getEthInfoFromDhcp_V1() {
        int network = ConnectivityManager.TYPE_ETHERNET;
        String mMacPreference = mConnectivityManager.getNetworkInfo(network).getExtraInfo();
 
        final LinkProperties linkProperties = mConnectivityManager.getLinkProperties(network);
        for (LinkAddress linkAddress : linkProperties.getLinkAddresses()) { //set ipaddress.
            if (linkAddress.getAddress() instanceof Inet4Address) {
                String mgetHostAddress = linkAddress.getAddress().getHostAddress();
                String netMask = intToNetmask(linkAddress.getPrefixLength());
                Log.v(TAG, "mgetHostAddress " + mgetHostAddress);
                Log.v(TAG, "netMask " + netMask);
                mEthIpAddress = mgetHostAddress;
                mEthNetmask = netMask;
                break;
            }
        }
 
        String dns1 = null;
        String dns2 = null;
        int dnsCount = 0;
        for (InetAddress inetAddress:linkProperties.getDnsServers()) {
            if (0 == dnsCount) {
                dns1 = inetAddress.getHostAddress().toString();
                if (inetAddress instanceof Inet4Address) {
                    dns1 = inetAddress.getHostAddress().toString();
                } else {
                    dns1 = "0.0.0.0";
                }
            }
            if (1 == dnsCount) {
                dns2 = inetAddress.getHostAddress().toString();
                if (inetAddress instanceof Inet4Address) {
                    dns2 = inetAddress.getHostAddress().toString();
                } else {
                    dns2 = "0.0.0.0";
                }
            }
            dnsCount++;
        }
 
        mEthdns1 = dns1;
        if (dnsCount > 1) {
            mEthdns2 = dns2;
        } else {
            dns2 = "0.0.0.0";
            mEthdns2 = dns2;
        }
 
        String Route = null;
        for (RouteInfo route:linkProperties.getRoutes()) {
            if (route.isIPv4Default()) {
                Route = route.getGateway().toString();
                break;
            }
        }
        if (Route != null) {
            String[] RouteStr = Route.split("/");
            mEthGateway = RouteStr[1];
        } else {
            mEthGateway = "0.0.0.0";
        }
        Log.v(TAG, "mIfaceName " + mIfaceName);
        Log.v(TAG, "mEthIpAddress " + mEthIpAddress);
        Log.v(TAG, "mEthNetmask " + mEthNetmask);
        Log.v(TAG, "mEthGateway " + mEthGateway);
        Log.v(TAG, "mEthdns1 " + mEthdns1);
        Log.v(TAG, "mEthdns2 " + mEthdns2);
 
    }
 
    public void getEthInfoFromDhcp() throws Exception {
        boolean isSdkAfterO = Build.VERSION.SDK_INT >= ConfigUtil.ANDROID_SDK_VERSION_P;
        String tempIpInfo;
        if (isSdkAfterO) {
            Method m = EthernetManager.class.getMethod("getIpAddress", String.class);
            tempIpInfo = (String) m.invoke(mEthManager, mIfaceName);
        } else {
            Method m = EthernetManager.class.getMethod("getIpAddress", null);
            tempIpInfo = (String) m.invoke(mEthManager, null);
        }
 
        if ((tempIpInfo != null) && (!tempIpInfo.equals(""))) {
            mEthIpAddress = tempIpInfo;
        } else {
            mEthIpAddress = nullIpInfo;
        }
 
        if (isSdkAfterO) {
            Method m = EthernetManager.class.getMethod("getNetmask", String.class);
            tempIpInfo = (String) m.invoke(mEthManager, mIfaceName);
        } else {
            Method m = EthernetManager.class.getMethod("getNetmask", null);
            tempIpInfo = (String) m.invoke(mEthManager, null);
        }
 
        if ((tempIpInfo != null) && (!tempIpInfo.equals(""))) {
            mEthNetmask = tempIpInfo;
        } else {
            mEthNetmask = nullIpInfo;
        }
 
        if (isSdkAfterO) {
            Method m = EthernetManager.class.getMethod("getGateway", String.class);
            tempIpInfo = (String) m.invoke(mEthManager, mIfaceName);
        } else {
            Method m = EthernetManager.class.getMethod("getGateway", null);
            tempIpInfo = (String) m.invoke(mEthManager, null);
        }
        if ((tempIpInfo != null) && (!tempIpInfo.equals(""))) {
            mEthGateway = tempIpInfo;
        } else {
            mEthGateway = nullIpInfo;
        }
 
        if (isSdkAfterO) {
            Method m = EthernetManager.class.getMethod("getDns", String.class);
            tempIpInfo = (String) m.invoke(mEthManager, mIfaceName);
        } else {
            Method m = EthernetManager.class.getMethod("getDns", null);
            tempIpInfo = (String) m.invoke(mEthManager, null);
        }
        if ((tempIpInfo != null) && (!tempIpInfo.equals(""))) {
            String data[] = tempIpInfo.split(",");
            mEthdns1 = data[0];
            if (data.length <= 1) {
                mEthdns2 = nullIpInfo;
            } else {
                mEthdns2 = data[1];
            }
        } else {
            mEthdns1 = nullIpInfo;
        }
    }
 
    public void getEthInfoFromStaticIp() throws Exception {
        IpConfiguration ipConfiguration = null;
        if (Build.VERSION.SDK_INT >= ConfigUtil.ANDROID_SDK_VERSION_P) {
            Method m = EthernetManager.class.getMethod("getConfiguration", String.class);
            ipConfiguration = (IpConfiguration) m.invoke(mEthManager, mIfaceName);
        } else {
            Method m = EthernetManager.class.getMethod("getConfiguration", null);
            ipConfiguration = (IpConfiguration) m.invoke(mEthManager, null);
        }
        StaticIpConfiguration staticIpConfiguration = ipConfiguration.getStaticIpConfiguration();
 
        if (staticIpConfiguration == null) {
            return;
        }
   /*
        LinkAddress ipAddress = staticIpConfiguration.ipAddress;
        InetAddress gateway = staticIpConfiguration.gateway;
        ArrayList<InetAddress> dnsServers = staticIpConfiguration.dnsServers;
 
        if (ipAddress != null) {
            mEthIpAddress = ipAddress.getAddress().getHostAddress();
            mEthNetmask = interMask2String(ipAddress.getPrefixLength());
        }
        if (gateway != null) {
            mEthGateway = gateway.getHostAddress();
        }
        mEthdns1 = dnsServers.get(0).getHostAddress();
 
        if (dnsServers.size() > 1) { // 只保留两个
            mEthdns2 = dnsServers.get(1).getHostAddress();
        }
   */
    }
 
    private void handleEtherStateChange(ETHERNET_STATE EtherState, long delayMillis) {
        mHandler.removeMessages(MSG_GET_ETHERNET_STATE);
        if (delayMillis > 0) {
            Message msg = new Message();
            msg.what = MSG_GET_ETHERNET_STATE;
            msg.obj = EtherState;
            mHandler.sendMessageDelayed(msg, delayMillis);
        } else {
            handleEtherStateChange(EtherState);
        }
    }
 
    private void handleEtherStateChange(ETHERNET_STATE EtherState) {
        Log.v(TAG, "curEtherState" + EtherState);
        progressBar.setVisibility(View.VISIBLE);
        switch (EtherState) {
            case ETHER_STATE_DISCONNECTED:
                /*mEthIpAddress = nullIpInfo;
                mEthNetmask = nullIpInfo;
                mEthGateway = nullIpInfo;
                mEthdns1 = nullIpInfo;
                mEthdns2 = nullIpInfo;
                refreshUI();
                break;*/
            case ETHER_STATE_CONNECTING:
                mEthIpAddress = gettingIpInfo;
                mEthNetmask = gettingIpInfo;
                mEthGateway = gettingIpInfo;
                mEthdns1 = gettingIpInfo;
                mEthdns2 = gettingIpInfo;
                txt_ethInfo.setText(gettingIpInfo);
                break;
            case ETHER_STATE_CONNECTED:
                try {
                    getEthInfo();
                    refreshUI();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            default:
                break;
        }
    }
 
    private void refreshUI() {
        StringBuilder sb = new StringBuilder();
        sb.append(mIfaceName + "\n");
        sb.append("ip: " + mEthIpAddress + "\n");
        sb.append("netmask: " + mEthNetmask + "\n");
        sb.append("gateway: " + mEthGateway + "\n");
        sb.append("dns1: " + mEthdns1 + "\n");
        sb.append("dns2: " + mEthdns2 + "\n");
        Log.v(TAG, sb.toString());
        txt_ethInfo.setText(sb.toString());
        progressBar.setVisibility(View.GONE);
        if (null == mEthIpAddress || mEthIpAddress.equals(nullIpInfo) || mEthIpAddress.equals(gettingIpInfo)
                || null == mEthNetmask || mEthNetmask.equals(nullIpInfo) || mEthNetmask.equals(gettingIpInfo)
                || null == mEthGateway || mEthGateway.equals(nullIpInfo) || mEthGateway.equals(gettingIpInfo)
                || null == mEthdns1 || mEthdns1.equals(nullIpInfo) || mEthdns1.equals(gettingIpInfo)
            /*|| null == mEthdns2 || mEthdns2.equals(nullIpInfo) || mEthdns2.equals(gettingIpInfo)*/) {
 
        } else if (mReadyToGetEthInfo) {
            mReadyToGetEthInfo = false;
            mHandler.removeMessages(MSG_GET_ETHERNET_TIMEOUT);
            mHandler.sendEmptyMessage(MSG_HTTP_TEST);
        }
    }
 
    //将子网掩码转换成ip子网掩码形式,比如输入32输出为255.255.255.255
    public String interMask2String(int prefixLength) {
        String netMask = null;
        int inetMask = prefixLength;
 
        int part = inetMask / 8;
        int remainder = inetMask % 8;
        int sum = 0;
 
        for (int i = 8; i > 8 - remainder; i--) {
            sum = sum + (int) Math.pow(2, i - 1);
        }
 
        if (part == 0) {
            netMask = sum + ".0.0.0";
        } else if (part == 1) {
            netMask = "255." + sum + ".0.0";
        } else if (part == 2) {
            netMask = "255.255." + sum + ".0";
        } else if (part == 3) {
            netMask = "255.255.255." + sum;
        } else if (part == 4) {
            netMask = "255.255.255.255";
        }
 
        return netMask;
    }
 
    private boolean httpUrlTest() {
        HttpURLConnection conn = null;
        InputStream is = null;
        String resultData = "";
        try {
            URL url = new URL(HTTP_TEST_URL);
            conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("GET");
            conn.setConnectTimeout(10000);
            conn.setReadTimeout(1000);
            if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
                is = conn.getInputStream();
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader bufferReader = new BufferedReader(isr);
                String inputLine = "";
                while ((inputLine = bufferReader.readLine()) != null) {
                    resultData += inputLine + "\n";
                }
                Log.v(TAG, "http respond:" + resultData);
                return resultData.length() > 20;
            } else {
                Log.e(TAG, "==========error code:" + conn.getResponseCode());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            if (conn != null) {
                conn.disconnect();
            }
        }
        return false;
    }
 
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            return false;
        }
        return super.dispatchKeyEvent(event);
    }
 
    class MyBroadcastReceiver extends BroadcastReceiver {
 
        public void onReceive(Context context, Intent intent) {
            if (!mReadyToGetEthInfo || mStop) {
                return;
            }
            String action = intent.getAction();
            Log.v(TAG, "action:" + action);
            if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
                NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
                Log.v(TAG, "===" + info.toString());
                if (null != info && ConnectivityManager.TYPE_ETHERNET == info.getType()) {
                    if (NetworkInfo.State.CONNECTED == info.getState()) {
                        handleEtherStateChange(ETHERNET_STATE.ETHER_STATE_CONNECTED, 0);
                    } else if (NetworkInfo.State.DISCONNECTED == info.getState()) {
                        handleEtherStateChange(ETHERNET_STATE.ETHER_STATE_DISCONNECTED, 0);
                    }
                }
            }
        }
    }
}