Only allow RecordDVR to flush buffer when the DVR is stopped

Test: make services
Bug: 176108239
Change-Id: I5fa31c34cac83bb5952576adf86c5a31ec62d9b5
Merged-In: I5fa31c34cac83bb5952576adf86c5a31ec62d9b5
This commit is contained in:
Amy Zhang
2020-12-22 12:48:52 -08:00
parent 9923250234
commit d3f0aa464c

View File

@@ -47,6 +47,7 @@ public class DvrRecorder implements AutoCloseable {
private static int sInstantId = 0;
private int mSegmentId = 0;
private int mOverflow;
private Boolean mIsStopped = null;
private native int nativeAttachFilter(Filter filter);
private native int nativeDetachFilter(Filter filter);
@@ -135,7 +136,13 @@ public class DvrRecorder implements AutoCloseable {
.write(FrameworkStatsLog.TV_TUNER_DVR_STATUS, mUserId,
FrameworkStatsLog.TV_TUNER_DVR_STATUS__TYPE__RECORD,
FrameworkStatsLog.TV_TUNER_DVR_STATUS__STATE__STARTED, mSegmentId, 0);
return nativeStartDvr();
synchronized (mIsStopped) {
int result = nativeStartDvr();
if (result == Tuner.RESULT_SUCCESS) {
mIsStopped = false;
}
return result;
}
}
/**
@@ -152,7 +159,13 @@ public class DvrRecorder implements AutoCloseable {
.write(FrameworkStatsLog.TV_TUNER_DVR_STATUS, mUserId,
FrameworkStatsLog.TV_TUNER_DVR_STATUS__TYPE__RECORD,
FrameworkStatsLog.TV_TUNER_DVR_STATUS__STATE__STOPPED, mSegmentId, mOverflow);
return nativeStopDvr();
synchronized (mIsStopped) {
int result = nativeStopDvr();
if (result == Tuner.RESULT_SUCCESS) {
mIsStopped = true;
}
return result;
}
}
/**
@@ -164,7 +177,13 @@ public class DvrRecorder implements AutoCloseable {
*/
@Result
public int flush() {
return nativeFlushDvr();
synchronized (mIsStopped) {
if (mIsStopped) {
return nativeFlushDvr();
}
Log.w(TAG, "Cannot flush non-stopped Record DVR.");
return Tuner.RESULT_INVALID_STATE;
}
}
/**