Skip to content

Commit cd56a26

Browse files
committed
io.appium.settings: recording: More descriptive log messages
Signed-off-by: sirmordred <[email protected]>
1 parent d1ae86a commit cd56a26

File tree

3 files changed

+53
-42
lines changed

3 files changed

+53
-42
lines changed

app/src/main/java/io/appium/settings/Settings.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,21 @@ public void onCreate(Bundle savedInstanceState) {
9393

9494
private void handleRecording(Intent intent) {
9595
if (intent == null) {
96-
Log.e(TAG, "handleRecording: intent is null");
96+
Log.e(TAG, "handleRecording: Unable to retrieve intent instance");
9797
finishActivity();
9898
return;
9999
}
100100

101101
String recordingAction = intent.getAction();
102102
if (recordingAction == null) {
103-
Log.e(TAG, "handleRecording: intent.getAction() is null");
103+
Log.e(TAG, "handleRecording: Unable to retrieve intent.action instance");
104104
finishActivity();
105105
return;
106106
}
107107

108108
if (!recordingAction.startsWith(ACTION_RECORDING_BASE)) {
109-
Log.i(TAG, "handleRecording: Different intent");
109+
Log.i(TAG, "handleRecording: Received different intent with action: "
110+
+ recordingAction);
110111
finishActivity();
111112
return;
112113
}
@@ -118,7 +119,7 @@ private void handleRecording(Intent intent) {
118119
}
119120

120121
if (!RecorderUtil.areRecordingPermissionsGranted(getApplicationContext())) {
121-
Log.e(TAG, "handleRecording: Required Permissions are not granted");
122+
Log.e(TAG, "handleRecording: Required permissions are not granted");
122123
finishActivity();
123124
return;
124125
}
@@ -144,7 +145,7 @@ so we need to call getExternalFilesDir() method twice
144145
}
145146
// if path is still null despite calling method twice, early exit
146147
if (externalStorageFile == null) {
147-
Log.e(TAG, "handleRecording: external storage file path returns null");
148+
Log.e(TAG, "handleRecording: Unable to retrieve external storage file path");
148149
finishActivity();
149150
return;
150151
}
@@ -159,7 +160,8 @@ so we need to call getExternalFilesDir() method twice
159160
Context.MEDIA_PROJECTION_SERVICE);
160161

161162
if (manager == null) {
162-
Log.e(TAG, "handleRecording: manager(MediaProjectionManager) is null");
163+
Log.e(TAG, "handleRecording: " +
164+
"Unable to retrieve MediaProjectionManager instance");
163165
finishActivity();
164166
return;
165167
}
@@ -175,7 +177,8 @@ so we need to call getExternalFilesDir() method twice
175177

