Skip to content

Commit

Permalink
Prevent Android cached app freezer from freezing the replay server
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisjimmyfb committed Dec 18, 2024
1 parent b5ba9bd commit 193cd3d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
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),
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
{
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")
.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));
}

// 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

0 comments on commit 193cd3d

Please sign in to comment.