@@ -202,13 +202,15 @@ public InCallManagerModule(ReactApplicationContext reactContext) {
202
202
203
203
private void manualTurnScreenOff () {
204
204
Log .d (TAG , "manualTurnScreenOff()" );
205
+ Activity mCurrentActivity = getCurrentActivity ();
206
+
207
+ if (mCurrentActivity == null ) {
208
+ Log .d (TAG , "ReactContext doesn't have any Activity attached." );
209
+ return ;
210
+ }
211
+
205
212
UiThreadUtil .runOnUiThread (new Runnable () {
206
213
public void run () {
207
- Activity mCurrentActivity = getCurrentActivity ();
208
- if (mCurrentActivity == null ) {
209
- Log .d (TAG , "ReactContext doesn't hava any Activity attached." );
210
- return ;
211
- }
212
214
Window window = mCurrentActivity .getWindow ();
213
215
WindowManager .LayoutParams params = window .getAttributes ();
214
216
lastLayoutParams = params ; // --- store last param
@@ -221,13 +223,15 @@ public void run() {
221
223
222
224
private void manualTurnScreenOn () {
223
225
Log .d (TAG , "manualTurnScreenOn()" );
226
+ Activity mCurrentActivity = getCurrentActivity ();
227
+
228
+ if (mCurrentActivity == null ) {
229
+ Log .d (TAG , "ReactContext doesn't have any Activity attached." );
230
+ return ;
231
+ }
232
+
224
233
UiThreadUtil .runOnUiThread (new Runnable () {
225
234
public void run () {
226
- Activity mCurrentActivity = getCurrentActivity ();
227
- if (mCurrentActivity == null ) {
228
- Log .d (TAG , "ReactContext doesn't hava any Activity attached." );
229
- return ;
230
- }
231
235
Window window = mCurrentActivity .getWindow ();
232
236
if (lastLayoutParams != null ) {
233
237
window .setAttributes (lastLayoutParams );
@@ -848,14 +852,18 @@ public void turnScreenOff() {
848
852
@ ReactMethod
849
853
public void setKeepScreenOn (final boolean enable ) {
850
854
Log .d (TAG , "setKeepScreenOn() " + enable );
855
+
856
+ Activity mCurrentActivity = getCurrentActivity ();
857
+
858
+ if (mCurrentActivity == null ) {
859
+ Log .d (TAG , "ReactContext doesn't have any Activity attached." );
860
+ return ;
861
+ }
862
+
851
863
UiThreadUtil .runOnUiThread (new Runnable () {
852
864
public void run () {
853
- Activity mCurrentActivity = getCurrentActivity ();
854
- if (mCurrentActivity == null ) {
855
- Log .d (TAG , "ReactContext doesn't hava any Activity attached." );
856
- return ;
857
- }
858
865
Window window = mCurrentActivity .getWindow ();
866
+
859
867
if (enable ) {
860
868
window .addFlags (WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON );
861
869
} else {
0 commit comments