From 9d3dcdfe1c15ffa1c8d3694a4f2bf5e2280aa5ba Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Thu, 23 Feb 2017 11:33:54 -0500 Subject: [PATCH] Fix roaming getting stuck after changing sims The header was keeping a map of roaming states which could have stray old subids in it when it shouldn't. It just needs to be cleared when the sims change. Test: runtest systemui Change-Id: I62c5acab5739b9c4acf69a8c7e00b2f75de903dc --- .../statusbar/phone/QuickStatusBarHeader.java | 13 +++ .../statusbar/NotificationMenuRowTest.java | 2 +- .../phone/QuickStatusBarHeaderTest.java | 84 +++++++++++++++++++ .../systemui/utils/TestableLooper.java | 8 +- .../com/android/systemui/utils/ViewUtils.java | 15 ++-- 5 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStatusBarHeaderTest.java diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java index 0e7b2f31cba28..c0708692cb39c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java @@ -29,6 +29,7 @@ import android.graphics.drawable.RippleDrawable; import android.os.UserManager; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; +import android.telephony.SubscriptionInfo; import android.util.AttributeSet; import android.util.SparseBooleanArray; import android.view.View; @@ -64,6 +65,8 @@ import com.android.systemui.statusbar.policy.UserInfoController; import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener; import com.android.systemui.tuner.TunerService; +import java.util.List; + public class QuickStatusBarHeader extends BaseStatusBarHeader implements NextAlarmChangeCallback, OnClickListener, OnUserInfoChangedListener, EmergencyListener, SignalCallback { @@ -440,10 +443,20 @@ public class QuickStatusBarHeader extends BaseStatusBarHeader implements } } + @Override + public void setSubs(List subs) { + mRoamingsBySubId.clear(); + updateRoaming(); + } + public void setMobileDataIndicators(IconState statusIcon, IconState qsIcon, int statusType, int qsType, boolean activityIn, boolean activityOut, String typeContentDescription, String description, boolean isWide, int subId, boolean roaming) { mRoamingsBySubId.put(subId, roaming); + updateRoaming(); + } + + private void updateRoaming() { boolean isRoaming = calculateRoaming(); if (mIsRoaming != isRoaming) { mIsRoaming = isRoaming; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationMenuRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationMenuRowTest.java index 72f6ca8ec7304..b8be4fa57c0fb 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationMenuRowTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationMenuRowTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; @RunWith(SysUIRunner.class) -@RunWithLooper +@RunWithLooper(setAsMainLooper = true) public class NotificationMenuRowTest extends LeakCheckedTest { @Before diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStatusBarHeaderTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStatusBarHeaderTest.java new file mode 100644 index 0000000000000..c55d43452771e --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStatusBarHeaderTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2017 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.statusbar.phone; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.TextView; + +import com.android.systemui.R; +import com.android.systemui.R.layout; +import com.android.systemui.SysUIRunner; +import com.android.systemui.utils.TestableLooper; +import com.android.systemui.utils.TestableLooper.RunWithLooper; +import com.android.systemui.utils.ViewUtils; +import com.android.systemui.utils.leaks.LeakCheckedTest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; + +@RunWith(SysUIRunner.class) +@RunWithLooper(setAsMainLooper = true) +public class QuickStatusBarHeaderTest extends LeakCheckedTest { + + @Before + public void setup() throws NoSuchFieldException, IllegalAccessException { + injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); + } + + @Test + public void testRoamingStuck() throws Exception { + TestableLooper looper = TestableLooper.get(this); + assertEquals(Looper.myLooper(), looper.getLooper()); + assertEquals(Looper.myLooper(), Looper.getMainLooper()); + QuickStatusBarHeader header = (QuickStatusBarHeader) LayoutInflater.from(mContext).inflate( + layout.quick_status_bar_expanded_header, null); + header.setExpanded(true); + + ViewUtils.attachView(header); + looper.processMessages(1); + TextView emergencyText = (TextView) header.findViewById( + R.id.header_emergency_calls_only); + int subId = 0; + header.setMobileDataIndicators(null, null, 0, 0, false, + false, null, null, false, subId, true); + looper.processAllMessages(); + assertEquals(mContext.getString(R.string.accessibility_data_connection_roaming), + emergencyText.getText()); + assertEquals(View.VISIBLE, emergencyText.getVisibility()); + + header.setSubs(new ArrayList<>()); + subId = 1; + header.setMobileDataIndicators(null, null, 0, 0, false, + false, null, null, false, subId, false); + looper.processAllMessages(); + + assertNotEquals(View.VISIBLE, emergencyText.getVisibility()); + assertEquals(Looper.myLooper(), Looper.getMainLooper()); + ViewUtils.detachView(header); + looper.processAllMessages(); + } + +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/utils/TestableLooper.java b/packages/SystemUI/tests/src/com/android/systemui/utils/TestableLooper.java index d27597331aa20..8902e0c23b5f8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/utils/TestableLooper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/utils/TestableLooper.java @@ -244,9 +244,11 @@ public class TestableLooper { mLooper.setAsMainLooper(); } - mBase.evaluate(); - - mLooper.destroy(); + try { + mBase.evaluate(); + } finally { + mLooper.destroy(); + } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/utils/ViewUtils.java b/packages/SystemUI/tests/src/com/android/systemui/utils/ViewUtils.java index 07e5f6663a3f2..678b9f407bcd2 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/utils/ViewUtils.java +++ b/packages/SystemUI/tests/src/com/android/systemui/utils/ViewUtils.java @@ -14,9 +14,11 @@ package com.android.systemui.utils; +import android.content.pm.ApplicationInfo; import android.graphics.PixelFormat; import android.os.Handler; import android.os.Looper; +import android.util.Log; import android.view.View; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; @@ -27,18 +29,19 @@ import com.android.systemui.SysuiTestCase; public class ViewUtils { public static void attachView(View view) { + // Make sure hardware acceleration isn't turned on. + view.getContext().getApplicationInfo().flags &= + ~(ApplicationInfo.FLAG_HARDWARE_ACCELERATED); WindowManager.LayoutParams lp = new WindowManager.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, LayoutParams.TYPE_APPLICATION_OVERLAY, 0, PixelFormat.TRANSLUCENT); - Handler handler = new Handler(Looper.getMainLooper()); - handler.post(() -> InstrumentationRegistry.getContext() - .getSystemService(WindowManager.class).addView(view, lp)); + InstrumentationRegistry.getContext() + .getSystemService(WindowManager.class).addView(view, lp); } public static void detachView(View view) { - Handler handler = new Handler(Looper.getMainLooper()); - handler.post(() -> InstrumentationRegistry.getContext() - .getSystemService(WindowManager.class).removeView(view)); + InstrumentationRegistry.getContext() + .getSystemService(WindowManager.class).removeViewImmediate(view); } }