Fix losing status bar icons on config changes
The DarkIconManager was not correctly calling set when icons were added, leaving them blank after a config change until a new set came in. Do some refactoring to fix this and make it more testable. Test: runtest systemui Change-Id: I0b231021f2ce7d82a3f84ebb281b4e4fc902a0aa Fixes: 35367550
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package com.android.systemui.statusbar.phone;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.view.Gravity;
|
||||
@@ -22,6 +23,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
|
||||
import com.android.internal.statusbar.StatusBarIcon;
|
||||
import com.android.systemui.Dependency;
|
||||
@@ -71,13 +73,18 @@ public interface StatusBarIconController {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIconAdded(int index, String slot, boolean blocked, StatusBarIcon icon) {
|
||||
StatusBarIconView view = new StatusBarIconView(mContext, slot, null, blocked);
|
||||
protected void onIconAdded(int index, String slot, boolean blocked,
|
||||
StatusBarIcon icon) {
|
||||
StatusBarIconView v = addIcon(index, slot, blocked, icon);
|
||||
mDarkIconDispatcher.addDarkReceiver(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LayoutParams onCreateLayoutParams() {
|
||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize);
|
||||
lp.setMargins(mIconHPadding, 0, mIconHPadding, 0);
|
||||
mGroup.addView(view, index, lp);
|
||||
mDarkIconDispatcher.addDarkReceiver(view);
|
||||
return lp;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,11 +123,26 @@ public interface StatusBarIconController {
|
||||
com.android.internal.R.dimen.status_bar_icon_size);
|
||||
}
|
||||
|
||||
protected void onIconAdded(int index, String slot, boolean blocked, StatusBarIcon icon) {
|
||||
StatusBarIconView view = new StatusBarIconView(mContext, slot, null, blocked);
|
||||
protected void onIconAdded(int index, String slot, boolean blocked,
|
||||
StatusBarIcon icon) {
|
||||
addIcon(index, slot, blocked, icon);
|
||||
}
|
||||
|
||||
protected StatusBarIconView addIcon(int index, String slot, boolean blocked,
|
||||
StatusBarIcon icon) {
|
||||
StatusBarIconView view = onCreateStatusBarIconView(slot, blocked);
|
||||
view.set(icon);
|
||||
mGroup.addView(view, index, new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize));
|
||||
mGroup.addView(view, index, onCreateLayoutParams());
|
||||
return view;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected StatusBarIconView onCreateStatusBarIconView(String slot, boolean blocked) {
|
||||
return new StatusBarIconView(mContext, slot, null, blocked);
|
||||
}
|
||||
|
||||
protected LinearLayout.LayoutParams onCreateLayoutParams() {
|
||||
return new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize);
|
||||
}
|
||||
|
||||
protected void destroy() {
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.internal.statusbar.StatusBarIcon;
|
||||
import com.android.systemui.statusbar.StatusBarIconView;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconController.DarkIconManager;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconController.IconManager;
|
||||
import com.android.systemui.statusbar.policy.DarkIconDispatcher;
|
||||
import com.android.systemui.utils.leaks.LeakCheckedTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper
|
||||
public class StatusBarIconControllerTest extends LeakCheckedTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
|
||||
mDependency.injectMockDependency(DarkIconDispatcher.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCalledOnAdd_IconManager() {
|
||||
LinearLayout layout = new LinearLayout(mContext);
|
||||
TestIconManager manager = new TestIconManager(layout);
|
||||
StatusBarIcon icon = mock(StatusBarIcon.class);
|
||||
|
||||
manager.onIconAdded(0, "test_slot", false, icon);
|
||||
verify(manager.mMock).set(eq(icon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCalledOnAdd_DarkIconManager() {
|
||||
LinearLayout layout = new LinearLayout(mContext);
|
||||
TestDarkIconManager manager = new TestDarkIconManager(layout);
|
||||
StatusBarIcon icon = mock(StatusBarIcon.class);
|
||||
|
||||
manager.onIconAdded(0, "test_slot", false, icon);
|
||||
verify(manager.mMock).set(eq(icon));
|
||||
}
|
||||
|
||||
private static class TestDarkIconManager extends DarkIconManager {
|
||||
|
||||
private final StatusBarIconView mMock;
|
||||
|
||||
public TestDarkIconManager(LinearLayout group) {
|
||||
super(group);
|
||||
mMock = mock(StatusBarIconView.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StatusBarIconView onCreateStatusBarIconView(String slot, boolean blocked) {
|
||||
return mMock;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestIconManager extends IconManager {
|
||||
|
||||
private final StatusBarIconView mMock;
|
||||
|
||||
public TestIconManager(ViewGroup group) {
|
||||
super(group);
|
||||
mMock = mock(StatusBarIconView.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StatusBarIconView onCreateStatusBarIconView(String slot, boolean blocked) {
|
||||
return mMock;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user