diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java index a73cad7d2c6d6..df4bbcfc46bb4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java @@ -321,7 +321,7 @@ public class KeyguardStatusBarView extends RelativeLayout { } } - public void setKeyguardUserSwitcherEnabled(boolean enabled) { + void setKeyguardUserSwitcherEnabled(boolean enabled) { mKeyguardUserSwitcherEnabled = enabled; } @@ -475,8 +475,10 @@ public class KeyguardStatusBarView extends RelativeLayout { /** * Set the clipping on the top of the view. + * + * Should only be called from {@link KeyguardStatusBarViewController}. */ - public void setTopClipping(int topClipping) { + void setTopClipping(int topClipping) { if (topClipping != mTopClipping) { mTopClipping = topClipping; updateClipping(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java index 8770e86df7351..25294165b3756 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java @@ -183,6 +183,11 @@ public class KeyguardStatusBarViewController extends ViewController { + mKeyguardStatusBarView = + (KeyguardStatusBarView) LayoutInflater.from(mContext) + .inflate(R.layout.keyguard_status_bar, null); + }); mController = new KeyguardStatusBarViewController( mKeyguardStatusBarView, @@ -133,4 +139,27 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase { verify(mBatteryController).addCallback(any()); } + + @Test + public void updateTopClipping_viewClippingUpdated() { + int viewTop = 20; + mKeyguardStatusBarView.setTop(viewTop); + int notificationPanelTop = 30; + + mController.updateTopClipping(notificationPanelTop); + + assertThat(mKeyguardStatusBarView.getClipBounds().top).isEqualTo( + notificationPanelTop - viewTop); + } + + @Test + public void setNotTopClipping_viewClippingUpdatedToZero() { + // Start out with some amount of top clipping. + mController.updateTopClipping(50); + assertThat(mKeyguardStatusBarView.getClipBounds().top).isGreaterThan(0); + + mController.setNoTopClipping(); + + assertThat(mKeyguardStatusBarView.getClipBounds().top).isEqualTo(0); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewTest.java new file mode 100644 index 0000000000000..3108ed9e7b98d --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewTest.java @@ -0,0 +1,59 @@ +/* + * 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.systemui.statusbar.phone; + +import static com.google.common.truth.Truth.assertThat; + +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; + +@SmallTest +@RunWith(AndroidTestingRunner.class) +@TestableLooper.RunWithLooper +public class KeyguardStatusBarViewTest extends SysuiTestCase { + + private KeyguardStatusBarView mKeyguardStatusBarView; + + @Before + public void setup() throws Exception { + allowTestableLooperAsMainThread(); + TestableLooper.get(this).runWithLooper(() -> { + mKeyguardStatusBarView = + (KeyguardStatusBarView) LayoutInflater.from(mContext) + .inflate(R.layout.keyguard_status_bar, null); + }); + } + + @Test + public void setTopClipping_clippingUpdated() { + int topClipping = 40; + + mKeyguardStatusBarView.setTopClipping(topClipping); + + assertThat(mKeyguardStatusBarView.getClipBounds().top).isEqualTo(topClipping); + } +}