summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabian Kozynski <kozynski@google.com> 2020-02-19 14:16:40 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-02-19 14:16:40 +0000
commit8698901a7624d3b67a74fc03e127ddb55aac1296 (patch)
tree44bb12e56abcb58a01a062da82f2078a68c0686a
parent9b01e486fdebd4160b602f0e83196444fe289e09 (diff)
parent00afd49556b4a73fd1717c5f0919d4a8703c46ae (diff)
Merge "Properly check for changes in CellSignalState"
-rw-r--r--packages/SystemUI/res/layout/qs_carrier.xml4
-rw-r--r--packages/SystemUI/res/layout/qs_carrier_group.xml4
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java1
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeaderController.java1
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/carrier/CellSignalState.kt43
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrier.java (renamed from packages/SystemUI/src/com/android/systemui/qs/QSCarrier.java)17
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroup.java (renamed from packages/SystemUI/src/com/android/systemui/qs/QSCarrierGroup.java)4
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroupController.java (renamed from packages/SystemUI/src/com/android/systemui/qs/QSCarrierGroupController.java)57
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/carrier/CellSignalStateTest.kt48
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierGroupControllerTest.java (renamed from packages/SystemUI/tests/src/com/android/systemui/qs/QSCarrierGroupControllerTest.java)4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierTest.java76
11 files changed, 203 insertions, 56 deletions
diff --git a/packages/SystemUI/res/layout/qs_carrier.xml b/packages/SystemUI/res/layout/qs_carrier.xml
index 28b2d21d0043..a5b8cfa5d60b 100644
--- a/packages/SystemUI/res/layout/qs_carrier.xml
+++ b/packages/SystemUI/res/layout/qs_carrier.xml
@@ -14,7 +14,7 @@
~ limitations under the License
-->
-<com.android.systemui.qs.QSCarrier
+<com.android.systemui.qs.carrier.QSCarrier
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_carrier"
android:layout_width="wrap_content"
@@ -46,4 +46,4 @@
android:singleLine="true"
android:maxEms="7"/>
-</com.android.systemui.qs.QSCarrier> \ No newline at end of file
+</com.android.systemui.qs.carrier.QSCarrier> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout/qs_carrier_group.xml b/packages/SystemUI/res/layout/qs_carrier_group.xml
index f2b0606979cc..fd53a8bb1a7c 100644
--- a/packages/SystemUI/res/layout/qs_carrier_group.xml
+++ b/packages/SystemUI/res/layout/qs_carrier_group.xml
@@ -15,7 +15,7 @@
-->
<!-- Extends LinearLayout -->
-<com.android.systemui.qs.QSCarrierGroup
+<com.android.systemui.qs.carrier.QSCarrierGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/qs_mobile"
android:layout_width="0dp"
@@ -71,4 +71,4 @@
android:layout_weight="1"
android:visibility="gone"/>
-</com.android.systemui.qs.QSCarrierGroup> \ No newline at end of file
+</com.android.systemui.qs.carrier.QSCarrierGroup> \ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java
index 8cd70cf63b8e..9fdfbfb39625 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java
@@ -60,6 +60,7 @@ import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.qs.QSDetail.Callback;
+import com.android.systemui.qs.carrier.QSCarrierGroup;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeaderController.java b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeaderController.java
index 867677a46a58..d899acbade4a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeaderController.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeaderController.java
@@ -17,6 +17,7 @@
package com.android.systemui.qs;
import com.android.systemui.R;
+import com.android.systemui.qs.carrier.QSCarrierGroupController;
import javax.inject.Inject;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/carrier/CellSignalState.kt b/packages/SystemUI/src/com/android/systemui/qs/carrier/CellSignalState.kt
new file mode 100644
index 000000000000..663f3f0e9ddb
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/carrier/CellSignalState.kt
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 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.systemui.qs.carrier
+
+/**
+ * Represents the state of cell signal for a particular slot.
+ *
+ * To be used between [QSCarrierGroupController] and [QSCarrier].
+ */
+data class CellSignalState(
+ @JvmField val visible: Boolean = false,
+ @JvmField val mobileSignalIconId: Int = 0,
+ @JvmField val contentDescription: String? = null,
+ @JvmField val typeContentDescription: String? = null,
+ @JvmField val roaming: Boolean = false
+) {
+ /**
+ * Changes the visibility of this state by returning a copy with the visibility changed.
+ *
+ * If the visibility would not change, the same state is returned.
+ *
+ * @param visible the new visibility state
+ * @return `this` if `this.visible == visible`. Else, a new copy with the visibility changed.
+ */
+ fun changeVisibility(visible: Boolean): CellSignalState {
+ if (this.visible == visible) return this
+ else return copy(visible = visible)
+ }
+} \ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSCarrier.java b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrier.java
index 5a9c360e3104..ad275f1fa6ab 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSCarrier.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrier.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.systemui.qs;
+package com.android.systemui.qs.carrier;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -29,6 +29,7 @@ import com.android.settingslib.Utils;
import com.android.settingslib.graph.SignalDrawable;
import com.android.systemui.DualToneHandler;
import com.android.systemui.R;
+import com.android.systemui.qs.QuickStatusBarHeader;
import java.util.Objects;
@@ -41,7 +42,7 @@ public class QSCarrier extends LinearLayout {
private DualToneHandler mDualToneHandler;
private ColorStateList mColorForegroundStateList;
private float mColorForegroundIntensity;
- private QSCarrierGroupController.CellSignalState mLastSignalState;
+ private CellSignalState mLastSignalState;
public QSCarrier(Context context) {
super(context);
@@ -76,8 +77,13 @@ public class QSCarrier extends LinearLayout {
mColorForegroundIntensity = QuickStatusBarHeader.getColorIntensity(colorForeground);
}
- public void updateState(QSCarrierGroupController.CellSignalState state) {
- if (Objects.equals(state, mLastSignalState)) return;
+ /**
+ * Update the state of this view
+ * @param state the current state of the signal for this view
+ * @return true if the state was actually changed
+ */
+ public boolean updateState(CellSignalState state) {
+ if (Objects.equals(state, mLastSignalState)) return false;
mLastSignalState = state;
mMobileGroup.setVisibility(state.visible ? View.VISIBLE : View.GONE);
if (state.visible) {
@@ -103,6 +109,7 @@ public class QSCarrier extends LinearLayout {
}
mMobileSignal.setContentDescription(contentDescription);
}
+ return true;
}
private boolean hasValidTypeContentDescription(String typeContentDescription) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSCarrierGroup.java b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroup.java
index 346c75da6a89..d03563ffb342 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSCarrierGroup.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroup.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.systemui.qs;
+package com.android.systemui.qs.carrier;
import android.content.Context;
import android.util.AttributeSet;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSCarrierGroupController.java b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroupController.java
index eb5b4cc4c0df..f9b14737332b 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSCarrierGroupController.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrierGroupController.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.systemui.qs;
+package com.android.systemui.qs.carrier;
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_YES;
@@ -29,7 +29,6 @@ import android.util.Log;
import android.view.View;
import android.widget.TextView;
-import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.keyguard.CarrierTextController;
@@ -38,7 +37,6 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.policy.NetworkController;
-import java.util.Objects;
import java.util.function.Consumer;
import javax.inject.Inject;
@@ -82,11 +80,13 @@ public class QSCarrierGroupController {
Log.e(TAG, "Invalid SIM slot index for subscription: " + subId);
return;
}
- mInfos[slotIndex].visible = statusIcon.visible;
- mInfos[slotIndex].mobileSignalIconId = statusIcon.icon;
- mInfos[slotIndex].contentDescription = statusIcon.contentDescription;
- mInfos[slotIndex].typeContentDescription = typeContentDescription.toString();
- mInfos[slotIndex].roaming = roaming;
+ mInfos[slotIndex] = new CellSignalState(
+ statusIcon.visible,
+ statusIcon.icon,
+ statusIcon.contentDescription,
+ typeContentDescription.toString(),
+ roaming
+ );
mMainHandler.obtainMessage(H.MSG_UPDATE_STATE).sendToTarget();
}
@@ -94,7 +94,7 @@ public class QSCarrierGroupController {
public void setNoSims(boolean hasNoSims, boolean simDetected) {
if (hasNoSims) {
for (int i = 0; i < SIM_SLOTS; i++) {
- mInfos[i].visible = false;
+ mInfos[i] = mInfos[i].changeVisibility(false);
}
}
mMainHandler.obtainMessage(H.MSG_UPDATE_STATE).sendToTarget();
@@ -236,7 +236,7 @@ public class QSCarrierGroupController {
+ info.subscriptionIds[i]);
continue;
}
- mInfos[slot].visible = true;
+ mInfos[slot] = mInfos[slot].changeVisibility(true);
slotSeen[slot] = true;
mCarrierGroups[slot].setCarrierText(
info.listOfCarriers[i].toString().trim());
@@ -244,7 +244,7 @@ public class QSCarrierGroupController {
}
for (int i = 0; i < SIM_SLOTS; i++) {
if (!slotSeen[i]) {
- mInfos[i].visible = false;
+ mInfos[i] = mInfos[i].changeVisibility(false);
mCarrierGroups[i].setVisibility(View.GONE);
}
}
@@ -255,7 +255,7 @@ public class QSCarrierGroupController {
// No sims or airplane mode (but not WFC). Do not show QSCarrierGroup, instead just show
// info.carrierText in a different view.
for (int i = 0; i < SIM_SLOTS; i++) {
- mInfos[i].visible = false;
+ mInfos[i] = mInfos[i].changeVisibility(false);
mCarrierGroups[i].setCarrierText("");
mCarrierGroups[i].setVisibility(View.GONE);
}
@@ -295,35 +295,6 @@ public class QSCarrierGroupController {
}
}
- static final class CellSignalState {
- boolean visible;
- int mobileSignalIconId;
- String contentDescription;
- String typeContentDescription;
- boolean roaming;
-
- @Override
- public boolean equals(@Nullable Object obj) {
- if (this == obj) return true;
- if (!(obj instanceof CellSignalState)) return false;
- CellSignalState other = (CellSignalState) obj;
- return this.visible == other.visible
- && this.mobileSignalIconId == other.mobileSignalIconId
- && Objects.equals(this.contentDescription, other.contentDescription)
- && Objects.equals(this.typeContentDescription, other.typeContentDescription)
- && this.roaming == other.roaming;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(visible,
- mobileSignalIconId,
- contentDescription,
- typeContentDescription,
- roaming);
- }
- }
-
public static class Builder {
private QSCarrierGroup mView;
private final ActivityStarter mActivityStarter;
@@ -343,7 +314,7 @@ public class QSCarrierGroupController {
mCarrierTextControllerBuilder = carrierTextControllerBuilder;
}
- Builder setQSCarrierGroup(QSCarrierGroup view) {
+ public Builder setQSCarrierGroup(QSCarrierGroup view) {
mView = view;
return this;
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/CellSignalStateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/CellSignalStateTest.kt
new file mode 100644
index 000000000000..75be74b13c87
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/CellSignalStateTest.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2020 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.systemui.qs.carrier
+
+import android.testing.AndroidTestingRunner
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import org.junit.Assert.assertNotSame
+import org.junit.Assert.assertSame
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidTestingRunner::class)
+@SmallTest
+class CellSignalStateTest : SysuiTestCase() {
+
+ @Test
+ fun testChangeVisibility_sameObject() {
+ val c = CellSignalState()
+
+ val other = c.changeVisibility(c.visible)
+
+ assertSame(c, other)
+ }
+
+ @Test
+ fun testChangeVisibility_otherObject() {
+ val c = CellSignalState()
+
+ val other = c.changeVisibility(!c.visible)
+
+ assertNotSame(c, other)
+ }
+} \ No newline at end of file
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSCarrierGroupControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierGroupControllerTest.java
index 715087dcd2b1..fa02231426ac 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSCarrierGroupControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierGroupControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.systemui.qs;
+package com.android.systemui.qs.carrier;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierTest.java
new file mode 100644
index 000000000000..022dc847130d
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2020 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.systemui.qs.carrier;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.view.LayoutInflater;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.systemui.R;
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+@SmallTest
+public class QSCarrierTest extends SysuiTestCase {
+
+ private QSCarrier mQSCarrier;
+ private TestableLooper mTestableLooper;
+
+ @Before
+ public void setUp() throws Exception {
+ mTestableLooper = TestableLooper.get(this);
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ mTestableLooper.runWithLooper(() ->
+ mQSCarrier = (QSCarrier) inflater.inflate(R.layout.qs_carrier, null));
+ }
+
+ @Test
+ public void testUpdateState_first() {
+ CellSignalState c = new CellSignalState(true, 0, "", "", false);
+
+ assertTrue(mQSCarrier.updateState(c));
+ }
+
+ @Test
+ public void testUpdateState_same() {
+ CellSignalState c = new CellSignalState(true, 0, "", "", false);
+
+ assertTrue(mQSCarrier.updateState(c));
+ assertFalse(mQSCarrier.updateState(c));
+ }
+
+ @Test
+ public void testUpdateState_changed() {
+ CellSignalState c = new CellSignalState(true, 0, "", "", false);
+
+ assertTrue(mQSCarrier.updateState(c));
+
+ CellSignalState other = c.changeVisibility(false);
+
+ assertTrue(mQSCarrier.updateState(other));
+ }
+}