| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.hardware.hdmi; |
| 17 |
|
| 18 |
import android.annotation.NonNull; |
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.os.Handler; |
| 21 |
import android.os.Looper; |
| 22 |
import android.os.RemoteException; |
| 23 |
import android.util.Log; |
| 24 |
|
| 25 |
import com.android.internal.annotations.VisibleForTesting; |
| 26 |
import com.android.internal.annotations.VisibleForTesting.Visibility; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final class HdmiAudioSystemClient extends HdmiClient { |
| 38 |
private static final String TAG = "HdmiAudioSystemClient"; |
| 39 |
|
| 40 |
private static final int REPORT_AUDIO_STATUS_INTERVAL_MS = 500; |
| 41 |
|
| 42 |
private final Handler mHandler; |
| 43 |
private boolean mCanSendAudioStatus = true; |
| 44 |
private boolean mPendingReportAudioStatus; |
| 45 |
|
| 46 |
private int mLastVolume; |
| 47 |
private int mLastMaxVolume; |
| 48 |
private boolean mLastIsMute; |
| 49 |
|
| 50 |
@VisibleForTesting(visibility = Visibility.PACKAGE) |
| 51 |
public HdmiAudioSystemClient(IHdmiControlService service) { |
| 52 |
this(service, null); |
| 53 |
} |
| 54 |
|
| 55 |
@VisibleForTesting(visibility = Visibility.PACKAGE) |
| 56 |
public HdmiAudioSystemClient(IHdmiControlService service, @Nullable Handler handler) { |
| 57 |
super(service); |
| 58 |
mHandler = handler == null ? new Handler(Looper.getMainLooper()) : handler; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public interface SetSystemAudioModeCallback { |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
void onComplete(int result); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
@Override |
| 77 |
public int getDeviceType() { |
| 78 |
return HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public void sendReportAudioStatusCecCommand(boolean isMuteAdjust, int volume, int maxVolume, |
| 90 |
boolean isMute) { |
| 91 |
if (isMuteAdjust) { |
| 92 |
|
| 93 |
try { |
| 94 |
mService.reportAudioStatus(getDeviceType(), volume, maxVolume, isMute); |
| 95 |
} catch (RemoteException e) { |
| 96 |
|
| 97 |
} |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
mLastVolume = volume; |
| 102 |
mLastMaxVolume = maxVolume; |
| 103 |
mLastIsMute = isMute; |
| 104 |
if (mCanSendAudioStatus) { |
| 105 |
try { |
| 106 |
mService.reportAudioStatus(getDeviceType(), volume, maxVolume, isMute); |
| 107 |
mCanSendAudioStatus = false; |
| 108 |
mHandler.postDelayed(new Runnable() { |
| 109 |
@Override |
| 110 |
public void run() { |
| 111 |
if (mPendingReportAudioStatus) { |
| 112 |
|
| 113 |
try { |
| 114 |
mService.reportAudioStatus(getDeviceType(), mLastVolume, |
| 115 |
mLastMaxVolume, mLastIsMute); |
| 116 |
mHandler.postDelayed(this, REPORT_AUDIO_STATUS_INTERVAL_MS); |
| 117 |
} catch (RemoteException e) { |
| 118 |
mCanSendAudioStatus = true; |
| 119 |
} finally { |
| 120 |
mPendingReportAudioStatus = false; |
| 121 |
} |
| 122 |
} else { |
| 123 |
mCanSendAudioStatus = true; |
| 124 |
} |
| 125 |
} |
| 126 |
}, REPORT_AUDIO_STATUS_INTERVAL_MS); |
| 127 |
} catch (RemoteException e) { |
| 128 |
|
| 129 |
} |
| 130 |
} else { |
| 131 |
|
| 132 |
mPendingReportAudioStatus = true; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public void setSystemAudioMode(boolean state, @NonNull SetSystemAudioModeCallback callback) { |
| 145 |
|
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public void setSystemAudioModeOnForAudioOnlySource() { |
| 157 |
try { |
| 158 |
mService.setSystemAudioModeOnForAudioOnlySource(); |
| 159 |
} catch (RemoteException e) { |
| 160 |
Log.d(TAG, "Failed to set System Audio Mode on for Audio Only source"); |
| 161 |
} |
| 162 |
} |
| 163 |
} |