Skip to content

Commit 6d927ef

Browse files
authored
Merge pull request #210 from Romick2005/master
Avoid starting new UI thread, if no current activity available.
2 parents e573b0c + 45e1673 commit 6d927ef

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

android/src/main/java/com/zxcpoiu/incallmanager/InCallManagerModule.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,15 @@ public InCallManagerModule(ReactApplicationContext reactContext) {
202202

203203
private void manualTurnScreenOff() {
204204
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+
205212
UiThreadUtil.runOnUiThread(new Runnable() {
206213
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-
}
212214
Window window = mCurrentActivity.getWindow();
213215
WindowManager.LayoutParams params = window.getAttributes();
214216
lastLayoutParams = params; // --- store last param
@@ -221,13 +223,15 @@ public void run() {
221223

222224
private void manualTurnScreenOn() {
223225
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+
224233
UiThreadUtil.runOnUiThread(new Runnable() {
225234
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-
}
231235
Window window = mCurrentActivity.getWindow();
232236
if (lastLayoutParams != null) {
233237
window.setAttributes(lastLayoutParams);
@@ -848,14 +852,18 @@ public void turnScreenOff() {
848852
@ReactMethod
849853
public void setKeepScreenOn(final boolean enable) {
850854
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+
851863
UiThreadUtil.runOnUiThread(new Runnable() {
852864
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-
}
858865
Window window = mCurrentActivity.getWindow();
866+
859867
if (enable) {
860868
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
861869
} else {

0 commit comments

Comments
 (0)