Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb1d6804 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Reinforce limited networks in data usage UI."

parents 2f61676f 30dde0f5
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -3466,6 +3466,11 @@ found in the list of installed applications.</string>
    <!-- Tab title for showing 2G and 3G data usage. [CHAR LIMIT=10] -->
    <string name="data_usage_tab_3g">2G-3G</string>

    <!-- Title shown when current operation applies to mobile networks. [CHAR LIMIT=10] -->
    <string name="data_usage_list_mobile">mobile</string>
    <!-- Title shown when current operation applies to no networks. [CHAR LIMIT=10] -->
    <string name="data_usage_list_none">none</string>

    <!-- Toggle switch title for enabling all mobile data network connections. [CHAR LIMIT=32] -->
    <string name="data_usage_enable_mobile">Mobile data</string>
    <!-- Toggle switch title for enabling 2G and 3G data network connections. [CHAR LIMIT=32] -->
@@ -3478,9 +3483,9 @@ found in the list of installed applications.</string>
    <!-- Checkbox label that restricts background data usage of a specific application. [CHAR LIMIT=32] -->
    <string name="data_usage_app_restrict_background">Restrict background data usage</string>
    <!-- Summary message for checkbox that restricts background data usage of a specific application. [CHAR LIMIT=64] -->
    <string name="data_usage_app_restrict_background_summary">Only allow application background data when using an unlimited network</string>
    <string name="data_usage_app_restrict_background_summary">Disable background data on networks that you\'ve chosen to limit (<xliff:g id="networks" example="Mobile, Wi-Fi">%1$s</xliff:g>).</string>
    <!-- Title of dialog shown when user restricts background data usage of a specific application. [CHAR LIMIT=48] -->
    <string name="data_usage_app_restrict_dialog_title">Restricting background data</string>
    <string name="data_usage_app_restrict_dialog_title">Restrict background data?</string>
    <!-- Body of dialog shown when user restricts background data usage of a specific application. [CHAR LIMIT=NONE] -->
    <string name="data_usage_app_restrict_dialog">This feature may negatively impact applications which depend on background data usage.\n\nMore appropriate data usage controls may be found within this application\'s settings.</string>

@@ -3501,9 +3506,9 @@ found in the list of installed applications.</string>
    <string name="data_usage_limit_dialog_4g">Your 4G data connection will be disabled when the specified limit is reached.\n\nTo avoid overage charges, consider using a reduced limit, as device and carrier accounting methods may vary.</string>

    <!-- Title of dialog shown before user restricts background data usage. [CHAR LIMIT=48] -->
    <string name="data_usage_restrict_background_title">Restricting background data</string>
    <string name="data_usage_restrict_background_title">Restrict background data?</string>
    <!-- Body of dialog shown before user restricts background data usage. [CHAR LIMIT=NONE] -->
    <string name="data_usage_restrict_background">This feature will disable auto-sync and may negatively impact applications which depend on background data usage.</string>
    <string name="data_usage_restrict_background">If you restrict background data, some apps and services won\'t work on networks that you\'ve chosen to limit.\n\nCurrently limited networks: <xliff:g id="networks" example="Mobile, Wi-Fi">%1$s</xliff:g></string>

    <!-- Label displaying current network data usage warning threshold. [CHAR LIMIT=18] -->
    <string name="data_usage_sweep_warning"><font size="21"><xliff:g id="number" example="128">^1</xliff:g></font> <font size="9"><xliff:g id="unit" example="KB">^2</xliff:g></font>\n<font size="12">warning</font></string>
+48 −10
Original line number Diff line number Diff line
@@ -322,9 +322,6 @@ public class DataUsageSummary extends Fragment {
            mAppRestrict = new CheckBox(inflater.getContext());
            mAppRestrict.setClickable(false);
            mAppRestrictView = inflatePreference(inflater, mAppSwitches, mAppRestrict);
            setPreferenceTitle(mAppRestrictView, R.string.data_usage_app_restrict_background);
            setPreferenceSummary(
                    mAppRestrictView, R.string.data_usage_app_restrict_background_summary);
            mAppRestrictView.setOnClickListener(mAppRestrictListener);
            mAppSwitches.addView(mAppRestrictView);
        }
