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

Commit 9ec0f1ec authored by Jason Monk's avatar Jason Monk
Browse files

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: If61b9b5f376daecc49f483b679378c5968a1501c
parent 0a4cf4b5
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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<SubscriptionInfo> 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;
+1 −1
Original line number Diff line number Diff line
@@ -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
+86 −0
Original line number Diff line number Diff line
/*
 * 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.Ignore;
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
    @Ignore("Flaky")
    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();
    }

}
+5 −3
Original line number Diff line number Diff line
@@ -244,11 +244,13 @@ public class TestableLooper {
                mLooper.setAsMainLooper();
            }

            try {
                mBase.evaluate();

            } finally {
                mLooper.destroy();
            }
        }
    }

    public interface MessageHandler {
        /**
+9 −6
Original line number Diff line number Diff line
@@ -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);
    }
}