Don't create one-handed-background-panel after rotation

From code flow, when onConfigurationChanged() by rotating
OneHandedBackgroundPanelOrganizer#showBackgroundPanelLayer()
will be invoked and then create one-handed-background-panel
even though OHM is not activated.
Besides, this could introduce overhead on SF.

Test: manual rotate and dumpsys check HWC layers
Test: atest WMShellUnitTests
Bug: 196306312
Change-Id: Ia766078d5c76b08ab5b24e0ce965ad1d085e4686
This commit is contained in:
Bill Lin
2021-08-12 14:11:25 +08:00
parent 3904d7eef7
commit 27da5b04d4
3 changed files with 36 additions and 1 deletions

View File

@@ -16,6 +16,8 @@
package com.android.wm.shell.onehanded;
import static com.android.wm.shell.onehanded.OneHandedState.STATE_ACTIVE;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
@@ -46,7 +48,7 @@ import java.util.concurrent.Executor;
* the screen has entered one handed mode.
*/
public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
implements OneHandedAnimationCallback {
implements OneHandedAnimationCallback, OneHandedState.OnStateChangedListener {
private static final String TAG = "OneHandedBackgroundPanelOrganizer";
private static final int THEME_COLOR_OFFSET = 10;
private static final int ALPHA_ANIMATION_DURATION = 200;
@@ -56,6 +58,7 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
private final OneHandedSurfaceTransactionHelper.SurfaceControlTransactionFactory
mTransactionFactory;
private @OneHandedState.State int mCurrentState;
private ValueAnimator mAlphaAnimator;
private float mTranslationFraction;
@@ -180,6 +183,9 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
* Called when transition finished.
*/
public void onStopFinished() {
if (mAlphaAnimator == null) {
return;
}
mAlphaAnimator.start();
}
@@ -224,6 +230,10 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
*/
public void onConfigurationChanged() {
updateThemeColors();
if (mCurrentState != STATE_ACTIVE) {
return;
}
showBackgroundPanelLayer();
}
@@ -242,6 +252,11 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
return Math.max(origColor - THEME_COLOR_OFFSET, 0) / 255.0f;
}
@Override
public void onStateChanged(int newState) {
mCurrentState = newState;
}
void dump(@NonNull PrintWriter pw) {
final String innerPrefix = " ";
pw.println(TAG);

View File

@@ -307,6 +307,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
mAccessibilityManager.addAccessibilityStateChangeListener(
mAccessibilityStateChangeListener);
mState.addSListeners(mBackgroundPanelOrganizer);
mState.addSListeners(mTutorialHandler);
}

View File

@@ -19,6 +19,9 @@ package com.android.wm.shell.onehanded;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.window.DisplayAreaOrganizer.FEATURE_ONE_HANDED_BACKGROUND_PANEL;
import static com.android.wm.shell.onehanded.OneHandedState.STATE_ACTIVE;
import static com.android.wm.shell.onehanded.OneHandedState.STATE_NONE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -109,4 +112,20 @@ public class OneHandedBackgroundPanelOrganizerTest extends OneHandedTestCase {
assertThat(mSpiedBackgroundPanelOrganizer.mBackgroundSurface).isNull();
}
@Test
public void testStateNone_onConfigurationChanged() {
mSpiedBackgroundPanelOrganizer.onStateChanged(STATE_NONE);
mSpiedBackgroundPanelOrganizer.onConfigurationChanged();
verify(mSpiedBackgroundPanelOrganizer, never()).showBackgroundPanelLayer();
}
@Test
public void testStateActivate_onConfigurationChanged() {
mSpiedBackgroundPanelOrganizer.onStateChanged(STATE_ACTIVE);
mSpiedBackgroundPanelOrganizer.onConfigurationChanged();
verify(mSpiedBackgroundPanelOrganizer).showBackgroundPanelLayer();
}
}