Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38caf1e0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[CEC Configuration] Add a fake HdmiCecConfig class for testing"

parents c20ac75c 87e76408
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}