Offset 2, 46 lines modifiedOffset 2, 43 lines modified
2 package·com.android.networkstack.tethering;2 package·com.android.networkstack.tethering;
  
3 import·java.io.PrintWriter;3 import·java.io.PrintWriter;
4 import·com.android.networkstack.tethering.util.StateMachine;4 import·com.android.networkstack.tethering.util.StateMachine;
5 import·android.net.LinkProperties;5 import·android.net.LinkProperties;
6 import·java.net.UnknownHostException;6 import·java.net.UnknownHostException;
7 import·java.net.InetAddress;7 import·java.net.InetAddress;
8 import·android.net.Network; 
9 import·java.util.Arrays; 
10 import·java.util.Collection; 
11 import·java.util.HashSet; 
12 import·java.util.Random;8 import·java.util.Random;
13 import·com.android.networkstack.tethering.util.IndentingPrintWriter;9 import·com.android.networkstack.tethering.util.IndentingPrintWriter;
 10 import·java.util.Collection;
 11 import·java.util.Arrays;
 12 import·android.net.Network;
14 import·java.util.Iterator;13 import·java.util.Iterator;
15 import·java.util.ArrayList;14 import·java.util.ArrayList;
16 import·java.util.List;15 import·java.util.List;
17 import·android.net.LinkAddress;16 import·android.net.LinkAddress;
18 import·android.net.util.PrefixUtils;17 import·android.net.util.PrefixUtils;
19 import·android.net.ip.IpServer;18 import·android.net.ip.IpServer;
20 import·android.content.Context;19 import·android.content.Context;
21 import·android.util.ArrayMap;20 import·android.util.ArrayMap;
22 import·android.net.IpPrefix;21 import·android.net.IpPrefix;
23 import·android.util.ArraySet;22 import·android.util.ArraySet;
24 import·android.net.ConnectivityManager;23 import·android.net.ConnectivityManager;
  
