Skip to content

Commit a2d710e

Browse files
committed
wakelock: acquire lock during whole ringtone and start process
some buggy devices would enter sleep/power saving mode while screen is turned of by proximity sensor. it may cause unexpected disconnection when user using earpiece to talk. so there is no need to acquire/release on every manualTurnScreen On/Off
1 parent dd6a4f7 commit a2d710e

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,6 @@ private boolean releasePartialWakeLock() {
304304

305305
private void manualTurnScreenOff() {
306306
Log.d(TAG, "manualTurnScreenOff()");
307-
if (!acquirePartialWakeLock()) {
308-
return;
309-
}
310307
UiThreadUtil.runOnUiThread(new Runnable() {
311308
public void run() {
312309
Activity mCurrentActivity = getCurrentActivity();
@@ -326,9 +323,6 @@ public void run() {
326323

327324
private void manualTurnScreenOn() {
328325
Log.d(TAG, "manualTurnScreenOn()");
329-
if (!releasePartialWakeLock()) {
330-
return;
331-
}
332326
UiThreadUtil.runOnUiThread(new Runnable() {
333327
public void run() {
334328
Activity mCurrentActivity = getCurrentActivity();
@@ -690,6 +684,7 @@ public void start(final String _media, final boolean auto, final String ringback
690684
automatic = auto;
691685
if (!audioManagerInitialized) {
692686
Log.d(TAG, "start audioRouteManager");
687+
acquirePartialWakeLock();
693688
storeOriginalAudioSetup();
694689
startEvents();
695690
// TODO: even if not acquired focus, we can still play sounds. but need figure out which is better.
@@ -724,6 +719,7 @@ public void stop(final String busytoneUriType) {
724719
restoreOriginalAudioSetup();
725720
audioManagerInitialized = false;
726721
}
722+
releasePartialWakeLock();
727723
}
728724
}
729725

@@ -1091,6 +1087,8 @@ public void startRingtone(final String ringtoneUriType, final int seconds) {
10911087
return;
10921088
}
10931089

1090+
acquirePartialWakeLock();
1091+
10941092
storeOriginalAudioSetup();
10951093
Map data = new HashMap<String, Object>();
10961094
mRingtone = new myMediaPlayer();
@@ -1105,8 +1103,6 @@ public void startRingtone(final String ringtoneUriType, final int seconds) {
11051103
data.put("audioContentType", AudioAttributes.CONTENT_TYPE_MUSIC);
11061104
*/
11071105
setMediaPlayerEvents((MediaPlayer) mRingtone, "mRingtone");
1108-
releasePokeFullWakeLock();
1109-
acquireFullWakeLock();
11101106
mRingtone.startPlay(data);
11111107

11121108
if (seconds > 0) {
@@ -1123,7 +1119,7 @@ public void run() {
11231119
}, seconds * 1000);
11241120
}
11251121
} catch(Exception e) {
1126-
releaseFullWakeLock();
1122+
releasePartialWakeLock();
11271123
Log.d(TAG, "startRingtone() failed");
11281124
}
11291125
}
@@ -1140,10 +1136,10 @@ public void stopRingtone() {
11401136
mRingtoneCountDownHandler.removeCallbacksAndMessages(null);
11411137
mRingtoneCountDownHandler = null;
11421138
}
1143-
releaseFullWakeLock();
11441139
} catch(Exception e) {
11451140
Log.d(TAG, "stopRingtone() failed");
11461141
}
1142+
releasePartialWakeLock();
11471143
}
11481144

11491145
private void setMediaPlayerEvents(MediaPlayer mp, final String name) {

0 commit comments

Comments
 (0)