extend wake lock scope to screen to avoid sound system from going to standby

This commit is contained in:
Jehan Monnier 2010-03-25 14:14:10 +01:00
parent 838be51880
commit d83152c489
6 changed files with 71 additions and 13 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.linphone"
android:versionCode="106"
android:versionName="1.06">
android:versionCode="107"
android:versionName="1.07">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="@drawable/linphone2" android:label="@string/app_name" android:debuggable = "true">

Binary file not shown.

View file

@ -88,6 +88,8 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
private SharedPreferences mPref;
String PREF_CHECK_CONFIG = "pref_check_config";
/**
*
* @return null if not ready yet
@ -103,13 +105,15 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mAddress.setText(aContact);
mDisplayName = aDisplayName;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialer);
mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"Linphone");
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE,"Linphone");
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
try {
@ -208,23 +212,42 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mInCallControlRow = (TableRow) findViewById(R.id.IncallControlRow);
mAddressLayout = (LinearLayout) findViewById(R.id.Addresslayout);
mInCallAddressLayout = (LinearLayout) findViewById(R.id.IncallAddressLayout);
mMute = (ToggleButton)findViewById(R.id.mic_mute_button);
mSpeaker = (ToggleButton)findViewById(R.id.speaker_button);
mInCallControlRow.setVisibility(View.GONE);
mInCallAddressLayout.setVisibility(View.GONE);
mDecline.setEnabled(false);
if (LinphoneService.isready()) {
if (LinphoneService.instance().getLinphoneCore().isIncall()) {
LinphoneCore lLinphoenCore = LinphoneService.instance().getLinphoneCore();
if (lLinphoenCore.isIncall()) {
mCall.setEnabled(false);
mHangup.setEnabled(!mCall.isEnabled());
mCallControlRow.setVisibility(View.GONE);
mInCallControlRow.setVisibility(View.VISIBLE);
mAddressLayout.setVisibility(View.GONE);
mInCallAddressLayout.setVisibility(View.VISIBLE);
mMute.setChecked(!lLinphoenCore.isMicMuted());
mMute.setCompoundDrawablesWithIntrinsicBounds(0
, mMute.isChecked()?R.drawable.mic_active:R.drawable.mic_muted
, 0
, 0);
String DisplayName = lLinphoenCore.getRemoteAddress().getDisplayName();
if (DisplayName!=null) {
mDisplayNameView.setText(DisplayName);
} else {
mDisplayNameView.setText(lLinphoenCore.getRemoteAddress().getUserName());
}
if ((Integer.parseInt(Build.VERSION.SDK) <=4 && mAudioManager.getMode() == AudioManager.MODE_NORMAL)
|| Integer.parseInt(Build.VERSION.SDK) >4 &&mAudioManager.isSpeakerphoneOn()) {
mSpeaker.setChecked(true);
}
mWakeLock.acquire();
}
}
mMute = (ToggleButton)findViewById(R.id.mic_mute_button);
mMute.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -241,7 +264,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
});
mSpeaker = (ToggleButton)findViewById(R.id.speaker_button);
mSpeaker.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -306,6 +329,12 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if (mWakeLock.isHeld()) mWakeLock.release();
}
@Override
protected void onResume() {
super.onResume();
@ -368,6 +397,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
break;
}
case GSTATE_CALL_OUT_INVITE: {
mWakeLock.acquire();
enterIncalMode(lc);
routeAudioToReceiver();
break;
@ -383,6 +413,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
break;
}
case GSTATE_CALL_ERROR: {
if (mWakeLock.isHeld()) mWakeLock.release();
Toast toast = Toast.makeText(this
,String.format(getString(R.string.call_error),lc.getRemoteAddress())
, Toast.LENGTH_LONG);
@ -404,7 +435,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
private void enterIncalMode(LinphoneCore lc) {
mWakeLock.acquire();
mCallControlRow.setVisibility(View.GONE);
mInCallControlRow.setVisibility(View.VISIBLE);
mAddressLayout.setVisibility(View.GONE);
@ -435,7 +466,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mMute.setChecked(true);
mSpeaker.setChecked(false);
mDecline.setEnabled(false);
mWakeLock.release();
if (mWakeLock.isHeld())mWakeLock.release();
}
private void routeAudioToSpeaker() {
if (Integer.parseInt(Build.VERSION.SDK) <= 4 /*<donut*/) {

View file

@ -48,6 +48,8 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
private static LinphoneActivity theLinphoneActivity;
private SensorManager mSensorManager;
private FrameLayout mMainFrame;
private static String SCREEN_IS_HIDDEN ="screen_is_hidden";
protected static LinphoneActivity instance()
{
if (theLinphoneActivity == null) {
@ -56,10 +58,18 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
return theLinphoneActivity;
}
}
protected void onSaveInstanceState (Bundle outState) {
if (mMainFrame.getVisibility() == View.INVISIBLE) {
outState.putBoolean(SCREEN_IS_HIDDEN, true);
} else {
outState.putBoolean(SCREEN_IS_HIDDEN, false);
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
theLinphoneActivity = this;
// start linphone as background
Intent intent = new Intent(Intent.ACTION_MAIN);
@ -105,7 +115,9 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
lTabHost.addTab(spec);
lTabHost.setCurrentTabByTag("dialer");
if (savedInstanceState !=null && savedInstanceState.getBoolean(SCREEN_IS_HIDDEN,false)) {
hideScreen(true);
}
}
@ -210,15 +222,21 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
public void onSensorChanged(SensorEvent event) {
if (LinphoneService.isready() == false) return; //nop nothing to do
WindowManager.LayoutParams lAttrs =getWindow().getAttributes();
if (LinphoneService.instance().getLinphoneCore().isIncall() && event.values[0] == 0) {
hideScreen(true);
} else if (mMainFrame.getVisibility() != View.VISIBLE && event.values[0] == 1) {
hideScreen(false);
}
}
private void hideScreen(boolean isHidden) {
WindowManager.LayoutParams lAttrs =getWindow().getAttributes();
if (isHidden) {
lAttrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
mMainFrame.setVisibility(View.INVISIBLE);
} else if (mMainFrame.getVisibility() != View.VISIBLE && event.values[0] == 1) {
} else {
lAttrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
mMainFrame.setVisibility(View.VISIBLE);
}
getWindow().setAttributes(lAttrs);
}
}

View file

@ -153,6 +153,11 @@ public interface LinphoneCore {
* @param isMuted
*/
public void muteMic(boolean isMuted);
/**
*
* @return true is mic is muted
*/
public boolean isMicMuted();
/**
* Build an address according to the current proxy config. In case destination is not a sip uri, the default proxy domain is automatically appended
* @param destination

View file

@ -56,6 +56,7 @@ class LinphoneCoreImpl implements LinphoneCore {
private native void inviteAddress(long nativePtr,long to);
private native void sendDtmf(long nativePtr,char dtmf);
private native void clearCallLogs(long nativePtr);
private native boolean isMicMuted(long nativePtr);
LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
@ -190,4 +191,7 @@ class LinphoneCoreImpl implements LinphoneCore {
public void clearCallLogs() {
clearCallLogs(nativePtr);
}
public boolean isMicMuted() {
return isMicMuted(nativePtr);
}
}