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

Commit 4b686147 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Clean up WifiDataUsageSummaryPreferenceController

Which is legacy and not finished implemented.

Bug: 295260929
Test: unit test
Test: robo test
Test: manual - on Mobile Settings page
Test: manual - on Network details page
Change-Id: I30ac639c1ba285a74038d5413b63e2c31c6cc8ba
parent 9e571e55
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -121,14 +121,5 @@

    </LinearLayout>

    <Button
        android:id="@+id/launch_mdp_app_button"
        android:layout_marginTop="12dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:text="@string/launch_mdp_app_text"
        style="@style/ActionPrimaryButton" />

</LinearLayout>
+0 −3
Original line number Diff line number Diff line
@@ -9729,9 +9729,6 @@
    <!-- Informational text about recent update time only, without carrier [CHAR LIMIT=30] -->
    <string name="no_carrier_update_now_text">Updated just now</string>
    <!-- Button to launch external data plan app [CHAR LIMIT=30] -->
    <string name="launch_mdp_app_text">View plan</string>
    <!-- Alternate launch button text for Wi-Fi only mode [CHAR LIMIT=30] -->
    <string name="launch_wifi_text">View details</string>
+0 −2
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ package com.android.settings.core;
public class FeatureFlags {
    public static final String AUDIO_SWITCHER_SETTINGS = "settings_audio_switcher";
    public static final String HEARING_AID_SETTINGS = "settings_bluetooth_hearing_aid";
    public static final String WIFI_DETAILS_DATAUSAGE_HEADER =
            "settings_wifi_details_datausage_header";
    public static final String CONTROLLER_ENHANCEMENT = "settings_controller_loading_enhancement";
    public static final String CONDITIONAL_CARDS = "settings_conditionals";
    public static final String TETHER_ALL_IN_ONE = "settings_tether_all_in_one";
+6 −84
Original line number Diff line number Diff line
@@ -17,14 +17,10 @@
package com.android.settings.datausage;

import android.annotation.AttrRes;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.icu.text.MessageFormat;
import android.net.ConnectivityManager;
import android.net.NetworkTemplate;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
@@ -32,7 +28,6 @@ import android.text.format.Formatter;
import android.text.style.AbsoluteSizeSpan;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -42,7 +37,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.Utils;
import com.android.settingslib.net.DataUsageController;
import com.android.settingslib.utils.StringUtil;
@@ -77,7 +71,6 @@ public class DataUsageSummaryPreference extends Preference {
    /** Name of carrier, or null if not available */
    private CharSequence mCarrierName;
    private CharSequence mLimitInfoText;
    private Intent mLaunchIntent;

    /** Progress to display on ProgressBar */
    private float mProgress;
@@ -92,11 +85,6 @@ public class DataUsageSummaryPreference extends Preference {
    /** The number of bytes used since the start of the cycle. */
    private long mDataplanUse;

    /** WiFi only mode */
    private boolean mWifiMode;
    private String mUsagePeriod;
    private boolean mSingleWifi;    // Shows only one specified WiFi network usage

    public DataUsageSummaryPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        setLayoutResource(R.layout.data_usage_summary_preference);
@@ -115,12 +103,11 @@ public class DataUsageSummaryPreference extends Preference {
    }

    public void setUsageInfo(long cycleEnd, long snapshotTime, CharSequence carrierName,
            int numPlans, Intent launchIntent) {
            int numPlans) {
        mCycleEndTimeMs = cycleEnd;
        mSnapshotTimeMs = snapshotTime;
        mCarrierName = carrierName;
        mNumPlans = numPlans;
        mLaunchIntent = launchIntent;
        notifyChanged();
    }

@@ -144,13 +131,6 @@ public class DataUsageSummaryPreference extends Preference {
        notifyChanged();
    }

    void setWifiMode(boolean isWifiMode, String usagePeriod, boolean isSingleWifi) {
        mWifiMode = isWifiMode;
        mUsagePeriod = usagePeriod;
        mSingleWifi = isSingleWifi;
        notifyChanged();
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);
@@ -171,67 +151,14 @@ public class DataUsageSummaryPreference extends Preference {

        TextView usageTitle = getUsageTitle(holder);
        TextView carrierInfo = getCarrierInfo(holder);
        Button launchButton = getLaunchButton(holder);
        TextView limitInfo = getDataLimits(holder);

        if (mWifiMode && mSingleWifi) {
            updateCycleTimeText(holder);

            usageTitle.setVisibility(View.GONE);
            launchButton.setVisibility(View.GONE);
            carrierInfo.setVisibility(View.GONE);

            limitInfo.setVisibility(TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
            limitInfo.setText(mLimitInfoText);
        } else if (mWifiMode) {
            usageTitle.setText(R.string.data_usage_wifi_title);
            usageTitle.setVisibility(View.VISIBLE);
            TextView cycleTime = getCycleTime(holder);
            cycleTime.setText(mUsagePeriod);
            carrierInfo.setVisibility(View.GONE);
            limitInfo.setVisibility(View.GONE);

            final long usageLevel = getHistoricalUsageLevel();
            if (usageLevel > 0L) {
                launchButton.setOnClickListener((view) -> {
                    launchWifiDataUsage(getContext());
                });
            } else {
                launchButton.setEnabled(false);
            }
            launchButton.setText(R.string.launch_wifi_text);
            launchButton.setVisibility(View.VISIBLE);
        } else {
        usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);
        updateCycleTimeText(holder);
        updateCarrierInfo(carrierInfo);
            if (mLaunchIntent != null) {
                launchButton.setOnClickListener((view) -> {
                    getContext().startActivity(mLaunchIntent);
                });
                launchButton.setVisibility(View.VISIBLE);
            } else {
                launchButton.setVisibility(View.GONE);
            }
            limitInfo.setVisibility(
                    TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
        limitInfo.setVisibility(TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
        limitInfo.setText(mLimitInfoText);
    }
    }

    @VisibleForTesting
    static void launchWifiDataUsage(Context context) {
        final Bundle args = new Bundle(1);
        args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE,
                new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI).build());
        args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_WIFI);
        final SubSettingLauncher launcher = new SubSettingLauncher(context)
                .setArguments(args)
                .setDestination(DataUsageList.class.getName())
                .setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN);
        launcher.setTitleRes(R.string.wifi_data_usage);
        launcher.launch();
    }

