[CEC Configuration] Add a fake HdmiCecConfig class for testing

Bug: 166426337
Test: atest HdmiCecLocalDevicePlaybackTest
Change-Id: I1b3f869d51a093cf1725ba92c18ef0f4862dbb1c
This commit is contained in:
Michal Olech
2020-11-06 15:01:13 +01:00
parent fcfdd08bdc
commit 87e764089e

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2020 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 android.annotation.NonNull;
import android.content.Context;
import android.util.Slog;
import com.android.server.hdmi.cec.config.CecSettings;
import com.android.server.hdmi.cec.config.XmlParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.datatype.DatatypeConfigurationException;
/**
* Fake class which loads default system configuration with user-configurable
* settings (useful for testing).
*/
final class FakeHdmiCecConfig extends HdmiCecConfig {
private static final String TAG = "FakeHdmiCecConfig";
private static final String SYSTEM_CONFIG_XML =
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
+ " <value string-value=\"broadcast\" />"
+ " <value string-value=\"none\" />"
+ " </allowed-values>"
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>";
FakeHdmiCecConfig(@NonNull Context context) {
super(context, new StorageAdapter(), parseFromString(SYSTEM_CONFIG_XML), null);
}
private static CecSettings parseFromString(@NonNull String configXml) {
CecSettings config = null;
try {
config = XmlParser.read(
new ByteArrayInputStream(configXml.getBytes()));
} catch (IOException | DatatypeConfigurationException | XmlPullParserException e) {
Slog.e(TAG, "Encountered an error while reading/parsing CEC config strings", e);
}
return config;
}
}