summaryrefslogtreecommitdiff
authorwei wang <wei.wang@amlogic.com>2018-01-10 10:35:50 (GMT)
committer Sandy Luo <sandy.luo@amlogic.com>2018-01-12 07:55:12 (GMT)
commite9751550d6d1e2a43ac46a016450c24a19e567c9 (patch)
treeb0cea46d9b7c80f64b42a85b1da503a8edd46e90
parentbcaa474b05395100d7a915a085a6015afd8db2ce (diff)
downloadtv-e9751550d6d1e2a43ac46a016450c24a19e567c9.zip
tv-e9751550d6d1e2a43ac46a016450c24a19e567c9.tar.gz
tv-e9751550d6d1e2a43ac46a016450c24a19e567c9.tar.bz2
droidlogic-tv: release overlayview when suspend [1/2]
PD# 158295 Change-Id: I701973936f25ed388290fbb48bf30b83c41813a7
Diffstat
-rw-r--r--core/java/com/droidlogic/app/tv/DroidLogicHdmiCecManager.java90
-rw-r--r--core/java/com/droidlogic/app/tv/DroidLogicTvInputService.java13
-rw-r--r--core/java/com/droidlogic/app/tv/TvInputBaseSession.java79
3 files changed, 178 insertions, 4 deletions
diff --git a/core/java/com/droidlogic/app/tv/DroidLogicHdmiCecManager.java b/core/java/com/droidlogic/app/tv/DroidLogicHdmiCecManager.java
index 8aff7a4..b52deb6 100644
--- a/core/java/com/droidlogic/app/tv/DroidLogicHdmiCecManager.java
+++ b/core/java/com/droidlogic/app/tv/DroidLogicHdmiCecManager.java
@@ -9,6 +9,13 @@ import android.provider.Settings;
import android.provider.Settings.Global;
import android.util.Log;
+import android.media.tv.TvInputHardwareInfo;
+import android.media.tv.TvInputManager;
+import android.os.Handler;
+
+import java.util.List;
+import java.util.ArrayList;
+import android.hardware.hdmi.HdmiDeviceInfo;
public class DroidLogicHdmiCecManager {
private static final String TAG = "DroidLogicHdmiCecManager";
@@ -17,11 +24,14 @@ public class DroidLogicHdmiCecManager {
private HdmiControlManager mHdmiControlManager;
private HdmiTvClient mTvClient;
private int mSelectPort = -1;
+ private final Handler mHandler = new Handler();
private int mSourceType = 0;
private final Object mLock = new Object();
private static DroidLogicHdmiCecManager mInstance = null;
+ private TvInputManager mTvInputManager;
+ private static boolean DEBUG = true;
public static synchronized DroidLogicHdmiCecManager getInstance(Context context) {
if (mInstance == null) {
@@ -38,6 +48,9 @@ public class DroidLogicHdmiCecManager {
if (mHdmiControlManager != null)
mTvClient = mHdmiControlManager.getTvClient();
+
+ if (mTvInputManager == null)
+ mTvInputManager = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE);
}
/**
@@ -104,10 +117,62 @@ public class DroidLogicHdmiCecManager {
}
}
+ public boolean activeHdmiCecSource(int deviceId) {
+ synchronized (mLock) {
+ getInputSourceType();
+
+ Log.d(TAG, "activeHdmiCecSource"+ ", deviceId = " + deviceId
+ + ", mSelectPort = " + mSelectPort+ ", mSourceType = " + mSourceType);
+
+ int devAddr = 0;
+ if (mHdmiControlManager == null || mSelectPort == deviceId)
+ return false;
+
+ boolean cecOption = (Global.getInt(mContext.getContentResolver(), Global.HDMI_CONTROL_ENABLED, 1) == 1);
+ if (!cecOption || mTvClient == null)
+ return false;
+
+
+
+ int portId = getPortIdByDeviceId(deviceId);
+ if (DEBUG)
+ Log.d(TAG, "portId = " + portId);
+ if (portId == 0)
+ return false;
+ mTvClient.portSelect(portId , new SelectCallback() {
+ @Override
+ public void onComplete(int result) {
+ if (result != HdmiControlManager.RESULT_SUCCESS)
+ mSelectPort = 0;
+ else
+ mSelectPort = portId ;
+ Log.d(TAG, "portSelect, onComplete result = " + result + ", mSelectPort = " + mSelectPort);
+ }
+ });
+
+ return true;
+ }
+ }
+
+ private int getPortIdByDeviceId(int deviceId){
+ List<TvInputHardwareInfo> hardwareList = mTvInputManager.getHardwareList();
+ if (hardwareList == null || hardwareList.size() == 0)
+ return -1;
+ Log.d(TAG, "getPortIdByDeviceId: " + deviceId);
+ for (TvInputHardwareInfo hardwareInfo : hardwareList) {
+ if (DEBUG)
+ Log.d(TAG, "getPortIdByDeviceId: " + hardwareInfo);
+ if (deviceId == hardwareInfo.getDeviceId())
+ return hardwareInfo.getHdmiPortId();
+ }
+ return -1;
+ }
+
public int getLogicalAddress (int deviceId) {
if (deviceId >= DroidLogicTvUtils.DEVICE_ID_HDMI1 && deviceId <= DroidLogicTvUtils.DEVICE_ID_HDMI4) {
int id = deviceId - DroidLogicTvUtils.DEVICE_ID_HDMI1 + 1;
for (HdmiDeviceInfo info : mTvClient.getDeviceList()) {
+ Log.d(TAG, "getLogicalAddress: " + info);
if (id == (info.getPhysicalAddress() >> 12)) {
return info.getLogicalAddress();
}
@@ -116,10 +181,23 @@ public class DroidLogicHdmiCecManager {
return 0;
}
+ public int getPhysicalAddress (int deviceId) {
+ if (deviceId >= DroidLogicTvUtils.DEVICE_ID_HDMI1 && deviceId <= DroidLogicTvUtils.DEVICE_ID_HDMI4) {
+ int id = deviceId - DroidLogicTvUtils.DEVICE_ID_HDMI1 + 1;
+ for (HdmiDeviceInfo info : mTvClient.getDeviceList()) {
+ if (id == (info.getPhysicalAddress() >> 12)) {
+ return info.getPhysicalAddress();
+ }
+ }
+ }
+ return 0;
+ }
+
public boolean hasHdmiCecDevice(int deviceId) {
if (deviceId >= DroidLogicTvUtils.DEVICE_ID_HDMI1 && deviceId <= DroidLogicTvUtils.DEVICE_ID_HDMI4) {
int id = deviceId - DroidLogicTvUtils.DEVICE_ID_HDMI1 + 1;
for (HdmiDeviceInfo info : mTvClient.getDeviceList()) {
+ Log.d(TAG, "hasHdmiCecDevice: " + info);
if (id == (info.getPhysicalAddress() >> 12)) {
return true;
}
@@ -132,4 +210,16 @@ public class DroidLogicHdmiCecManager {
mSourceType = Settings.System.getInt(mContext.getContentResolver(), DroidLogicTvUtils.TV_CURRENT_DEVICE_ID, 0);
return mSourceType;
}
+
+ public boolean isHdmiCecDeviceConneted(int deviceId){
+ Log.d(TAG, "isHdmiCecDeviceConneted,deviceId: " + deviceId);
+ int portId = getPortIdByDeviceId(deviceId);
+ Log.d(TAG, "portId: " + portId);
+ for (HdmiDeviceInfo info : mTvClient.getDeviceList()) {
+ if (DEBUG) Log.d(TAG, "info" + info.toString());
+ if (info.getPortId() == portId)
+ return true;
+ }
+ return false;
+ }
}
diff --git a/core/java/com/droidlogic/app/tv/DroidLogicTvInputService.java b/core/java/com/droidlogic/app/tv/DroidLogicTvInputService.java
index 0989cee..d867874 100644
--- a/core/java/com/droidlogic/app/tv/DroidLogicTvInputService.java
+++ b/core/java/com/droidlogic/app/tv/DroidLogicTvInputService.java
@@ -508,7 +508,7 @@ public class DroidLogicTvInputService extends TvInputService implements
Log.d(TAG, "startTvPlay inputId=" + mCurrentInputId + " surface=" + mSurface);
if (mHardware != null && mSurface != null && mSurface.isValid()) {
//mHardware.setSurface(mSurface, mConfigs[0]);
- selectHdmiDevice(mDeviceId);
+ //selectHdmiDevice(mDeviceId);
return ACTION_SUCCESS;
}
return ACTION_FAILED;
@@ -600,9 +600,14 @@ public class DroidLogicTvInputService extends TvInputService implements
} else {
return null;
}
- Log.d(TAG, "createTvInputInfo, id:" + info.getId());
- updateInfoListIfNeededLocked(phyaddr, info, false);
- selectHdmiDevice(sourceType);
+ Log.d(TAG, "createTvInputInfo, id:" + deviceInfo.toString()+",deviceId:"+deviceInfo.getDeviceId());
+ updateInfoListIfNeededLocked(getHardwareDeviceId(parentId), info, false);
+ //selectHdmiDevice(sourceType);
+
+ DroidLogicHdmiCecManager hdmi_cec = DroidLogicHdmiCecManager.getInstance(this);
+ int logicalAddr = hdmi_cec.getLogicalAddress (sourceType);
+ if (deviceInfo != null && deviceInfo.getDevicePowerStatus() != HdmiControlManager.POWER_STATUS_UNKNOWN && logicalAddr != 5)
+ selectHdmiDevice(sourceType);
return info;
}
diff --git a/core/java/com/droidlogic/app/tv/TvInputBaseSession.java b/core/java/com/droidlogic/app/tv/TvInputBaseSession.java
index f28af29..47c6eed 100644
--- a/core/java/com/droidlogic/app/tv/TvInputBaseSession.java
+++ b/core/java/com/droidlogic/app/tv/TvInputBaseSession.java
@@ -28,6 +28,14 @@ import android.provider.Settings.Global;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.HdmiTvClient.SelectCallback;
+import com.droidlogic.app.tv.DroidLogicHdmiCecManager;
+import android.media.tv.TvInputInfo;
+//import android.hardware.hdmi.HdmiClient;
+import android.content.BroadcastReceiver;
+import android.content.IntentFilter;
+import android.content.Intent;
+import java.util.List;
+
public abstract class TvInputBaseSession extends TvInputService.Session implements Handler.Callback {
private static final boolean DEBUG = true;
private static final String TAG = "TvInputBaseSession";
@@ -49,6 +57,8 @@ public abstract class TvInputBaseSession extends TvInputService.Session implemen
protected boolean isBlockNoRatingEnable = false;
protected boolean isUnlockCurrent_NR = false;
+ private HdmiControlManager mHdmiControlManager ;
+
public TvInputBaseSession(Context context, String inputId, int deviceId) {
super(context);
mContext = context;
@@ -57,10 +67,18 @@ public abstract class TvInputBaseSession extends TvInputService.Session implemen
mTvControlManager = TvControlManager.getInstance();
mSessionHandler = new Handler(context.getMainLooper(), this);
+ mTvInputManager = (TvInputManager)mContext.getSystemService(Context.TV_INPUT_SERVICE);
int block_norating = Settings.System.getInt(mContext.getContentResolver(), DroidLogicTvUtils.BLOCK_NORATING, 0);
isBlockNoRatingEnable = block_norating == 0 ? false : true;
if (DEBUG)
Log.d(TAG, "isBlockNoRatingEnable = " + isBlockNoRatingEnable);
+ Log.d(TAG, "TvInputBaseSession,inputId:" + inputId+", devieId:"+deviceId);
+ mHdmiControlManager = (HdmiControlManager) mContext.getSystemService(Context.HDMI_CONTROL_SERVICE);
+
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
+ intentFilter.addAction(Intent.ACTION_SCREEN_ON);
+ mContext.registerReceiver(mBroadcastReceiver, intentFilter);
}
public void setSessionId(int id) {
@@ -82,6 +100,7 @@ public abstract class TvInputBaseSession extends TvInputService.Session implemen
public void doRelease() {
Log.d(TAG, "doRelease");
//setAudiodMute(false);
+ mContext.unregisterReceiver(mBroadcastReceiver);
setOverlayViewEnabled(false);
if (mOverlayView != null) {
mOverlayView.releaseResource();
@@ -142,6 +161,19 @@ public abstract class TvInputBaseSession extends TvInputService.Session implemen
setOverlayViewEnabled(true);
}
+ private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+ if (DEBUG) Log.d(TAG, "Received ACTION_SCREEN_OFF");
+ setOverlayViewEnabled(false);
+ } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+ if (DEBUG) Log.d(TAG, "Received ACTION_SCREEN_ON");
+ setOverlayViewEnabled(true);
+ }
+ }
+ };
+
@Override
public View onCreateOverlayView() {
return mOverlayView;
@@ -211,4 +243,51 @@ public abstract class TvInputBaseSession extends TvInputService.Session implemen
}
return false;
}
+
+ @Override
+ public void onSetMain(boolean isMain) {
+ Log.d(TAG, "onSetMain:" + isMain);
+ TvInputInfo info = mTvInputManager.getTvInputInfo(mInputId);
+ if (info == null) {
+ Log.w(TAG, " mInputId:" + mInputId+" has no TvInputInfo");
+ return;
+ }
+ Log.d(TAG, " mDeviceId:" + mDeviceId+",mInputId:"+mInputId+", type:"+info.getType());
+ List<TvInputInfo> inputList = mTvInputManager.getTvInputList();
+ DroidLogicHdmiCecManager hdmi_cec = DroidLogicHdmiCecManager.getInstance(mContext);
+
+ if (isMain) {
+ if (info.getType() == TvInputInfo.TYPE_HDMI) {
+ boolean hasCecDevConnected = hdmi_cec.isHdmiCecDeviceConneted(mDeviceId);
+ boolean isCecDevAdded = false;
+ for (TvInputInfo input : inputList) {
+ String parentId = input.getParentId();
+ //Log.d(TAG, " input:" + input.toString()+" ,getParentId: "+ parentId);
+ if (parentId != null && parentId.equals(mInputId)) {
+ isCecDevAdded = true;
+ break;
+ }
+ }
+ Log.d(TAG, "isCecDevAdded:" + isCecDevAdded);
+ if (hasCecDevConnected && isCecDevAdded)
+ hdmi_cec.activeHdmiCecSource(mDeviceId);
+ else if (hasCecDevConnected && !isCecDevAdded)
+ hdmi_cec.selectHdmiDevice(mDeviceId);
+ else if (!hasCecDevConnected && !isCecDevAdded)
+ hdmi_cec.activeHdmiCecSource(mDeviceId);
+ else
+ Log.e(TAG, "ERROR occur!!!!!" );
+ } else
+ hdmi_cec.selectHdmiDevice(0);
+ } else {
+ //There seems to be no use to handle setMain(false);
+ HdmiTvClient hdmitvclient = mHdmiControlManager.getTvClient();
+ HdmiDeviceInfo activeInfo = hdmitvclient.getActiveSource();
+ if (activeInfo != null) {
+ Log.d(TAG, "activeInfo:"+activeInfo.toString());
+ if (activeInfo.getPhysicalAddress() == hdmi_cec.getPhysicalAddress(mDeviceId))
+ hdmi_cec.selectHdmiDevice(0);
+ } else
+ Log.d(TAG, "activeInfo is null");}
+ }
}