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

Commit 4ad4e78c authored by Amy's avatar Amy Committed by shubang
Browse files

Set System Audio Mode on when switch to Audio Only source

ag/5298361

Test: local tested.
Bug:80296134
Change-Id: Ie774b0ebe9a147dd650ff92c7af62439d9ae9af0
parent 01b979c8
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -15,10 +15,12 @@
 */
package android.hardware.hdmi;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting.Visibility;
@@ -56,6 +58,21 @@ public final class HdmiAudioSystemClient extends HdmiClient {
        mHandler = handler == null ? new Handler(Looper.getMainLooper()) : handler;
    }

    /**
     * Callback interface used to get the set System Audio Mode result.
     *
     * @hide
     */
    // TODO(b/110094868): unhide and add @SystemApi for Q
    public interface SetSystemAudioModeCallback {
        /**
         * Called when the input was changed.
         *
         * @param result the result of the set System Audio Mode
         */
        void onComplete(int result);
    }

    /** @hide */
    // TODO(b/110094868): unhide and add @SystemApi for Q
    @Override
@@ -117,4 +134,34 @@ public final class HdmiAudioSystemClient extends HdmiClient {
            mPendingReportAudioStatus = true;
        }
    }

    /**
     * Set System Audio Mode on/off with audio system device.
     *
     * @param state true to set System Audio Mode on. False to set off.
     * @param callback callback offer the setting result.
     *
     * @hide
     */
    // TODO(b/110094868): unhide and add @SystemApi for Q
    public void setSystemAudioMode(boolean state, @NonNull SetSystemAudioModeCallback callback) {
        // TODO(amyjojo): implement this when needed.
    }

    /**
     * When device is switching to an audio only source, this method is called to broadcast
     * a setSystemAudioMode on message to the HDMI CEC system without querying Active Source or
     * TV supporting System Audio Control or not. This is to get volume control passthrough
     * from STB even if TV does not support it.
     *
     * @hide
     */
    // TODO(b/110094868): unhide and add @SystemApi for Q
    public void setSystemAudioModeOnForAudioOnlySource() {
        try {
            mService.setSystemAudioModeOnForAudioOnlySource();
        } catch (RemoteException e) {
            Log.d(TAG, "Failed to set System Audio Mode on for Audio Only source");
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -73,4 +73,5 @@ interface IHdmiControlService {
    void addHdmiMhlVendorCommandListener(IHdmiMhlVendorCommandListener listener);
    void setStandbyMode(boolean isStandbyModeOn);
    void reportAudioStatus(int deviceType, int volume, int maxVolume, boolean isMute);
    void setSystemAudioModeOnForAudioOnlySource();
}
+4 −0
Original line number Diff line number Diff line
@@ -318,6 +318,10 @@ public class HdmiAudioSystemClientTest {
            mMaxVolume = maxVolume;
            mIsMute = isMute;
        }

        @Override
        public void setSystemAudioModeOnForAudioOnlySource() {
        }
    }

}
+21 −0
Original line number Diff line number Diff line
@@ -1839,6 +1839,27 @@ public class HdmiControlService extends SystemService {
            });
        }

        @Override
        public void setSystemAudioModeOnForAudioOnlySource() {
            enforceAccessPermission();
            runOnServiceThread(new Runnable() {
                @Override
                public void run() {
                    if (!isAudioSystemDevice()) {
                        Slog.e(TAG, "Not an audio system device. Won't set system audio mode on");
                        return;
                    }
                    if (!audioSystem().checkSupportAndSetSystemAudioMode(true)) {
                        Slog.e(TAG, "System Audio Mode is not supported.");
                        return;
                    }
                    sendCecCommand(
                            HdmiCecMessageBuilder.buildSetSystemAudioMode(
                                    audioSystem().mAddress, Constants.ADDR_BROADCAST, true));
                }
            });
        }

        @Override
        protected void dump(FileDescriptor fd, final PrintWriter writer, String[] args) {
            if (!DumpUtils.checkDumpPermission(getContext(), TAG, writer)) return;