diff --git a/services/tests/servicestests/src/com/android/server/hdmi/FakeHdmiCecConfig.java b/services/tests/servicestests/src/com/android/server/hdmi/FakeHdmiCecConfig.java new file mode 100644 index 0000000000000..fb6266d89005f --- /dev/null +++ b/services/tests/servicestests/src/com/android/server/hdmi/FakeHdmiCecConfig.java @@ -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 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + 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; + } +}