Skip to content

Remote recording control #20

Merged
merged 71 commits into from
Mar 10, 2021
Merged

Remote recording control #20

merged 71 commits into from
Mar 10, 2021

Conversation

azaat
Copy link
Collaborator

@azaat azaat commented Dec 10, 2020

No description provided.

@azaat azaat linked an issue Dec 10, 2020 that may be closed by this pull request
4 tasks
private final ServerSocket mRpcSocket;
private final Properties mConfig;
private final RemoteRpcRequestHandler mRequestHandler;
private final AtomicBoolean mIsExecuting = new AtomicBoolean();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like volatile boolean should be enough here.

}

public void stopExecuting() {
mIsExecuting.set(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB! It is safe to .stopExecuting even in case mIsExecuting is already false

@@ -1494,6 +1513,12 @@ protected void onPause() {
super.onPause(); // docs say to call this before freeing other things
this.app_is_paused = true;

// Stop Remote controller for OpenCamera Sensors
if (mRpcServer != null && mRpcServer.isExecuting()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (mRpcServer != null && mRpcServer.isExecuting()) {
if (mRpcServer != null) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it the check is redundant

Log.d(TAG, "App rpc listener thread started");

} catch (IOException e) {
e.printStackTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
e.printStackTrace();
e.printStackTrace();
mRpcServer = null;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not need broken object.

"\n" +
message +
"\n" +
config.getProperty("CHUNK_END_DELIMITER");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Advice: do not read property every time, store value in private field on initialization, if the property value does not change between application restarts.

mRpcSocket.setReuseAddress(true);
mRpcSocket.setSoTimeout(SOCKET_WAIT_TIME_MS);

if (MyDebug.LOG) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing handshake. At least some string with version and available features\options string . Or each reply should contain this kind of server identification. (f.e. like User Agent string from browser or HTTP reply header from server)

BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

String inputLine;
while (!clientSocket.isClosed() && (inputLine = reader.readLine()) != null) {
Copy link
Collaborator

@iakov iakov Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Advice: check the exit condition (mIsExecuting) here too. Server must shutdown immediately despite the input length.

if (MyDebug.LOG) {
Log.d(TAG, "closing connection to client");
}
outputByte.close();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to finally block.

}

// Stopped accepting requests, close the server socket
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Advice: enclose the whole processing loop into try/finally to close the socket in the finally block.

private final double mAvgDurationNs;

// Accepts a sorted collection
private static double median(List<Long> numList) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function is actually useful now and the performance is not critical, just call Collections.sort. It is safe to be called on small sorted List, but will guarantee the sorted order.

@azaat azaat merged commit b2459f8 into master Mar 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Android 11 feautures support, extend firebase test devices Implement remote recording
4 participants