Commit 8f080001 authored by Luca Stefani's avatar Luca Stefani Committed by Han Wang
Browse files

Recorder: Stop service after stopping casting

 * Or the service will clean itself up later, which causes NPE
   because multiple stopCasting() calls.

Change-Id: I8ecaa17a16612e962d07bf92201182a2440dca55
parent a2e9b40f
......@@ -169,11 +169,6 @@ public class ScreencastService extends Service implements MediaProviderHelper.On
mMediaProjectionManager = getSystemService(MediaProjectionManager.class);
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_USER_BACKGROUND);
filter.addAction(Intent.ACTION_SHUTDOWN);
registerReceiver(mBroadcastReceiver, filter);
mNotificationManager = getSystemService(NotificationManager.class);
if (mNotificationManager == null || mNotificationManager.getNotificationChannel(
......@@ -190,13 +185,6 @@ public class ScreencastService extends Service implements MediaProviderHelper.On
mNotificationManager.createNotificationChannel(notificationChannel);
}
@Override
public void onDestroy() {
stopCasting();
unregisterReceiver(mBroadcastReceiver);
super.onDestroy();
}
@Override
public void onContentWritten(@Nullable String uri) {
stopForeground(true);
......@@ -229,9 +217,14 @@ public class ScreencastService extends Service implements MediaProviderHelper.On
int resultCode = intent.getIntExtra(EXTRA_RESULT_CODE, Activity.RESULT_CANCELED);
mUseAudio = intent.getBooleanExtra(EXTRA_USE_AUDIO, false);
Intent data = intent.getParcelableExtra(EXTRA_DATA);
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_USER_BACKGROUND);
filter.addAction(Intent.ACTION_SHUTDOWN);
if (data != null) {
mMediaProjection = mMediaProjectionManager.getMediaProjection(resultCode, data);
startRecording();
registerReceiver(mBroadcastReceiver, filter);
}
return START_STICKY;
}
......@@ -303,7 +296,9 @@ public class ScreencastService extends Service implements MediaProviderHelper.On
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
private void stopRecording() {
private void stopCasting() {
Utils.setStatus(getApplicationContext(), Utils.PREF_RECORDING_NOTHING);
mMediaRecorder.stop();
mMediaRecorder.release();
mMediaRecorder = null;
......@@ -311,22 +306,16 @@ public class ScreencastService extends Service implements MediaProviderHelper.On
mMediaProjection = null;
mInputSurface.release();
mVirtualDisplay.release();
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
mTimer.cancel();
mTimer = null;
MediaProviderHelper.addVideoToContentProvider(getContentResolver(), mPath, this);
}
private void stopCasting() {
Utils.setStatus(getApplicationContext(), Utils.PREF_RECORDING_NOTHING);
stopRecording();
if (hasNoAvailableSpace()) {
Toast.makeText(this, R.string.screen_not_enough_storage, Toast.LENGTH_LONG).show();
}
unregisterReceiver(mBroadcastReceiver);
stopSelf();
}
private NotificationCompat.Builder createNotificationBuilder() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment