diff options
Diffstat (limited to 'services/java')
5 files changed, 47 insertions, 69 deletions
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 02a78de..eca7af7 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); |