Move some logic to MobileState
Some variables were being created in MobileSignalController#notifyListeners() that were just an aggregation of a few fields on MobileState. This CL replaces those with method calls on MobileState to clean things up and make them loggable from the state. Test: atest SystemUITests Test: m -j RunSettingsLibRoboTests ROBOTEST_FILTER="com.android.settingslib.MobileStateTest" Bug: 197851948 Change-Id: I06d5e56923897cddb53189359dc9444cdfee6e78 Merged-In: I06d5e56923897cddb53189359dc9444cdfee6e78
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.android.settingslib;
|
||||
|
||||
import com.android.settingslib.mobile.TelephonyIcons;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -40,9 +42,17 @@ public class SignalIcon {
|
||||
// For logging.
|
||||
public final String name;
|
||||
|
||||
public IconGroup(String name, int[][] sbIcons, int[][] qsIcons, int[] contentDesc,
|
||||
int sbNullState, int qsNullState, int sbDiscState, int qsDiscState,
|
||||
int discContentDesc) {
|
||||
public IconGroup(
|
||||
String name,
|
||||
int[][] sbIcons,
|
||||
int[][] qsIcons,
|
||||
int[] contentDesc,
|
||||
int sbNullState,
|
||||
int qsNullState,
|
||||
int sbDiscState,
|
||||
int qsDiscState,
|
||||
int discContentDesc
|
||||
) {
|
||||
this.name = name;
|
||||
this.sbIcons = sbIcons;
|
||||
this.qsIcons = qsIcons;
|
||||
@@ -131,6 +141,19 @@ public class SignalIcon {
|
||||
&& other.activityOut == activityOut
|
||||
&& other.rssi == rssi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
connected,
|
||||
enabled,
|
||||
level,
|
||||
inetCondition,
|
||||
iconGroup,
|
||||
activityIn,
|
||||
activityOut,
|
||||
rssi);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,11 +163,28 @@ public class SignalIcon {
|
||||
public final int dataContentDescription; // mContentDescriptionDataType
|
||||
public final int dataType;
|
||||
|
||||
public MobileIconGroup(String name, int[][] sbIcons, int[][] qsIcons, int[] contentDesc,
|
||||
int sbNullState, int qsNullState, int sbDiscState, int qsDiscState,
|
||||
int discContentDesc, int dataContentDesc, int dataType) {
|
||||
super(name, sbIcons, qsIcons, contentDesc, sbNullState, qsNullState, sbDiscState,
|
||||
qsDiscState, discContentDesc);
|
||||
public MobileIconGroup(
|
||||
String name,
|
||||
int[][] sbIcons,
|
||||
int[][] qsIcons,
|
||||
int[] contentDesc,
|
||||
int sbNullState,
|
||||
int qsNullState,
|
||||
int sbDiscState,
|
||||
int qsDiscState,
|
||||
int discContentDesc,
|
||||
int dataContentDesc,
|
||||
int dataType
|
||||
) {
|
||||
super(name,
|
||||
sbIcons,
|
||||
qsIcons,
|
||||
contentDesc,
|
||||
sbNullState,
|
||||
qsNullState,
|
||||
sbDiscState,
|
||||
qsDiscState,
|
||||
discContentDesc);
|
||||
this.dataContentDescription = dataContentDesc;
|
||||
this.dataType = dataType;
|
||||
}
|
||||
@@ -183,6 +223,22 @@ public class SignalIcon {
|
||||
defaultDataOff = state.defaultDataOff;
|
||||
}
|
||||
|
||||
/** @return true if this state is disabled or not default data */
|
||||
public boolean isDataDisabledOrNotDefault() {
|
||||
return (iconGroup == TelephonyIcons.DATA_DISABLED
|
||||
|| (iconGroup == TelephonyIcons.NOT_DEFAULT_DATA)) && userSetup;
|
||||
}
|
||||
|
||||
/** @return if this state is considered to have inbound activity */
|
||||
public boolean hasActivityIn() {
|
||||
return dataConnected && !carrierNetworkChangeMode && activityIn;
|
||||
}
|
||||
|
||||
/** @return if this state is considered to have outbound activity */
|
||||
public boolean hasActivityOut() {
|
||||
return dataConnected && !carrierNetworkChangeMode && activityOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toString(StringBuilder builder) {
|
||||
super.toString(builder);
|
||||
@@ -204,17 +260,33 @@ public class SignalIcon {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return super.equals(o)
|
||||
&& Objects.equals(((MobileState) o).networkName, networkName)
|
||||
&& Objects.equals(((MobileState) o).networkNameData, networkNameData)
|
||||
&& ((MobileState) o).dataSim == dataSim
|
||||
&& ((MobileState) o).dataConnected == dataConnected
|
||||
&& ((MobileState) o).isEmergency == isEmergency
|
||||
&& ((MobileState) o).airplaneMode == airplaneMode
|
||||
&& ((MobileState) o).carrierNetworkChangeMode == carrierNetworkChangeMode
|
||||
&& ((MobileState) o).userSetup == userSetup
|
||||
&& ((MobileState) o).isDefault == isDefault
|
||||
&& ((MobileState) o).roaming == roaming
|
||||
&& ((MobileState) o).defaultDataOff == defaultDataOff;
|
||||
&& Objects.equals(((MobileState) o).networkName, networkName)
|
||||
&& Objects.equals(((MobileState) o).networkNameData, networkNameData)
|
||||
&& ((MobileState) o).dataSim == dataSim
|
||||
&& ((MobileState) o).dataConnected == dataConnected
|
||||
&& ((MobileState) o).isEmergency == isEmergency
|
||||
&& ((MobileState) o).airplaneMode == airplaneMode
|
||||
&& ((MobileState) o).carrierNetworkChangeMode == carrierNetworkChangeMode
|
||||
&& ((MobileState) o).userSetup == userSetup
|
||||
&& ((MobileState) o).isDefault == isDefault
|
||||
&& ((MobileState) o).roaming == roaming
|
||||
&& ((MobileState) o).defaultDataOff == defaultDataOff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(),
|
||||
networkName,
|
||||
networkNameData,
|
||||
dataSim,
|
||||
dataConnected,
|
||||
isEmergency,
|
||||
airplaneMode,
|
||||
carrierNetworkChangeMode,
|
||||
userSetup,
|
||||
isDefault,
|
||||
roaming,
|
||||
defaultDataOff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.settingslib;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import com.android.settingslib.mobile.TelephonyIcons;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MobileStateTest {
|
||||
|
||||
private SignalIcon.MobileState mState = new SignalIcon.MobileState();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDataDisabledOrNotDefault_dataDisabled() {
|
||||
mState.iconGroup = TelephonyIcons.DATA_DISABLED;
|
||||
mState.userSetup = true;
|
||||
|
||||
assertTrue(mState.isDataDisabledOrNotDefault());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDataDisabledOrNotDefault_notDefaultData() {
|
||||
mState.iconGroup = TelephonyIcons.NOT_DEFAULT_DATA;
|
||||
mState.userSetup = true;
|
||||
|
||||
assertTrue(mState.isDataDisabledOrNotDefault());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDataDisabledOrNotDefault_notDisabled() {
|
||||
mState.iconGroup = TelephonyIcons.G;
|
||||
mState.userSetup = true;
|
||||
|
||||
assertFalse(mState.isDataDisabledOrNotDefault());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasActivityIn_noData_noActivity() {
|
||||
mState.dataConnected = false;
|
||||
mState.carrierNetworkChangeMode = false;
|
||||
mState.activityIn = false;
|
||||
|
||||
assertFalse(mState.hasActivityIn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasActivityIn_noData_activityIn() {
|
||||
mState.dataConnected = false;
|
||||
mState.carrierNetworkChangeMode = false;
|
||||
mState.activityIn = true;
|
||||
|
||||
assertFalse(mState.hasActivityIn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasActivityIn_dataConnected_activityIn() {
|
||||
mState.dataConnected = true;
|
||||
mState.carrierNetworkChangeMode = false;
|
||||
mState.activityIn = true;
|
||||
|
||||
assertTrue(mState.hasActivityIn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasActivityIn_carrierNetworkChange() {
|
||||
mState.dataConnected = true;
|
||||
mState.carrierNetworkChangeMode = true;
|
||||
mState.activityIn = true;
|
||||
|
||||
assertFalse(mState.hasActivityIn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasActivityOut_noData_noActivity() {
|
||||
mState.dataConnected = false;
|
||||
mState.carrierNetworkChangeMode = false;
|
||||
mState.activityOut = false;
|
||||
|
||||
assertFalse(mState.hasActivityOut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasActivityOut_noData_activityOut() {
|
||||
mState.dataConnected = false;
|
||||
mState.carrierNetworkChangeMode = false;
|
||||
mState.activityOut = true;
|
||||
|
||||
assertFalse(mState.hasActivityOut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasActivityOut_dataConnected_activityOut() {
|
||||
mState.dataConnected = true;
|
||||
mState.carrierNetworkChangeMode = false;
|
||||
mState.activityOut = true;
|
||||
|
||||
assertTrue(mState.hasActivityOut());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasActivityOut_carrierNetworkChange() {
|
||||
mState.dataConnected = true;
|
||||
mState.carrierNetworkChangeMode = true;
|
||||
mState.activityOut = true;
|
||||
|
||||
assertFalse(mState.hasActivityOut());
|
||||
}
|
||||
}
|
||||
@@ -91,8 +91,7 @@ public class MobileSignalController extends SignalController<MobileState, Mobile
|
||||
private int mImsType = IMS_TYPE_WWAN;
|
||||
// Save entire info for logging, we only use the id.
|
||||
final SubscriptionInfo mSubscriptionInfo;
|
||||
// @VisibleForDemoMode
|
||||
Map<String, MobileIconGroup> mNetworkToIconLookup;
|
||||
private Map<String, MobileIconGroup> mNetworkToIconLookup;
|
||||
|
||||
// Since some pieces of the phone state are interdependent we store it locally,
|
||||
// this could potentially become part of MobileState for simplification/complication
|
||||
@@ -385,9 +384,8 @@ public class MobileSignalController extends SignalController<MobileState, Mobile
|
||||
if (mCurrentState.inetCondition == 0) {
|
||||
dataContentDescription = mContext.getString(R.string.data_connection_no_internet);
|
||||
}
|
||||
final boolean dataDisabled = (mCurrentState.iconGroup == TelephonyIcons.DATA_DISABLED
|
||||
|| (mCurrentState.iconGroup == TelephonyIcons.NOT_DEFAULT_DATA))
|
||||
&& mCurrentState.userSetup;
|
||||
|
||||
final boolean dataDisabled = mCurrentState.isDataDisabledOrNotDefault();
|
||||
|
||||
if (mProviderModelBehavior) {
|
||||
// Show icon in QS when we are connected or data is disabled.
|
||||
@@ -404,12 +402,7 @@ public class MobileSignalController extends SignalController<MobileState, Mobile
|
||||
&& !mCurrentState.isEmergency, getQsCurrentIconId(), contentDescription);
|
||||
description = mCurrentState.isEmergency ? null : mCurrentState.networkName;
|
||||
}
|
||||
boolean activityIn = mCurrentState.dataConnected
|
||||
&& !mCurrentState.carrierNetworkChangeMode
|
||||
&& mCurrentState.activityIn;
|
||||
boolean activityOut = mCurrentState.dataConnected
|
||||
&& !mCurrentState.carrierNetworkChangeMode
|
||||
&& mCurrentState.activityOut;
|
||||
|
||||
showDataIcon &= mCurrentState.dataSim && mCurrentState.isDefault;
|
||||
boolean showTriangle = showDataIcon && !mCurrentState.airplaneMode;
|
||||
int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.dataType : 0;
|
||||
@@ -417,10 +410,18 @@ public class MobileSignalController extends SignalController<MobileState, Mobile
|
||||
IconState statusIcon = new IconState(showDataIcon && !mCurrentState.airplaneMode,
|
||||
getCurrentIconId(), contentDescription);
|
||||
MobileDataIndicators mobileDataIndicators = new MobileDataIndicators(
|
||||
statusIcon, qsIcon, typeIcon, qsTypeIcon,
|
||||
activityIn, activityOut, dataContentDescription, dataContentDescriptionHtml,
|
||||
description, mSubscriptionInfo.getSubscriptionId(),
|
||||
mCurrentState.roaming, showTriangle);
|
||||
statusIcon,
|
||||
qsIcon,
|
||||
typeIcon,
|
||||
qsTypeIcon,
|
||||
mCurrentState.hasActivityIn(),
|
||||
mCurrentState.hasActivityOut(),
|
||||
dataContentDescription,
|
||||
dataContentDescriptionHtml,
|
||||
description,
|
||||
mSubscriptionInfo.getSubscriptionId(),
|
||||
mCurrentState.roaming,
|
||||
showTriangle);
|
||||
callback.setMobileDataIndicators(mobileDataIndicators);
|
||||
} else {
|
||||
boolean showDataIcon = mCurrentState.dataConnected || dataDisabled;
|
||||
@@ -452,20 +453,22 @@ public class MobileSignalController extends SignalController<MobileState, Mobile
|
||||
}
|
||||
}
|
||||
|
||||
boolean activityIn = mCurrentState.dataConnected
|
||||
&& !mCurrentState.carrierNetworkChangeMode
|
||||
&& mCurrentState.activityIn;
|
||||
boolean activityOut = mCurrentState.dataConnected
|
||||
&& !mCurrentState.carrierNetworkChangeMode
|
||||
&& mCurrentState.activityOut;
|
||||
showDataIcon &= mCurrentState.isDefault || dataDisabled;
|
||||
int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.dataType : 0;
|
||||
boolean showTriangle = mCurrentState.enabled && !mCurrentState.airplaneMode;
|
||||
MobileDataIndicators mobileDataIndicators = new MobileDataIndicators(
|
||||
statusIcon, qsIcon, typeIcon, qsTypeIcon,
|
||||
activityIn, activityOut, dataContentDescription, dataContentDescriptionHtml,
|
||||
description, mSubscriptionInfo.getSubscriptionId(),
|
||||
mCurrentState.roaming, showTriangle);
|
||||
statusIcon,
|
||||
qsIcon,
|
||||
typeIcon,
|
||||
qsTypeIcon,
|
||||
mCurrentState.hasActivityIn(),
|
||||
mCurrentState.hasActivityOut(),
|
||||
dataContentDescription,
|
||||
dataContentDescriptionHtml,
|
||||
description,
|
||||
mSubscriptionInfo.getSubscriptionId(),
|
||||
mCurrentState.roaming,
|
||||
showTriangle);
|
||||
callback.setMobileDataIndicators(mobileDataIndicators);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user