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

Commit f3baeb1e authored by Lei Yu's avatar Lei Yu Committed by Android (Google) Code Review
Browse files

Merge changes Iad3bc131,Id43cb480

* changes:
  Update NetworkSelectSettings page
  Recopy NetworkSelectSetting from phone to settings
parents 130c4770 227526a8
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<!--
Copyright (C) 2014 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="9.208dp"
    android:height="17dp"
    android:viewportWidth="13.0"
    android:viewportHeight="24.0"
    android:tint="?android:attr/colorControlNormal">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M4.600000,7.800000l0.700000,0.000000l0.000000,1.300000L4.600000,9.100000L4.600000,11.000000L3.000000,11.000000L3.000000,9.200000L0.100000,9.200000L0.000000,8.100000L3.000000,2.500000l1.700000,0.000000L4.700000,7.800000zM1.600000,7.800000L3.000000,7.800000l0.000000,-3.000000L2.900000,5.000000L1.600000,7.800000z"/>
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M11.900000,9.900000c-0.200000,0.400000 -0.600000,0.700000 -1.000000,0.900000s-1.000000,0.400000 -1.800000,0.400000c-0.900000,0.000000 -1.700000,-0.300000 -2.200000,-0.800000S6.100000,9.000000 6.100000,7.900000L6.100000,5.600000c0.000000,-1.100000 0.300000,-1.900000 0.800000,-2.400000S8.100000,2.400000 9.000000,2.400000c1.000000,0.000000 1.700000,0.200000 2.100000,0.700000s0.700000,1.200000 0.700000,2.100000l-1.600000,0.000000c0.000000,-0.500000 -0.100000,-0.900000 -0.200000,-1.100000S9.500000,3.700000 9.000000,3.700000c-0.400000,0.000000 -0.700000,0.200000 -0.900000,0.500000S7.700000,5.000000 7.700000,5.600000l0.000000,2.300000c0.000000,0.700000 0.100000,1.100000 0.300000,1.400000s0.600000,0.500000 1.000000,0.500000c0.300000,0.000000 0.600000,0.000000 0.700000,-0.100000s0.300000,-0.200000 0.400000,-0.300000L10.099999,7.800000L9.000000,7.800000L9.000000,6.600000l2.900000,0.000000L11.900000,9.900000z"/>
</vector>
 No newline at end of file
+26 −12
Original line number Diff line number Diff line
@@ -22,17 +22,18 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.telephony.CellInfo;
import android.telephony.CellSignalStrength;
import android.telephony.SignalStrength;
import android.util.Log;
import android.view.Gravity;

import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settingslib.graph.SignalDrawable;

import java.util.List;

import androidx.preference.Preference;

/**
 * A Preference represents a network operator in the NetworkSelectSetting fragment.
 */