    private void updateDataUsageLabels(PreferenceViewHolder holder) {
        TextView usageNumberField = getDataUsed(holder);
@@ -403,11 +330,6 @@ public class DataUsageSummaryPreference extends Preference {
        return (TextView) holder.findViewById(R.id.data_remaining_view);
    }

    @VisibleForTesting
    protected Button getLaunchButton(PreferenceViewHolder holder) {
        return (Button) holder.findViewById(R.id.launch_mdp_app_button);
    }

    @VisibleForTesting
    protected LinearLayout getLabelBar(PreferenceViewHolder holder) {
        return (LinearLayout) holder.findViewById(R.id.label_bar);
+6 −81
Original line number Diff line number Diff line
@@ -18,13 +18,8 @@ package com.android.settings.datausage;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.INetworkPolicyManager;
import android.net.NetworkTemplate;
import android.os.ServiceManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionPlan;
import android.text.TextUtils;
import android.util.Log;
@@ -83,8 +78,6 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
    /** The ending time of the billing cycle in ms since the epoch */
    private long mCycleEnd;

    private Intent mManageSubscriptionIntent;

    private Future<Long> mHistoricalUsageLevel;

    public DataUsageSummaryPreferenceController(Activity activity, int subscriptionId) {
@@ -111,10 +104,6 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc

        if (subInfo != null) {
            mDefaultTemplate = DataUsageLib.getMobileTemplate(context, subscriptionId);
        } else if (DataUsageUtils.hasWifiRadio(context)) {
            mDefaultTemplate = new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI).build();
        } else {
            mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, subscriptionId);
        }
    }

@@ -154,8 +143,7 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc

