@Override public void onCreate() { super.onCreate(); mHandlerThread = new HandlerThread(getClass().getSimpleName()); mHandlerThread.start(); mDbHandler = new Handler(mHandlerThread.getLooper()); mCaptioningManager = (CaptioningManager) getSystemService(Context.CAPTIONING_SERVICE); setTheme(android.R.style.Theme_Holo_Light_NoActionBar); mSessions = new ArrayList<>(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED); intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED); registerReceiver(mParentalControlsBroadcastReceiver, intentFilter); }
private void resumeToWatchedPositionIfNeeded() { if (mInitialSeekPositionMs != TvInputManager.TIME_SHIFT_INVALID_TIME) { mTvView.timeShiftSeekTo(getRealSeekPosition(mInitialSeekPositionMs, SEEK_POSITION_MARGIN_MS) + mStartPositionMs); mInitialSeekPositionMs = TvInputManager.TIME_SHIFT_INVALID_TIME; } if (mPauseOnPrepared) { mTvView.timeShiftPause(); mPlaybackState = PlaybackState.STATE_PAUSED; mPauseOnPrepared = false; } else { mTvView.timeShiftResume(); mPlaybackState = PlaybackState.STATE_PLAYING; } mCallback.onPlaybackStateChanged(mPlaybackState, 1); }
private void updateWatchAction() { List<RecordedProgram> programs = mDvrDataManager.getRecordedPrograms(mSeries.getId()); Collections.sort(programs, RecordedProgram.EPISODE_COMPARATOR); mRecommendRecordedProgram = getRecommendProgram(programs); if (mRecommendRecordedProgram == null) { mActionsAdapter.clear(ACTION_WATCH); } else { String episodeStatus; if(mDvrWatchedPositionManager.getWatchedStatus(mRecommendRecordedProgram) == DvrWatchedPositionManager.DVR_WATCHED_STATUS_WATCHING) { episodeStatus = mResumeLabel; mInitialPlaybackPositionMs = mDvrWatchedPositionManager .getWatchedPosition(mRecommendRecordedProgram.getId()); } else { episodeStatus = mWatchLabel; mInitialPlaybackPositionMs = TvInputManager.TIME_SHIFT_INVALID_TIME; } String episodeDisplayNumber = mRecommendRecordedProgram.getEpisodeDisplayNumber( getContext()); mActionsAdapter.set(ACTION_WATCH, new Action(ACTION_WATCH, episodeStatus, episodeDisplayNumber, mWatchDrawable)); } }
@Override public void onRecordedProgramsRemoved(RecordedProgram... recordedPrograms) { boolean needToUpdateCardView = false; for (RecordedProgram recordedProgram : recordedPrograms) { if (TextUtils.equals(recordedProgram.getSeriesId(), mSeriesRecording.getSeriesId())) { if (mWatchedPositionManager.getWatchedPosition(recordedProgram.getId()) == TvInputManager.TIME_SHIFT_INVALID_TIME) { mWatchedPositionManager.removeListener(this, recordedProgram.getId()); } needToUpdateCardView = true; } } if (needToUpdateCardView) { updateCardViewContent(); } }
private void updateCardViewContent() { int count = 0; int quantityStringID; List<RecordedProgram> recordedPrograms = mDvrDataManager.getRecordedPrograms(mSeriesRecording.getId()); if (recordedPrograms.size() == 0) { count = mDvrManager.getAvailableScheduledRecording(mSeriesRecording.getId()).size(); quantityStringID = R.plurals.dvr_count_scheduled_recordings; } else { for (RecordedProgram recordedProgram : recordedPrograms) { if (mWatchedPositionManager.getWatchedPosition(recordedProgram.getId()) == TvInputManager.TIME_SHIFT_INVALID_TIME) { count++; } } if (count == 0) { count = recordedPrograms.size(); quantityStringID = R.plurals.dvr_count_recordings; } else { quantityStringID = R.plurals.dvr_count_new_recordings; } } mCardView.setContent(mCardView.getResources() .getQuantityString(quantityStringID, count, count), null); }
@Override protected OnActionClickedListener onCreateOnActionClickedListener() { return new OnActionClickedListener() { @Override public void onActionClicked(Action action) { if (action.getId() == ACTION_PLAY_FROM_BEGINNING) { startPlayback(mRecordedProgram, TvInputManager.TIME_SHIFT_INVALID_TIME); } else if (action.getId() == ACTION_RESUME_PLAYING) { startPlayback(mRecordedProgram, mDvrWatchedPositionManager .getWatchedPosition(mRecordedProgram.getId())); } else if (action.getId() == ACTION_DELETE_RECORDING) { DvrManager dvrManager = TvApplication .getSingletons(getActivity()).getDvrManager(); dvrManager.removeRecordedProgram(mRecordedProgram); getActivity().finish(); } } }; }
private void onStart() { if (!mStarted) { mStarted = true; mCancelLoadTask = false; if (!PermissionUtils.hasAccessWatchedHistory(mContext)) { mWatchedHistoryManager = new WatchedHistoryManager(mContext); mWatchedHistoryManager.setListener(this); mWatchedHistoryManager.start(); } else { mContext.getContentResolver().registerContentObserver( TvContract.WatchedPrograms.CONTENT_URI, true, mContentObserver); mHandler.obtainMessage(MSG_UPDATE_WATCH_HISTORY, TvContract.WatchedPrograms.CONTENT_URI) .sendToTarget(); } mTvInputManager = (TvInputManager) mContext.getSystemService(Context.TV_INPUT_SERVICE); mTvInputManager.registerCallback(mInternalCallback, mHandler); for (TvInputInfo input : mTvInputManager.getTvInputList()) { mInputs.add(input.getId()); } } if (mChannelRecordMapLoaded) { mHandler.sendEmptyMessage(MSG_NOTIFY_CHANNEL_RECORD_MAP_LOADED); } }
@Override protected void onStart() { if (DEBUG) Log.d(TAG,"onStart()"); super.onStart(); mScreenOffIntentReceived = false; mActivityStarted = true; mTracker.sendMainStart(); mMainDurationTimer.start(); applyParentalControlSettings(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED); intentFilter.addAction(Intent.ACTION_SCREEN_OFF); intentFilter.addAction(Intent.ACTION_SCREEN_ON); registerReceiver(mBroadcastReceiver, intentFilter); Intent notificationIntent = new Intent(this, NotificationService.class); notificationIntent.setAction(NotificationService.ACTION_SHOW_RECOMMENDATION); startService(notificationIntent); }
private void updateAvailabilityToast(StreamInfo info) { if (info.isVideoAvailable()) { return; } int stringId; switch (info.getVideoUnavailableReason()) { case TunableTvView.VIDEO_UNAVAILABLE_REASON_NOT_TUNED: case TunableTvView.VIDEO_UNAVAILABLE_REASON_NO_RESOURCE: case TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING: case TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING: case TvInputManager.VIDEO_UNAVAILABLE_REASON_AUDIO_ONLY: case TvInputManager.VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL: return; case TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN: default: stringId = R.string.msg_channel_unavailable_unknown; break; } Toast.makeText(this, stringId, Toast.LENGTH_SHORT).show(); }
/** * Updates availability. It returns true, if availability is changed. */ private void updateAvailability() { boolean available; // current playing input cannot be available for PIP. Channel currentChannel = mChannelTuner.getCurrentChannel(); if (mIsPassthrough) { if (currentChannel != null && currentChannel.getInputId().equals(mInputId)) { available = false; } else { available = mInputManager.getInputState(mInputId) == TvInputManager.INPUT_STATE_CONNECTED; } } else { if (currentChannel != null && !currentChannel.isPassthrough()) { available = false; } else { available = mChannelTuner.getBrowsableChannelCount() > 0; } } if (mAvailable != available) { mAvailable = available; for (Listener l : mListeners) { l.onPipInputStateUpdated(); } } }
private boolean doTune(Uri channelUri) { if (mSessionState != STATE_IDLE) { mSession.onError(TvInputManager.RECORDING_ERROR_UNKNOWN); Log.e(TAG, "Tuning was requested from wrong status."); return false; } mChannel = getChannel(channelUri); if (mChannel == null) { mSession.onError(TvInputManager.RECORDING_ERROR_UNKNOWN); Log.w(TAG, "Failed to start recording. Couldn't find the channel for " + mChannel); return false; } if (!mDvrStorageStatusManager.isStorageSufficient()) { mSession.onError(TvInputManager.RECORDING_ERROR_INSUFFICIENT_SPACE); Log.w(TAG, "Tuning failed due to insufficient storage."); return false; } mTunerSource = mSourceManager.createDataSource(mContext, mChannel, this); if (mTunerSource == null) { mSession.onError(TvInputManager.RECORDING_ERROR_RESOURCE_BUSY); Log.w(TAG, "Tuner stream cannot be created due to resource shortage."); return false; } mSessionState = STATE_TUNED; return true; }
private void stopPlayback() { mChannelDataManager.removeAllCallbacksAndMessages(); if (mPlayer != null) { mPlayer.setPlayWhenReady(false); mPlayer.release(); mPlayer = null; mPlayerState = ExoPlayer.STATE_IDLE; mPlaybackParams.setSpeed(1.0f); mPlayerStarted = false; mReportedDrawnToSurface = false; mPreparingStartTimeMs = INVALID_TIME; mBufferingStartTimeMs = INVALID_TIME; mReadyStartTimeMs = INVALID_TIME; mSession.sendUiMessage(TunerSession.MSG_UI_HIDE_AUDIO_UNPLAYABLE); mSession.notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_UNAVAILABLE); } }
/** * Updates tuner input's info. * * @param context {@link Context} instance */ public static void updateTunerInputInfo(Context context) { if (BuildCompat.isAtLeastN()) { if (DEBUG) Log.d(TAG, "updateTunerInputInfo()"); TvInputInfo info = buildTunerInputInfo(context, isBuiltInTuner(context)); if (info != null) { ((TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE)) .updateTvInputInfo(info); if (DEBUG) { Log.d(TAG, "TvInputInfo [" + info.loadLabel(context) + "] updated: " + info.toString()); } } else { if (DEBUG) { Log.d(TAG, "Updating tuner input's info failed. Input is not ready yet."); } } } }
@Override public boolean onTune(Uri channelUri) { lastTune = new Date(); currentChannelUri = channelUri; // notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING); if(tvInputProvider instanceof SplashScreenable) { notifyVideoAvailable(); setOverlayViewEnabled(false); setOverlayViewEnabled(true); isStillLoading = true; } else notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING); setOverlayViewEnabled(true); new TuningTask().execute(channelUri, this); return true; }
@Override public boolean onTune(Uri channelUri) { Log.d(TAG, "onTune " + channelUri); notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING); String[] projection = {TvContract.Channels.COLUMN_INTERNAL_PROVIDER_DATA}; try (Cursor cursor = context.getContentResolver().query( channelUri, projection, null, // selection null, // selectionArgs null // sortOrder )) { if (cursor == null || !cursor.moveToNext()) { Log.e(TAG, "Channel not found: " + channelUri); return false; } String url = cursor.getString(0); play(url); return true; } }
private void startPlayback() { if (mCurrentChannel != null) { notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING); try { mDtvManager.start(mCurrentChannel); } catch (InternalException e) { e.printStackTrace(); } mLog.d("[startPlayback] mImageViewRadio SHOW: " + (mCurrentChannel.getServiceType() == ServiceType.DIG_RAD)); if (mImageViewRadio != null) { mImageViewRadio.setVisibility(mCurrentChannel.getServiceType() == ServiceType .DIG_RAD ? View.VISIBLE : View.GONE); } notifyVideoAvailable(); } }
@Override public void onCreate() { mLog.d("[onCreateService]"); super.onCreate(); mSessionTable = new Hashtable<String, TvSession>(); try { DtvManager.instantiate(this); } catch (RemoteException e) { e.printStackTrace(); } mDtvManager = DtvManager.getInstance(); if (mDtvManager == null) { mLog.e("DVBManager is null!"); } mDtvManager.getDtvManager().getServiceControl().registerCallback(mServiceCallback); IntentFilter filter = new IntentFilter(); filter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED); filter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED); registerReceiver(mContentRatingReceiver, filter); }
@Override public boolean onPlayProgram(Program program, long startPosMs) { if (program == null) { requestEpgSync(getCurrentChannelUri()); notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING); return false; } createPlayer(program.getInternalProviderData().getVideoType(), Uri.parse(program.getInternalProviderData().getVideoUrl())); if (startPosMs > 0) { mPlayer.seekTo(startPosMs); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE); } mPlayer.setPlayWhenReady(true); return true; }
@Override public void onStateChanged(boolean playWhenReady, int playbackState) { if (mPlayer == null) { return; } if (playWhenReady && playbackState == ExoPlayer.STATE_READY) { notifyTracksChanged(getAllTracks()); String audioId = getTrackId(TvTrackInfo.TYPE_AUDIO, mPlayer.getSelectedTrack(TvTrackInfo.TYPE_AUDIO)); String videoId = getTrackId(TvTrackInfo.TYPE_VIDEO, mPlayer.getSelectedTrack(TvTrackInfo.TYPE_VIDEO)); String textId = getTrackId(TvTrackInfo.TYPE_SUBTITLE, mPlayer.getSelectedTrack(TvTrackInfo.TYPE_SUBTITLE)); notifyTrackSelected(TvTrackInfo.TYPE_AUDIO, audioId); notifyTrackSelected(TvTrackInfo.TYPE_VIDEO, videoId); notifyTrackSelected(TvTrackInfo.TYPE_SUBTITLE, textId); notifyVideoAvailable(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Math.abs(mPlayer.getPlaybackSpeed() - 1) < 0.1 && playWhenReady && playbackState == ExoPlayer.STATE_BUFFERING) { notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING); } }
@Override public void onCreate() { super.onCreate(); // Create background thread mDbHandlerThread = new HandlerThread(getClass().getSimpleName()); mDbHandlerThread.start(); // Initialize the channel map and set observer for changes mContentResolver = BaseTvInputService.this.getContentResolver(); updateChannelMap(); mChannelObserver = new ContentObserver(new Handler(mDbHandlerThread.getLooper())) { @Override public void onChange(boolean selfChange) { updateChannelMap(); } }; mContentResolver.registerContentObserver(TvContract.Channels.CONTENT_URI, true, mChannelObserver); // Setup our BroadcastReceiver IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED); intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED); registerReceiver(mParentalControlsBroadcastReceiver, intentFilter); }
@Override public boolean onTune(Uri channelUri) { mNeedToCheckChannelAd = true; notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING); mChannelUri = channelUri; long channelId = ContentUris.parseId(channelUri); mCurrentChannel = mChannelMap.get(channelId); mTimeShiftedPlaybackPosition = TvInputManager.TIME_SHIFT_INVALID_TIME; // Release Ads assets releaseAdController(); mHandler.removeMessages(MSG_PLAY_AD); if (mDbHandler != null) { mUnblockedRatingSet.clear(); mDbHandler.removeCallbacks(mGetCurrentProgramRunnable); mGetCurrentProgramRunnable = new GetCurrentProgramRunnable(mChannelUri); mDbHandler.post(mGetCurrentProgramRunnable); } return true; }
@Override public TvPlayer onAdReadyToPlay(String adVideoUrl) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_UNAVAILABLE); } onPlayAdvertisement(new Advertisement.Builder(mAdvertisement) .setRequestUrl(adVideoUrl) .build()); setTvPlayerSurface(mSurface); setTvPlayerVolume(mVolume); long currentTimeMs = System.currentTimeMillis(); long adStartTime = mAdvertisement.getStartTimeUtcMillis(); if (adStartTime > 0 && adStartTime < currentTimeMs) { getTvPlayer().seekTo(currentTimeMs - adStartTime); } return getTvPlayer(); }
@Override public void run() { ContentResolver resolver = mContext.getContentResolver(); Program program = null; long timeShiftedDifference = System.currentTimeMillis() - mTimeShiftedPlaybackPosition; if (mTimeShiftedPlaybackPosition != TvInputManager.TIME_SHIFT_INVALID_TIME && timeShiftedDifference > TIME_SHIFTED_MINIMUM_DIFFERENCE_MILLIS) { program = TvContractUtils.getNextProgram(resolver, mChannelUri, mCurrentProgram); } else { mTimeShiftedPlaybackPosition = TvInputManager.TIME_SHIFT_INVALID_TIME; program = TvContractUtils.getCurrentProgram(resolver, mChannelUri); } mHandler.removeMessages(MSG_PLAY_CONTENT); mHandler.obtainMessage(MSG_PLAY_CONTENT, program).sendToTarget(); }
@Override public void run() { ContentResolver contentResolver = mContext.getContentResolver(); Cursor cursor = contentResolver.query(mRecordedProgramUri, RecordedProgram.PROJECTION, null, null, null); if (cursor == null) { // The recorded program does not exist. notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN); } else { if (cursor.moveToNext()) { RecordedProgram recordedProgram = RecordedProgram.fromCursor(cursor); if (DEBUG) { Log.d(TAG, "Play program " + recordedProgram.getTitle()); Log.d(TAG, recordedProgram.getRecordingDataUri()); } if (recordedProgram == null) { Log.e(TAG, "RecordedProgram at " + mRecordedProgramUri + " does not " + "exist"); notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN); } mHandler.removeMessages(MSG_PLAY_RECORDED_CONTENT); mHandler.obtainMessage(MSG_PLAY_RECORDED_CONTENT, recordedProgram) .sendToTarget(); } } }
private boolean playMediaUrl(String mediaUrl) { getTvPlayer(); Log.d(TAG, "Play " + mediaUrl); try { if (mediaUrl.startsWith("assets://")) { AssetFileDescriptor fileDescriptor = getAssets().openFd(mediaUrl.substring(9)); mMockTvPlayer.playMediaFromAssets(fileDescriptor); } else { mMockTvPlayer.playMedia(mediaUrl); } } catch (IOException e) { e.printStackTrace(); notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN); return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE); } notifyVideoAvailable(); return true; }
protected RichTvInputSessionImpl(Context context, String inputId) { super(context); mContext = context; mInputId = inputId; mTvInputManager = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE); mLastBlockedRating = null; mCaptionEnabled = mCaptioningManager.isEnabled(); mHandler = new Handler(this); }
@Override public boolean onTune(Uri channelUri) { notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING); mUnblockedRatingSet.clear(); mDbHandler.removeCallbacks(mPlayCurrentProgramRunnable); mPlayCurrentProgramRunnable = new PlayCurrentProgramRunnable(channelUri); mDbHandler.post(mPlayCurrentProgramRunnable); return true; }
public void update() { mContentRatingSystems.clear(); TvInputManager manager = (TvInputManager) mContext.getSystemService(Context.TV_INPUT_SERVICE); ContentRatingsParser parser = new ContentRatingsParser(mContext); List<TvContentRatingSystemInfo> infos = manager.getTvContentRatingSystemList(); for (TvContentRatingSystemInfo info : infos) { List<ContentRatingSystem> list = parser.parse(info); if (list != null) { mContentRatingSystems.addAll(list); } } }
/** * Handles the global key KEYCODE_TV_INPUT. */ public void handleTvInputKey() { TvInputManager tvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE); List<TvInputInfo> tvInputs = tvInputManager.getTvInputList(); int inputCount = 0; boolean hasTunerInput = false; for (TvInputInfo input : tvInputs) { if (input.isPassthroughInput()) { if (!input.isHidden(this)) { ++inputCount; } } else if (!hasTunerInput) { hasTunerInput = true; ++inputCount; } } if (inputCount < 2) { return; } Activity activityToHandle = mMainActivityWrapper.isResumed() ? mMainActivityWrapper.getMainActivity() : mSelectInputActivity; if (activityToHandle != null) { // If startActivity is called, MainActivity.onPause is unnecessarily called. To // prevent it, MainActivity.dispatchKeyEvent is directly called. activityToHandle.dispatchKeyEvent( new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TV_INPUT)); activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TV_INPUT)); } else if (mMainActivityWrapper.isStarted()) { Bundle extras = new Bundle(); extras.putString(Utils.EXTRA_KEY_ACTION, Utils.EXTRA_ACTION_SHOW_TV_INPUT); startMainActivity(extras); } else { startActivity(new Intent(this, SelectInputActivity.class).setFlags( Intent.FLAG_ACTIVITY_NEW_TASK)); } }
/** * Checks the input counts and enable/disable TvActivity. Also updates the input list in * {@link SetupUtils}. * * @param calledByTunerServiceChanged true if it is called when TunerTvInputService * is enabled or disabled. * @param tunerServiceEnabled it's available only when calledByTunerServiceChanged is true. * @param dontKillApp when TvActivity is enabled or disabled by this method, the app restarts * by default. But, if dontKillApp is true, the app won't restart. */ public void handleInputCountChanged(boolean calledByTunerServiceChanged, boolean tunerServiceEnabled, boolean dontKillApp) { TvInputManager inputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE); boolean enable = (calledByTunerServiceChanged && tunerServiceEnabled) || Features.UNHIDE.isEnabled(TvApplication.this); if (!enable) { List<TvInputInfo> inputs = inputManager.getTvInputList(); boolean skipTunerInputCheck = false; // Enable the TvActivity only if there is at least one tuner type input. if (!skipTunerInputCheck) { for (TvInputInfo input : inputs) { if (calledByTunerServiceChanged && !tunerServiceEnabled && TunerTvInputService.getInputId(this).equals(input.getId())) { continue; } if (input.getType() == TvInputInfo.TYPE_TUNER) { enable = true; break; } } } if (DEBUG) Log.d(TAG, "Enable MainActivity: " + enable); } PackageManager packageManager = getPackageManager(); ComponentName name = new ComponentName(this, TvActivity.class); int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (packageManager.getComponentEnabledSetting(name) != newState) { packageManager.setComponentEnabledSetting(name, newState, dontKillApp ? PackageManager.DONT_KILL_APP : 0); } SetupUtils.getInstance(TvApplication.this).onInputListUpdated(inputManager); }
/** * Resets playback. */ public void reset() { if (DEBUG) Log.d(TAG, "reset()"); mCallback.onPlaybackStateChanged(PlaybackState.STATE_NONE, 1); mPlaybackState = PlaybackState.STATE_NONE; mTvView.reset(); mTimeShiftPlayAvailable = false; mStartPositionMs = TvInputManager.TIME_SHIFT_INVALID_TIME; mTimeShiftCurrentPositionMs = 0; mPlaybackParams.setSpeed(1.0f); mProgram = null; }
@DvrWatchedStatus public int getWatchedStatus(RecordedProgram recordedProgram) { long watchedPosition = getWatchedPosition(recordedProgram.getId()); if (watchedPosition == TvInputManager.TIME_SHIFT_INVALID_TIME) { return DVR_WATCHED_STATUS_NEW; } else if (watchedPosition > recordedProgram .getDurationMillis() * DVR_WATCHED_THRESHOLD_RATE) { return DVR_WATCHED_STATUS_WATCHED; } else { return DVR_WATCHED_STATUS_WATCHING; } }
@Override public void onError(int reason) { if (DEBUG) Log.d(TAG, "onError reason " + reason); if (mRecordingSession == null) { return; } switch (reason) { case TvInputManager.RECORDING_ERROR_INSUFFICIENT_SPACE: mMainThreadHandler.post(new Runnable() { @Override public void run() { if (TvApplication.getSingletons(mContext).getMainActivityWrapper() .isResumed()) { Toast.makeText(mContext.getApplicationContext(), R.string.dvr_error_insufficient_space_description, Toast.LENGTH_LONG) .show(); } else { Utils.setRecordingFailedReason(mContext.getApplicationContext(), TvInputManager.RECORDING_ERROR_INSUFFICIENT_SPACE); } } }); // Pass through default: failAndQuit(); break; } }
private void launchPlaybackActivity(RecordedProgram mRecordedProgram, long seekTimeMs, boolean pinChecked) { Intent intent = new Intent(getActivity(), DvrPlaybackActivity.class); intent.putExtra(Utils.EXTRA_KEY_RECORDED_PROGRAM_ID, mRecordedProgram.getId()); if (seekTimeMs != TvInputManager.TIME_SHIFT_INVALID_TIME) { intent.putExtra(Utils.EXTRA_KEY_RECORDED_PROGRAM_SEEK_TIME, seekTimeMs); } intent.putExtra(Utils.EXTRA_KEY_RECORDED_PROGRAM_PIN_CHECKED, pinChecked); getActivity().startActivity(intent); }
@Override public void onWatchedPositionChanged(long recordedProgramId, long positionMs) { if (positionMs != TvInputManager.TIME_SHIFT_INVALID_TIME) { mWatchedPositionManager.removeListener(this, recordedProgramId); updateCardViewContent(); } }
public void onBound(SeriesRecording seriesRecording) { mSeriesRecording = seriesRecording; mDvrDataManager.addScheduledRecordingListener(this); mDvrDataManager.addRecordedProgramListener(this); for (RecordedProgram recordedProgram : mDvrDataManager.getRecordedPrograms(mSeriesRecording.getId())) { if (mWatchedPositionManager.getWatchedPosition(recordedProgram.getId()) == TvInputManager.TIME_SHIFT_INVALID_TIME) { mWatchedPositionManager.addListener(this, recordedProgram.getId()); } } updateCardViewContent(); }
DataManagerSearch(Context context) { mContext = context; mTvInputManager = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE); ApplicationSingletons appSingletons = TvApplication.getSingletons(context); mChannelDataManager = appSingletons.getChannelDataManager(); mProgramDataManager = appSingletons.getProgramDataManager(); }
@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"); // We need to stop TvView, when the screen is turned off. If not and TIS uses // MediaPlayer, a device may not go to the sleep mode and audio can be heard, // because MediaPlayer keeps playing media by its wake lock. mScreenOffIntentReceived = true; markCurrentChannelDuringScreenOff(); stopAll(true); } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { if (DEBUG) Log.d(TAG, "Received ACTION_SCREEN_ON"); if (!mActivityResumed && mVisibleBehind) { // ACTION_SCREEN_ON is usually called after onResume. But, if media is played // under launcher with requestVisibleBehind(true), onResume will not be called. // In this case, we need to resume TvView and PipView explicitly. resumeTvIfNeeded(); resumePipIfNeeded(); } } else if (intent.getAction().equals( TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED)) { if (DEBUG) Log.d(TAG, "Received parental control settings change"); checkChannelLockNeeded(mTvView); checkChannelLockNeeded(mPipView); applyParentalControlSettings(); } }
@Override public void onVideoUnavailable(String inputId, int reason) { hideScreenByVideoAvailability(inputId, reason); if (mOnTuneListener != null) { mOnTuneListener.onStreamInfoChanged(TunableTvView.this); } switch (reason) { case TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING: case TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN: case TvInputManager.VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL: mTracker.sendChannelVideoUnavailable(mCurrentChannel, reason); default: // do nothing } }
/** * Warms up the input to reduce the start time. */ public void warmUpInput(String inputId, Uri channelUri) { if (!mStarted && inputId != null && channelUri != null) { if (mTvViewSession != null) { mTvViewSession.tune(inputId, channelUri); } else { mTvView.tune(inputId, channelUri); } hideScreenByVideoAvailability(inputId, TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING); } }