@@ -40,21 +41,26 @@ public class NetworkOperatorPreference extends Preference {

    private static final String TAG = "NetworkOperatorPref";
    private static final boolean DBG = false;

    private static final int LEVEL_NONE = -1;

    // number of signal strength level
    public static final int NUMBER_OF_LEVELS = SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
    private CellInfo mCellInfo;
    private List<String> mForbiddenPlmns;
    private int mLevel = -1;
    private int mLevel = LEVEL_NONE;
    private boolean mShow4GForLTE;

    // The following constants are used to draw signal icon.
    private static final Drawable EMPTY_DRAWABLE = new ColorDrawable(Color.TRANSPARENT);
    private static final int NO_CELL_DATA_CONNECTED_ICON = 0;

    public NetworkOperatorPreference(
            CellInfo cellinfo, Context context, List<String> forbiddenPlmns) {
            CellInfo cellinfo, Context context, List<String> forbiddenPlmns, boolean show4GForLTE) {
        super(context);
        mCellInfo = cellinfo;
        mForbiddenPlmns = forbiddenPlmns;
        mShow4GForLTE = show4GForLTE;
        refresh();
    }

@@ -72,7 +78,9 @@ public class NetworkOperatorPreference extends Preference {
            networkTitle += " " + getContext().getResources().getString(R.string.forbidden_network);
        }
        setTitle(networkTitle);
        int level = mCellInfo.getCellSignalStrength().getLevel();

        final CellSignalStrength signalStrength = mCellInfo.getCellSignalStrength();
        final int level = signalStrength != null ? signalStrength.getLevel() : LEVEL_NONE;
        if (DBG) Log.d(TAG, "refresh level: " + String.valueOf(level));
        if (mLevel != level) {
            mLevel = level;
@@ -87,15 +95,21 @@ public class NetworkOperatorPreference extends Preference {
        updateIcon(level);
    }

    private static int getIconIdForCell(CellInfo ci) {
    private int getIconIdForCell(CellInfo ci) {
        final int type = ci.getCellIdentity().getType();
        switch (type) {
            case CellInfo.TYPE_GSM: return R.drawable.signal_strength_g;
            case CellInfo.TYPE_GSM:
                return R.drawable.signal_strength_g;
            case CellInfo.TYPE_WCDMA: // fall through
            case CellInfo.TYPE_TDSCDMA: return R.drawable.signal_strength_3g;
            case CellInfo.TYPE_LTE: return R.drawable.signal_strength_lte;
            case CellInfo.TYPE_CDMA: return R.drawable.signal_strength_1x;
            default: return 0;
            case CellInfo.TYPE_TDSCDMA:
                return R.drawable.signal_strength_3g;
            case CellInfo.TYPE_LTE:
                return mShow4GForLTE
                        ? R.drawable.ic_signal_strength_4g : R.drawable.signal_strength_lte;
            case CellInfo.TYPE_CDMA:
                return R.drawable.signal_strength_1x;
            default:
                return 0;
        }
    }

+137 −292

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ com.android.settings.inputmethod.SpellCheckersSettings
com.android.settings.localepicker.LocaleListEditor
com.android.settings.network.ApnEditor
com.android.settings.network.ApnSettings
com.android.settings.network.telephony.NetworkSelectSettings
com.android.settings.notification.AppNotificationSettings
com.android.settings.notification.ChannelGroupNotificationSettings
com.android.settings.notification.ChannelNotificationSettings
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.network.telephony;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.telephony.CellInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;

import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;

import com.android.settings.testutils.SettingsRobolectricTestRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;

import java.util.Arrays;

@RunWith(SettingsRobolectricTestRunner.class)
public class NetworkSelectSettingsTest {
    private static final int SUB_ID = 2;

    @Mock
    private TelephonyManager mTelephonyManager;
    @Mock
    private SubscriptionManager mSubscriptionManager;
    @Mock
    private CellInfo mCellInfo1;
    @Mock
    private CellInfo mCellInfo2;
    @Mock
    private PreferenceManager mPreferenceManager;
    private Context mContext;

    private PreferenceCategory mConnectedPreferenceCategory;
    private PreferenceCategory mPreferenceCategory;

    private NetworkSelectSettings mNetworkSelectSettings;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        mContext = spy(RuntimeEnvironment.application);
        when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
        when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
        when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);

        when(mCellInfo1.isRegistered()).thenReturn(true);
        when(mCellInfo2.isRegistered()).thenReturn(false);

        mConnectedPreferenceCategory = spy(new PreferenceCategory(mContext));
        doReturn(mPreferenceManager).when(mConnectedPreferenceCategory).getPreferenceManager();
        mPreferenceCategory = spy(new PreferenceCategory(mContext));
        doReturn(mPreferenceManager).when(mPreferenceCategory).getPreferenceManager();

        mNetworkSelectSettings = spy(new NetworkSelectSettings());
        doReturn(mContext).when(mNetworkSelectSettings).getContext();
        mNetworkSelectSettings.mTelephonyManager = mTelephonyManager;
        mNetworkSelectSettings.mConnectedPreferenceCategory = mConnectedPreferenceCategory;
        mNetworkSelectSettings.mPreferenceCategory = mPreferenceCategory;
        mNetworkSelectSettings.mCellInfoList = Arrays.asList(mCellInfo1, mCellInfo2);
    }

    @Test
    public void updateAllPreferenceCategory_containCorrectPreference() {
        mNetworkSelectSettings.updateAllPreferenceCategory();

        assertThat(mConnectedPreferenceCategory.getPreferenceCount()).isEqualTo(1);
        final NetworkOperatorPreference connectedPreference =
                (NetworkOperatorPreference) mConnectedPreferenceCategory.getPreference(0);
        assertThat(connectedPreference.getCellInfo()).isEqualTo(mCellInfo1);
        assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
        final NetworkOperatorPreference preference =
                (NetworkOperatorPreference) mPreferenceCategory.getPreference(0);
        assertThat(preference.getCellInfo()).isEqualTo(mCellInfo2);
    }

}