    @Override
    public int getAvailabilityStatus(int subId) {
        return (getSubscriptionInfo(subId) != null)
                || DataUsageUtils.hasWifiRadio(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
        return getSubscriptionInfo(subId) != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
    }

    @Override
@@ -163,6 +151,9 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
        DataUsageSummaryPreference summaryPreference = (DataUsageSummaryPreference) preference;

        final SubscriptionInfo subInfo = getSubscriptionInfo(mSubId);
        if (subInfo == null) {
            return;
        }
        if (mDataUsageController == null) {
            updateConfiguration(mContext, mSubId, subInfo);
        }
@@ -175,25 +166,6 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc

        long usageLevel = info.usageLevel;

        if (subInfo != null) {
            summaryPreference.setWifiMode(/* isWifiMode */ false,
                    /* usagePeriod */ null, /* isSingleWifi */ false);
        } else {
            summaryPreference.setWifiMode(/* isWifiMode */ true, /* usagePeriod */
                    info.period, /* isSingleWifi */ false);
            summaryPreference.setLimitInfo(null);
            summaryPreference.setUsageNumbers(displayUsageLevel(usageLevel),
                    /* dataPlanSize */ -1L,
                    /* hasMobileData */ true);
            summaryPreference.setChartEnabled(false);
            summaryPreference.setUsageInfo(info.cycleEnd,
                    /* snapshotTime */ -1L,
                    /* carrierName */ null,
                    /* numPlans */ 0,
                    /* launchIntent */ null);
            return;
        }

        refreshDataplanInfo(info, subInfo);

        if (info.warningLevel > 0 && info.limitLevel > 0) {
@@ -229,8 +201,7 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
                    DataUsageUtils.formatDataUsage(mContext, mDataBarSize));
            summaryPreference.setProgress(mDataplanUse / (float) mDataBarSize);
        }
        summaryPreference.setUsageInfo(mCycleEnd, mSnapshotTime, mCarrierName,
                mDataplanCount, mManageSubscriptionIntent);
        summaryPreference.setUsageInfo(mCycleEnd, mSnapshotTime, mCarrierName, mDataplanCount);
    }

    private long displayUsageLevel(long usageLevel) {
@@ -278,53 +249,7 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
                mSnapshotTime = primaryPlan.getDataUsageTime();
            }
        }
        // Temporarily return null, since no current users of SubscriptionPlan have this intent set.
        // TODO (b/170330084): Remove after refactoring 5G SubscriptionPlan logic.
        // mManageSubscriptionIntent = createManageSubscriptionIntent(mSubId);
        mManageSubscriptionIntent = null;
        Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubId
                + ", intent " + mManageSubscriptionIntent);
    }

    /**
     * Create an {@link Intent} that can be launched towards the carrier app
     * that is currently defining the billing relationship plan through
     * {@link INetworkPolicyManager#setSubscriptionPlans(int, SubscriptionPlan [], String)}.
     *
     * @return ready to launch Intent targeted towards the carrier app, or
     *         {@code null} if no carrier app is defined, or if the defined
     *         carrier app provides no management activity.
     */
    @VisibleForTesting
    Intent createManageSubscriptionIntent(int subId) {
        final INetworkPolicyManager iNetPolicyManager = INetworkPolicyManager.Stub.asInterface(
                ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
        String owner = "";
        try {
            owner = iNetPolicyManager.getSubscriptionPlansOwner(subId);
        } catch (Exception ex) {
            Log.w(TAG, "Fail to get subscription plan owner for subId " + subId, ex);
        }

        if (TextUtils.isEmpty(owner)) {
            return null;
        }

        final List<SubscriptionPlan> plans = getSubscriptionPlans(subId);
        if (plans.isEmpty()) {
            return null;
        }

        final Intent intent = new Intent(SubscriptionManager.ACTION_MANAGE_SUBSCRIPTION_PLANS);
        intent.setPackage(owner);
        intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);

        if (mContext.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
            return null;
        }

        return intent;
        Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubId);
    }

    private static SubscriptionPlan getPrimaryPlan(List<SubscriptionPlan> plans) {
Loading