176178
finishActivity();
177179
} else {
178-
Log.e(TAG, "handleRecording: Unknown recording intent.action:" + recordingAction);
180+
Log.e(TAG, "handleRecording: Unknown recording intent with action:"
181+
+ recordingAction);
179182
finishActivity();
180183
}
181184
}
@@ -191,7 +194,8 @@ protected void onActivityResult(final int requestCode, final int resultCode, fin
191194
{
192195
super.onActivityResult(requestCode, resultCode, data);
193196
if (REQUEST_CODE_SCREEN_CAPTURE != requestCode) {
194-
Log.e(TAG, "handleRecording: onActivityResult: Unknown request code");
197+
Log.e(TAG, "handleRecording: onActivityResult: " +
198+
"Received unknown request with code: " + requestCode);
195199
finishActivity();
196200
return;
197201
}

app/src/main/java/io/appium/settings/recorder/RecorderService.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public RecorderService() {
4747

4848
@Override
4949
public void onDestroy() {
50-
Log.v(TAG, "onDestroy:");
50+
Log.v(TAG, "onDestroy called: Stopping recorder");
5151
if (recorderThread != null && recorderThread.isRecordingRunning()) {
5252
recorderThread.stopRecording();
5353
}
@@ -63,11 +63,17 @@ public IBinder onBind(final Intent intent) {
6363
@RequiresApi(api = Build.VERSION_CODES.Q)
6464
@Override
6565
public int onStartCommand(final Intent intent, final int flags, final int startId) {
66-
Log.v(TAG, "onStartCommand:intent=" + intent);
66+
if (intent == null) {
67+
Log.e(TAG, "onStartCommand: Unable to retrieve recording intent");
68+
return START_NOT_STICKY;
69+
}
70+
final String action = intent.getAction();
71+
if (action == null) {
72+
Log.e(TAG, "onStartCommand: Unable to retrieve recording intent:action");
73+
return START_NOT_STICKY;
74+
}
6775

6876
int result = START_STICKY;
69-
final String action = intent != null ? intent.getAction() : null;
70-
Log.v(TAG, "onStartCommand:action string: " + action);
7177
if (ACTION_RECORDING_START.equals(action)) {
7278
showNotification(); // TODO is this really necessary
7379

@@ -77,15 +83,17 @@ public int onStartCommand(final Intent intent, final int flags, final int startI
7783
if (mMediaProjectionManager != null) {
7884
startScreenRecord(mMediaProjectionManager, intent);
7985
} else {
80-
Log.e(TAG, "mMediaProjectionManager null");
86+
Log.e(TAG, "onStartCommand: " +
87+
"Unable to retrieve MediaProjectionManager instance");
8188
result = START_NOT_STICKY;
8289
}
8390
} else if (ACTION_RECORDING_STOP.equals(action)) {
84-
Log.v(TAG, "onStartCommand:intent=" + "stop");
91+
Log.v(TAG, "onStartCommand: Received recording stop intent, stopping recording");
8592
stopScreenRecord();
8693
result = START_NOT_STICKY;
8794
} else {
88-
Log.w(TAG, "onStartCommand: Unknown ACTION name");
95+
Log.v(TAG, "onStartCommand: Received unknown recording intent with action: "
96+
+ action);
8997
result = START_NOT_STICKY;
9098
}
9199

@@ -99,27 +107,28 @@ public int onStartCommand(final Intent intent, final int flags, final int startI
99107
private void startScreenRecord(MediaProjectionManager mediaProjectionManager,
100108
final Intent intent) {
101109
if (recorderThread != null) {
102-
Log.v(TAG, "recorder thread is not null");
103110
if (recorderThread.isRecordingRunning()) {
104-
Log.v(TAG, "recording is already continuing");
111+
Log.v(TAG, "Recording is already continuing, exiting");
112+
return;
105113
} else {
106-
Log.v(TAG, "recording is stopped");
114+
Log.w(TAG, "Recording is stopped, " +
115+
"but recording instance is still alive, starting recording");
116+
recorderThread = null;
107117
}
108-
return;
109118
}
110119

111120
int resultCode = intent.getIntExtra(ACTION_RECORDING_RESULT_CODE, 0);
112121
// get MediaProjection
113122
final MediaProjection projection = mediaProjectionManager.getMediaProjection(resultCode,
114123
intent);
115124
if (projection == null) {
116-
Log.e(TAG, "MediaProjection is null");
125+
Log.e(TAG, "Recording is stopped, Unable to retrieve MediaProjection instance");
117126
return;
118127
}
119128

120129
String outputFilePath = intent.getStringExtra(ACTION_RECORDING_FILENAME);
121130
if (outputFilePath == null) {
122-
Log.i(TAG, "outputFilePath is null");
131+
Log.e(TAG, "Recording is stopped, Unable to retrieve outputFilePath instance");
123132
return;
124133
}
125134

@@ -140,19 +149,14 @@ private void startScreenRecord(MediaProjectionManager mediaProjectionManager,
140149
rawWidth = metrics.heightPixels;
141150
rawHeight = metrics.widthPixels;
142151
}
143-
Log.v(TAG, String.format("startRecording:(%d,%d)(%d,%d)",
144-
metrics.widthPixels, metrics.heightPixels, rawWidth, rawHeight));
145152
} else if (recordingRotation == 90 || recordingRotation == 270) {
146153
rawWidth = metrics.heightPixels;
147154
rawHeight = metrics.widthPixels;
148-
Log.v(TAG, String.format("startRecording:(%d,%d)(%d,%d)",
149-
metrics.widthPixels, metrics.heightPixels, rawWidth, rawHeight));
150-
} else {
151-
// degree 0 and degree 180 conditions
152-
Log.v(TAG, String.format("startRecording:(%d,%d)(%d,%d)",
153-
metrics.widthPixels, metrics.heightPixels, rawWidth, rawHeight));
154155
}
155156

157+
Log.v(TAG, String.format("Starting recording with width/height(not clamped):(%d,%d)",
158+
rawWidth, rawHeight));
159+
156160
recorderThread = new RecorderThread(projection, outputFilePath,
157161
rawWidth, rawHeight, recordingRotation);
158162
recorderThread.startRecording();

app/src/main/java/io/appium/settings/recorder/RecorderThread.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class RecorderThread implements Runnable {
7070
@Override
7171
public void onPaused() {
7272
super.onPaused();
73-
Log.v(TAG, "Display paused");
73+
Log.v(TAG, "VirtualDisplay callback: Display streaming paused");
7474
}
7575

7676
@Override
@@ -209,7 +209,7 @@ public void run() {
209209
}
210210
} catch (Exception e) {
211211
if (!stopped) {
212-
Log.e(TAG, "Audio error", e);
212+
Log.e(TAG, "Recording stopped, Audio Thread error", e);
213213
hasAsyncError = true;
214214
e.printStackTrace();
215215
}
@@ -234,7 +234,8 @@ private long getPresentationTimeUs() {
234234
private int calcBitRate(int width, int height) {
235235
final int bitrate = (int) (RecorderConstant.BITRATE_MULTIPLIER *
236236
RecorderConstant.VIDEO_CODEC_FRAME_RATE * width * height);
237-
Log.i(TAG, String.format("bitrate=%5.2f[Mbps]", bitrate / 1024f / 1024f));
237+
Log.i(TAG, String.format("Recording starting with bitrate=%5.2f[Mbps]",
238+
bitrate / 1024f / 1024f));
238239
return bitrate;
239240
}
240241

@@ -253,18 +254,19 @@ private boolean writeAudioBufferToFile(MediaCodec audioEncoder, MediaMuxer muxer
253254
encoderStatus = audioEncoder.dequeueOutputBuffer(bufferInfo, 0);
254255
if (encoderStatus == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
255256
if (audioTrackIndex > 0) {
256-
Log.e(TAG, "audioTrackIndex greater than zero");
257+
Log.e(TAG, "Recording stopped, audioTrackIndex greater than zero");
257258
return false;
258259
}
259260
audioTrackIndex = muxer.addTrack(audioEncoder.getOutputFormat());
260261
startMuxerIfSetUp(muxer);
261262
} else if (encoderStatus < 0 && encoderStatus != MediaCodec.INFO_TRY_AGAIN_LATER) {
262-
Log.w(TAG, "unexpected result from audio encoder.dequeueOutputBuffer: "
263-
+ encoderStatus);
263+
Log.w(TAG, "Unexpected result from audio encoder.dequeueOutputBuffer: "
264+
+ encoderStatus + ", however continuing recording");
264265
} else if (encoderStatus >= 0) {
265266
ByteBuffer encodedData = audioEncoder.getOutputBuffer(encoderStatus);
266267
if (encodedData == null) {
267-
Log.e(TAG, "encodedData null");
268+
Log.e(TAG, "Recording stopped, " +
269+
"Unable to retrieve output buffer of audio encoder");
268270
return false;
269271
}
270272

@@ -278,7 +280,7 @@ private boolean writeAudioBufferToFile(MediaCodec audioEncoder, MediaMuxer muxer
278280
audioEncoder.releaseOutputBuffer(encoderStatus, false);
279281

280282
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
281-
Log.v(TAG, "buffer eos");
283+
Log.v(TAG, "Recording stopped, audio encoder buffer reached end of stream");
282284
return false;
283285
}
284286
}
@@ -294,18 +296,19 @@ private boolean writeVideoBufferToFile(MediaCodec videoEncoder, MediaMuxer muxer
294296
RecorderConstant.MEDIA_QUEUE_BUFFERING_DEFAULT_TIMEOUT_MS);
295297
if (encoderStatus == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
296298
if (videoTrackIndex > 0) {
297-
Log.e(TAG, "videoTrackIndex greater than zero");
299+
Log.e(TAG, "Recording stopped, videoTrackIndex greater than zero");
298300
return false;
299301
}
300302
videoTrackIndex = muxer.addTrack(videoEncoder.getOutputFormat());
301303
startMuxerIfSetUp(muxer);
302304
} else if (encoderStatus < 0 && encoderStatus != MediaCodec.INFO_TRY_AGAIN_LATER) {
303-
Log.w(TAG, "unexpected result from encoder.dequeueOutputBuffer: "
304-
+ encoderStatus);
305+
Log.w(TAG, "Unexpected result from encoder.dequeueOutputBuffer: "
306+
+ encoderStatus + ", however continuing recording");
305307
} else if (encoderStatus >= 0) {
306308
ByteBuffer encodedData = videoEncoder.getOutputBuffer(encoderStatus);
307309
if (encodedData == null) {
308-
Log.w(TAG, "videoEncoder, encodedData null");
310+
Log.w(TAG, "Recording stopped, " +
311+
"Unable to retrieve output buffer of videoEncoder");
309312
return false;
310313
}
311314

@@ -318,7 +321,7 @@ private boolean writeVideoBufferToFile(MediaCodec videoEncoder, MediaMuxer muxer
318321
videoEncoder.releaseOutputBuffer(encoderStatus, false);
319322

320323
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
321-
Log.v(TAG, "videoEncoder, buffer eos");
324+
Log.v(TAG, "Recording stopped, video encoder buffer reached end of stream");
322325
return false;
323326
}
324327
}

0 commit comments

Comments
 (0)