Read/Write flags from/to system settings
Use Settings for storing several flags/values to keep the data persistent across power cycle, and also to make them configurable via system Settings UI. Bug: 16185931 Change-Id: I98650863e4237fd91c1b35717f14a570e049427c
This commit is contained in:
@@ -154,6 +154,9 @@ final class Constants {
|
||||
|
||||
static final int UNKNOWN_VENDOR_ID = 0xFFFFFF;
|
||||
|
||||
static final int TRUE = 1;
|
||||
static final int FALSE = 0;
|
||||
|
||||
// Constants related to operands of HDMI CEC commands.
|
||||
// Refer to CEC Table 29 in HDMI Spec v1.4b.
|
||||
// [Abort Reason]
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.media.AudioPort;
|
||||
import android.media.AudioSystem;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings.Global;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
|
||||
@@ -89,22 +90,19 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
|
||||
HdmiCecLocalDeviceTv(HdmiControlService service) {
|
||||
super(service, HdmiCecDeviceInfo.DEVICE_TV);
|
||||
mPrevPortId = Constants.INVALID_PORT_ID;
|
||||
// TODO: load system audio mode and set it to mSystemAudioMode.
|
||||
}
|
||||
|
||||
@Override
|
||||
@ServiceThreadOnly
|
||||
protected void onAddressAllocated(int logicalAddress) {
|
||||
assertRunOnServiceThread();
|
||||
// TODO: vendor-specific initialization here.
|
||||
|
||||
mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(
|
||||
mAddress, mService.getPhysicalAddress(), mDeviceType));
|
||||
mService.sendCecCommand(HdmiCecMessageBuilder.buildDeviceVendorIdCommand(
|
||||
mAddress, mService.getVendorId()));
|
||||
mSystemAudioMode = mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_ENABLED, false);
|
||||
launchRoutingControl(true);
|
||||
launchDeviceDiscovery();
|
||||
|
||||
registerAudioPortUpdateListener();
|
||||
// TODO: unregister audio port update listener if local device is released.
|
||||
}
|
||||
@@ -516,10 +514,10 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
|
||||
// If there is AVR, initiate System Audio Auto initiation action,
|
||||
// which turns on and off system audio according to last system
|
||||
// audio setting.
|
||||
HdmiCecDeviceInfo avrInfo = getAvrDeviceInfo();
|
||||
if (avrInfo != null) {
|
||||
if (mSystemAudioMode && getAvrDeviceInfo() != null) {
|
||||
addAndStartAction(new SystemAudioAutoInitiationAction(
|
||||
HdmiCecLocalDeviceTv.this, avrInfo.getLogicalAddress()));
|
||||
HdmiCecLocalDeviceTv.this,
|
||||
getAvrDeviceInfo().getLogicalAddress()));
|
||||
if (mArcEstablished) {
|
||||
startArcAction(true);
|
||||
}
|
||||
@@ -551,11 +549,13 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
|
||||
}
|
||||
|
||||
// # Seq 25
|
||||
void setSystemAudioMode(boolean on) {
|
||||
void setSystemAudioMode(boolean on, boolean updateSetting) {
|
||||
synchronized (mLock) {
|
||||
if (on != mSystemAudioMode) {
|
||||
mSystemAudioMode = on;
|
||||
// TODO: Need to set the preference for SystemAudioMode.
|
||||
if (updateSetting) {
|
||||
mService.writeBooleanSetting(Global.HDMI_SYSTEM_AUDIO_ENABLED, on);
|
||||
}
|
||||
mService.announceSystemAudioModeChange(on);
|
||||
}
|
||||
}
|
||||
@@ -756,7 +756,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
|
||||
if (!isMessageForSystemAudio(message)) {
|
||||
return false;
|
||||
}
|
||||
setSystemAudioMode(HdmiUtils.parseCommandParamSystemAudioStatus(message));
|
||||
setSystemAudioMode(HdmiUtils.parseCommandParamSystemAudioStatus(message), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1093,9 +1093,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
|
||||
removeAction(SystemAudioStatusAction.class);
|
||||
removeAction(VolumeControlAction.class);
|
||||
|
||||
// Once adding additional param which describes whether to record it to NVM or not to this
|
||||
// method, put "false" for it.
|
||||
setSystemAudioMode(false);
|
||||
// Turn off the mode but do not write it the settings, so that the next time TV powers on
|
||||
// the system audio mode setting can be restored automatically.
|
||||
setSystemAudioMode(false, false);
|
||||
}
|
||||
|
||||
@ServiceThreadOnly
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.server.hdmi;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
@@ -42,6 +43,8 @@ import android.os.Looper;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings.Global;
|
||||
import android.provider.Settings.SettingNotFoundException;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
@@ -206,6 +209,8 @@ public final class HdmiControlService extends SystemService {
|
||||
public void onStart() {
|
||||
mIoThread.start();
|
||||
mPowerStatus = HdmiControlManager.POWER_STATUS_TRANSIENT_TO_ON;
|
||||
mProhibitMode = false;
|
||||
mHdmiControlEnabled = readBooleanSetting(Global.HDMI_CONTROL_ENABLED, true);
|
||||
mCecController = HdmiCecController.create(this);
|
||||
|
||||
if (mCecController != null) {
|
||||
@@ -235,12 +240,16 @@ public final class HdmiControlService extends SystemService {
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
getContext().registerReceiver(mPowerStateReceiver, filter);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Read the preference for SystemAudioMode and initialize mSystemAudioMode and
|
||||
// start to monitor the preference value and invoke SystemAudioActionFromTv if needed.
|
||||
mHdmiControlEnabled = true;
|
||||
// TODO: Get control flag from persistent storage
|
||||
mProhibitMode = false;
|
||||
boolean readBooleanSetting(String key, boolean defVal) {
|
||||
ContentResolver cr = getContext().getContentResolver();
|
||||
return Global.getInt(cr, key, defVal ? Constants.TRUE : Constants.FALSE) == Constants.TRUE;
|
||||
}
|
||||
|
||||
void writeBooleanSetting(String key, boolean value) {
|
||||
ContentResolver cr = getContext().getContentResolver();
|
||||
Global.putInt(cr, key, value ? Constants.TRUE : Constants.FALSE);
|
||||
}
|
||||
|
||||
@ServiceThreadOnly
|
||||
|
||||
@@ -240,8 +240,8 @@ final class HotplugDetectionAction extends FeatureAction {
|
||||
return;
|
||||
}
|
||||
|
||||
// Turn off system audio mode.
|
||||
tv().setSystemAudioMode(false);
|
||||
// Turn off system audio mode and update settings.
|
||||
tv().setSystemAudioMode(false, true);
|
||||
if (tv().isArcEstabilished()) {
|
||||
addAndStartAction(new RequestArcTerminationAction(localDevice(), address));
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ abstract class SystemAudioAction extends FeatureAction {
|
||||
}
|
||||
|
||||
protected void setSystemAudioMode(boolean mode) {
|
||||
tv().setSystemAudioMode(mode);
|
||||
tv().setSystemAudioMode(mode, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -48,7 +48,7 @@ final class SystemAudioAutoInitiationAction extends FeatureAction {
|
||||
@Override
|
||||
public void onSendCompleted(int error) {
|
||||
if (error != Constants.SEND_RESULT_SUCCESS) {
|
||||
tv().setSystemAudioMode(false);
|
||||
tv().setSystemAudioMode(false, true);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ final class SystemAudioAutoInitiationAction extends FeatureAction {
|
||||
} else {
|
||||
// If the last setting is non-system audio, turn off system audio mode
|
||||
// and update system audio status (volume or mute).
|
||||
tv().setSystemAudioMode(false);
|
||||
tv().setSystemAudioMode(false, true);
|
||||
if (canChangeSystemAudio()) {
|
||||
addAndStartAction(new SystemAudioStatusAction(tv(), mAvrAddress, null));
|
||||
}
|
||||
@@ -106,7 +106,7 @@ final class SystemAudioAutoInitiationAction extends FeatureAction {
|
||||
addAndStartAction(new SystemAudioActionFromTv(tv(), mAvrAddress, true, null));
|
||||
}
|
||||
} else {
|
||||
tv().setSystemAudioMode(false);
|
||||
tv().setSystemAudioMode(false, true);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user