diff options
author | Jeff Sharkey <jsharkey@android.com> | 2011-07-14 20:37:37 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2011-07-14 20:43:27 -0700 |
commit | 4e814c348ce205fcc1a273427f95ef1d100ed60c (patch) | |
tree | 6464b7f58b1177ce8a1ffb0d8f8e9298ca861e84 /services/java/com/android | |
parent | 4a8df318b06a85a90309149ebcbff3b25077de15 (diff) | |
download | frameworks_base-4e814c348ce205fcc1a273427f95ef1d100ed60c.zip frameworks_base-4e814c348ce205fcc1a273427f95ef1d100ed60c.tar.gz frameworks_base-4e814c348ce205fcc1a273427f95ef1d100ed60c.tar.bz2 |
Hide NetworkTemplate details, buffered stats I/O.
Move template matching to builder methods instead of exposing the
internal constants. Also rule to match Ethernet usage. Buffer
reading and writing of network stats, making operations 5x faster.
Change-Id: Iedb2d0ab3b26a976811c050f84a164e909eb74b6
Diffstat (limited to 'services/java/com/android')
-rw-r--r-- | services/java/com/android/server/net/NetworkPolicyManagerService.java | 6 | ||||
-rw-r--r-- | services/java/com/android/server/net/NetworkStatsService.java | 23 |
2 files changed, 15 insertions, 14 deletions
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java index d30b66b..0c78fe7 100644 --- a/services/java/com/android/server/net/NetworkPolicyManagerService.java +++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java @@ -24,8 +24,8 @@ import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY; import static android.Manifest.permission.READ_PHONE_STATE; import static android.content.Intent.ACTION_UID_REMOVED; import static android.content.Intent.EXTRA_UID; +import static android.net.ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; -import static android.net.ConnectivityManager.*; import static android.net.ConnectivityManager.TYPE_MOBILE; import static android.net.NetworkPolicy.LIMIT_DISABLED; import static android.net.NetworkPolicy.WARNING_DISABLED; @@ -42,7 +42,7 @@ import static android.net.NetworkPolicyManager.dumpRules; import static android.net.NetworkPolicyManager.isUidValidForPolicy; import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER; import static android.net.NetworkTemplate.MATCH_MOBILE_4G; -import static android.net.NetworkTemplate.MATCH_MOBILE_ALL; +import static android.net.NetworkTemplate.buildTemplateMobileAll; import static android.text.format.DateUtils.DAY_IN_MILLIS; import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_UPDATED; @@ -678,7 +678,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { time.setToNow(); final int cycleDay = time.monthDay; - final NetworkTemplate template = new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId); + final NetworkTemplate template = buildTemplateMobileAll(subscriberId); mNetworkPolicy.add( new NetworkPolicy(template, cycleDay, 4 * GB_IN_BYTES, LIMIT_DISABLED)); writePolicyLocked(); diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index 54e94db..7ec6b81 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -73,11 +73,12 @@ import com.android.internal.os.AtomicFile; import com.google.android.collect.Maps; import com.google.android.collect.Sets; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileDescriptor; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -719,10 +720,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // clear any existing stats and read from disk mNetworkStats.clear(); - FileInputStream fis = null; + DataInputStream in = null; try { - fis = mNetworkFile.openRead(); - final DataInputStream in = new DataInputStream(fis); + in = new DataInputStream(new BufferedInputStream(mNetworkFile.openRead())); // verify file magic header intact final int magic = in.readInt(); @@ -751,7 +751,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } catch (IOException e) { Slog.e(TAG, "problem reading network stats", e); } finally { - IoUtils.closeQuietly(fis); + IoUtils.closeQuietly(in); } } @@ -768,10 +768,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // clear any existing stats and read from disk mUidStats.clear(); - FileInputStream fis = null; + DataInputStream in = null; try { - fis = mUidFile.openRead(); - final DataInputStream in = new DataInputStream(fis); + in = new DataInputStream(new BufferedInputStream(mUidFile.openRead())); // verify file magic header intact final int magic = in.readInt(); @@ -826,7 +825,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } catch (IOException e) { Slog.e(TAG, "problem reading uid stats", e); } finally { - IoUtils.closeQuietly(fis); + IoUtils.closeQuietly(in); } } @@ -838,7 +837,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { FileOutputStream fos = null; try { fos = mNetworkFile.startWrite(); - final DataOutputStream out = new DataOutputStream(fos); + final DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fos)); out.writeInt(FILE_MAGIC); out.writeInt(VERSION_NETWORK_INIT); @@ -850,6 +849,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { history.writeToStream(out); } + out.flush(); mNetworkFile.finishWrite(fos); } catch (IOException e) { if (fos != null) { @@ -871,7 +871,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { FileOutputStream fos = null; try { fos = mUidFile.startWrite(); - final DataOutputStream out = new DataOutputStream(fos); + final DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fos)); out.writeInt(FILE_MAGIC); out.writeInt(VERSION_UID_WITH_TAG); @@ -895,6 +895,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } + out.flush(); mUidFile.finishWrite(fos); } catch (IOException e) { if (fos != null) { |