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
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settingslib;
|
package com.android.settingslib;
|
||||||
|
|
||||||
|
import com.android.settingslib.mobile.TelephonyIcons;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -40,9 +42,17 @@ public class SignalIcon {
|
|||||||
// For logging.
|
// For logging.
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
||||||
public IconGroup(String name, int[][] sbIcons, int[][] qsIcons, int[] contentDesc,
|
public IconGroup(
|
||||||
int sbNullState, int qsNullState, int sbDiscState, int qsDiscState,
|
String name,
|
||||||
int discContentDesc) {
|
int[][] sbIcons,
|
||||||
|
int[][] qsIcons,
|
||||||
|
int[] contentDesc,
|
||||||
|
int sbNullState,
|
||||||
|
int qsNullState,
|
||||||
|
int sbDiscState,
|
||||||
|
int qsDiscState,
|
||||||
|
int discContentDesc
|
||||||
|
) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.sbIcons = sbIcons;
|
this.sbIcons = sbIcons;
|
||||||
this.qsIcons = qsIcons;
|
this.qsIcons = qsIcons;
|
||||||
@@ -131,6 +141,19 @@ public class SignalIcon {
|
|||||||
&& other.activityOut == activityOut
|
&& other.activityOut == activityOut
|
||||||
&& other.rssi == rssi;
|
&& 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 dataContentDescription; // mContentDescriptionDataType
|
||||||
public final int dataType;
|
public final int dataType;
|
||||||
|
|
||||||
public MobileIconGroup(String name, int[][] sbIcons, int[][] qsIcons, int[] contentDesc,
|
public MobileIconGroup(
|
||||||
int sbNullState, int qsNullState, int sbDiscState, int qsDiscState,
|
String name,
|
||||||
int discContentDesc, int dataContentDesc, int dataType) {
|
int[][] sbIcons,
|
||||||
super(name, sbIcons, qsIcons, contentDesc, sbNullState, qsNullState, sbDiscState,
|
int[][] qsIcons,
|
||||||
qsDiscState, discContentDesc);
|
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.dataContentDescription = dataContentDesc;
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
}
|
}
|
||||||
@@ -183,6 +223,22 @@ public class SignalIcon {
|
|||||||
defaultDataOff = state.defaultDataOff;
|
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
|
@Override
|
||||||
protected void toString(StringBuilder builder) {
|
protected void toString(StringBuilder builder) {
|
||||||
super.toString(builder);
|
super.toString(builder);
|
||||||
@@ -204,17 +260,33 @@ public class SignalIcon {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return super.equals(o)
|
return super.equals(o)
|
||||||
&& Objects.equals(((MobileState) o).networkName, networkName)
|
&& Objects.equals(((MobileState) o).networkName, networkName)
|
||||||
&& Objects.equals(((MobileState) o).networkNameData, networkNameData)
|
&& Objects.equals(((MobileState) o).networkNameData, networkNameData)
|
||||||
&& ((MobileState) o).dataSim == dataSim
|
&& ((MobileState) o).dataSim == dataSim
|
||||||
&& ((MobileState) o).dataConnected == dataConnected
|
&& ((MobileState) o).dataConnected == dataConnected
|
||||||
&& ((MobileState) o).isEmergency == isEmergency
|
&& ((MobileState) o).isEmergency == isEmergency
|
||||||
&& ((MobileState) o).airplaneMode == airplaneMode
|
&& ((MobileState) o).airplaneMode == airplaneMode
|
||||||
&& ((MobileState) o).carrierNetworkChangeMode == carrierNetworkChangeMode
|
&& ((MobileState) o).carrierNetworkChangeMode == carrierNetworkChangeMode
|
||||||
&& ((MobileState) o).userSetup == userSetup
|
&& ((MobileState) o).userSetup == userSetup
|
||||||
&& ((MobileState) o).isDefault == isDefault
|
&& ((MobileState) o).isDefault == isDefault
|
||||||
&& ((MobileState) o).roaming == roaming
|
&& ((MobileState) o).roaming == roaming
|
||||||
&& ((MobileState) o).defaultDataOff == defaultDataOff;
|
&& ((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;
|
private int mImsType = IMS_TYPE_WWAN;
|
||||||
// Save entire info for logging, we only use the id.
|
// Save entire info for logging, we only use the id.
|
||||||
final SubscriptionInfo mSubscriptionInfo;
|
final SubscriptionInfo mSubscriptionInfo;
|
||||||
// @VisibleForDemoMode
|
private Map<String, MobileIconGroup> mNetworkToIconLookup;
|
||||||
Map<String, MobileIconGroup> mNetworkToIconLookup;
|
|
||||||
|
|
||||||
// Since some pieces of the phone state are interdependent we store it locally,
|
// Since some pieces of the phone state are interdependent we store it locally,
|
||||||
// this could potentially become part of MobileState for simplification/complication
|
// 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) {
|
if (mCurrentState.inetCondition == 0) {
|
||||||
dataContentDescription = mContext.getString(R.string.data_connection_no_internet);
|
dataContentDescription = mContext.getString(R.string.data_connection_no_internet);
|
||||||
}
|
}
|
||||||
final boolean dataDisabled = (mCurrentState.iconGroup == TelephonyIcons.DATA_DISABLED
|
|
||||||
|| (mCurrentState.iconGroup == TelephonyIcons.NOT_DEFAULT_DATA))
|
final boolean dataDisabled = mCurrentState.isDataDisabledOrNotDefault();
|
||||||
&& mCurrentState.userSetup;
|
|
||||||
|
|
||||||
if (mProviderModelBehavior) {
|
if (mProviderModelBehavior) {
|
||||||
// Show icon in QS when we are connected or data is disabled.
|
// 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);
|
&& !mCurrentState.isEmergency, getQsCurrentIconId(), contentDescription);
|
||||||
description = mCurrentState.isEmergency ? null : mCurrentState.networkName;
|
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;
|
showDataIcon &= mCurrentState.dataSim && mCurrentState.isDefault;
|
||||||
boolean showTriangle = showDataIcon && !mCurrentState.airplaneMode;
|
boolean showTriangle = showDataIcon && !mCurrentState.airplaneMode;
|
||||||
int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.dataType : 0;
|
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,
|
IconState statusIcon = new IconState(showDataIcon && !mCurrentState.airplaneMode,
|
||||||
getCurrentIconId(), contentDescription);
|
getCurrentIconId(), contentDescription);
|
||||||
MobileDataIndicators mobileDataIndicators = new MobileDataIndicators(
|
MobileDataIndicators mobileDataIndicators = new MobileDataIndicators(
|
||||||
statusIcon, qsIcon, typeIcon, qsTypeIcon,
|
statusIcon,
|
||||||
activityIn, activityOut, dataContentDescription, dataContentDescriptionHtml,
|
qsIcon,
|
||||||
description, mSubscriptionInfo.getSubscriptionId(),
|
typeIcon,
|
||||||
mCurrentState.roaming, showTriangle);
|
qsTypeIcon,
|
||||||
|
mCurrentState.hasActivityIn(),
|
||||||
|
mCurrentState.hasActivityOut(),
|
||||||
|
dataContentDescription,
|
||||||
|
dataContentDescriptionHtml,
|
||||||
|
description,
|
||||||
|
mSubscriptionInfo.getSubscriptionId(),
|
||||||
|
mCurrentState.roaming,
|
||||||
|
showTriangle);
|
||||||
callback.setMobileDataIndicators(mobileDataIndicators);
|
callback.setMobileDataIndicators(mobileDataIndicators);
|
||||||
} else {
|
} else {
|
||||||
boolean showDataIcon = mCurrentState.dataConnected || dataDisabled;
|
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;
|
showDataIcon &= mCurrentState.isDefault || dataDisabled;
|
||||||
int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.dataType : 0;
|
int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.dataType : 0;
|
||||||
boolean showTriangle = mCurrentState.enabled && !mCurrentState.airplaneMode;
|
boolean showTriangle = mCurrentState.enabled && !mCurrentState.airplaneMode;
|
||||||
MobileDataIndicators mobileDataIndicators = new MobileDataIndicators(
|
MobileDataIndicators mobileDataIndicators = new MobileDataIndicators(
|
||||||
statusIcon, qsIcon, typeIcon, qsTypeIcon,
|
statusIcon,
|
||||||
activityIn, activityOut, dataContentDescription, dataContentDescriptionHtml,
|
qsIcon,
|
||||||
description, mSubscriptionInfo.getSubscriptionId(),
|
typeIcon,
|
||||||
mCurrentState.roaming, showTriangle);
|
qsTypeIcon,
|
||||||
|
mCurrentState.hasActivityIn(),
|
||||||
|
mCurrentState.hasActivityOut(),
|
||||||
|
dataContentDescription,
|
||||||
|
dataContentDescriptionHtml,
|
||||||
|
description,
|
||||||
|
mSubscriptionInfo.getSubscriptionId(),
|
||||||
|
mCurrentState.roaming,
|
||||||
|
showTriangle);
|
||||||
callback.setMobileDataIndicators(mobileDataIndicators);
|
callback.setMobileDataIndicators(mobileDataIndicators);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user