diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index ec6f747db8f3e..6cea9b3355dce 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -5567,6 +5567,10 @@ public class StatusBar extends SystemUI implements DemoMode, private Set mNonBlockablePkgs; + public boolean isDeviceInteractive() { + return mDeviceInteractive; + } + @Override // NotificationData.Environment public boolean isDeviceProvisioned() { return mDeviceProvisionedController.isDeviceProvisioned(); diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java index eaad2f9bd4578..103eb6ec927f7 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java @@ -48,8 +48,10 @@ import android.view.accessibility.AccessibilityManager; import com.android.internal.annotations.GuardedBy; import com.android.systemui.Dumpable; import com.android.systemui.R; +import com.android.systemui.SysUiServiceProvider; import com.android.systemui.plugins.VolumeDialogController; import com.android.systemui.qs.tiles.DndTile; +import com.android.systemui.statusbar.phone.StatusBar; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -89,11 +91,12 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa private final W mWorker; private final Context mContext; private AudioManager mAudio; + protected StatusBar mStatusBar; private final NotificationManager mNoMan; private final SettingObserver mObserver; private final Receiver mReceiver = new Receiver(); private final MediaSessions mMediaSessions; - private final C mCallbacks = new C(); + protected C mCallbacks = new C(); private final State mState = new State(); private final MediaSessionsCallbacks mMediaSessionsCallbacksW = new MediaSessionsCallbacks(); private final Vibrator mVibrator; @@ -123,6 +126,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa mReceiver.init(); mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); mHasVibrator = mVibrator != null && mVibrator.hasVibrator(); + updateStatusBar(); boolean accessibilityVolumeStreamActive = context.getSystemService( AccessibilityManager.class).isAccessibilityVolumeStreamActive(); @@ -326,8 +330,17 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa return changed; } - private boolean onVolumeChangedW(int stream, int flags) { - final boolean showUI = (flags & AudioManager.FLAG_SHOW_UI) != 0; + private void updateStatusBar() { + if (mStatusBar == null) { + mStatusBar = SysUiServiceProvider.getComponent(mContext, StatusBar.class); + } + } + + boolean onVolumeChangedW(int stream, int flags) { + updateStatusBar(); + + final boolean showUI = (mStatusBar != null && mStatusBar.isDeviceInteractive()) && + ((flags & AudioManager.FLAG_SHOW_UI) != 0); final boolean fromKey = (flags & AudioManager.FLAG_FROM_KEY) != 0; final boolean showVibrateHint = (flags & AudioManager.FLAG_SHOW_VIBRATE_HINT) != 0; final boolean showSilentHint = (flags & AudioManager.FLAG_SHOW_SILENT_HINT) != 0; @@ -638,7 +651,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa } } - private final class C implements Callbacks { + class C implements Callbacks { private final HashMap mCallbackMap = new HashMap<>(); public void add(Callbacks callback, Handler handler) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java new file mode 100644 index 0000000000000..8060f5beb9b24 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java @@ -0,0 +1,70 @@ +/* + * 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.volume; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.media.AudioManager; +import android.support.test.filters.SmallTest; +import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.phone.StatusBar; + +import org.junit.Before; +import org.junit.Test; + +@SmallTest +public class VolumeDialogControllerImplTest extends SysuiTestCase { + + TestableVolumeDialogControllerImpl mVolumeController; + VolumeDialogControllerImpl.C mCallback; + StatusBar mStatusBar; + + @Before + public void setup() throws Exception { + mCallback = mock(VolumeDialogControllerImpl.C.class); + mStatusBar = mock(StatusBar.class); + mVolumeController = new TestableVolumeDialogControllerImpl(mContext, mCallback, mStatusBar); + } + + @Test + public void testVolumeChangeW_deviceNotInteractiveAOD() { + when(mStatusBar.isDeviceInteractive()).thenReturn(false); + mVolumeController.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI); + verify(mCallback, never()).onShowRequested(Events.SHOW_REASON_VOLUME_CHANGED); + } + + @Test + public void testVolumeChangeW_deviceInteractive() { + when(mStatusBar.isDeviceInteractive()).thenReturn(true); + mVolumeController.onVolumeChangedW(0, AudioManager.FLAG_SHOW_UI); + verify(mCallback, times(1)).onShowRequested(Events.SHOW_REASON_VOLUME_CHANGED); + } + + static class TestableVolumeDialogControllerImpl extends VolumeDialogControllerImpl { + public TestableVolumeDialogControllerImpl(Context context, C callback, StatusBar s) { + super(context); + mCallbacks = callback; + mStatusBar = s; + } + } + +}