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

Commit 0fa7262c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Listen to mobile data enabled flag change."

parents 8c451742 917721c8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@
            </intent>
        </Preference>

        <com.android.settings.DividedCategory
        <PreferenceCategory
            android:key="recent_location_requests"
            android:title="@string/location_category_recent_location_requests" />

+0 −36
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package com.android.settings;

import android.content.Context;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;

/**
 * PreferenceCategory that allows a divider above it.
 */
public class DividedCategory extends PreferenceCategory {

    public DividedCategory(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);
        holder.setDividerAllowedAbove(true);
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -58,8 +58,9 @@ public class BillingCyclePreference extends Preference implements TemplatePrefer
        mSubId = subId;
        mServices = services;
        mPolicy = services.mPolicyEditor.getPolicy(mTemplate);
        setSummary(getContext().getString(R.string.billing_cycle_fragment_summary,
                mPolicy != null ? mPolicy.cycleDay : 1));
        setSummary(getContext().getString(R.string.billing_cycle_fragment_summary, mPolicy != null
                ? mPolicy.cycleDay
                : "1"));
        setIntent(getIntent());
    }

+51 −48
Original line number Diff line number Diff line
@@ -46,8 +46,10 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.datausage.CycleAdapter.SpinnerInterface;
import com.android.settingslib.AppItem;
import com.android.settingslib.net.ChartData;
import com.android.settingslib.net.ChartDataLoader;
@@ -56,9 +58,7 @@ import com.android.settingslib.net.UidDetailProvider;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
@@ -73,6 +73,10 @@ import static com.android.settings.datausage.DataUsageSummary.TEST_RADIOS_PROP;
 * to inspect based on usage cycle and control through {@link NetworkPolicy}.
 */
public class DataUsageList extends DataUsageBase {

    public static final String EXTRA_SUB_ID = "sub_id";
    public static final String EXTRA_NETWORK_TEMPLATE = "network_template";