25 public·class·PrivateAddressCoordinator24 public·class·PrivateAddressCoordinator
26 {25 {
27 ····private·final·TetheringConfiguration·mConfig; 
28 ····private·final·ConnectivityManager·mConnectivityMgr;26 ····private·final·ConnectivityManager·mConnectivityMgr;
29 ····private·final·ArraySet·mDownstreams;27 ····private·final·ArraySet·mDownstreams;
30 ····private·final·IpPrefix·mTetheringPrefix;28 ····private·final·IpPrefix·mTetheringPrefix;
31 ····private·final·ArrayMap·mUpstreamPrefixMap;29 ····private·final·ArrayMap·mUpstreamPrefixMap;
32 ····30 ····
33 ····public·PrivateAddressCoordinator(final·Context·context,·final·TetheringConfiguration·mConfig)·{31 ····public·PrivateAddressCoordinator(final·Context·context)·{
34 ········this.mDownstreams·=·new·ArraySet();32 ········this.mDownstreams·=·new·ArraySet();
35 ········this.mUpstreamPrefixMap·=·new·ArrayMap();33 ········this.mUpstreamPrefixMap·=·new·ArrayMap();
36 ········this.mTetheringPrefix·=·new·IpPrefix("192.168.0.0/16");34 ········this.mTetheringPrefix·=·new·IpPrefix("192.168.0.0/16");
37 ········this.mConnectivityMgr·=·(ConnectivityManager)context.getSystemService("connectivity");35 ········this.mConnectivityMgr·=·(ConnectivityManager)context.getSystemService("connectivity");
38 ········this.mConfig·=·mConfig; 
39 ····}36 ····}
40 ····37 ····
41 ····private·IpPrefix·getDownstreamPrefix(final·IpServer·ipServer)·{38 ····private·IpPrefix·getDownstreamPrefix(final·IpServer·ipServer)·{
42 ········final·LinkAddress·address·=·ipServer.getAddress();39 ········final·LinkAddress·address·=·ipServer.getAddress();
43 ········if·(address·==·null)·{40 ········if·(address·==·null)·{
44 ············return·null;41 ············return·null;
45 ········}42 ········}
Offset 111, 19 lines modifiedOffset 108, 32 lines modified
111 ············if·(ipPrefix.equals((Object)this.getDownstreamPrefix(iterator.next())))·{108 ············if·(ipPrefix.equals((Object)this.getDownstreamPrefix(iterator.next())))·{
112 ················return·true;109 ················return·true;
113 ············}110 ············}
114 ········}111 ········}
115 ········return·false;112 ········return·false;
116 ····}113 ····}
117 ····114 ····
118 ····private·boolean·isReservedSubnet(final·int·n)·{115 ····private·void·maybeRemoveDeprectedUpstreams()·{
119 ········return·n·==·44·||·n·==·49;116 ········if·(this.mDownstreams.isEmpty())·{
 117 ············if·(!this.mUpstreamPrefixMap.isEmpty())·{
 118 ················final·ArrayList<Network>·list·=·new·ArrayList<Network>();
 119 ················final·List<Network>·list2·=·Arrays.asList(this.mConnectivityMgr.getAllNetworks());
 120 ················for·(int·i·=·0;·i·<·this.mUpstreamPrefixMap.size();·++i)·{
 121 ····················final·Network·network·=·(Network)this.mUpstreamPrefixMap.keyAt(i);
 122 ····················if·(!list2.contains(network))·{
 123 ························list.add(network);
 124 ····················}
 125 ················}
 126 ················this.mUpstreamPrefixMap.removeAll((Collection)list);
 127 ············}
 128 ········}
120 ····}129 ····}
121 ····130 ····
122 ····void·dump(final·IndentingPrintWriter·indentingPrintWriter)·{131 ····void·dump(final·IndentingPrintWriter·indentingPrintWriter)·{
 132 ········indentingPrintWriter.decreaseIndent();
123 ········((PrintWriter)indentingPrintWriter).println("mUpstreamPrefixMap:");133 ········((PrintWriter)indentingPrintWriter).println("mUpstreamPrefixMap:");
124 ········indentingPrintWriter.increaseIndent();134 ········indentingPrintWriter.increaseIndent();
125 ········int·n·=·0;135 ········int·n·=·0;
126 ········String·s;136 ········String·s;
127 ········while·(true)·{137 ········while·(true)·{
128 ············final·int·size·=·this.mUpstreamPrefixMap.size();138 ············final·int·size·=·this.mUpstreamPrefixMap.size();
129 ············s·=·"·-·";139 ············s·=·"·-·";
Offset 150, 52 lines modifiedOffset 160, 40 lines modified
150 ········indentingPrintWriter.decreaseIndent();160 ········indentingPrintWriter.decreaseIndent();
151 ····}161 ····}
152 ····162 ····
153 ····public·int·getRandomSubAddr()·{163 ····public·int·getRandomSubAddr()·{
154 ········return·new·Random().nextInt()·&·(char)(-1);164 ········return·new·Random().nextInt()·&·(char)(-1);
155 ····}165 ····}
156 ····166 ····
157 ····public·void·maybeRemoveDeprecatedUpstreams()·{ 
158 ········if·(this.mUpstreamPrefixMap.isEmpty())·{ 
159 ············return; 
160 ········} 
161 ········final·HashSet·set·=·new·HashSet(this.mUpstreamPrefixMap.keySet()); 
162 ········set.removeAll(Arrays.asList(this.mConnectivityMgr.getAllNetworks())); 
163 ········this.mUpstreamPrefixMap.removeAll((Collection)set); 
164 ····} 
165 ···· 
166 ····public·void·releaseDownstream(final·IpServer·ipServer)·{167 ····public·void·releaseDownstream(final·IpServer·ipServer)·{
167 ········this.mDownstreams.remove((Object)ipServer);168 ········this.mDownstreams.remove((Object)ipServer);
168 ····}169 ····}
169 ····170 ····
170 ····public·void·removeUpstreamPrefix(final·Network·network)·{171 ····public·void·removeUpstreamPrefix(final·Network·network)·{
171 ········this.mUpstreamPrefixMap.remove((Object)network);172 ········this.mUpstreamPrefixMap.remove((Object)network);
172 ····}173 ····}
173 ····174 ····
174 ····public·LinkAddress·requestDownstreamAddress(final·IpServer·ipServer)·{175 ····public·LinkAddress·requestDownstreamAddress(final·IpServer·ipServer)·{
175 ········final·boolean·shouldEnableWifiP2pDedicatedIp·=·this.mConfig.shouldEnableWifiP2pDedicatedIp();176 ········this.maybeRemoveDeprectedUpstreams();
176 ········final·int·n·=·3; 
177 ········if·(shouldEnableWifiP2pDedicatedIp·&&·ipServer.interfaceType()·==·n)·{ 
178 ············return·new·LinkAddress("192.168.49.1/24"); 
179 ········} 
180 ········final·byte[]·rawAddress·=·this.mTetheringPrefix.getRawAddress();177 ········final·byte[]·rawAddress·=·this.mTetheringPrefix.getRawAddress();
181 ········final·int·randomSubAddr·=·this.getRandomSubAddr();178 ········final·int·randomSubAddr·=·this.getRandomSubAddr();
182 ········final·int·n2·=·randomSubAddr·>>·8·&·0xFF;179 ········final·int·n·=·randomSubAddr·>>·8·&·0xFF;
 180 ········final·int·n2·=·3;
183 ········final·byte[]·array2;181 ········final·byte[]·array2;
184 ········final·byte[]·array·=·array2·=·new·byte[n];182 ········final·byte[]·array·=·array2·=·new·byte[n2];
185 ········array2[0]·=·0;183 ········array2[0]·=·0;
186 ········array2[1]·=·1;184 ········array2[1]·=·1;
187 ········array2[2]·=·-1;185 ········array2[2]·=·-1;
188 ········rawAddress[n]·=·this.getSanitizedAddressSuffix(randomSubAddr,·array);186 ········rawAddress[n2]·=·this.getSanitizedAddressSuffix(randomSubAddr,·array);
189 ········int·i·=·0;187 ········int·i·=·0;
190 ········while·(i·<·256)·{188 ········while·(i·<·256)·{
191 ············final·int·n3·=·n2·+·i·&·0xFF;189 ············final·int·n3·=·n·+·i·&·0xFF;
192 ············Label_0209:·{190 ············Label_0166:·{
193 ················if·(this.isReservedSubnet(n3))·{191 ················if·(n3·==·44)·{
194 ····················break·Label_0209;192 ····················break·Label_0166;
195 ················}193 ················}
196 ················rawAddress[2]·=·(byte)n3;194 ················rawAddress[2]·=·(byte)n3;
197 ················try·{195 ················try·{
198 ····················final·InetAddress·byAddress·=·InetAddress.getByAddress(rawAddress);196 ····················final·InetAddress·byAddress·=·InetAddress.getByAddress(rawAddress);
199 ····················final·int·n4·=·24;197 ····················final·int·n4·=·24;
200 ····················final·IpPrefix·ipPrefix·=·new·IpPrefix(byAddress,·n4);198 ····················final·IpPrefix·ipPrefix·=·new·IpPrefix(byAddress,·n4);
201 ····················if·(!this.isDownstreamPrefixInUse(ipPrefix))·{199 ····················if·(!this.isDownstreamPrefixInUse(ipPrefix))·{