Skip to content

Commit 4aec69d

Browse files
committed
Prevent Android cpu suspend and cached app freezer
1 parent 7fe2749 commit 4aec69d

File tree

5 files changed

+81
-5
lines changed

5 files changed

+81
-5
lines changed

renderdoc/core/replay_proxy.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ ReplayProxy::ReplayProxy(ReadSerialiser &reader, WriteSerialiser &writer, IRepla
246246
m_Proxy(proxy),
247247
m_Remote(NULL),
248248
m_Replay(NULL),
249+
m_PreviewWindow(NULL),
249250
m_RemoteServer(false)
250251
{
251252
m_StructuredFile = new SDFile;

renderdoccmd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ if(ANDROID)
224224

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

renderdoccmd/android/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
88
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
99
<uses-permission android:name="android.permission.INTERNET" />
10-
10+
<uses-permission android:name="android.permission.WAKE_LOCK"/>
11+
1112
<!-- Use GL ES 3.2 version -->
1213
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
1314

1415
<application android:debuggable="true" android:label="RenderDocCmd" android:icon="@drawable/icon" android:hasCode="true">
1516
<activity android:name=".Loader" android:label="RenderDoc" android:exported="true" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar">
1617
<meta-data android:name="android.app.lib_name" android:value="renderdoccmd"/>
1718
</activity>
18-
19+
20+
<service android:name=".DummyService" android:exported="false" />
21+
1922
</application>
2023
</manifest>
2124
<!-- END_INCLUDE(manifest) -->
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package @RENDERDOC_ANDROID_PACKAGE_NAME@;
2+
import android.app.Notification;
3+
import android.content.Intent;
4+
import android.os.Binder;
5+
import android.os.Handler;
6+
import android.os.HandlerThread;
7+
import android.os.IBinder;
8+
import android.os.Looper;
9+
import android.os.Message;
10+
import android.os.Process;
11+
12+
public class DummyService extends android.app.Service
13+
{
14+
private Looper serviceLooper;
15+
private Handler serviceHandler;
16+
17+
@Override
18+
public void onCreate() {
19+
HandlerThread thread = new HandlerThread("DummyServiceThread", Process.THREAD_PRIORITY_BACKGROUND);
20+
thread.start();
21+
22+
serviceLooper = thread.getLooper();
23+
serviceHandler = new Handler(serviceLooper);
24+
}
25+
26+
@Override
27+
public int onStartCommand(Intent intent, int flags, int startId) {
28+
Notification notification = new Notification.Builder(this)
29+
.setPriority(Notification.PRIORITY_LOW)
30+
.setSmallIcon(R.drawable.icon)
31+
.setContentTitle("RenderDoc Dummy Foreground Service")
32+
.setContentText("RenderDoc needs this dummy foreground service to prevent cached app freezer from interrupting the network connection")
33+
.build();
34+
startForeground(startId, notification);
35+
36+
// If we get killed, don't restart
37+
return START_NOT_STICKY;
38+
}
39+
40+
@Override
41+
public IBinder onBind(Intent intent) {
42+
return null;
43+
}
44+
45+
@Override
46+
public void onDestroy() {
47+
}
48+
}

renderdoccmd/android/Loader.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package @RENDERDOC_ANDROID_PACKAGE_NAME@;
2-
import android.os.Build;
32
import android.app.Activity;
4-
import android.view.WindowManager;
5-
import android.os.Environment;
3+
import android.content.Context;
64
import android.content.Intent;
5+
import android.os.Build;
6+
import android.os.Environment;
7+
import android.os.PowerManager;
8+
import android.view.WindowManager;
79

810
public class Loader extends android.app.NativeActivity
911
{
@@ -17,6 +19,17 @@ protected void onCreate(android.os.Bundle savedInstanceState) {
1719
super.onCreate(savedInstanceState);
1820
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
1921

22+
Context context = getApplicationContext();
23+
if(context != null) {
24+
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
25+
if(powerManager != null) {
26+
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "renderdoc");
27+
wakeLock.acquire();
28+
}
29+
30+
context.startService(new Intent(this, DummyService.class));
31+
}
32+
2033
// if we're running on something older than Android M (6.0), return now
2134
// before requesting permissions as it's not supported
2235
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
@@ -55,4 +68,14 @@ protected void onCreate(android.os.Bundle savedInstanceState) {
5568
} catch(Exception e) { }
5669
}
5770
}
71+
72+
@Override
73+
protected void onDestroy() {
74+
if(wakeLock != null && wakeLock.isHeld()) {
75+
wakeLock.release();
76+
}
77+
super.onDestroy();
78+
}
79+
80+
private PowerManager.WakeLock wakeLock = null;
5881
}

0 commit comments

Comments
 (0)