    private static final String TAG = "DataUsage";
    private static final boolean LOGD = false;

@@ -82,8 +86,14 @@ public class DataUsageList extends DataUsageBase {

    private static final int LOADER_CHART_DATA = 2;
    private static final int LOADER_SUMMARY = 3;
    public static final String EXTRA_SUB_ID = "sub_id";
    public static final String EXTRA_NETWORK_TEMPLATE = "network_template";

    private final CellDataPreference.DataStateListener mDataStateListener =
            new CellDataPreference.DataStateListener() {
                @Override
                public void onChange(boolean selfChange) {
                    updatePolicy();
                }
            };

    private INetworkStatsSession mStatsSession;

@@ -93,15 +103,7 @@ public class DataUsageList extends DataUsageBase {
    private int mSubId;
    private ChartData mChartData;

    /** Flag used to ignore listeners during binding. */
    private boolean mBinding;

    private UidDetailProvider mUidDetailProvider;

    /**
     * Local cache of data enabled for subId, used to work around delays.
     */
    private final Map<String, Boolean> mMobileDataEnabled = new HashMap<String, Boolean>();
    private CycleAdapter mCycleAdapter;
    private Spinner mCycleSpinner;
    private Preference mUsageAmount;
@@ -146,9 +148,14 @@ public class DataUsageList extends DataUsageBase {
        super.onViewCreated(v, savedInstanceState);

        mHeader = setPinnedHeaderView(R.layout.apps_filter_spinner);
        mCycleSpinner = (Spinner) mHeader.findViewById(R.id.filter_spinner);
        mCycleAdapter = new CycleAdapter(mCycleSpinner.getContext(),
                new CycleAdapter.SpinnerInterface() {
        mHeader.findViewById(R.id.filter_settings).setOnClickListener(btn -> {
            final Bundle args = new Bundle();
            args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
            startFragment(DataUsageList.this, BillingCycleSettings.class.getName(),
                    R.string.billing_cycle, 0, args);
        });
        mCycleSpinner = mHeader.findViewById(R.id.filter_spinner);
        mCycleAdapter = new CycleAdapter(mCycleSpinner.getContext(), new SpinnerInterface() {
            @Override
            public void setAdapter(CycleAdapter cycleAdapter) {
                mCycleSpinner.setAdapter(cycleAdapter);
@@ -175,7 +182,7 @@ public class DataUsageList extends DataUsageBase {
    @Override
    public void onResume() {
        super.onResume();

        mDataStateListener.setListener(true, mSubId, getContext());
        updateBody();

        // kick off background task to update stats
@@ -201,6 +208,12 @@ public class DataUsageList extends DataUsageBase {
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    @Override
    public void onPause() {
        super.onPause();
        mDataStateListener.setListener(false, mSubId, getContext());
    }

    @Override
    public void onDestroy() {
        mUidDetailProvider.clearCache();
@@ -217,7 +230,6 @@ public class DataUsageList extends DataUsageBase {
     * binds them to visible controls.
     */
    private void updateBody() {
        mBinding = true;
        if (!isAdded()) return;

        final Context context = getActivity();
@@ -231,8 +243,6 @@ public class DataUsageList extends DataUsageBase {
        // detail mode can change visible menus, invalidate
        getActivity().invalidateOptionsMenu();

        mBinding = false;

        int seriesColor = context.getColor(R.color.sim_noitification);
        if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            final SubscriptionInfo sir = services.mSubscriptionManager
@@ -252,35 +262,24 @@ public class DataUsageList extends DataUsageBase {
     * Update chart sweeps and cycle list to reflect {@link NetworkPolicy} for
     * current {@link #mTemplate}.
     */
    private void updatePolicy(boolean refreshCycle) {
    private void updatePolicy() {
        final NetworkPolicy policy = services.mPolicyEditor.getPolicy(mTemplate);
        final View configureButton = mHeader.findViewById(R.id.filter_settings);
        //SUB SELECT
        if (isNetworkPolicyModifiable(policy, mSubId) && isMobileDataAvailable(mSubId)) {
            mChart.setNetworkPolicy(policy);
            mHeader.findViewById(R.id.filter_settings).setVisibility(View.VISIBLE);
            mHeader.findViewById(R.id.filter_settings).setOnClickListener(
                    new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle args = new Bundle();
                    args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
                    startFragment(DataUsageList.this, BillingCycleSettings.class.getName(),
                            R.string.billing_cycle, 0, args);
                }
            });
            configureButton.setVisibility(View.VISIBLE);
        } else {
            // controls are disabled; don't bind warning/limit sweeps
            mChart.setNetworkPolicy(null);
            mHeader.findViewById(R.id.filter_settings).setVisibility(View.GONE);
            configureButton.setVisibility(View.GONE);
        }

        if (refreshCycle) {
        // generate cycle list based on policy and available history
        if (mCycleAdapter.updateCycleList(policy, mChartData)) {
            updateDetailData();
        }
    }
    }

    /**
     * Update details based on {@link #mChart} inspection range depending on
@@ -413,6 +412,7 @@ public class DataUsageList extends DataUsageBase {
    /**
     * Accumulate data usage of a network stats entry for the item mapped by the collapse key.
     * Creates the item if needed.
     *
     * @param collapseKey  the collapse key used to map the item.
     * @param knownItems   collection of known (already existing) items.
     * @param entry        the network stats entry to extract data usage from.
@@ -481,9 +481,12 @@ public class DataUsageList extends DataUsageBase {
        final boolean isReady = tele.getSimState(slotId) == SIM_STATE_READY;

        boolean retVal = conn.isNetworkSupported(TYPE_MOBILE) && isReady;
        if (LOGD) Log.d(TAG, "hasReadyMobileRadio: subId=" + subId
                + " conn.isNetworkSupported(TYPE_MOBILE)=" + conn.isNetworkSupported(TYPE_MOBILE)
        if (LOGD) {
            Log.d(TAG, "hasReadyMobileRadio: subId=" + subId
                    + " conn.isNetworkSupported(TYPE_MOBILE)="
                    + conn.isNetworkSupported(TYPE_MOBILE)
                    + " isReady=" + isReady);
        }
        return retVal;
    }

@@ -524,8 +527,8 @@ public class DataUsageList extends DataUsageBase {
            mChartData = data;
            mChart.setNetworkStats(mChartData.network);

            // calcuate policy cycles based on available data
            updatePolicy(true);
            // calculate policy cycles based on available data
            updatePolicy();
        }

        @Override
+2 −2
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@ package com.android.settings.datausage;
import android.content.Context;
import android.net.NetworkTemplate;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.util.AttributeSet;
import com.android.settings.DividedCategory;

public class TemplatePreferenceCategory extends DividedCategory implements TemplatePreference {
public class TemplatePreferenceCategory extends PreferenceCategory implements TemplatePreference {

    private NetworkTemplate mTemplate;
    private int mSubId;
Loading