Add tests for HDMI-CEC statsd atom logging
Test: atest HdmiCecAtomLoggingTest Change-Id: I63b3641ef202779b95404af75e2e1d821f5b4d76
This commit is contained in:
@@ -18,9 +18,14 @@ package com.android.server.hdmi;
|
||||
|
||||
import android.stats.hdmi.HdmiStatsEnums;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.FrameworkStatsLog;
|
||||
|
||||
class HdmiCecAtomWriter {
|
||||
/**
|
||||
* Provides methods for writing HDMI-CEC statsd atoms.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public class HdmiCecAtomWriter {
|
||||
|
||||
private static final int FEATURE_ABORT_OPCODE_UNKNOWN = 0x100;
|
||||
private static final int ERROR_CODE_UNKNOWN = -1;
|
||||
|
||||
@@ -635,7 +635,7 @@ final class HdmiCecController {
|
||||
*/
|
||||
private int incomingMessageDirection(int srcAddress, int dstAddress) {
|
||||
boolean sourceIsLocal = false;
|
||||
boolean destinationIsLocal = false;
|
||||
boolean destinationIsLocal = dstAddress == Constants.ADDR_BROADCAST;
|
||||
for (HdmiCecLocalDevice localDevice : mService.getHdmiCecNetwork().getLocalDeviceList()) {
|
||||
int logicalAddress = localDevice.getDeviceInfo().getLogicalAddress();
|
||||
if (logicalAddress == srcAddress) {
|
||||
|
||||
@@ -59,7 +59,8 @@ import java.util.concurrent.ArrayBlockingQueue;
|
||||
* Note that the information cached in this class is not guaranteed to be up-to-date, especially OSD
|
||||
* names, power states can be outdated.
|
||||
*/
|
||||
class HdmiCecNetwork {
|
||||
@VisibleForTesting
|
||||
public class HdmiCecNetwork {
|
||||
private static final String TAG = "HdmiCecNetwork";
|
||||
|
||||
protected final Object mLock;
|
||||
|
||||
@@ -564,7 +564,8 @@ public class HdmiControlService extends SystemService {
|
||||
mTvInputManager.unregisterCallback(callback);
|
||||
}
|
||||
|
||||
PowerManager getPowerManager() {
|
||||
@VisibleForTesting
|
||||
protected PowerManager getPowerManager() {
|
||||
return mPowerManager;
|
||||
}
|
||||
|
||||
@@ -729,7 +730,8 @@ public class HdmiControlService extends SystemService {
|
||||
Global.putInt(cr, key, toInt(value));
|
||||
}
|
||||
|
||||
void writeStringSystemProperty(String key, String value) {
|
||||
@VisibleForTesting
|
||||
protected void writeStringSystemProperty(String key, String value) {
|
||||
SystemProperties.set(key, value);
|
||||
}
|
||||
|
||||
@@ -3366,7 +3368,7 @@ public class HdmiControlService extends SystemService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
HdmiCecAtomWriter getAtomWriter() {
|
||||
protected HdmiCecAtomWriter getAtomWriter() {
|
||||
return mAtomWriter;
|
||||
}
|
||||
|
||||
@@ -3395,7 +3397,8 @@ public class HdmiControlService extends SystemService {
|
||||
HdmiControlService.PERMISSION);
|
||||
}
|
||||
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
@VisibleForTesting
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return mHdmiCecConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,17 +98,17 @@ public class ActiveSourceActionTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
PowerManager getPowerManager() {
|
||||
protected PowerManager getPowerManager() {
|
||||
return powerManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeStringSystemProperty(String key, String value) {
|
||||
protected void writeStringSystemProperty(String key, String value) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ArcInitiationActionFromAvrTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
PowerManager getPowerManager() {
|
||||
protected PowerManager getPowerManager() {
|
||||
return powerManager;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public class ArcInitiationActionFromAvrTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ArcTerminationActionFromAvrTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
PowerManager getPowerManager() {
|
||||
protected PowerManager getPowerManager() {
|
||||
return powerManager;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class ArcTerminationActionFromAvrTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.server.hdmi;
|
||||
|
||||
import static com.android.server.hdmi.Constants.ADDR_PLAYBACK_1;
|
||||
import static com.android.server.hdmi.Constants.ADDR_TV;
|
||||
import static com.android.server.hdmi.Constants.PATH_RELATIONSHIP_ANCESTOR;
|
||||
import static com.android.server.hdmi.HdmiControlService.INITIATED_BY_ENABLE_CEC;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.hardware.hdmi.HdmiPortInfo;
|
||||
import android.hardware.tv.cec.V1_0.SendMessageResult;
|
||||
import android.os.Handler;
|
||||
import android.os.IPowerManager;
|
||||
import android.os.IThermalService;
|
||||
import android.os.Looper;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.test.TestLooper;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.stats.hdmi.nano.HdmiStatsEnums;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.server.SystemService;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests for the {@link HdmiCecAtomWriter} class and its usage by the HDMI-CEC framework.
|
||||
*/
|
||||
@SmallTest
|
||||
@Presubmit
|
||||
@RunWith(JUnit4.class)
|
||||
public class HdmiCecAtomLoggingTest {
|
||||
private HdmiCecAtomWriter mHdmiCecAtomWriterSpy;
|
||||
private HdmiControlService mHdmiControlServiceSpy;
|
||||
private HdmiCecController mHdmiCecController;
|
||||
private HdmiCecLocalDevicePlayback mHdmiCecLocalDevicePlayback;
|
||||
private HdmiMhlControllerStub mHdmiMhlControllerStub;
|
||||
private FakeNativeWrapper mNativeWrapper;
|
||||
private HdmiCecNetwork mHdmiCecNetwork;
|
||||
private Looper mLooper;
|
||||
private TestLooper mTestLooper = new TestLooper();
|
||||
private int mPhysicalAddress = 0x1110;
|
||||
private ArrayList<HdmiCecLocalDevice> mLocalDevices = new ArrayList<>();
|
||||
private HdmiPortInfo[] mHdmiPortInfo;
|
||||
|
||||
@Mock private IPowerManager mIPowerManagerMock;
|
||||
@Mock private IThermalService mIThermalServiceMock;
|
||||
|
||||
@Before
|
||||
public void setUp() throws RemoteException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mHdmiCecAtomWriterSpy = spy(new HdmiCecAtomWriter());
|
||||
|
||||
mLooper = mTestLooper.getLooper();
|
||||
|
||||
Context mContextSpy = spy(new ContextWrapper(
|
||||
InstrumentationRegistry.getInstrumentation().getTargetContext()));
|
||||
|
||||
PowerManager powerManager = new PowerManager(
|
||||
mContextSpy, mIPowerManagerMock, mIThermalServiceMock, new Handler(mLooper));
|
||||
doReturn(powerManager).when(mContextSpy).getSystemService(Context.POWER_SERVICE);
|
||||
doReturn(true).when(mIPowerManagerMock).isInteractive();
|
||||
|
||||
mHdmiControlServiceSpy = spy(new HdmiControlService(mContextSpy));
|
||||
doNothing().when(mHdmiControlServiceSpy)
|
||||
.writeStringSystemProperty(anyString(), anyString());
|
||||
doReturn(mHdmiCecAtomWriterSpy).when(mHdmiControlServiceSpy).getAtomWriter();
|
||||
|
||||
HdmiCecConfig hdmiCecConfig = new FakeHdmiCecConfig(mContextSpy);
|
||||
doReturn(hdmiCecConfig).when(mHdmiControlServiceSpy).getHdmiCecConfig();
|
||||
|
||||
mHdmiControlServiceSpy.setIoLooper(mLooper);
|
||||
mHdmiControlServiceSpy.setMessageValidator(
|
||||
new HdmiCecMessageValidator(mHdmiControlServiceSpy));
|
||||
mHdmiControlServiceSpy.setCecMessageBuffer(
|
||||
new CecMessageBuffer(mHdmiControlServiceSpy));
|
||||
|
||||
mNativeWrapper = new FakeNativeWrapper();
|
||||
mNativeWrapper.setPhysicalAddress(mPhysicalAddress);
|
||||
|
||||
mHdmiCecController = HdmiCecController.createWithNativeWrapper(
|
||||
mHdmiControlServiceSpy, mNativeWrapper, mHdmiCecAtomWriterSpy);
|
||||
mHdmiControlServiceSpy.setCecController(mHdmiCecController);
|
||||
|
||||
mHdmiMhlControllerStub = HdmiMhlControllerStub.create(mHdmiControlServiceSpy);
|
||||
mHdmiControlServiceSpy.setHdmiMhlController(
|
||||
mHdmiMhlControllerStub);
|
||||
|
||||
mHdmiCecNetwork = new HdmiCecNetwork(mHdmiControlServiceSpy,
|
||||
mHdmiCecController, mHdmiMhlControllerStub);
|
||||
mHdmiControlServiceSpy.setHdmiCecNetwork(mHdmiCecNetwork);
|
||||
|
||||
HdmiPortInfo[] hdmiPortInfos = new HdmiPortInfo[1];
|
||||
hdmiPortInfos[0] =
|
||||
new HdmiPortInfo(1, HdmiPortInfo.PORT_OUTPUT, 0x0000, true, false, false);
|
||||
mNativeWrapper.setPortInfo(hdmiPortInfos);
|
||||
mNativeWrapper.setPortConnectionStatus(1, true);
|
||||
|
||||
mHdmiCecLocalDevicePlayback = new HdmiCecLocalDevicePlayback(mHdmiControlServiceSpy);
|
||||
mHdmiCecLocalDevicePlayback.init();
|
||||
mLocalDevices.add(mHdmiCecLocalDevicePlayback);
|
||||
|
||||
mHdmiControlServiceSpy.initService();
|
||||
mHdmiControlServiceSpy.allocateLogicalAddress(mLocalDevices, INITIATED_BY_ENABLE_CEC);
|
||||
mHdmiControlServiceSpy.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
|
||||
|
||||
mTestLooper.dispatchAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActiveSourceChanged_calledOnSetActiveSource() {
|
||||
mHdmiControlServiceSpy.setActiveSource(1, 0x1111, "caller");
|
||||
verify(mHdmiCecAtomWriterSpy, times(1))
|
||||
.activeSourceChanged(1, 0x1111, PATH_RELATIONSHIP_ANCESTOR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageReported_calledOnOutgoingMessage() {
|
||||
HdmiCecMessage message = HdmiCecMessageBuilder.buildActiveSource(ADDR_PLAYBACK_1,
|
||||
mPhysicalAddress);
|
||||
|
||||
mHdmiCecController.sendCommand(message);
|
||||
|
||||
verify(mHdmiCecAtomWriterSpy, times(1)).messageReported(
|
||||
message,
|
||||
HdmiStatsEnums.OUTGOING,
|
||||
SendMessageResult.SUCCESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageReported_calledOnIncomingMessage() {
|
||||
HdmiCecMessage message = HdmiCecMessageBuilder.buildActiveSource(ADDR_TV, 0x0000);
|
||||
|
||||
mNativeWrapper.onCecMessage(message);
|
||||
mTestLooper.dispatchAll();
|
||||
|
||||
verify(mHdmiCecAtomWriterSpy, times(1)).messageReported(
|
||||
message,
|
||||
HdmiStatsEnums.INCOMING);
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public class HdmiCecLocalDeviceAudioSystemTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeStringSystemProperty(String key, String value) {
|
||||
protected void writeStringSystemProperty(String key, String value) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -185,12 +185,12 @@ public class HdmiCecLocalDeviceAudioSystemTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
PowerManager getPowerManager() {
|
||||
protected PowerManager getPowerManager() {
|
||||
return powerManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -114,7 +114,7 @@ public class HdmiCecLocalDevicePlaybackTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeStringSystemProperty(String key, String value) {
|
||||
protected void writeStringSystemProperty(String key, String value) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -124,12 +124,12 @@ public class HdmiCecLocalDevicePlaybackTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
PowerManager getPowerManager() {
|
||||
protected PowerManager getPowerManager() {
|
||||
return powerManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -88,17 +88,17 @@ public class HdmiCecLocalDeviceTvTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeStringSystemProperty(String key, String value) {
|
||||
protected void writeStringSystemProperty(String key, String value) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
PowerManager getPowerManager() {
|
||||
protected PowerManager getPowerManager() {
|
||||
return powerManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -95,7 +95,7 @@ public class HdmiCecPowerStatusControllerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeStringSystemProperty(String key, String value) {
|
||||
protected void writeStringSystemProperty(String key, String value) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public class HdmiCecPowerStatusControllerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -151,7 +151,7 @@ public class HdmiControlServiceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -162,7 +162,7 @@ public class SystemAudioInitiationActionFromAvrTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
HdmiCecConfig getHdmiCecConfig() {
|
||||
protected HdmiCecConfig getHdmiCecConfig() {
|
||||
return hdmiCecConfig;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user