自动接听电话
strings.xml: <string name="pref_auto_answer">Auto answer incoming calls</string>
non_localizable_strings.xml: <string name="pref_auto_answer_key">pref_auto_answer_key</string>
在xml文件中有这个线索, 在界面设置如下
将Auto answer incoming calls打上对勾, 就可以接听电话.
去掉视频的接受选择框
private void showAcceptCallUpdateDialog() {
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorC));
d.setAlpha(200);
dialog.setContentView(R.layout.dialog);
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
dialog.getWindow().setBackgroundDrawable(d);
TextView customText = (TextView) dialog.findViewById(R.id.customText);
customText.setText(getResources().getString(R.string.add_video_dialog));
Button delete = (Button) dialog.findViewById(R.id.delete_button);
delete.setText(R.string.accept);
Button cancel = (Button) dialog.findViewById(R.id.cancel);
cancel.setText(R.string.decline);
delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
int camera = getPackageManager().checkPermission(Manifest.permission.CAMERA, getPackageName());
Log.i("[Permission] Camera permission is " + (camera == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
if (camera == PackageManager.PERMISSION_GRANTED) {
LinphoneUtils._log("CallActivity#Turn", "showAcceptCallUpdateDialog CallActivity.instance().acceptCallUpdate(true);");
CallActivity.instance().acceptCallUpdate(true);
} else {
checkAndRequestPermission(Manifest.permission.CAMERA, PERMISSIONS_REQUEST_CAMERA);
}
dialog.dismiss();
dialog = null;
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (CallActivity.isInstanciated()) {
LinphoneUtils._log("CallActivity#Trun", "showAcceptCallUpdate CallActivity.instance().acceptCallUpdate(false);");
CallActivity.instance().acceptCallUpdate(false);
}
dialog.dismiss();
dialog = null;
}
});
dialog.show();
}
整个都去掉
界面设置源代码分析
1. xml文件中
strings.xml: <string name="pref_auto_answer">Auto answer incoming calls</string>
non_localizable_strings.xml: <string name="pref_auto_answer_key">pref_auto_answer_key</string>
2. 搜索pref_auto_anwer
没有, 可能就是显示在界面上.
3. 搜索perf_auto_anwer
org/linphone/SettingsFragment.java: CheckBoxPreference autoAnswer = (CheckBoxPreference) findPreference(getString(R.string.pref_auto_answer_key));
org/linphone/SettingsFragment.java: findPreference(getString(R.string.pref_auto_answer_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
4. 原来使用的是sharedpreference
设置配置文件
public void enableAutoAnswer(boolean enable) {
getConfig().setBool("app", "auto_answer", enable);
}
获取配置文件
mPrefs.isAutoAnswerEnabled()
public boolean isAutoAnswerEnabled() {
return getConfig().getBool("app", "auto_answer", false);
}
5. 研究一下配置文件getConf
public LpConfig getConfig() {
LinphoneCore lc = getLc();
if (lc != null) {
return lc.getConfig();
}
if (!LinphoneManager.isInstanciated()) {
File linphonerc = new File(basePath + "/.linphonerc");
if (linphonerc.exists()) { // 文件已经存在
return LinphoneCoreFactory.instance().createLpConfig(linphonerc.getAbsolutePath());
} else if (mContext != null) { // 重新创建文件
InputStream inputStream = mContext.getResources().openRawResource(R.raw.linphonerc_default);
InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader buffreader = new BufferedReader(inputreader);
StringBuilder text = new StringBuilder();
String line;
try {
while ((line = buffreader.readLine()) != null) {
text.append(line);
text.append('\n');
}
} catch (IOException ioe) {
Log.e(ioe);
}
return LinphoneCoreFactory.instance().createLpConfigFromString(text.toString());
}
} else {
return LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile);
}
return null;
}
.linphonerc文件 这是个隐藏文件
[net]
download_bw=100
upload_bw=100
mtu=1300
nat_policy_ref=mTZGZsUk7v6CyRU
[sip]
contact="Linphone Android" <sip:linphone.android@unknown-host>
use_info=0
keepalive_period=30000
guess_hostname=1
inc_timeout=15
register_only_when_network_is_up=1
auto_net_state_mon=0
auto_answer_replacing_calls=1
ping_with_options=0
rls_uri=sip:rls@sip.linphone.org
use_rls_presence=1
verify_server_certs=1
verify_server_cn=1
ipv6_migration_done=1
media_encryption=none
root_ca=/data/data/org.linphone/files/rootca.pem
in_call_timeout=0
delayed_timeout=4
register_only_when_upnp_is_ok=1
[video]
size=qvga
capture=1
display=1
automatically_initiate=1
automatically_accept=1
framerate=0.000000
preset=custom
[app]
tunnel=disabled
push_notification=1
debug=0
activation_code_length=4
first_launch=0
auto_answer=1
[tunnel]
port=443
[misc]
log_collection_upload_server_url=https://www.linphone.org:444/lft.php
file_transfer_server_url=https://www.linphone.org:444/lft.php
max_calls=10
history_max_size=100
uuid=e9960e62-8537-4865-a847-f804e18e595b
friends_migration_done=1
user_certificates_path=/data/data/org.linphone/files
store_friends=0
[rtp]
audio_rtp_port=7076
video_rtp_port=9078
audio_jitt_comp=60
video_jitt_comp=60
nortp_timeout=30
disable_upnp=1
text_rtp_port=11078
audio_adaptive_jitt_comp_enabled=1
video_adaptive_jitt_comp_enabled=1
[sound]
dtmf_player_amp=0.1
ec_calibrator_cool_tones=1
remote_ring=/data/data/org.linphone/files/ringback.wav
playback_gain_db=0.000000
mic_gain_db=0.000000
#remove this property for any application that is not Linphone public version itself
[in-app-purchase]
server_url=https://sip3.linphone.org:444/inapp.php
purchasable_items_ids=test_account_subscription
[assistant]
domain=sip.linphone.org
password_max_length=-1
password_min_length=1
username_length=-1
username_max_length=64
username_min_length=1
username_regex=^[a-z0-9_.\-]*$
xmlrpc_url=https://sip3.linphone.org:444/wizard.php
[nat_policy_0]
ref=mTZGZsUk7v6CyRU
[audio_codec_0]
mime=opus
rate=48000
channels=2
enabled=0
[audio_codec_1]
mime=SILK
rate=16000
channels=1
enabled=0
[audio_codec_2]
mime=speex
rate=16000
channels=1
enabled=1
[audio_codec_3]
mime=speex
rate=8000
channels=1
enabled=0
[audio_codec_4]
mime=PCMU
rate=8000
channels=1
enabled=0
[audio_codec_5]
mime=PCMA
rate=8000
channels=1
enabled=0
[audio_codec_6]
mime=GSM
rate=8000
channels=1
enabled=0
[audio_codec_7]
mime=G722
rate=8000
channels=1
enabled=0
[audio_codec_8]
mime=iLBC
rate=8000
channels=1
enabled=0
[audio_codec_9]
mime=G729
rate=8000
channels=1
enabled=0
[audio_codec_10]
mime=iSAC
rate=16000
channels=1
enabled=0
[audio_codec_11]
mime=speex
rate=32000
channels=1
enabled=0
[audio_codec_12]
mime=SILK
rate=8000
channels=1
enabled=0
[audio_codec_13]
mime=SILK
rate=12000
channels=1
enabled=0
[audio_codec_14]
mime=SILK
rate=24000
channels=1
enabled=0
[audio_codec_15]
mime=L16
rate=44100
channels=2
enabled=0
[audio_codec_16]
mime=L16
rate=44100
channels=1
enabled=0
[video_codec_0]
mime=VP8
rate=90000
enabled=1
6. 看看到底是谁,在哪里使用了它
原来时callstate中
if (state == State.IncomingReceived && LinphonePreferences.instance().isAutoAnswerEnabled()) {
try {
mLc.acceptCall(call);
} catch (LinphoneCoreException e) {
Log.e(e);
}
}
自动接听和不自动接听的区别
1. 自动接听
flannery LinphoneManager#config if (state == State.IncomingReceived && LinphonePreferences.instance().isAutoAnswerEnabled())
flannery LinphoneManager#config if (state == State.Connected)
flannery LinphoneManager#config if (state == State.StreamsRunning)
flannery LinphoneManager#config if (state == State.CallUpdatedByRemote)
flannery LinphoneManager#config if (state == State.StreamsRunning)
flannery LinphoneManager#config if (state == State.CallEnd || state == State.Error)
2. 不自动接听
//电话打进来
flannery LinphoneManager#config else if (state == State.IncomingReceived || (state == State.CallIncomingEarlyMedia && mR.getBoolean(R.bool.allow_ringing_while_early_media)))
//接电话
flannery LinphoneManager#config else if (call == ringingCall && isRinging)
flannery LinphoneManager#config if (state == State.Connected)
flannery LinphoneManager#config if (state == State.StreamsRunning)
//收视频
flannery LinphoneManager#config if (state == State.StreamsRunning)
flannery LinphoneManager#config if (state == State.CallUpdatedByRemote)
flannery LinphoneManager#config if (state == State.StreamsRunning)
flannery LinphoneManager#config if (state == State.CallEnd || state == State.Error)
自动接听详解
if (state == State.IncomingReceived && LinphonePreferences.instance().isAutoAnswerEnabled())
mLc.acceptCall(call);
if (state == State.StreamsRunning)
startBluetooth();
if (mIncallWakeLock == null) {
mIncallWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "incall");
}
if (!mIncallWakeLock.isHeld()) {
Log.i("New call active : acquiring incall (CPU only) wake lock");
mIncallWakeLock.acquire();
} else {
Log.i("New call active while incall (CPU only) wake lock already active");
}
if (state == State.CallUpdatedByRemote)
LinphoneUtils._log("LinphoneManager#config", "if (state == State.CallUpdatedByRemote)");
// If the correspondent proposes video while audio call
boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled();
boolean autoAcceptCameraPolicy = LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests();
if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) {
try {
LinphoneManager.getLc().deferCallUpdate(call);
} catch (LinphoneCoreException e) {
Log.e(e);
}
}
if (state == State.StreamsRunning)
同上
if (state == State.CallEnd || state == State.Error)
LinphoneUtils._log("LinphoneManager#config", " if (state == State.CallEnd || state == State.Error)");
if (mLc.getCallsNb() == 0) {
Context activity = getContext();
if (mAudioFocused) {
int res = mAudioManager.abandonAudioFocus(null);
Log.d("Audio focus released a bit later: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied"));
mAudioFocused = false;
}
if (activity != null) {
TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
Log.d("---AudioManager: back to MODE_NORMAL");
mAudioManager.setMode(AudioManager.MODE_NORMAL);
Log.d("All call terminated, routing back to earpiece");
routeAudioToReceiver();
}
}
if (mIncallWakeLock != null && mIncallWakeLock.isHeld()) {
mIncallWakeLock.release();
Log.i("Last call ended: releasing incall (CPU only) wake lock");
} else {
Log.i("Last call ended: no incall (CPU only) wake lock were held");
}
}
自动接听视频
代码过程
03-10 15:28:46.805 29557-29557/org.linphone I/System.out: flannery LinphoneActivity#generic onCreate(Bundle)
03-10 15:28:46.806 29557-29557/org.linphone I/System.out: flannery LinphoneGenericActivitydf#generic onCreate(Bundle)
03-10 15:28:47.038 29557-29557/org.linphone I/System.out: flannery about changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation)
03-10 15:29:10.489 29557-29557/org.linphone I/System.out: flannery LinphoneManager#config if (state == State.IncomingReceived && LinphonePreferences.instance().isAutoAnswerEnabled())
03-10 15:29:10.497 29557-29557/org.linphone I/System.out: flannery LinphoneManager#config if (state == State.Connected)
03-10 15:29:10.528 29557-29557/org.linphone I/System.out: flannery LinphoneService callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state Connected, String message Connected)
03-10 15:29:10.619 29557-29557/org.linphone I/System.out: flannery LinphoneActivity callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state Connected, String message Connected)
03-10 15:29:10.729 29557-29557/org.linphone I/System.out: flannery LinphoneManager#config if (state == State.StreamsRunning)
03-10 15:29:10.737 29557-29557/org.linphone I/System.out: flannery LinphoneService callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state StreamsRunning, String message Connected (streams running))
03-10 15:29:10.737 29557-29557/org.linphone I/System.out: flannery LinphoneActivity callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state StreamsRunning, String message Connected (streams running))
03-10 15:29:10.737 29557-29557/org.linphone I/System.out: flannery LinphoneService callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state IncomingReceived, String message Incoming call)
03-10 15:29:10.754 29557-29557/org.linphone I/System.out: flannery LinphoneActivity callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state IncomingReceived, String message Incoming call)
03-10 15:29:10.754 29557-29557/org.linphone I/System.out: flannery LinphoneActivity startActivity(new Intent(LinphoneActivity.instance(), CallIncomingActivity.class));
03-10 15:29:10.998 29557-29557/org.linphone I/System.out: flannery LinphoneGenericActivitydf#generic onCreate(Bundle)
03-10 15:29:10.998 29557-29557/org.linphone I/System.out: flannery CallActivity#generic onCreate(Bundle savedInstanceState)
03-10 15:29:11.476 29557-29557/org.linphone I/System.out: flannery CallActivity refreshCallList(Resources resources)
03-10 15:29:18.858 29557-29557/org.linphone I/System.out: flannery CallActivity onClick#if (id == R.id.video)
03-10 15:29:18.859 29557-29557/org.linphone I/System.out: flannery CallActivity onClick#camera == PackageManager.PERMISSION_GRANTED
03-10 15:29:18.859 29557-29557/org.linphone I/System.out: flannery CallActivity disableVideo(final boolean videoDisabled) videoDisabled = false
03-10 15:29:18.860 29557-29557/org.linphone I/System.out: flannery LinphoneCallParamsImpl isLowBandwidthEnabled()
03-10 15:29:18.861 29557-29557/org.linphone I/System.out: flannery CallActivity if (call.getRemoteParams() != null true && !call.getRemoteParams().isLowBandwidthEnabled() true call.getRemoteParams= org.linphone.core.LinphoneCallParamsImpl@d86b957)
03-10 15:29:18.861 29557-29557/org.linphone I/System.out: flannery LinphoneCallParamsImpl isLowBandwidthEnabled()
03-10 15:29:18.861 29557-29557/org.linphone I/System.out: flannery CallActivity LinphoneManager.getInstance().addVideo();
03-10 15:29:18.869 29557-29557/org.linphone I/System.out: flannery BandwidthManager callParams.setVideoEnabled(true); callParams.setAudioBandwidth(0);
03-10 15:29:18.869 29557-29557/org.linphone I/System.out: flannery LinphoneCallParamsImpl setVideoEnabled(boolean b) true
03-10 15:29:18.869 29557-29557/org.linphone I/System.out: flannery LinphoneCallParamsImpl setAudioBandwidth(int value)
03-10 15:29:18.871 29557-29557/org.linphone I/System.out: flannery LinphoneService callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state Updating, String message Updating call)
03-10 15:29:18.871 29557-29557/org.linphone I/System.out: flannery CallActivity#Turn callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, final LinphoneCall callCall 3095689808, LinphoneCall.State stateUpdating, String messageUpdating call)
03-10 15:29:18.875 29557-29557/org.linphone I/System.out: flannery CallActivity refreshCallList(Resources resources)
03-10 15:29:19.884 29557-29557/org.linphone I/System.out: flannery LinphoneManager#config if (state == State.StreamsRunning)
03-10 15:29:19.888 29557-29557/org.linphone I/System.out: flannery LinphoneService callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state StreamsRunning, String message Streams running)
03-10 15:29:19.953 29557-29557/org.linphone I/System.out: flannery CallActivity#Turn callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, final LinphoneCall callCall 3095689808, LinphoneCall.State stateStreamsRunning, String messageStreams running)
03-10 15:29:19.953 29557-29557/org.linphone I/System.out: flannery CallActivity } else if (state == State.StreamsRunning) {
03-10 15:29:19.954 29557-29557/org.linphone I/System.out: flannery LinphoneCallParamsImpl isLowBandwidthEnabled()
03-10 15:29:19.955 29557-29557/org.linphone I/System.out: flannery CallActivity#Turn showVideoView()
03-10 15:29:20.012 29557-29557/org.linphone I/System.out: flannery CallActivity if (status != null) {
03-10 15:29:20.029 29557-29557/org.linphone I/System.out: flannery CallActivity refreshCallList(Resources resources)
03-10 15:29:25.972 29557-29557/org.linphone I/System.out: flannery LinphoneManager#config if (state == State.CallEnd || state == State.Error)
03-10 15:29:26.002 29557-29557/org.linphone I/System.out: flannery LinphoneService callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state CallEnd, String message Call terminated)
03-10 15:29:26.008 29557-29557/org.linphone I/System.out: flannery CallActivity#Turn callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, final LinphoneCall callCall 3095689808, LinphoneCall.State stateCallEnd, String messageCall terminated)
03-10 15:29:26.034 29557-29557/org.linphone I/System.out: flannery LinphoneService callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, LinphoneCall call Call 3095689808, LinphoneCall.State state Released, String message Call released)
03-10 15:29:26.034 29557-29557/org.linphone I/System.out: flannery CallActivity#Turn callState(LinphoneCore lc org.linphone.core.LinphoneCoreImpl@c6920ac, final LinphoneCall callCall 3095689808, LinphoneCall.State stateReleased, String messageCall released)
03-10 15:29:26.089 29557-29557/org.linphone I/System.out: flannery LinphoneGenericActivitydf#generic onCreate(Bundle)
03-10 15:29:26.089 29557-29557/org.linphone I/System.out: flannery CallIncomingActivity#generic onCreate(Bundle);
03-10 15:29:26.182 29557-29557/org.linphone I/System.out: flannery LinphoneGenericActivitydf#generic onCreate(Bundle)
资料
自动接听电话
Linphone探索:5 . Linphone配置大全
non_localizable_custom.xml