Merge "Show data restricted apps, unify strings."

This commit is contained in:
Jeff Sharkey
2012-04-13 20:16:00 -07:00
committed by Android (Google) Code Review
4 changed files with 55 additions and 40 deletions

View File

@@ -45,17 +45,6 @@
android:paddingRight="@*android:dimen/preference_item_padding_side" android:paddingRight="@*android:dimen/preference_item_padding_side"
android:paddingTop="8dip" android:paddingTop="8dip"
android:paddingBottom="8dip" android:paddingBottom="8dip"
android:singleLine="true"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@*android:dimen/preference_item_padding_side"
android:paddingRight="@*android:dimen/preference_item_padding_side"
android:paddingBottom="8dip"
android:text="@string/data_usage_disclaimer"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView

View File

@@ -3626,10 +3626,8 @@
<!-- Label for data usage occuring while application in background. [CHAR LIMIT=48] --> <!-- Label for data usage occuring while application in background. [CHAR LIMIT=48] -->
<string name="data_usage_label_background">Background</string> <string name="data_usage_label_background">Background</string>
<!-- Disclaimer that contrasts device versus carrier reporting. [CHAR LIMIT=80] --> <!-- Label for application which has its data usage restricted. [CHAR LIMIT=16] -->
<string name="data_usage_disclaimer" product="tablet">Measured by your tablet. Your carrier\'s data usage accounting may differ.</string> <string name="data_usage_app_restricted">restricted</string>
<!-- Disclaimer that contrasts device versus carrier reporting. [CHAR LIMIT=80] -->
<string name="data_usage_disclaimer" product="default">Measured by your phone. Your carrier\'s data usage accounting may differ.</string>
<!-- Body of dialog shown to request confirmation that mobile data will be disabled. [CHAR LIMIT=NONE] --> <!-- Body of dialog shown to request confirmation that mobile data will be disabled. [CHAR LIMIT=NONE] -->
<string name="data_usage_disable_mobile">Disable mobile data?</string> <string name="data_usage_disable_mobile">Disable mobile data?</string>
@@ -3695,9 +3693,9 @@
<!-- Title of dialog shown before user limits data usage. [CHAR LIMIT=48] --> <!-- Title of dialog shown before user limits data usage. [CHAR LIMIT=48] -->
<string name="data_usage_limit_dialog_title">Limiting data usage</string> <string name="data_usage_limit_dialog_title">Limiting data usage</string>
<!-- Body of dialog shown before user limits mobile data usage. [CHAR LIMIT=NONE] --> <!-- Body of dialog shown before user limits mobile data usage. [CHAR LIMIT=NONE] -->
<string name="data_usage_limit_dialog" product="tablet">Your <xliff:g id="networks" example="mobile">%1$s</xliff:g> data connection will be disabled when the specified limit is reached.\n\nSince data usage is measured by your tablet, and your carrier may account for usage differently, consider using a conservative limit.</string> <string name="data_usage_limit_dialog_mobile" product="tablet">Your mobile data connection will be disabled when the specified limit is reached.\n\nSince data usage is measured by your tablet, and your carrier may account for usage differently, consider using a conservative limit.</string>
<!-- Body of dialog shown before user limits mobile data usage. [CHAR LIMIT=NONE] --> <!-- Body of dialog shown before user limits mobile data usage. [CHAR LIMIT=NONE] -->
<string name="data_usage_limit_dialog" product="default">Your <xliff:g id="networks" example="mobile">%1$s</xliff:g> data connection will be disabled when the specified limit is reached.\n\nSince data usage is measured by your phone, and your carrier may account for usage differently, consider using a conservative limit.</string> <string name="data_usage_limit_dialog_mobile" product="default">Your mobile data connection will be disabled when the specified limit is reached.\n\nSince data usage is measured by your phone, and your carrier may account for usage differently, consider using a conservative limit.</string>
<!-- Title of dialog shown before user restricts background data usage. [CHAR LIMIT=48] --> <!-- Title of dialog shown before user restricts background data usage. [CHAR LIMIT=48] -->
<string name="data_usage_restrict_background_title">Restrict background data?</string> <string name="data_usage_restrict_background_title">Restrict background data?</string>
@@ -3714,7 +3712,12 @@
<!-- Combination of total network bytes sent and received by an application. [CHAR LIMIT=NONE] --> <!-- Combination of total network bytes sent and received by an application. [CHAR LIMIT=NONE] -->
<string name="data_usage_received_sent"><xliff:g id="received" example="128KB">%1$s</xliff:g> received, <xliff:g id="sent" example="1.3GB">%2$s</xliff:g> sent</string> <string name="data_usage_received_sent"><xliff:g id="received" example="128KB">%1$s</xliff:g> received, <xliff:g id="sent" example="1.3GB">%2$s</xliff:g> sent</string>
<!-- Label displaying total network data transferred during a specific time period. [CHAR LIMIT=64] --> <!-- Label displaying total network data transferred during a specific time period. [CHAR LIMIT=64] -->
<string name="data_usage_total_during_range"><xliff:g id="range" example="Jul 1 - Jul 31">%2$s</xliff:g>: about <xliff:g id="total" example="128KB">%1$s</xliff:g> used</string> <string name="data_usage_total_during_range"><xliff:g id="range" example="Jul 1 - Jul 31">%2$s</xliff:g>: about <xliff:g id="total" example="128KB">%1$s</xliff:g> used.</string>
<!-- Label displaying total network data transferred during a specific time period, including a disclaimer that contrasts device versus carrier reporting. [CHAR LIMIT=80] -->
<string name="data_usage_total_during_range_mobile" product="tablet"><xliff:g id="range" example="Jul 1 - Jul 31">%2$s</xliff:g>: about <xliff:g id="total" example="128KB">%1$s</xliff:g> used, as measured by your tablet. Your carrier\'s data usage accounting may differ.</string>
<!-- Label displaying total network data transferred during a specific time period, including a disclaimer that contrasts device versus carrier reporting. [CHAR LIMIT=80] -->
<string name="data_usage_total_during_range_mobile" product="default"><xliff:g id="range" example="Jul 1 - Jul 31">%2$s</xliff:g>: about <xliff:g id="total" example="128KB">%1$s</xliff:g> used, as measured by your phone. Your carrier\'s data usage accounting may differ.</string>
<!-- Dialog title for selecting paid networks. [CHAR LIMIT=25] --> <!-- Dialog title for selecting paid networks. [CHAR LIMIT=25] -->
<string name="data_usage_metered_title">Expensive networks</string> <string name="data_usage_metered_title">Expensive networks</string>

