1. 程式人生 > 其它 >Android7.1 關閉路由器DHCP後還能獲取到ip地址

Android7.1 關閉路由器DHCP後還能獲取到ip地址

frameworks\base\services\net\java\android\net\dhcp\DhcpClient.java 確定mIsIpRecoverEnabled=false;解決此問題。 原因: private boolean doIpRecover() { if (mIsIpRecoverEnabled == false) { Log.d(TAG, "IP recover: it was disabled"); return false; } if (mPastDhcpLease == null) { Log.d(TAG, "IP recover: mPastDhcpLease is empty"); return false; } Log.d(TAG, "IP recover: mPastDhcpLease = " + mPastDhcpLease); long reCaculatedLeaseMillis = mPastDhcpLease.systemExpiredTime - SystemClock.elapsedRealtime(); Log.d(TAG, "IP recover: reCaculatedLeaseMillis = " + reCaculatedLeaseMillis); if (reCaculatedLeaseMillis < 0) { // configure infinite lease mDhcpLeaseExpiry = 0; Log.e(TAG, "IP recover: lease had been expired! configure to infinite lease"); } else { mDhcpLeaseExpiry = SystemClock.elapsedRealtime() + reCaculatedLeaseMillis; Log.d(TAG, "IP recover: mDhcpLeaseExpiry = " + mDhcpLeaseExpiry); } byte arpResult[] = null; ArpPeer ap = null; boolean retVal = false; try { InetAddress ipAddress = mPastDhcpLease.ipAddress.getAddress(); Log.d(TAG, "IP recover: arp address = " + "#$%K" + logDumpIpv4(3, ipAddress.getHostAddress())); ap = new ArpPeer(mIfaceName, Inet4Address.ANY, ipAddress); // doArp will blocking several seconds, to create thread if needed arpResult = ap.doArp(5000); if (arpResult == null) { int leaseDuration = (int)reCaculatedLeaseMillis/1000; mPastDhcpLease.setLeaseDuration(leaseDuration); acceptDhcpResults(mPastDhcpLease, "Confirmed"); Log.d(TAG, "doIpRecover no arp response, IP can be reused"); retVal = true; } else { Log.d(TAG, "doIpRecover DAD detected!!"); } } catch (ErrnoException ee) { Log.d(TAG, "err :" + ee); } catch (IllegalArgumentException ie) { Log.d(TAG, "err :" + ie); } catch (SocketException se) { Log.d(TAG, "err :" + se); } finally { if (ap != null) ap.close(); } return retVal; } /// @}