@@ -731,6 +728,11 @@ public class DataUsageSummary extends Fragment {

        if (NetworkPolicyManager.isUidValidForPolicy(context, mUid) && !getRestrictBackground()
                && isBandwidthControlEnabled()) {
            setPreferenceTitle(mAppRestrictView, R.string.data_usage_app_restrict_background);
            setPreferenceSummary(mAppRestrictView,
                    getString(R.string.data_usage_app_restrict_background_summary,
                            buildLimitedNetworksList()));

            mAppRestrictView.setVisibility(View.VISIBLE);
            mAppRestrict.setChecked(getAppRestrictBackground());

@@ -1470,8 +1472,6 @@ public class DataUsageSummary extends Fragment {
     */
    public static class ConfirmDataRoamingFragment extends DialogFragment {
        public static void show(DataUsageSummary parent) {
            final Bundle args = new Bundle();

            final ConfirmDataRoamingFragment dialog = new ConfirmDataRoamingFragment();
            dialog.setTargetFragment(parent, 0);
            dialog.show(parent.getFragmentManager(), TAG_CONFIRM_ROAMING);
@@ -1505,8 +1505,6 @@ public class DataUsageSummary extends Fragment {
     */
    public static class ConfirmRestrictFragment extends DialogFragment {
        public static void show(DataUsageSummary parent) {
            final Bundle args = new Bundle();

            final ConfirmRestrictFragment dialog = new ConfirmRestrictFragment();
            dialog.setTargetFragment(parent, 0);
            dialog.show(parent.getFragmentManager(), TAG_CONFIRM_RESTRICT);
@@ -1518,7 +1516,13 @@ public class DataUsageSummary extends Fragment {

            final AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle(R.string.data_usage_restrict_background_title);
            builder.setMessage(R.string.data_usage_restrict_background);

            final DataUsageSummary target = (DataUsageSummary) getTargetFragment();
            if (target != null) {
                final CharSequence limitedNetworks = target.buildLimitedNetworksList();
                builder.setMessage(
                        getString(R.string.data_usage_restrict_background, limitedNetworks));
            }

            builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
@@ -1731,6 +1735,40 @@ public class DataUsageSummary extends Fragment {
        return view;
    }

    /**
     * Build string describing currently limited networks, which defines when
     * background data is restricted.
     */
    private CharSequence buildLimitedNetworksList() {
        final Context context = getActivity();
        final String subscriberId = getActiveSubscriberId(context);

        // build combined list of all limited networks
        final ArrayList<CharSequence> limited = Lists.newArrayList();
        if (mPolicyEditor.hasLimitedPolicy(buildTemplateMobileAll(subscriberId))) {
            limited.add(getText(R.string.data_usage_list_mobile));
        }
        if (mPolicyEditor.hasLimitedPolicy(buildTemplateMobile3gLower(subscriberId))) {
            limited.add(getText(R.string.data_usage_tab_3g));
        }
        if (mPolicyEditor.hasLimitedPolicy(buildTemplateMobile4g(subscriberId))) {
            limited.add(getText(R.string.data_usage_tab_4g));
        }
        if (mPolicyEditor.hasLimitedPolicy(buildTemplateWifi())) {
            limited.add(getText(R.string.data_usage_tab_wifi));
        }
        if (mPolicyEditor.hasLimitedPolicy(buildTemplateEthernet())) {
            limited.add(getText(R.string.data_usage_tab_ethernet));
        }

        // handle case where no networks limited
        if (limited.isEmpty()) {
            limited.add(getText(R.string.data_usage_list_none));
        }

        return TextUtils.join(limited);
    }

    /**
     * Set {@link android.R.id#title} for a preference view inflated with
     * {@link #inflatePreference(LayoutInflater, ViewGroup, View)}.
@@ -1744,9 +1782,9 @@ public class DataUsageSummary extends Fragment {
     * Set {@link android.R.id#summary} for a preference view inflated with
     * {@link #inflatePreference(LayoutInflater, ViewGroup, View)}.
     */
    private static void setPreferenceSummary(View parent, int resId) {
    private static void setPreferenceSummary(View parent, CharSequence string) {
        final TextView summary = (TextView) parent.findViewById(android.R.id.summary);
        summary.setVisibility(View.VISIBLE);
        summary.setText(resId);
        summary.setText(string);
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -91,6 +91,11 @@ public class NetworkPolicyEditor {
        }
    }

    public boolean hasLimitedPolicy(NetworkTemplate template) {
        final NetworkPolicy policy = getPolicy(template);
        return policy != null && policy.limitBytes != LIMIT_DISABLED;
    }

    public NetworkPolicy getPolicy(NetworkTemplate template) {
        for (NetworkPolicy policy : mPolicies) {
            if (policy.template.equals(template)) {
@@ -179,5 +184,4 @@ public class NetworkPolicyEditor {

        }
    }

}
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public class ChartGridView extends View {
        mBorder.setBounds(0, 0, width, height);
        mBorder.draw(canvas);

        final int padding = mLayoutStart.getHeight() / 8;
        final int padding = mLayoutStart != null ? mLayoutStart.getHeight() / 8 : 0;

        final Layout start = mLayoutStart;
        if (start != null) {