View File

@@ -1147,8 +1147,15 @@ public class DataUsageSummary extends Fragment {
final String totalPhrase = Formatter.formatFileSize(context, totalBytes); final String totalPhrase = Formatter.formatFileSize(context, totalBytes);
final String rangePhrase = formatDateRange(context, start, end); final String rangePhrase = formatDateRange(context, start, end);
mUsageSummary.setText( final int summaryRes;
getString(R.string.data_usage_total_during_range, totalPhrase, rangePhrase)); if (TAB_MOBILE.equals(mCurrentTab) || TAB_3G.equals(mCurrentApp)
|| TAB_4G.equals(mCurrentApp)) {
summaryRes = R.string.data_usage_total_during_range_mobile;
} else {
summaryRes = R.string.data_usage_total_during_range;
}
mUsageSummary.setText(getString(summaryRes, totalPhrase, rangePhrase));
} }
private final LoaderCallbacks<ChartData> mChartDataCallbacks = new LoaderCallbacks< private final LoaderCallbacks<ChartData> mChartDataCallbacks = new LoaderCallbacks<
@@ -1191,13 +1198,15 @@ public class DataUsageSummary extends Fragment {
@Override @Override
public void onLoadFinished(Loader<NetworkStats> loader, NetworkStats data) { public void onLoadFinished(Loader<NetworkStats> loader, NetworkStats data) {
mAdapter.bindStats(data); final int[] restrictedAppIds = mPolicyManager.getAppsWithPolicy(
POLICY_REJECT_METERED_BACKGROUND);
mAdapter.bindStats(data, restrictedAppIds);
updateEmptyVisible(); updateEmptyVisible();
} }
@Override @Override
public void onLoaderReset(Loader<NetworkStats> loader) { public void onLoaderReset(Loader<NetworkStats> loader) {
mAdapter.bindStats(null); mAdapter.bindStats(null, new int[0]);
updateEmptyVisible(); updateEmptyVisible();
} }
@@ -1374,6 +1383,7 @@ public class DataUsageSummary extends Fragment {
public static class AppItem implements Comparable<AppItem>, Parcelable { public static class AppItem implements Comparable<AppItem>, Parcelable {
public final int appId; public final int appId;
public boolean restricted;
public SparseBooleanArray uids = new SparseBooleanArray(); public SparseBooleanArray uids = new SparseBooleanArray();
public long total; public long total;
@@ -1439,7 +1449,7 @@ public class DataUsageSummary extends Fragment {
/** /**
* Bind the given {@link NetworkStats}, or {@code null} to clear list. * Bind the given {@link NetworkStats}, or {@code null} to clear list.
*/ */
public void bindStats(NetworkStats stats) { public void bindStats(NetworkStats stats, int[] restrictedAppIds) {
mItems.clear(); mItems.clear();
final AppItem systemItem = new AppItem(android.os.Process.SYSTEM_UID); final AppItem systemItem = new AppItem(android.os.Process.SYSTEM_UID);
@@ -1468,6 +1478,16 @@ public class DataUsageSummary extends Fragment {
} }
} }
for (int appId : restrictedAppIds) {
AppItem item = knownUids.get(appId);
if (item == null) {
item = new AppItem(appId);
item.total = -1;
mItems.add(item);
}
item.restricted = true;
}
if (systemItem.total > 0) { if (systemItem.total > 0) {
mItems.add(systemItem); mItems.add(systemItem);
} }
@@ -1513,7 +1533,13 @@ public class DataUsageSummary extends Fragment {
final AppItem item = mItems.get(position); final AppItem item = mItems.get(position);
UidDetailTask.bindView(mProvider, item, convertView); UidDetailTask.bindView(mProvider, item, convertView);
text1.setText(Formatter.formatFileSize(context, item.total)); if (item.restricted && item.total <= 0) {
text1.setText(R.string.data_usage_app_restricted);
progress.setVisibility(View.GONE);
} else {
text1.setText(Formatter.formatFileSize(context, item.total));
progress.setVisibility(View.VISIBLE);
}
final int percentTotal = mLargest != 0 ? (int) (item.total * 100 / mLargest) : 0; final int percentTotal = mLargest != 0 ? (int) (item.total * 100 / mLargest) : 0;
progress.setProgress(percentTotal); progress.setProgress(percentTotal);
@@ -1580,16 +1606,13 @@ public class DataUsageSummary extends Fragment {
// TODO: customize default limits based on network template // TODO: customize default limits based on network template
final String currentTab = parent.mCurrentTab; final String currentTab = parent.mCurrentTab;
if (TAB_3G.equals(currentTab)) { if (TAB_3G.equals(currentTab)) {
message = buildDialogMessage(res, R.string.data_usage_tab_3g); message = res.getString(R.string.data_usage_limit_dialog_mobile);
limitBytes = 5 * GB_IN_BYTES; limitBytes = 5 * GB_IN_BYTES;
} else if (TAB_4G.equals(currentTab)) { } else if (TAB_4G.equals(currentTab)) {
message = buildDialogMessage(res, R.string.data_usage_tab_4g); message = res.getString(R.string.data_usage_limit_dialog_mobile);
limitBytes = 5 * GB_IN_BYTES; limitBytes = 5 * GB_IN_BYTES;
} else if (TAB_MOBILE.equals(currentTab)) { } else if (TAB_MOBILE.equals(currentTab)) {
message = buildDialogMessage(res, R.string.data_usage_list_mobile); message = res.getString(R.string.data_usage_limit_dialog_mobile);
limitBytes = 5 * GB_IN_BYTES;
} else if (TAB_WIFI.equals(currentTab)) {
message = buildDialogMessage(res, R.string.data_usage_tab_wifi);
limitBytes = 5 * GB_IN_BYTES; limitBytes = 5 * GB_IN_BYTES;
} else { } else {
throw new IllegalArgumentException("unknown current tab: " + currentTab); throw new IllegalArgumentException("unknown current tab: " + currentTab);
@@ -1605,10 +1628,6 @@ public class DataUsageSummary extends Fragment {
dialog.show(parent.getFragmentManager(), TAG_CONFIRM_LIMIT); dialog.show(parent.getFragmentManager(), TAG_CONFIRM_LIMIT);
} }
private static CharSequence buildDialogMessage(Resources res, int networkResId) {
return res.getString(R.string.data_usage_limit_dialog, res.getString(networkResId));
}
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity(); final Context context = getActivity();

View File

@@ -21,6 +21,7 @@ import static android.net.NetworkStats.SET_FOREGROUND;
import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStatsHistory.FIELD_RX_BYTES; import static android.net.NetworkStatsHistory.FIELD_RX_BYTES;
import static android.net.NetworkStatsHistory.FIELD_TX_BYTES; import static android.net.NetworkStatsHistory.FIELD_TX_BYTES;
import static android.text.format.DateUtils.HOUR_IN_MILLIS;
import android.content.AsyncTaskLoader; import android.content.AsyncTaskLoader;
import android.content.Context; import android.content.Context;
@@ -88,9 +89,6 @@ public class ChartDataLoader extends AsyncTaskLoader<ChartData> {
data.network = mSession.getHistoryForNetwork(template, fields); data.network = mSession.getHistoryForNetwork(template, fields);
if (app != null) { if (app != null) {
data.detailDefault = null;
data.detailForeground = null;
// load stats for current uid and template // load stats for current uid and template
final int size = app.uids.size(); final int size = app.uids.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
@@ -101,9 +99,15 @@ public class ChartDataLoader extends AsyncTaskLoader<ChartData> {
template, uid, SET_FOREGROUND, data.detailForeground); template, uid, SET_FOREGROUND, data.detailForeground);
} }
data.detail = new NetworkStatsHistory(data.detailForeground.getBucketDuration()); if (size > 0) {
data.detail.recordEntireHistory(data.detailDefault); data.detail = new NetworkStatsHistory(data.detailForeground.getBucketDuration());
data.detail.recordEntireHistory(data.detailForeground); data.detail.recordEntireHistory(data.detailDefault);
data.detail.recordEntireHistory(data.detailForeground);
} else {
data.detailDefault = new NetworkStatsHistory(HOUR_IN_MILLIS);
data.detailForeground = new NetworkStatsHistory(HOUR_IN_MILLIS);
data.detail = new NetworkStatsHistory(HOUR_IN_MILLIS);
}
} }
return data; return data;