blob: 87597263168a19210a7dd2201f466f0f4748f62e [file] [log] [blame]
Beth Thibodeau5898ac42018-10-26 13:00:09 -04001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.screenrecord;
18
Beth Thibodeau5898ac42018-10-26 13:00:09 -040019import android.app.Notification;
20import android.app.NotificationChannel;
21import android.app.NotificationManager;
22import android.app.PendingIntent;
23import android.app.Service;
Beth Thibodeaueb48d0a2019-07-24 15:23:54 -040024import android.content.ContentResolver;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040025import android.content.Context;
26import android.content.Intent;
Beth Thibodeau630225c2020-02-04 17:16:45 -050027import android.content.res.Resources;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040028import android.graphics.Bitmap;
29import android.graphics.drawable.Icon;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040030import android.media.MediaRecorder;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040031import android.net.Uri;
Beth Thibodeau28b44892020-01-22 13:56:37 -050032import android.os.Bundle;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040033import android.os.IBinder;
Beth Thibodeau630225c2020-02-04 17:16:45 -050034import android.os.RemoteException;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040035import android.provider.Settings;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040036import android.util.Log;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040037import android.widget.Toast;
38
Beth Thibodeauabb338f2020-03-03 16:17:24 -050039import com.android.internal.annotations.VisibleForTesting;
40import com.android.internal.logging.UiEventLogger;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040041import com.android.systemui.R;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040042import com.android.systemui.dagger.qualifiers.LongRunning;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040043
Beth Thibodeau5898ac42018-10-26 13:00:09 -040044import java.io.IOException;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040045import java.util.concurrent.Executor;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040046
Beth Thibodeau77c25452020-01-09 14:33:47 -050047import javax.inject.Inject;
48
Beth Thibodeau5898ac42018-10-26 13:00:09 -040049/**
50 * A service which records the device screen and optionally microphone input.
51 */
Beth Thibodeau26fefde2020-02-21 16:04:41 -050052public class RecordingService extends Service implements MediaRecorder.OnInfoListener {
Beth Thibodeau77c25452020-01-09 14:33:47 -050053 public static final int REQUEST_CODE = 2;
54
Jay Aliomer0bd491a2020-03-16 14:34:10 -040055 private static final int NOTIFICATION_RECORDING_ID = 4274;
56 private static final int NOTIFICATION_PROCESSING_ID = 4275;
57 private static final int NOTIFICATION_VIEW_ID = 4273;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040058 private static final String TAG = "RecordingService";
59 private static final String CHANNEL_ID = "screen_record";
60 private static final String EXTRA_RESULT_CODE = "extra_resultCode";
61 private static final String EXTRA_DATA = "extra_data";
62 private static final String EXTRA_PATH = "extra_path";
Jay Aliomer0bd491a2020-03-16 14:34:10 -040063 private static final String EXTRA_AUDIO_SOURCE = "extra_useAudio";
Beth Thibodeau5898ac42018-10-26 13:00:09 -040064 private static final String EXTRA_SHOW_TAPS = "extra_showTaps";
Beth Thibodeau5898ac42018-10-26 13:00:09 -040065
66 private static final String ACTION_START = "com.android.systemui.screenrecord.START";
67 private static final String ACTION_STOP = "com.android.systemui.screenrecord.STOP";
Beth Thibodeauabb338f2020-03-03 16:17:24 -050068 private static final String ACTION_STOP_NOTIF =
69 "com.android.systemui.screenrecord.STOP_FROM_NOTIF";
Beth Thibodeau5898ac42018-10-26 13:00:09 -040070 private static final String ACTION_SHARE = "com.android.systemui.screenrecord.SHARE";
71 private static final String ACTION_DELETE = "com.android.systemui.screenrecord.DELETE";
72
Beth Thibodeau77c25452020-01-09 14:33:47 -050073 private final RecordingController mController;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040074
Jay Aliomer0bd491a2020-03-16 14:34:10 -040075 private ScreenRecordingAudioSource mAudioSource;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040076 private boolean mShowTaps;
Beth Thibodeau28b44892020-01-22 13:56:37 -050077 private boolean mOriginalShowTaps;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040078 private ScreenMediaRecorder mRecorder;
79 private final Executor mLongExecutor;
Beth Thibodeauabb338f2020-03-03 16:17:24 -050080 private final UiEventLogger mUiEventLogger;
81 private final NotificationManager mNotificationManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040082
Beth Thibodeau77c25452020-01-09 14:33:47 -050083 @Inject
Beth Thibodeauabb338f2020-03-03 16:17:24 -050084 public RecordingService(RecordingController controller, @LongRunning Executor executor,
85 UiEventLogger uiEventLogger, NotificationManager notificationManager) {
Beth Thibodeau77c25452020-01-09 14:33:47 -050086 mController = controller;
Jay Aliomer0bd491a2020-03-16 14:34:10 -040087 mLongExecutor = executor;
Beth Thibodeauabb338f2020-03-03 16:17:24 -050088 mUiEventLogger = uiEventLogger;
89 mNotificationManager = notificationManager;
Beth Thibodeau77c25452020-01-09 14:33:47 -050090 }
91
Beth Thibodeau5898ac42018-10-26 13:00:09 -040092 /**
93 * Get an intent to start the recording service.
94 *
95 * @param context Context from the requesting activity
96 * @param resultCode The result code from {@link android.app.Activity#onActivityResult(int, int,
97 * android.content.Intent)}
98 * @param data The data from {@link android.app.Activity#onActivityResult(int, int,
99 * android.content.Intent)}
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400100 * @param audioSource The ordinal value of the audio source
101 * {@link com.android.systemui.screenrecord.ScreenRecordingAudioSource}
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400102 * @param showTaps True to make touches visible while recording
103 */
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400104 public static Intent getStartIntent(Context context, int resultCode,
105 int audioSource, boolean showTaps) {
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400106 return new Intent(context, RecordingService.class)
107 .setAction(ACTION_START)
108 .putExtra(EXTRA_RESULT_CODE, resultCode)
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400109 .putExtra(EXTRA_AUDIO_SOURCE, audioSource)
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400110 .putExtra(EXTRA_SHOW_TAPS, showTaps);
111 }
112
113 @Override
114 public int onStartCommand(Intent intent, int flags, int startId) {
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400115 if (intent == null) {
116 return Service.START_NOT_STICKY;
117 }
118 String action = intent.getAction();
Beth Thibodeau11e6cbf2019-08-08 14:52:24 -0400119 Log.d(TAG, "onStartCommand " + action);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400120
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400121 switch (action) {
122 case ACTION_START:
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400123 mAudioSource = ScreenRecordingAudioSource
124 .values()[intent.getIntExtra(EXTRA_AUDIO_SOURCE, 0)];
125 Log.d(TAG, "recording with audio source" + mAudioSource);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400126 mShowTaps = intent.getBooleanExtra(EXTRA_SHOW_TAPS, false);
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400127
128 mOriginalShowTaps = Settings.System.getInt(
129 getApplicationContext().getContentResolver(),
130 Settings.System.SHOW_TOUCHES, 0) != 0;
131
132 setTapsVisible(mShowTaps);
133
134 mRecorder = new ScreenMediaRecorder(
135 getApplicationContext(),
136 getUserId(),
137 mAudioSource,
138 this
139 );
140 startRecording();
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400141 break;
142
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500143 case ACTION_STOP_NOTIF:
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400144 case ACTION_STOP:
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500145 // only difference for actions is the log event
146 if (ACTION_STOP_NOTIF.equals(action)) {
147 mUiEventLogger.log(Events.ScreenRecordEvent.SCREEN_RECORD_END_NOTIFICATION);
148 } else {
149 mUiEventLogger.log(Events.ScreenRecordEvent.SCREEN_RECORD_END_QS_TILE);
150 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400151 stopRecording();
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500152 mNotificationManager.cancel(NOTIFICATION_RECORDING_ID);
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400153 stopSelf();
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400154 break;
155
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400156 case ACTION_SHARE:
Beth Thibodeau11e6cbf2019-08-08 14:52:24 -0400157 Uri shareUri = Uri.parse(intent.getStringExtra(EXTRA_PATH));
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400158
159 Intent shareIntent = new Intent(Intent.ACTION_SEND)
160 .setType("video/mp4")
161 .putExtra(Intent.EXTRA_STREAM, shareUri);
162 String shareLabel = getResources().getString(R.string.screenrecord_share_label);
163
164 // Close quick shade
165 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
166
167 // Remove notification
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500168 mNotificationManager.cancel(NOTIFICATION_VIEW_ID);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400169
170 startActivity(Intent.createChooser(shareIntent, shareLabel)
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400171 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400172 break;
173 case ACTION_DELETE:
174 // Close quick shade
175 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
176
Beth Thibodeau11e6cbf2019-08-08 14:52:24 -0400177 ContentResolver resolver = getContentResolver();
178 Uri uri = Uri.parse(intent.getStringExtra(EXTRA_PATH));
179 resolver.delete(uri, null, null);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400180
Beth Thibodeau11e6cbf2019-08-08 14:52:24 -0400181 Toast.makeText(
182 this,
183 R.string.screenrecord_delete_description,
184 Toast.LENGTH_LONG).show();
185
186 // Remove notification
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500187 mNotificationManager.cancel(NOTIFICATION_VIEW_ID);
Beth Thibodeau11e6cbf2019-08-08 14:52:24 -0400188 Log.d(TAG, "Deleted recording " + uri);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400189 break;
190 }
191 return Service.START_STICKY;
192 }
193
194 @Override
195 public IBinder onBind(Intent intent) {
196 return null;
197 }
198
199 @Override
200 public void onCreate() {
201 super.onCreate();
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400202 }
203
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500204 @VisibleForTesting
205 protected ScreenMediaRecorder getRecorder() {
206 return mRecorder;
207 }
208
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400209 /**
210 * Begin the recording session
211 */
212 private void startRecording() {
213 try {
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500214 getRecorder().start();
Beth Thibodeau77c25452020-01-09 14:33:47 -0500215 mController.updateState(true);
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400216 createRecordingNotification();
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500217 mUiEventLogger.log(Events.ScreenRecordEvent.SCREEN_RECORD_START);
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400218 } catch (IOException | RemoteException e) {
219 Toast.makeText(this,
220 R.string.screenrecord_start_error, Toast.LENGTH_LONG)
221 .show();
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400222 e.printStackTrace();
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400223 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400224 }
225
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500226 @VisibleForTesting
227 protected void createRecordingNotification() {
Beth Thibodeau630225c2020-02-04 17:16:45 -0500228 Resources res = getResources();
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400229 NotificationChannel channel = new NotificationChannel(
230 CHANNEL_ID,
231 getString(R.string.screenrecord_name),
Beth Thibodeau28b44892020-01-22 13:56:37 -0500232 NotificationManager.IMPORTANCE_DEFAULT);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400233 channel.setDescription(getString(R.string.screenrecord_channel_description));
234 channel.enableVibration(true);
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500235 mNotificationManager.createNotificationChannel(channel);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400236
Beth Thibodeau28b44892020-01-22 13:56:37 -0500237 Bundle extras = new Bundle();
238 extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME,
Beth Thibodeau630225c2020-02-04 17:16:45 -0500239 res.getString(R.string.screenrecord_name));
240
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400241 String notificationTitle = mAudioSource == ScreenRecordingAudioSource.NONE
Jay Aliomer246a25e2020-05-26 22:57:34 -0400242 ? res.getString(R.string.screenrecord_ongoing_screen_only)
243 : res.getString(R.string.screenrecord_ongoing_screen_and_audio);
Beth Thibodeau28b44892020-01-22 13:56:37 -0500244
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500245
246 Intent stopIntent = getNotificationIntent(this);
247 Notification.Builder builder = new Notification.Builder(this, CHANNEL_ID)
Beth Thibodeau28b44892020-01-22 13:56:37 -0500248 .setSmallIcon(R.drawable.ic_screenrecord)
Beth Thibodeau630225c2020-02-04 17:16:45 -0500249 .setContentTitle(notificationTitle)
Beth Thibodeau28b44892020-01-22 13:56:37 -0500250 .setContentText(getResources().getString(R.string.screenrecord_stop_text))
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400251 .setUsesChronometer(true)
Beth Thibodeau28b44892020-01-22 13:56:37 -0500252 .setColorized(true)
253 .setColor(getResources().getColor(R.color.GM2_red_700))
254 .setOngoing(true)
255 .setContentIntent(
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500256 PendingIntent.getService(this, REQUEST_CODE, stopIntent,
Beth Thibodeau28b44892020-01-22 13:56:37 -0500257 PendingIntent.FLAG_UPDATE_CURRENT))
258 .addExtras(extras);
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500259 startForeground(NOTIFICATION_RECORDING_ID, builder.build());
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400260 }
261
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500262 @VisibleForTesting
263 protected Notification createProcessingNotification() {
264 Resources res = getApplicationContext().getResources();
265 String notificationTitle = mAudioSource == ScreenRecordingAudioSource.NONE
266 ? res.getString(R.string.screenrecord_ongoing_screen_only)
267 : res.getString(R.string.screenrecord_ongoing_screen_and_audio);
268 Notification.Builder builder = new Notification.Builder(getApplicationContext(), CHANNEL_ID)
269 .setContentTitle(notificationTitle)
270 .setContentText(
271 getResources().getString(R.string.screenrecord_background_processing_label))
272 .setSmallIcon(R.drawable.ic_screenrecord);
273 return builder.build();
274 }
275
276 @VisibleForTesting
277 protected Notification createSaveNotification(ScreenMediaRecorder.SavedRecording recording) {
Jay Aliomer57e2aa42020-06-04 15:28:09 -0400278 Uri uri = recording.getUri();
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400279 Intent viewIntent = new Intent(Intent.ACTION_VIEW)
280 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION)
Beth Thibodeaueb48d0a2019-07-24 15:23:54 -0400281 .setDataAndType(uri, "video/mp4");
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400282
283 Notification.Action shareAction = new Notification.Action.Builder(
Beth Thibodeau28b44892020-01-22 13:56:37 -0500284 Icon.createWithResource(this, R.drawable.ic_screenrecord),
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400285 getResources().getString(R.string.screenrecord_share_label),
286 PendingIntent.getService(
287 this,
288 REQUEST_CODE,
Beth Thibodeaueb48d0a2019-07-24 15:23:54 -0400289 getShareIntent(this, uri.toString()),
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400290 PendingIntent.FLAG_UPDATE_CURRENT))
291 .build();
292
293 Notification.Action deleteAction = new Notification.Action.Builder(
Beth Thibodeau28b44892020-01-22 13:56:37 -0500294 Icon.createWithResource(this, R.drawable.ic_screenrecord),
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400295 getResources().getString(R.string.screenrecord_delete_label),
296 PendingIntent.getService(
297 this,
298 REQUEST_CODE,
Beth Thibodeaueb48d0a2019-07-24 15:23:54 -0400299 getDeleteIntent(this, uri.toString()),
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400300 PendingIntent.FLAG_UPDATE_CURRENT))
301 .build();
302
Beth Thibodeau28b44892020-01-22 13:56:37 -0500303 Bundle extras = new Bundle();
304 extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME,
305 getResources().getString(R.string.screenrecord_name));
306
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400307 Notification.Builder builder = new Notification.Builder(this, CHANNEL_ID)
Beth Thibodeau28b44892020-01-22 13:56:37 -0500308 .setSmallIcon(R.drawable.ic_screenrecord)
Beth Thibodeau630225c2020-02-04 17:16:45 -0500309 .setContentTitle(getResources().getString(R.string.screenrecord_save_message))
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400310 .setContentIntent(PendingIntent.getActivity(
311 this,
312 REQUEST_CODE,
313 viewIntent,
Beth Thibodeau4cecd352020-06-15 13:24:18 -0400314 PendingIntent.FLAG_IMMUTABLE))
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400315 .addAction(shareAction)
316 .addAction(deleteAction)
Beth Thibodeau28b44892020-01-22 13:56:37 -0500317 .setAutoCancel(true)
318 .addExtras(extras);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400319
320 // Add thumbnail if available
Jay Aliomer57e2aa42020-06-04 15:28:09 -0400321 Bitmap thumbnailBitmap = recording.getThumbnail();
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400322 if (thumbnailBitmap != null) {
323 Notification.BigPictureStyle pictureStyle = new Notification.BigPictureStyle()
324 .bigPicture(thumbnailBitmap)
325 .bigLargeIcon((Bitmap) null);
326 builder.setLargeIcon(thumbnailBitmap).setStyle(pictureStyle);
327 }
328 return builder.build();
329 }
330
331 private void stopRecording() {
Beth Thibodeau28b44892020-01-22 13:56:37 -0500332 setTapsVisible(mOriginalShowTaps);
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500333 if (getRecorder() != null) {
334 getRecorder().end();
335 saveRecording();
336 } else {
337 Log.e(TAG, "stopRecording called, but recorder was null");
338 }
Beth Thibodeau77c25452020-01-09 14:33:47 -0500339 mController.updateState(false);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400340 }
341
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500342 private void saveRecording() {
343 mNotificationManager.notify(NOTIFICATION_PROCESSING_ID, createProcessingNotification());
Beth Thibodeau11e6cbf2019-08-08 14:52:24 -0400344
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400345 mLongExecutor.execute(() -> {
346 try {
347 Log.d(TAG, "saving recording");
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500348 Notification notification = createSaveNotification(getRecorder().save());
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400349 if (!mController.isRecording()) {
350 Log.d(TAG, "showing saved notification");
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500351 mNotificationManager.notify(NOTIFICATION_VIEW_ID, notification);
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400352 }
353 } catch (IOException e) {
354 Log.e(TAG, "Error saving screen recording: " + e.getMessage());
355 Toast.makeText(this, R.string.screenrecord_delete_error, Toast.LENGTH_LONG)
356 .show();
357 } finally {
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500358 mNotificationManager.cancel(NOTIFICATION_PROCESSING_ID);
Jay Aliomer0bd491a2020-03-16 14:34:10 -0400359 }
360 });
Beth Thibodeau11e6cbf2019-08-08 14:52:24 -0400361 }
362
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400363 private void setTapsVisible(boolean turnOn) {
364 int value = turnOn ? 1 : 0;
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500365 Settings.System.putInt(getContentResolver(), Settings.System.SHOW_TOUCHES, value);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400366 }
367
Beth Thibodeau77c25452020-01-09 14:33:47 -0500368 /**
369 * Get an intent to stop the recording service.
370 * @param context Context from the requesting activity
371 * @return
372 */
373 public static Intent getStopIntent(Context context) {
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400374 return new Intent(context, RecordingService.class).setAction(ACTION_STOP);
375 }
376
Beth Thibodeauabb338f2020-03-03 16:17:24 -0500377 /**
378 * Get the recording notification content intent
379 * @param context
380 * @return
381 */
382 protected static Intent getNotificationIntent(Context context) {
383 return new Intent(context, RecordingService.class).setAction(ACTION_STOP_NOTIF);
384 }
385
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400386 private static Intent getShareIntent(Context context, String path) {
387 return new Intent(context, RecordingService.class).setAction(ACTION_SHARE)
388 .putExtra(EXTRA_PATH, path);
389 }
390
391 private static Intent getDeleteIntent(Context context, String path) {
392 return new Intent(context, RecordingService.class).setAction(ACTION_DELETE)
393 .putExtra(EXTRA_PATH, path);
394 }
Beth Thibodeau26fefde2020-02-21 16:04:41 -0500395
396 @Override
397 public void onInfo(MediaRecorder mr, int what, int extra) {
398 Log.d(TAG, "Media recorder info: " + what);
399 onStartCommand(getStopIntent(this), 0, 0);
400 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400401}