Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Android Cached App Freezer from freezing the replay server #3504

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions renderdoc/core/replay_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ ReplayProxy::ReplayProxy(ReadSerialiser &reader, WriteSerialiser &writer, IRepla
m_Proxy(proxy),
m_Remote(NULL),
m_Replay(NULL),
m_PreviewWindow(NULL),
Copy link

Choose a reason for hiding this comment

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

This looks like an unrelated fix, consider moving to a separate PR.

m_RemoteServer(false)
{
m_StructuredFile = new SDFile;
Expand Down
1 change: 1 addition & 0 deletions renderdoccmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ if(ANDROID)

# Copy in android package files, replacing the package name with the architecture-specific package name
configure_file(android/Loader.java ${CMAKE_CURRENT_BINARY_DIR}/src/org/renderdoc/renderdoccmd/Loader.java)
configure_file(android/DummyService.java ${CMAKE_CURRENT_BINARY_DIR}/src/org/renderdoc/renderdoccmd/DummyService.java)
configure_file(android/AndroidManifest.xml ${CMAKE_CURRENT_BINARY_DIR}/AndroidManifest.xml)
configure_file(android/icon.png ${CMAKE_CURRENT_BINARY_DIR}/res/drawable/icon.png COPYONLY)

Expand Down
6 changes: 4 additions & 2 deletions renderdoccmd/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />

<!-- Use GL ES 3.2 version -->
<uses-feature android:glEsVersion="0x00030000" android:required="true" />

<application android:debuggable="true" android:label="RenderDocCmd" android:icon="@drawable/icon" android:hasCode="true">
<activity android:name=".Loader" android:label="RenderDoc" android:exported="true" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar">
<meta-data android:name="android.app.lib_name" android:value="renderdoccmd"/>
</activity>


<service android:name=".DummyService" android:exported="false" />

</application>
</manifest>
<!-- END_INCLUDE(manifest) -->
48 changes: 48 additions & 0 deletions renderdoccmd/android/DummyService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package @RENDERDOC_ANDROID_PACKAGE_NAME@;
import android.app.Notification;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Process;

public class DummyService extends android.app.Service
Copy link

Choose a reason for hiding this comment

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

Perhaps something like KeepaliveService might be more descriptive?

{
private Looper serviceLooper;
private Handler serviceHandler;

@Override
public void onCreate() {
HandlerThread thread = new HandlerThread("DummyServiceThread", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();

serviceLooper = thread.getLooper();
serviceHandler = new Handler(serviceLooper);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Notification notification = new Notification.Builder(this)
.setPriority(Notification.PRIORITY_LOW)
.setSmallIcon(R.drawable.icon)
.setContentTitle("RenderDoc Dummy Foreground Service")
.setContentText("RenderDoc needs this dummy foreground service to prevent cached app freezer from interrupting the network connection")
Copy link

Choose a reason for hiding this comment

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

Maybe something like "RenderDoc server running" as the text, with "RenderDoc" as the title? Cached app freezer is an implementation detail that's unimportant to the user.

.build();
startForeground(startId, notification);

// If we get killed, don't restart
return START_NOT_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onDestroy() {
}
}
12 changes: 9 additions & 3 deletions renderdoccmd/android/Loader.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package @RENDERDOC_ANDROID_PACKAGE_NAME@;
import android.os.Build;
import android.app.Activity;
import android.view.WindowManager;
import android.os.Environment;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Environment;
import android.view.WindowManager;

public class Loader extends android.app.NativeActivity
{
Expand All @@ -17,6 +18,11 @@ protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Context context = getApplicationContext();
if(context != null) {
context.startService(new Intent(this, DummyService.class));
Copy link

Choose a reason for hiding this comment

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

Should we also stop the foreground service when the activity is destroyed, or if the remote server exits for whatever reason?

}

// if we're running on something older than Android M (6.0), return now
// before requesting permissions as it's not supported
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
Expand Down