diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/MediaRouter.java | 51 | ||||
-rw-r--r-- | media/java/android/media/musicrecognition/OWNERS | 6 | ||||
-rw-r--r-- | media/java/android/media/tv/ITvInputManager.aidl | 2 | ||||
-rw-r--r-- | media/java/android/media/tv/ITvInputSession.aidl | 2 | ||||
-rw-r--r-- | media/java/android/media/tv/ITvInputSessionWrapper.java | 20 | ||||
-rw-r--r-- | media/java/android/media/tv/TvContract.java | 65 | ||||
-rw-r--r-- | media/java/android/media/tv/TvInputInfo.java | 40 | ||||
-rw-r--r-- | media/java/android/media/tv/TvInputManager.java | 34 | ||||
-rwxr-xr-x | media/java/android/media/tv/TvInputService.java | 38 | ||||
-rw-r--r-- | media/java/android/media/tv/TvRecordingClient.java | 135 | ||||
-rw-r--r-- | media/java/android/media/tv/tuner/Tuner.java | 76 | ||||
-rw-r--r-- | media/java/android/media/tv/tuner/frontend/FrontendInfo.java | 4 | ||||
-rw-r--r-- | media/java/android/mtp/MtpStorageManager.java | 6 | ||||
-rw-r--r-- | media/jni/android_media_tv_Tuner.cpp | 15 | ||||
-rw-r--r-- | media/jni/android_media_tv_Tuner.h | 1 |
15 files changed, 440 insertions, 55 deletions
diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index cf643dd113f5..1a367d9b1734 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -44,6 +44,7 @@ import android.os.ServiceManager; import android.os.UserHandle; import android.text.TextUtils; import android.util.Log; +import android.util.SparseIntArray; import android.view.Display; import java.lang.annotation.Retention; @@ -94,6 +95,7 @@ public class MediaRouter { RouteInfo mDefaultAudioVideo; RouteInfo mBluetoothA2dpRoute; + boolean mIsBluetoothA2dpOn; RouteInfo mSelectedRoute; @@ -108,9 +110,16 @@ public class MediaRouter { IMediaRouterClient mClient; MediaRouterClientState mClientState; + SparseIntArray mStreamVolume = new SparseIntArray(); + final IAudioRoutesObserver.Stub mAudioRoutesObserver = new IAudioRoutesObserver.Stub() { @Override public void dispatchAudioRoutesChanged(final AudioRoutesInfo newRoutes) { + try { + mIsBluetoothA2dpOn = mAudioService.isBluetoothA2dpOn(); + } catch (RemoteException e) { + Log.e(TAG, "Error querying Bluetooth A2DP state", e); + } mHandler.post(new Runnable() { @Override public void run() { updateAudioRoutes(newRoutes); @@ -259,13 +268,24 @@ public class MediaRouter { mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName; } - boolean isBluetoothA2dpOn() { - try { - return mBluetoothA2dpRoute != null && mAudioService.isBluetoothA2dpOn(); - } catch (RemoteException e) { - Log.e(TAG, "Error querying Bluetooth A2DP state", e); - return false; + int getStreamVolume(int streamType) { + int idx = mStreamVolume.indexOfKey(streamType); + if (idx < 0) { + int volume = 0; + try { + volume = mAudioService.getStreamVolume(streamType); + mStreamVolume.put(streamType, volume); + } catch (RemoteException e) { + Log.e(TAG, "Error getting local stream volume", e); + } finally { + return volume; + } } + return mStreamVolume.valueAt(idx); + } + + boolean isBluetoothA2dpOn() { + return mBluetoothA2dpRoute != null && mIsBluetoothA2dpOn; } void updateDiscoveryRequest() { @@ -1426,12 +1446,8 @@ public class MediaRouter { selectedRoute == sStatic.mDefaultAudioVideo) { dispatchRouteVolumeChanged(selectedRoute); } else if (sStatic.mBluetoothA2dpRoute != null) { - try { - dispatchRouteVolumeChanged(sStatic.mAudioService.isBluetoothA2dpOn() ? - sStatic.mBluetoothA2dpRoute : sStatic.mDefaultAudioVideo); - } catch (RemoteException e) { - Log.e(TAG, "Error checking Bluetooth A2DP state to report volume change", e); - } + dispatchRouteVolumeChanged(sStatic.mIsBluetoothA2dpOn + ? sStatic.mBluetoothA2dpRoute : sStatic.mDefaultAudioVideo); } else { dispatchRouteVolumeChanged(sStatic.mDefaultAudioVideo); } @@ -1956,13 +1972,7 @@ public class MediaRouter { */ public int getVolume() { if (mPlaybackType == PLAYBACK_TYPE_LOCAL) { - int vol = 0; - try { - vol = sStatic.mAudioService.getStreamVolume(mPlaybackStream); - } catch (RemoteException e) { - Log.e(TAG, "Error getting local stream volume", e); - } - return vol; + return sStatic.getStreamVolume(mPlaybackStream); } else { return mVolume; } @@ -3077,11 +3087,12 @@ public class MediaRouter { if (intent.getAction().equals(AudioManager.VOLUME_CHANGED_ACTION)) { final int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); + final int newVolume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); + sStatic.mStreamVolume.put(streamType, newVolume); if (streamType != AudioManager.STREAM_MUSIC) { return; } - final int newVolume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); final int oldVolume = intent.getIntExtra( AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, 0); if (newVolume != oldVolume) { diff --git a/media/java/android/media/musicrecognition/OWNERS b/media/java/android/media/musicrecognition/OWNERS new file mode 100644 index 000000000000..58f5d40dd8c3 --- /dev/null +++ b/media/java/android/media/musicrecognition/OWNERS @@ -0,0 +1,6 @@ +# Bug component: 830636 + +joannechung@google.com +oni@google.com +volnov@google.com + diff --git a/media/java/android/media/tv/ITvInputManager.aidl b/media/java/android/media/tv/ITvInputManager.aidl index 1fbb67260895..5d7fdff70f5c 100644 --- a/media/java/android/media/tv/ITvInputManager.aidl +++ b/media/java/android/media/tv/ITvInputManager.aidl @@ -91,6 +91,8 @@ interface ITvInputManager { // For the recording session void startRecording(in IBinder sessionToken, in Uri programUri, in Bundle params, int userId); void stopRecording(in IBinder sessionToken, int userId); + void pauseRecording(in IBinder sessionToken, in Bundle params, int userId); + void resumeRecording(in IBinder sessionToken, in Bundle params, int userId); // For TV input hardware binding List<TvInputHardwareInfo> getHardwareList(); diff --git a/media/java/android/media/tv/ITvInputSession.aidl b/media/java/android/media/tv/ITvInputSession.aidl index 24b87d50b33e..158cf211d9f0 100644 --- a/media/java/android/media/tv/ITvInputSession.aidl +++ b/media/java/android/media/tv/ITvInputSession.aidl @@ -58,4 +58,6 @@ oneway interface ITvInputSession { // For the recording session void startRecording(in Uri programUri, in Bundle params); void stopRecording(); + void pauseRecording(in Bundle params); + void resumeRecording(in Bundle params); } diff --git a/media/java/android/media/tv/ITvInputSessionWrapper.java b/media/java/android/media/tv/ITvInputSessionWrapper.java index e89d33d70d5c..abccf8da9cfc 100644 --- a/media/java/android/media/tv/ITvInputSessionWrapper.java +++ b/media/java/android/media/tv/ITvInputSessionWrapper.java @@ -68,6 +68,8 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand private static final int DO_TIME_SHIFT_ENABLE_POSITION_TRACKING = 19; private static final int DO_START_RECORDING = 20; private static final int DO_STOP_RECORDING = 21; + private static final int DO_PAUSE_RECORDING = 22; + private static final int DO_RESUME_RECORDING = 23; private final boolean mIsRecordingSession; private final HandlerCaller mCaller; @@ -224,6 +226,14 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand mTvInputRecordingSessionImpl.stopRecording(); break; } + case DO_PAUSE_RECORDING: { + mTvInputRecordingSessionImpl.pauseRecording((Bundle) msg.obj); + break; + } + case DO_RESUME_RECORDING: { + mTvInputRecordingSessionImpl.resumeRecording((Bundle) msg.obj); + break; + } default: { Log.w(TAG, "Unhandled message code: " + msg.what); break; @@ -363,6 +373,16 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_STOP_RECORDING)); } + @Override + public void pauseRecording(@Nullable Bundle params) { + mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_PAUSE_RECORDING, params)); + } + + @Override + public void resumeRecording(@Nullable Bundle params) { + mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_RESUME_RECORDING, params)); + } + private final class TvInputEventReceiver extends InputEventReceiver { public TvInputEventReceiver(InputChannel inputChannel, Looper looper) { super(inputChannel, looper); diff --git a/media/java/android/media/tv/TvContract.java b/media/java/android/media/tv/TvContract.java index 433c6227cd5f..30a14c84b72e 100644 --- a/media/java/android/media/tv/TvContract.java +++ b/media/java/android/media/tv/TvContract.java @@ -2450,6 +2450,71 @@ public final class TvContract { */ public static final String COLUMN_GLOBAL_CONTENT_ID = "global_content_id"; + /** + * The remote control key preset number that is assigned to this channel. + * + * <p> This can be used for one-touch-tuning, tuning to the channel with + * pressing the preset button. + * + * <p> Type: INTEGER (remote control key preset number) + */ + public static final String COLUMN_REMOTE_CONTROL_KEY_PRESET_NUMBER = + "remote_control_key_preset_number"; + + /** + * The flag indicating whether this TV channel is scrambled or not. + * + * <p>Use the same coding for scrambled in the underlying broadcast standard + * if {@code free_ca_mode} in SDT is defined there (e.g. ETSI EN 300 468). + * + * <p>Type: INTEGER (boolean) + */ + public static final String COLUMN_SCRAMBLED = "scrambled"; + + /** + * The typical video resolution. + * + * <p>This is primarily used to filter out channels based on video resolution + * by applications. The value is from SDT if defined there. (e.g. ETSI EN 300 468) + * The value should match one of the followings: {@link #VIDEO_RESOLUTION_SD}, + * {@link #VIDEO_RESOLUTION_HD}, {@link #VIDEO_RESOLUTION_UHD}. + * + * <p>Type: TEXT + * + */ + public static final String COLUMN_VIDEO_RESOLUTION = "video_resolution"; + + /** + * The channel list ID of this TV channel. + * + * <p>It is used to identify the channel list constructed from broadcast SI based on the + * underlying broadcast standard or country/operator profile, if applicable. Otherwise, + * leave empty. + * + * <p>The ID can be defined by individual TV input services. For example, one may assign a + * service operator name for the service operator channel list constructed from broadcast + * SI or one may assign the {@code profile_name} of the operator_info() APDU defined in CI + * Plus 1.3 for the dedicated CICAM operator profile channel list constructed + * from CICAM NIT. + * + * <p>Type: TEXT + */ + public static final String COLUMN_CHANNEL_LIST_ID = "channel_list_id"; + + /** + * The comma-separated genre string of this TV channel. + * + * <p>Use the same language appeared in the underlying broadcast standard, if applicable. + * Otherwise, leave empty. Use + * {@link Genres#encode Genres.encode()} to create a text that can be stored in this column. + * Use {@link Genres#decode Genres.decode()} to get the broadcast genre strings from the + * text stored in the column. + * + * <p>Type: TEXT + * @see Programs#COLUMN_BROADCAST_GENRE + */ + public static final String COLUMN_BROADCAST_GENRE = Programs.COLUMN_BROADCAST_GENRE; + private Channels() {} /** diff --git a/media/java/android/media/tv/TvInputInfo.java b/media/java/android/media/tv/TvInputInfo.java index 195ad5bc10f9..54cb2bff5566 100644 --- a/media/java/android/media/tv/TvInputInfo.java +++ b/media/java/android/media/tv/TvInputInfo.java @@ -143,6 +143,7 @@ public final class TvInputInfo implements Parcelable { // Attributes from XML meta data. private final String mSetupActivity; private final boolean mCanRecord; + private final boolean mCanPauseRecording; private final int mTunerCount; // Attributes specific to HDMI @@ -264,8 +265,8 @@ public final class TvInputInfo implements Parcelable { private TvInputInfo(ResolveInfo service, String id, int type, boolean isHardwareInput, CharSequence label, int labelResId, Icon icon, Icon iconStandby, Icon iconDisconnected, - String setupActivity, boolean canRecord, int tunerCount, HdmiDeviceInfo hdmiDeviceInfo, - boolean isConnectedToHdmiSwitch, + String setupActivity, boolean canRecord, boolean canPauseRecording, int tunerCount, + HdmiDeviceInfo hdmiDeviceInfo, boolean isConnectedToHdmiSwitch, @HdmiAddressRelativePosition int hdmiConnectionRelativePosition, String parentId, Bundle extras) { mService = service; @@ -279,6 +280,7 @@ public final class TvInputInfo implements Parcelable { mIconDisconnected = iconDisconnected; mSetupActivity = setupActivity; mCanRecord = canRecord; + mCanPauseRecording = canPauseRecording; mTunerCount = tunerCount; mHdmiDeviceInfo = hdmiDeviceInfo; mIsConnectedToHdmiSwitch = isConnectedToHdmiSwitch; @@ -386,6 +388,14 @@ public final class TvInputInfo implements Parcelable { } /** + * Returns {@code true} if this TV input can pause recording TV programs, + * {@code false} otherwise. + */ + public boolean canPauseRecording() { + return mCanPauseRecording; + } + + /** * Returns domain-specific extras associated with this TV input. */ public Bundle getExtras() { @@ -571,6 +581,7 @@ public final class TvInputInfo implements Parcelable { && Objects.equals(mIconDisconnected, obj.mIconDisconnected) && TextUtils.equals(mSetupActivity, obj.mSetupActivity) && mCanRecord == obj.mCanRecord + && mCanPauseRecording == obj.mCanPauseRecording && mTunerCount == obj.mTunerCount && Objects.equals(mHdmiDeviceInfo, obj.mHdmiDeviceInfo) && mIsConnectedToHdmiSwitch == obj.mIsConnectedToHdmiSwitch @@ -606,6 +617,7 @@ public final class TvInputInfo implements Parcelable { dest.writeParcelable(mIconDisconnected, flags); dest.writeString(mSetupActivity); dest.writeByte(mCanRecord ? (byte) 1 : 0); + dest.writeByte(mCanPauseRecording ? (byte) 1 : 0); dest.writeInt(mTunerCount); dest.writeParcelable(mHdmiDeviceInfo, flags); dest.writeByte(mIsConnectedToHdmiSwitch ? (byte) 1 : 0); @@ -648,6 +660,7 @@ public final class TvInputInfo implements Parcelable { mIconDisconnected = in.readParcelable(null); mSetupActivity = in.readString(); mCanRecord = in.readByte() == 1; + mCanPauseRecording = in.readByte() == 1; mTunerCount = in.readInt(); mHdmiDeviceInfo = in.readParcelable(null); mIsConnectedToHdmiSwitch = in.readByte() == 1; @@ -695,6 +708,7 @@ public final class TvInputInfo implements Parcelable { private Icon mIconDisconnected; private String mSetupActivity; private Boolean mCanRecord; + private Boolean mCanPauseRecording; private Integer mTunerCount; private TvInputHardwareInfo mTvInputHardwareInfo; private HdmiDeviceInfo mHdmiDeviceInfo; @@ -879,6 +893,18 @@ public final class TvInputInfo implements Parcelable { } /** + * Sets whether this TV input can pause recording TV programs or not. + * + * @param canPauseRecording Whether this TV input can pause recording TV programs. + * @return This Builder object to allow for chaining of calls to builder methods. + */ + @NonNull + public Builder setCanPauseRecording(boolean canPauseRecording) { + this.mCanPauseRecording = canPauseRecording; + return this; + } + + /** * Sets domain-specific extras associated with this TV input. * * @param extras Domain-specific extras associated with this TV input. Keys <em>must</em> be @@ -927,7 +953,9 @@ public final class TvInputInfo implements Parcelable { parseServiceMetadata(type); return new TvInputInfo(mResolveInfo, id, type, isHardwareInput, mLabel, mLabelResId, mIcon, mIconStandby, mIconDisconnected, mSetupActivity, - mCanRecord == null ? false : mCanRecord, mTunerCount == null ? 0 : mTunerCount, + mCanRecord == null ? false : mCanRecord, + mCanPauseRecording == null ? false : mCanPauseRecording, + mTunerCount == null ? 0 : mTunerCount, mHdmiDeviceInfo, isConnectedToHdmiSwitch, hdmiConnectionRelativePosition, mParentId, mExtras); } @@ -997,6 +1025,12 @@ public final class TvInputInfo implements Parcelable { mTunerCount = sa.getInt( com.android.internal.R.styleable.TvInputService_tunerCount, 1); } + if (mCanPauseRecording == null) { + mCanPauseRecording = sa.getBoolean( + com.android.internal.R.styleable.TvInputService_canPauseRecording, + false); + } + sa.recycle(); } catch (IOException | XmlPullParserException e) { throw new IllegalStateException("Failed reading meta-data for " + si.packageName, e); diff --git a/media/java/android/media/tv/TvInputManager.java b/media/java/android/media/tv/TvInputManager.java index 98a01a4cb449..6341dc263efd 100644 --- a/media/java/android/media/tv/TvInputManager.java +++ b/media/java/android/media/tv/TvInputManager.java @@ -2476,6 +2476,40 @@ public final class TvInputManager { } /** + * Pauses TV program recording in the current recording session. + * + * @param params A set of extra parameters which might be handled with this event. + */ + void pauseRecording(@NonNull Bundle params) { + if (mToken == null) { + Log.w(TAG, "The session has been already released"); + return; + } + try { + mService.pauseRecording(mToken, params, mUserId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Resumes TV program recording in the current recording session. + * + * @param params A set of extra parameters which might be handled with this event. + */ + void resumeRecording(@NonNull Bundle params) { + if (mToken == null) { + Log.w(TAG, "The session has been already released"); + return; + } + try { + mService.resumeRecording(mToken, params, mUserId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Calls {@link TvInputService.Session#appPrivateCommand(String, Bundle) * TvInputService.Session.appPrivateCommand()} on the current TvView. * diff --git a/media/java/android/media/tv/TvInputService.java b/media/java/android/media/tv/TvInputService.java index abbf4780bcc1..0fe9d504b951 100755 --- a/media/java/android/media/tv/TvInputService.java +++ b/media/java/android/media/tv/TvInputService.java @@ -1852,6 +1852,28 @@ public abstract class TvInputService extends Service { /** + * Called when the application requests to pause TV program recording. Recording must pause + * immediately when this method is called. + * + * If the pause request cannot be fulfilled, the session must call + * {@link #notifyError(int)}. + * + * @param params Domain-specific data for recording request. + */ + public void onPauseRecording(@NonNull Bundle params) { } + + /** + * Called when the application requests to resume TV program recording. Recording must + * resume immediately when this method is called. + * + * If the resume request cannot be fulfilled, the session must call + * {@link #notifyError(int)}. + * + * @param params Domain-specific data for recording request. + */ + public void onResumeRecording(@NonNull Bundle params) { } + + /** * Called when the application requests to release all the resources held by this recording * session. */ @@ -1903,6 +1925,22 @@ public abstract class TvInputService extends Service { } /** + * Calls {@link #onPauseRecording(Bundle)}. + * + */ + void pauseRecording(@NonNull Bundle params) { + onPauseRecording(params); + } + + /** + * Calls {@link #onResumeRecording(Bundle)}. + * + */ + void resumeRecording(@NonNull Bundle params) { + onResumeRecording(params); + } + + /** * Calls {@link #onAppPrivateCommand(String, Bundle)}. */ void appPrivateCommand(String action, Bundle data) { diff --git a/media/java/android/media/tv/TvRecordingClient.java b/media/java/android/media/tv/TvRecordingClient.java index 23fadac8a72b..180e2bd6845b 100644 --- a/media/java/android/media/tv/TvRecordingClient.java +++ b/media/java/android/media/tv/TvRecordingClient.java @@ -30,6 +30,7 @@ import android.util.Log; import android.util.Pair; import java.util.ArrayDeque; +import java.util.Objects; import java.util.Queue; /** @@ -49,6 +50,8 @@ public class TvRecordingClient { private boolean mIsRecordingStarted; private boolean mIsTuned; + private boolean mIsPaused; + private boolean mIsRecordingStopping; private final Queue<Pair<String, Bundle>> mPendingAppPrivateCommands = new ArrayDeque<>(); /** @@ -113,17 +116,22 @@ public class TvRecordingClient { if (TextUtils.isEmpty(inputId)) { throw new IllegalArgumentException("inputId cannot be null or an empty string"); } - if (mIsRecordingStarted) { + if (mIsRecordingStarted && !mIsPaused) { throw new IllegalStateException("tune failed - recording already started"); } if (mSessionCallback != null && TextUtils.equals(mSessionCallback.mInputId, inputId)) { if (mSession != null) { + mSessionCallback.mChannelUri = channelUri; mSession.tune(channelUri, params); } else { mSessionCallback.mChannelUri = channelUri; mSessionCallback.mConnectionParams = params; } + mIsTuned = false; } else { + if (mIsPaused) { + throw new IllegalStateException("tune failed - inputId is changed during pause"); + } resetInternal(); mSessionCallback = new MySessionCallback(inputId, channelUri, params); if (mTvInputManager != null) { @@ -148,6 +156,8 @@ public class TvRecordingClient { mSession.release(); mIsTuned = false; mIsRecordingStarted = false; + mIsPaused = false; + mIsRecordingStopping = false; mSession = null; } } @@ -169,7 +179,8 @@ public class TvRecordingClient { * * @param programUri The URI for the TV program to record, built by * {@link TvContract#buildProgramUri(long)}. Can be {@code null}. - * @throws IllegalStateException If {@link #tune} request hasn't been handled yet. + * @throws IllegalStateException If {@link #tune} request hasn't been handled yet or during + * pause. */ public void startRecording(@Nullable Uri programUri) { startRecording(programUri, Bundle.EMPTY); @@ -195,11 +206,16 @@ public class TvRecordingClient { * @param params Domain-specific data for this request. Keys <em>must</em> be a scoped * name, i.e. prefixed with a package name you own, so that different developers will * not create conflicting keys. - * @throws IllegalStateException If {@link #tune} request hasn't been handled yet. + * @throws IllegalStateException If {@link #tune} request hasn't been handled yet or during + * pause. */ public void startRecording(@Nullable Uri programUri, @NonNull Bundle params) { - if (!mIsTuned) { - throw new IllegalStateException("startRecording failed - not yet tuned"); + if (mIsRecordingStopping || !mIsTuned || mIsPaused) { + throw new IllegalStateException("startRecording failed -" + + "recording not yet stopped or not yet tuned or paused"); + } + if (mIsRecordingStarted) { + Log.w(TAG, "startRecording failed - recording already started"); } if (mSession != null) { mSession.startRecording(programUri, params); @@ -225,6 +241,103 @@ public class TvRecordingClient { } if (mSession != null) { mSession.stopRecording(); + if (mIsRecordingStarted) { + mIsRecordingStopping = true; + } + } + } + + /** + * Pause TV program recording in the current recording session. Recording is expected to pause + * immediately when this method is called. If recording has not yet started in the current + * recording session, this method does nothing. + * + * <p>In pause status, the application can tune during recording. To continue recording, + * please call {@link TvRecordingClient#resumeRecording()} to resume instead of + * {@link TvRecordingClient#startRecording(Uri)}. Application can stop + * the recording with {@link TvRecordingClient#stopRecording()} in recording pause status. + * + * <p>If the pause request cannot be fulfilled, the recording session will respond by calling + * {@link RecordingCallback#onError(int)}. + */ + public void pauseRecording() { + pauseRecording(Bundle.EMPTY); + } + + /** + * Pause TV program recording in the current recording session. Recording is expected to pause + * immediately when this method is called. If recording has not yet started in the current + * recording session, this method does nothing. + * + * <p>In pause status, the application can tune during recording. To continue recording, + * please call {@link TvRecordingClient#resumeRecording()} to resume instead of + * {@link TvRecordingClient#startRecording(Uri)}. Application can stop + * the recording with {@link TvRecordingClient#stopRecording()} in recording pause status. + * + * <p>If the pause request cannot be fulfilled, the recording session will respond by calling + * {@link RecordingCallback#onError(int)}. + * + * @param params Domain-specific data for this request. + */ + public void pauseRecording(@NonNull Bundle params) { + if (!mIsRecordingStarted || mIsRecordingStopping) { + throw new IllegalStateException( + "pauseRecording failed - recording not yet started or stopping"); + } + TvInputInfo info = mTvInputManager.getTvInputInfo(mSessionCallback.mInputId); + if (info == null || !info.canPauseRecording()) { + throw new UnsupportedOperationException( + "pauseRecording failed - operation not supported"); + } + if (mIsPaused) { + Log.w(TAG, "pauseRecording failed - recording already paused"); + } + if (mSession != null) { + mSession.pauseRecording(params); + mIsPaused = true; + } + } + + /** + * Resume TV program recording only in recording pause status in the current recording session. + * Recording is expected to resume immediately when this method is called. If recording has not + * yet paused in the current recording session, this method does nothing. + * + * <p>When record is resumed, the recording is continue and can not re-tune. Application can + * stop the recording with {@link TvRecordingClient#stopRecording()} after record resumed. + * + * <p>If the pause request cannot be fulfilled, the recording session will respond by calling + * {@link RecordingCallback#onError(int)}. + */ + public void resumeRecording() { + resumeRecording(Bundle.EMPTY); + } + + /** + * Resume TV program recording only in recording pause status in the current recording session. + * Recording is expected to resume immediately when this method is called. If recording has not + * yet paused in the current recording session, this method does nothing. + * + * <p>When record is resumed, the recording is continues and can not re-tune. Application can + * stop the recording with {@link TvRecordingClient#stopRecording()} after record resumed. + * + * <p>If the resume request cannot be fulfilled, the recording session will respond by calling + * {@link RecordingCallback#onError(int)}. + * + * @param params Domain-specific data for this request. + */ + public void resumeRecording(@NonNull Bundle params) { + if (!mIsRecordingStarted || mIsRecordingStopping || !mIsTuned) { + throw new IllegalStateException( + "resumeRecording failed - recording not yet started or stopping or " + + "not yet tuned"); + } + if (!mIsPaused) { + Log.w(TAG, "resumeRecording failed - recording not yet paused"); + } + if (mSession != null) { + mSession.resumeRecording(params); + mIsPaused = false; } } @@ -367,6 +480,10 @@ public class TvRecordingClient { Log.w(TAG, "onTuned - session not created"); return; } + if (mIsTuned || !Objects.equals(mChannelUri, channelUri)) { + Log.w(TAG, "onTuned - already tuned or not yet tuned to last channel"); + return; + } mIsTuned = true; mCallback.onTuned(channelUri); } @@ -382,6 +499,8 @@ public class TvRecordingClient { } mIsTuned = false; mIsRecordingStarted = false; + mIsPaused = false; + mIsRecordingStopping = false; mSessionCallback = null; mSession = null; if (mCallback != null) { @@ -398,7 +517,13 @@ public class TvRecordingClient { Log.w(TAG, "onRecordingStopped - session not created"); return; } + if (!mIsRecordingStarted) { + Log.w(TAG, "onRecordingStopped - recording not yet started"); + return; + } mIsRecordingStarted = false; + mIsPaused = false; + mIsRecordingStopping = false; mCallback.onRecordingStopped(recordedProgramUri); } diff --git a/media/java/android/media/tv/tuner/Tuner.java b/media/java/android/media/tv/tuner/Tuner.java index e148d0e29b5a..b743a958828a 100644 --- a/media/java/android/media/tv/tuner/Tuner.java +++ b/media/java/android/media/tv/tuner/Tuner.java @@ -60,6 +60,7 @@ import com.android.internal.util.FrameworkStatsLog; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -210,6 +211,7 @@ public class Tuner implements AutoCloseable { @Nullable private FrontendInfo mFrontendInfo; private Integer mFrontendHandle; + private Boolean mIsSharedFrontend = false; private int mFrontendType = FrontendSettings.TYPE_UNDEFINED; private int mUserId; private Lnb mLnb; @@ -228,8 +230,8 @@ public class Tuner implements AutoCloseable { private Executor mOnResourceLostListenerExecutor; private Integer mDemuxHandle; - private Map<Integer, Descrambler> mDescramblers = new HashMap<>(); - private List<Filter> mFilters = new ArrayList<>(); + private Map<Integer, WeakReference<Descrambler>> mDescramblers = new HashMap<>(); + private List<WeakReference<Filter>> mFilters = new ArrayList<WeakReference<Filter>>(); private final TunerResourceManager.ResourcesReclaimListener mResourceListener = new TunerResourceManager.ResourcesReclaimListener() { @@ -240,6 +242,7 @@ public class Tuner implements AutoCloseable { .write(FrameworkStatsLog.TV_TUNER_STATE_CHANGED, mUserId, FrameworkStatsLog.TV_TUNER_STATE_CHANGED__STATE__UNKNOWN); } + releaseAll(); mHandler.sendMessage(mHandler.obtainMessage(MSG_RESOURCE_LOST)); } }; @@ -336,8 +339,11 @@ public class Tuner implements AutoCloseable { */ public void shareFrontendFromTuner(@NonNull Tuner tuner) { mTunerResourceManager.shareFrontend(mClientId, tuner.mClientId); - mFrontendHandle = tuner.mFrontendHandle; - mFrontend = nativeOpenFrontendByHandle(mFrontendHandle); + synchronized (mIsSharedFrontend) { + mFrontendHandle = tuner.mFrontendHandle; + mFrontend = tuner.mFrontend; + mIsSharedFrontend = true; + } } /** @@ -368,32 +374,47 @@ public class Tuner implements AutoCloseable { private void releaseAll() { if (mFrontendHandle != null) { - int res = nativeCloseFrontend(mFrontendHandle); - if (res != Tuner.RESULT_SUCCESS) { - TunerUtils.throwExceptionForResult(res, "failed to close frontend"); + synchronized (mIsSharedFrontend) { + if (!mIsSharedFrontend) { + int res = nativeCloseFrontend(mFrontendHandle); + if (res != Tuner.RESULT_SUCCESS) { + TunerUtils.throwExceptionForResult(res, "failed to close frontend"); + } + } + mIsSharedFrontend = false; } mTunerResourceManager.releaseFrontend(mFrontendHandle, mClientId); FrameworkStatsLog .write(FrameworkStatsLog.TV_TUNER_STATE_CHANGED, mUserId, - FrameworkStatsLog.TV_TUNER_STATE_CHANGED__STATE__UNKNOWN); + FrameworkStatsLog.TV_TUNER_STATE_CHANGED__STATE__UNKNOWN); mFrontendHandle = null; mFrontend = null; } if (mLnb != null) { mLnb.close(); } - if (!mDescramblers.isEmpty()) { - for (Map.Entry<Integer, Descrambler> d : mDescramblers.entrySet()) { - d.getValue().close(); - mTunerResourceManager.releaseDescrambler(d.getKey(), mClientId); + synchronized (mDescramblers) { + if (!mDescramblers.isEmpty()) { + for (Map.Entry<Integer, WeakReference<Descrambler>> d : mDescramblers.entrySet()) { + Descrambler descrambler = d.getValue().get(); + if (descrambler != null) { + descrambler.close(); + } + mTunerResourceManager.releaseDescrambler(d.getKey(), mClientId); + } + mDescramblers.clear(); } - mDescramblers.clear(); } - if (!mFilters.isEmpty()) { - for (Filter f : mFilters) { - f.close(); + synchronized (mFilters) { + if (!mFilters.isEmpty()) { + for (WeakReference<Filter> weakFilter : mFilters) { + Filter filter = weakFilter.get(); + if (filter != null) { + filter.close(); + } + } + mFilters.clear(); } - mFilters.clear(); } if (mDemuxHandle != null) { int res = nativeCloseDemux(mDemuxHandle); @@ -500,7 +521,6 @@ public class Tuner implements AutoCloseable { break; } case MSG_RESOURCE_LOST: { - releaseAll(); if (mOnResourceLostListener != null && mOnResourceLostListenerExecutor != null) { mOnResourceLostListenerExecutor.execute( @@ -616,10 +636,14 @@ public class Tuner implements AutoCloseable { @Result public int scan(@NonNull FrontendSettings settings, @ScanType int scanType, @NonNull @CallbackExecutor Executor executor, @NonNull ScanCallback scanCallback) { - if (mScanCallback != null || mScanCallbackExecutor != null) { + /** + * Scan can be called again for blink scan if scanCallback and executor are same as before. + */ + if (((mScanCallback != null) && (mScanCallback != scanCallback)) + || ((mScanCallbackExecutor != null) && (mScanCallbackExecutor != executor))) { throw new IllegalStateException( - "Scan already in progress. stopScan must be called before a new scan can be " - + "started."); + "Different Scan session already in progress. stopScan must be called " + + "before a new scan session can be " + "started."); } mFrontendType = settings.getType(); if (checkResource(TunerResourceManager.TUNER_RESOURCE_TYPE_FRONTEND)) { @@ -950,7 +974,10 @@ public class Tuner implements AutoCloseable { if (mHandler == null) { mHandler = createEventHandler(); } - mFilters.add(filter); + synchronized (mFilters) { + WeakReference<Filter> weakFilter = new WeakReference<Filter>(filter); + mFilters.add(weakFilter); + } } return filter; } @@ -1118,7 +1145,10 @@ public class Tuner implements AutoCloseable { int handle = descramblerHandle[0]; Descrambler descrambler = nativeOpenDescramblerByHandle(handle); if (descrambler != null) { - mDescramblers.put(handle, descrambler); + synchronized (mDescramblers) { + WeakReference weakDescrambler = new WeakReference<Descrambler>(descrambler); + mDescramblers.put(handle, weakDescrambler); + } } else { mTunerResourceManager.releaseDescrambler(handle, mClientId); } diff --git a/media/java/android/media/tv/tuner/frontend/FrontendInfo.java b/media/java/android/media/tv/tuner/frontend/FrontendInfo.java index 334900ba705a..766d6032955f 100644 --- a/media/java/android/media/tv/tuner/frontend/FrontendInfo.java +++ b/media/java/android/media/tv/tuner/frontend/FrontendInfo.java @@ -43,6 +43,10 @@ public class FrontendInfo { FrontendCapabilities frontendCap) { mId = id; mType = type; + // if max Frequency is negative, we set it as max value of the Integer. + if (maxFrequency < 0) { + maxFrequency = Integer.MAX_VALUE; + } mFrequencyRange = new Range<>(minFrequency, maxFrequency); mSymbolRateRange = new Range<>(minSymbolRate, maxSymbolRate); mAcquireRange = acquireRange; diff --git a/media/java/android/mtp/MtpStorageManager.java b/media/java/android/mtp/MtpStorageManager.java index c0eb5e8bbea9..0bede0dccbed 100644 --- a/media/java/android/mtp/MtpStorageManager.java +++ b/media/java/android/mtp/MtpStorageManager.java @@ -958,7 +958,7 @@ public class MtpStorageManager { MtpObject parent = obj.getParent(); MtpObject oldObj = parent.getChild(oldName); if (!success) { - // If the rename failed, we want oldObj to be the original and obj to be the dummy. + // If the rename failed, we want oldObj to be the original and obj to be the stand-in. // Switch the objects, except for their name and state. MtpObject temp = oldObj; MtpObjectState oldState = oldObj.getState(); @@ -1034,7 +1034,7 @@ public class MtpStorageManager { return generalBeginRemoveObject(obj, MtpOperation.RENAME) && generalBeginCopyObject(newObj, false); } - // Move obj to new parent, create a dummy object in the old parent. + // Move obj to new parent, create a fake object in the old parent. MtpObject oldObj = obj.copy(false); obj.setParent(newParent); oldObj.getParent().addChild(oldObj); @@ -1063,7 +1063,7 @@ public class MtpStorageManager { return generalEndCopyObject(newObj, success, true) && ret; } if (!success) { - // If the rename failed, we want oldObj to be the original and obj to be the dummy. + // If the rename failed, we want oldObj to be the original and obj to be the stand-in. // Switch the objects, except for their parent and state. MtpObject temp = oldObj; MtpObjectState oldState = oldObj.getState(); diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp index 5db672993df1..5daf8b0f88f8 100644 --- a/media/jni/android_media_tv_Tuner.cpp +++ b/media/jni/android_media_tv_Tuner.cpp @@ -171,6 +171,12 @@ static int IP_V6_LENGTH = 16; void DestroyCallback(const C2Buffer * /* buf */, void *arg) { android::sp<android::MediaEvent> event = (android::MediaEvent *)arg; + if (event->mLinearBlockObj != NULL) { + JNIEnv *env = android::AndroidRuntime::getJNIEnv(); + env->DeleteWeakGlobalRef(event->mLinearBlockObj); + event->mLinearBlockObj = NULL; + } + event->mAvHandleRefCnt--; event->finalize(); } @@ -182,6 +188,12 @@ LnbCallback::LnbCallback(jobject lnbObj, LnbId id) : mId(id) { mLnb = env->NewWeakGlobalRef(lnbObj); } +LnbCallback::~LnbCallback() { + JNIEnv *env = AndroidRuntime::getJNIEnv(); + env->DeleteWeakGlobalRef(mLnb); + mLnb = NULL; +} + Return<void> LnbCallback::onEvent(LnbEventType lnbEventType) { ALOGD("LnbCallback::onEvent, type=%d", lnbEventType); JNIEnv *env = AndroidRuntime::getJNIEnv(); @@ -305,6 +317,7 @@ MediaEvent::MediaEvent(sp<IFilter> iFilter, hidl_handle avHandle, JNIEnv *env = AndroidRuntime::getJNIEnv(); mMediaEventObj = env->NewWeakGlobalRef(obj); mAvHandle = native_handle_clone(avHandle.getNativeHandle()); + mLinearBlockObj = NULL; } MediaEvent::~MediaEvent() { @@ -367,7 +380,7 @@ jobject MediaEvent::getLinearBlock() { true); mLinearBlockObj = env->NewWeakGlobalRef(linearBlock); mAvHandleRefCnt++; - return mLinearBlockObj; + return linearBlock; } else { native_handle_close(const_cast<native_handle_t*>( reinterpret_cast<const native_handle_t*>(mIonHandle))); diff --git a/media/jni/android_media_tv_Tuner.h b/media/jni/android_media_tv_Tuner.h index fd2995917475..c4deeaf887bb 100644 --- a/media/jni/android_media_tv_Tuner.h +++ b/media/jni/android_media_tv_Tuner.h @@ -73,6 +73,7 @@ namespace android { struct LnbCallback : public ILnbCallback { LnbCallback(jweak tunerObj, LnbId id); + ~LnbCallback(); virtual Return<void> onEvent(LnbEventType lnbEventType); virtual Return<void> onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage); jweak mLnb; |