Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3cf7f5aa authored by Benson Huang's avatar Benson Huang Committed by Nicholas Sauer
Browse files

[FM] "Can't play the track you requested" pops up after tapping "LISTEN"

Select "Start Recording" in options menu -> Wait for SD storage
to be nearly fully occupied -> "Insufficient storage" toast
message displays and "Save recording" dialog pops up ->Tap "Save"
to save the recording -> Tap "LISTEN" to playback the recording,
"Can't play the track you requested" pops up.

The fix is to also check storage free space when handling message
MSG_UPDATE_NOTIFICATION.

bug: 19007352
from: https://partner-android-review.googlesource.com/#/c/193407/



Change-Id: I63d7e22e699cb3ddb90e32a785d5c264258b6a06
Signed-off-by: default avatarBenson Huang <benson.huang@mediatek.com>
parent a1412c7e
Loading
Loading
Loading
Loading
+25 −18
Original line number Diff line number Diff line
@@ -258,6 +258,7 @@ public class FmRecordActivity extends Activity implements
        mHandler.removeMessages(MSG_UPDATE_NOTIFICATION);
        if (mService != null) {
            mService.removeNotification();
            mService.updatePlayingNotification();
        }
    }

@@ -357,24 +358,11 @@ public class FmRecordActivity extends Activity implements
            switch (msg.what) {
                case FmListener.MSGID_REFRESH:
                    if (mService != null) {
                        long recordTime = mService.getRecordTime();
                        recordTime = recordTime / 1000L;
                        mMintues.setText(addPaddingForString(recordTime / TIME_BASE));
                        mSeconds.setText(addPaddingForString(recordTime % TIME_BASE));

                        // Check storage free space
                        String recordingSdcard = FmUtils.getDefaultStoragePath();
                        if (!FmUtils.hasEnoughSpace(recordingSdcard)) {
                            // Need to record more than 1s.
                            // Avoid calling MediaRecorder.stop() before native record starts.
                            if (recordTime > 1000) {
                                // Insufficient storage
                                mService.stopRecordingAsync();
                                Toast.makeText(FmRecordActivity.this,
                                        R.string.toast_sdcard_insufficient_space,
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                        long recordTimeInMillis = mService.getRecordTime();
                        long recordTimeInSec = recordTimeInMillis / 1000L;
                        mMintues.setText(addPaddingForString(recordTimeInSec / TIME_BASE));
                        mSeconds.setText(addPaddingForString(recordTimeInSec % TIME_BASE));
                        checkStorageSpaceAndStop();
                    }
                    mHandler.sendEmptyMessageDelayed(FmListener.MSGID_REFRESH, 1000);
                    break;
@@ -382,6 +370,7 @@ public class FmRecordActivity extends Activity implements
                case MSG_UPDATE_NOTIFICATION:
                    if (mService != null) {
                        updateRecordingNotification(mService.getRecordTime());
                        checkStorageSpaceAndStop();
                    }
                    mHandler.sendEmptyMessageDelayed(MSG_UPDATE_NOTIFICATION, 1000);
                    break;
@@ -415,6 +404,24 @@ public class FmRecordActivity extends Activity implements
        };
    };

    private void checkStorageSpaceAndStop() {
        long recordTimeInMillis = mService.getRecordTime();
        long recordTimeInSec = recordTimeInMillis / 1000L;
        // Check storage free space
        String recordingSdcard = FmUtils.getDefaultStoragePath();
        if (!FmUtils.hasEnoughSpace(recordingSdcard)) {
            // Need to record more than 1s.
            // Avoid calling MediaRecorder.stop() before native record starts.
            if (recordTimeInSec >= 1) {
                // Insufficient storage
                mService.stopRecordingAsync();
                Toast.makeText(FmRecordActivity.this,
                        R.string.toast_sdcard_insufficient_space,
                        Toast.LENGTH_SHORT).show();
            }
        }
    }

    private void handleRecordError(int errorType) {
        Log.d(TAG, "handleRecordError, errorType = " + errorType);
        String showString = null;