diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-09-11 20:16:59 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-11 20:16:59 +0000 |
commit | ceccceccffbd2668b98e21487f2323f80d2c7b98 (patch) | |
tree | aba1d4902c557287350a10325a7b334351f663c4 /services | |
parent | d292f790be5074998c1adc5feb4fea031d0d3d09 (diff) | |
parent | aca405cd592679af4a4b31b01dfed6fd59c4a168 (diff) | |
download | frameworks_base-ceccceccffbd2668b98e21487f2323f80d2c7b98.zip frameworks_base-ceccceccffbd2668b98e21487f2323f80d2c7b98.tar.gz frameworks_base-ceccceccffbd2668b98e21487f2323f80d2c7b98.tar.bz2 |
Merge changes Ib1274847,I2eb2a1bf into klp-dev
* changes:
Fix SDK build.
Request all tethering interfaces, fix corruption.
Diffstat (limited to 'services')
6 files changed, 50 insertions, 74 deletions
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 1af7cc8..3f8d7eb 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -58,8 +58,8 @@ import android.net.INetworkPolicyManager; import android.net.INetworkStatsService; import android.net.LinkAddress; import android.net.LinkProperties; -import android.net.LinkQualityInfo; import android.net.LinkProperties.CompareResult; +import android.net.LinkQualityInfo; import android.net.MobileDataStateTracker; import android.net.NetworkConfig; import android.net.NetworkInfo; @@ -89,7 +89,6 @@ import android.os.ParcelFileDescriptor; import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; -import android.os.ResultReceiver; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; @@ -114,7 +113,6 @@ import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.XmlUtils; -import com.android.net.IProxyService; import com.android.server.am.BatteryStatsService; import com.android.server.connectivity.DataConnectionStats; import com.android.server.connectivity.Nat464Xlat; @@ -3209,12 +3207,6 @@ public class ConnectivityService extends IConnectivityManager.Stub { return mTethering.getTetheredIfaces(); } - @Override - public String[] getTetheredIfacePairs() { - enforceTetherAccessPermission(); - return mTethering.getTetheredIfacePairs(); - } - public String[] getTetheringErroredIfaces() { enforceTetherAccessPermission(); return mTethering.getErroredIfaces(); diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index 82cc540..92f99c2 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -24,15 +24,15 @@ import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.UID_ALL; import static android.net.TrafficStats.UID_TETHERING; import static com.android.server.NetworkManagementService.NetdResponseCode.ClatdStatusResult; +import static com.android.server.NetworkManagementService.NetdResponseCode.GetMarkResult; import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceGetCfgResult; import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceListResult; import static com.android.server.NetworkManagementService.NetdResponseCode.IpFwdStatusResult; import static com.android.server.NetworkManagementService.NetdResponseCode.TetherDnsFwdTgtListResult; import static com.android.server.NetworkManagementService.NetdResponseCode.TetherInterfaceListResult; import static com.android.server.NetworkManagementService.NetdResponseCode.TetherStatusResult; -import static com.android.server.NetworkManagementService.NetdResponseCode.TetheringStatsResult; +import static com.android.server.NetworkManagementService.NetdResponseCode.TetheringStatsListResult; import static com.android.server.NetworkManagementService.NetdResponseCode.TtyListResult; -import static com.android.server.NetworkManagementService.NetdResponseCode.GetMarkResult; import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED; import android.content.Context; @@ -118,6 +118,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub public static final int TetherInterfaceListResult = 111; public static final int TetherDnsFwdTgtListResult = 112; public static final int TtyListResult = 113; + public static final int TetheringStatsListResult = 114; public static final int TetherStatusResult = 210; public static final int IpFwdStatusResult = 211; @@ -523,7 +524,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub throw new IllegalStateException(msg); } - int flags, scope; + int flags; + int scope; try { flags = Integer.parseInt(cooked[5]); scope = Integer.parseInt(cooked[6]); @@ -1373,55 +1375,42 @@ public class NetworkManagementService extends INetworkManagementService.Stub } @Override - public NetworkStats getNetworkStatsTethering(String[] ifacePairs) { + public NetworkStats getNetworkStatsTethering() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); - if (ifacePairs.length % 2 != 0) { - throw new IllegalArgumentException( - "unexpected ifacePairs; length=" + ifacePairs.length); - } - final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1); - for (int i = 0; i < ifacePairs.length; i += 2) { - final String ifaceIn = ifacePairs[i]; - final String ifaceOut = ifacePairs[i + 1]; - if (ifaceIn != null && ifaceOut != null) { - stats.combineValues(getNetworkStatsTethering(ifaceIn, ifaceOut)); - } - } - return stats; - } - - private NetworkStats.Entry getNetworkStatsTethering(String ifaceIn, String ifaceOut) { - final NativeDaemonEvent event; try { - event = mConnector.execute("bandwidth", "gettetherstats", ifaceIn, ifaceOut); + final NativeDaemonEvent[] events = mConnector.executeForList( + "bandwidth", "gettetherstats"); + for (NativeDaemonEvent event : events) { + if (event.getCode() != TetheringStatsListResult) continue; + + // 114 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets + final StringTokenizer tok = new StringTokenizer(event.getMessage()); + try { + final String ifaceIn = tok.nextToken(); + final String ifaceOut = tok.nextToken(); + + final NetworkStats.Entry entry = new NetworkStats.Entry(); + entry.iface = ifaceOut; + entry.uid = UID_TETHERING; + entry.set = SET_DEFAULT; + entry.tag = TAG_NONE; + entry.rxBytes = Long.parseLong(tok.nextToken()); + entry.rxPackets = Long.parseLong(tok.nextToken()); + entry.txBytes = Long.parseLong(tok.nextToken()); + entry.txPackets = Long.parseLong(tok.nextToken()); + stats.combineValues(entry); + } catch (NoSuchElementException e) { + throw new IllegalStateException("problem parsing tethering stats: " + event); + } catch (NumberFormatException e) { + throw new IllegalStateException("problem parsing tethering stats: " + event); + } + } } catch (NativeDaemonConnectorException e) { throw e.rethrowAsParcelableException(); } - - event.checkCode(TetheringStatsResult); - - // 221 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets - final StringTokenizer tok = new StringTokenizer(event.getMessage()); - tok.nextToken(); - tok.nextToken(); - - try { - final NetworkStats.Entry entry = new NetworkStats.Entry(); - entry.iface = ifaceIn; - entry.uid = UID_TETHERING; - entry.set = SET_DEFAULT; - entry.tag = TAG_NONE; - entry.rxBytes = Long.parseLong(tok.nextToken()); - entry.rxPackets = Long.parseLong(tok.nextToken()); - entry.txBytes = Long.parseLong(tok.nextToken()); - entry.txPackets = Long.parseLong(tok.nextToken()); - return entry; - } catch (NumberFormatException e) { - throw new IllegalStateException( - "problem parsing tethering stats for " + ifaceIn + " " + ifaceOut + ": " + e); - } + return stats; } @Override diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java index fb4c1cf..231a40a 100644 --- a/services/java/com/android/server/connectivity/Tethering.java +++ b/services/java/com/android/server/connectivity/Tethering.java @@ -688,19 +688,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub { return retVal; } - public String[] getTetheredIfacePairs() { - final ArrayList<String> list = Lists.newArrayList(); - synchronized (mPublicSync) { - for (TetherInterfaceSM sm : mIfaces.values()) { - if (sm.isTethered()) { - list.add(sm.mMyUpstreamIfaceName); - list.add(sm.mIfaceName); - } - } - } - return list.toArray(new String[list.size()]); - } - public String[] getTetherableIfaces() { ArrayList<String> list = new ArrayList<String>(); synchronized (mPublicSync) { diff --git a/services/java/com/android/server/net/NetworkStatsRecorder.java b/services/java/com/android/server/net/NetworkStatsRecorder.java index 2b32b41..cea084b 100644 --- a/services/java/com/android/server/net/NetworkStatsRecorder.java +++ b/services/java/com/android/server/net/NetworkStatsRecorder.java @@ -135,6 +135,9 @@ public class NetworkStatsRecorder { } catch (IOException e) { Log.wtf(TAG, "problem completely reading network stats", e); recoverFromWtf(); + } catch (OutOfMemoryError e) { + Log.wtf(TAG, "problem completely reading network stats", e); + recoverFromWtf(); } } return complete; @@ -226,6 +229,9 @@ public class NetworkStatsRecorder { } catch (IOException e) { Log.wtf(TAG, "problem persisting pending stats", e); recoverFromWtf(); + } catch (OutOfMemoryError e) { + Log.wtf(TAG, "problem persisting pending stats", e); + recoverFromWtf(); } } } @@ -241,6 +247,9 @@ public class NetworkStatsRecorder { } catch (IOException e) { Log.wtf(TAG, "problem removing UIDs " + Arrays.toString(uids), e); recoverFromWtf(); + } catch (OutOfMemoryError e) { + Log.wtf(TAG, "problem removing UIDs " + Arrays.toString(uids), e); + recoverFromWtf(); } // Remove any pending stats diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index 05eeb36..1e8a7b0 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -412,6 +412,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } catch (IOException e) { Log.wtf(TAG, "problem during legacy upgrade", e); + } catch (OutOfMemoryError e) { + Log.wtf(TAG, "problem during legacy upgrade", e); } } @@ -1186,8 +1188,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { */ private NetworkStats getNetworkStatsTethering() throws RemoteException { try { - final String[] tetheredIfacePairs = mConnManager.getTetheredIfacePairs(); - return mNetworkManager.getNetworkStatsTethering(tetheredIfacePairs); + return mNetworkManager.getNetworkStatsTethering(); } catch (IllegalStateException e) { Log.wtf(TAG, "problem reading network stats", e); return new NetworkStats(0L, 10); diff --git a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java index a9909b2..a1af8cb 100644 --- a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java @@ -40,7 +40,6 @@ import static android.text.format.DateUtils.MINUTE_IN_MILLIS; import static android.text.format.DateUtils.WEEK_IN_MILLIS; import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL; import static org.easymock.EasyMock.anyLong; -import static org.easymock.EasyMock.aryEq; import static org.easymock.EasyMock.capture; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.eq; @@ -74,13 +73,13 @@ import com.android.server.net.NetworkStatsService; import com.android.server.net.NetworkStatsService.NetworkStatsSettings; import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config; +import libcore.io.IoUtils; + import org.easymock.Capture; import org.easymock.EasyMock; import java.io.File; -import libcore.io.IoUtils; - /** * Tests for {@link NetworkStatsService}. */ @@ -919,8 +918,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase { expect(mNetManager.getNetworkStatsUidDetail(eq(UID_ALL))).andReturn(detail).atLeastOnce(); // also include tethering details, since they are folded into UID - expect(mConnManager.getTetheredIfacePairs()).andReturn(tetherIfacePairs).atLeastOnce(); - expect(mNetManager.getNetworkStatsTethering(aryEq(tetherIfacePairs))) + expect(mNetManager.getNetworkStatsTethering()) .andReturn(tetherStats).atLeastOnce(); } |