author | Tellen Yu <tellen.yu@amlogic.com> | 2018-01-19 09:46:39 (GMT) |
---|---|---|
committer | Tellen Yu <tellen.yu@amlogic.com> | 2018-01-19 09:46:51 (GMT) |
commit | d946a3cc75b4d9bd5a71da14b1c8d90398756f87 (patch) | |
tree | 10744a28ba903ba4390dd16935fc03aef6b795e7 | |
parent | 372a36029881be05b353e66db482ad59acacae63 (diff) | |
parent | 75d9f937d188606485803f7e2d43e97dfddaa70f (diff) | |
download | tv-d946a3cc75b4d9bd5a71da14b1c8d90398756f87.zip tv-d946a3cc75b4d9bd5a71da14b1c8d90398756f87.tar.gz tv-d946a3cc75b4d9bd5a71da14b1c8d90398756f87.tar.bz2 |
Merge remote-tracking branch 'remotes/amlogic/n-amlogic' into HEAD
Change-Id: I8f23c5e718eaf9f586d8ae8a8cf0daac1aa89fd6
4 files changed, 215 insertions, 20 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..57db083 100644 --- a/core/java/com/droidlogic/app/tv/DroidLogicTvInputService.java +++ b/core/java/com/droidlogic/app/tv/DroidLogicTvInputService.java @@ -70,6 +70,7 @@ public class DroidLogicTvInputService extends TvInputService implements private String mChildClassName; private SurfaceHandler mSessionHandler; private static final int MSG_DO_TUNE = 0; + private static final int MSG_DO_RELEASE = 1; private static final int MSG_DO_SET_SURFACE = 3; private static final int RETUNE_TIMEOUT = 20; // 1 second private static int mSelectPort = -1; @@ -165,8 +166,10 @@ public class DroidLogicTvInputService extends TvInputService implements * @param session {@link HdmiInputSession} or {@link AVInputSession} */ protected void registerInputSession(TvInputBaseSession session) { - Log.d(TAG, "registerInputSession"); + Log.d(TAG, "registerInputSession:"+session); mSession = session; + if (session == null) + return; mCurrentSessionId = session.mId; Log.d(TAG, "inputId["+mCurrentInputId+"]"); Log.d(TAG, "xsession["+session+"]"); @@ -309,7 +312,10 @@ public class DroidLogicTvInputService extends TvInputService implements if (DEBUG) Log.d(TAG, "onSigChange" + status.ordinal() + status.toString()); - + if (mSession == null) { + Log.w(TAG, "mSession is null ,discard this signal!"); + return; + } onSigChanged(signal_info); if (status == TVInSignalInfo.SignalStatus.TVIN_SIG_STATUS_NOSIG @@ -411,13 +417,14 @@ public class DroidLogicTvInputService extends TvInputService implements Log.d(TAG, "scanning frame stable!"); Bundle bundle = new Bundle(); bundle.putInt(DroidLogicTvUtils.SIG_INFO_C_FREQ, event.CurScanningFrq); - mSession.notifySessionEvent(DroidLogicTvUtils.SIG_INFO_C_SCANNING_FRAME_STABLE_EVENT, bundle); + if (mSession != null) + mSession.notifySessionEvent(DroidLogicTvUtils.SIG_INFO_C_SCANNING_FRAME_STABLE_EVENT, bundle); } public void onUpdateCurrentChannel(ChannelInfo channel, boolean store) {} protected boolean setSurfaceInService(Surface surface, TvInputBaseSession session ) { - Log.d(TAG, "SetSurface"); + Log.d(TAG, "setSurfaceInService,session:"+session); Message message = mSessionHandler.obtainMessage(); message.what = MSG_DO_SET_SURFACE; @@ -431,7 +438,7 @@ public class DroidLogicTvInputService extends TvInputService implements } protected boolean doTuneInService(Uri channelUri, int sessionId) { - Log.d(TAG, "[source_switch_time]:" +getUptimeSeconds() + "s, onTune channelUri=" + channelUri); + Log.d(TAG, "doTuneInService,[source_switch_time]:" +getUptimeSeconds() + "s, onTune channelUri=" + channelUri); if (mSession != null) mSession.hideUI(); @@ -439,6 +446,11 @@ public class DroidLogicTvInputService extends TvInputService implements return false; } + protected void doReleaseInService (int sessionId) { + Log.d(TAG, "doReleaseInService,[source_switch_time]:" +getUptimeSeconds() + "s,sessionid:"+sessionId); + mSessionHandler.obtainMessage(MSG_DO_RELEASE, sessionId, 0).sendToTarget(); + } + private final class SurfaceHandler extends Handler { @Override public void handleMessage(Message message) { @@ -453,6 +465,9 @@ public class DroidLogicTvInputService extends TvInputService implements SomeArgs args = (SomeArgs) message.obj; doSetSurface((Surface)args.arg1, (TvInputBaseSession)args.arg2); break; + case MSG_DO_RELEASE: + doSessionRelease(message.arg1); + break; } } } @@ -465,10 +480,15 @@ public class DroidLogicTvInputService extends TvInputService implements Log.d(TAG, "onSetSurface get invalid surface"); return; } else if (surface != null) { + if (mSession == null) { + Log.w(TAG, "session should not be null when surface is not null!!!!!"); + int test_ww = mSession.getDeviceId(); + return; + } if (mHardware != null && mSurface != null && (mSourceType >= DroidLogicTvUtils.DEVICE_ID_HDMI1) && (mSourceType <= DroidLogicTvUtils.DEVICE_ID_HDMI4)) { - stopTvPlay(mSession.mId); + stopTvPlay(mSession.mId); } registerInputSession(session); setCurrentSessionById(mSession.mId); @@ -496,19 +516,25 @@ public class DroidLogicTvInputService extends TvInputService implements Message msg = mSessionHandler.obtainMessage(MSG_DO_TUNE, sessionId, 0, uri); mSessionHandler.sendMessageDelayed(msg, 50); timeout--; - return ACTION_FAILED; - } + } else + doTuneFinish(ACTION_FAILED, uri, sessionId); + return ACTION_FAILED; } mSystemControlManager.writeSysFs("/sys/class/deinterlace/di0/config", "hold_video 0"); doTuneFinish(ACTION_SUCCESS, uri, sessionId); return ACTION_SUCCESS; } + private void doSessionRelease(int sessionId) { + Log.d(TAG, "doRelese, sessionId = " + sessionId); + doReleaseFinish(sessionId); + } + private int startTvPlay() { 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; @@ -525,6 +551,7 @@ public class DroidLogicTvInputService extends TvInputService implements } public void setCurrentSessionById(int sessionId){} public void doTuneFinish(int result, Uri uri, int sessionId){}; + public void doReleaseFinish(int sessionId){}; public void tvPlayStopped(int sessionId){}; protected int getCurrentSessionId() { @@ -600,9 +627,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..03d8da3 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) { @@ -79,9 +97,10 @@ public abstract class TvInputBaseSession extends TvInputService.Session implemen return mDeviceId; } - public void doRelease() { - Log.d(TAG, "doRelease"); + public void performDoReleaseSession() { + Log.d(TAG, "performDoReleaseSession,session:"+this); //setAudiodMute(false); + mContext.unregisterReceiver(mBroadcastReceiver); setOverlayViewEnabled(false); if (mOverlayView != null) { mOverlayView.releaseResource(); @@ -93,11 +112,6 @@ public abstract class TvInputBaseSession extends TvInputService.Session implemen public void doUnblockContent(TvContentRating rating) {} @Override - public void onRelease() { - doRelease(); - } - - @Override public void onSurfaceChanged(int format, int width, int height) { } @@ -142,6 +156,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 +238,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");} + } } diff --git a/core/java/com/droidlogic/app/tv/TvStoreManager.java b/core/java/com/droidlogic/app/tv/TvStoreManager.java index 155923d..67579a8 100644 --- a/core/java/com/droidlogic/app/tv/TvStoreManager.java +++ b/core/java/com/droidlogic/app/tv/TvStoreManager.java @@ -1014,7 +1014,6 @@ public abstract class TvStoreManager { //take evt:progress as a store-loop end. if (!isFinalStoreStage - && (event.mode != TVChannelParams.MODE_ANALOG) && !mScanMode.isDTVManulScan()) { storeTvChannel(isRealtimeStore, isFinalStoreStage); mDisplayNumber2 = mInitialDisplayNumber;//dtv pop all channels scanned every store-loop |