Skip to content

Commit

Permalink
Move SIP settings to phone account settings.
Browse files Browse the repository at this point in the history
+ Moved "SIP accounts" and "Receive incoming calls" settings from
the SIP settings creen to the Phone account settings screen.
+ To facilitate this, I moved some helper functions which used to
be in SipSettings to SipUtil. Their logical innards are for the
most part unchanged.
- Removed "SIP settings" preference screen added in call settings.
- Removed "Receive incoming calls" from SipSettings activity.
- Deleted unused SIP settings layout.
+ Changed back button behavior in SIP settings activity so that
back takes it to phone account settings, rather than call feature
settings.
+ Made some necessary classes/functions in sip/ public. Ihab said
that these were this way because of some refactoring at some point,
and it should be fine to make them public to achieve the necessary
class accessibility to facilitate this CL.

Bug: 17487262
Change-Id: I8e24abf624cadf9afc7aeff28781802732fef07d
  • Loading branch information
Andrew Lee committed Sep 24, 2014
1 parent 6c9c1e5 commit 4d37f52
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 124 deletions.
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
<string name="wifi_calling_do_not_use">Do not use Wi-Fi calling</string>
<!-- Indication for option to not use a call assistant. -->
<string name="wifi_calling_do_not_use_call_assistant">Do not use call assistant</string>
<!-- Indication for option to not use a call assistant. -->
<string name="wifi_calling_call_assistant_none">None</string>
<!-- Label for selected Wi-Fi call manager -->
<string name="wifi_calling_call_assistant">Call assistant</string>
<!-- Label for switch setting to enable/disable the use of SIM call managers. -->
Expand Down
18 changes: 17 additions & 1 deletion res/xml/phone_account_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<com.android.phone.settings.AccountSelectionPreference
android:key="wifi_calling_call_assistant_preference"
android:title="@string/wifi_calling_call_assistant"
android:summary="@string/wifi_calling_call_assistant_configure_no_selection" />
android:summary="@string/wifi_calling_call_assistant_none" />

<Preference
android:key="wifi_calling_configure_call_assistant_preference"
Expand All @@ -46,13 +46,29 @@
android:title="@string/sip_settings"
android:persistent="false">

<PreferenceScreen
android:title="@string/sip_accounts"
android:persistent="false">

<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.phone"
android:targetClass="com.android.services.telephony.sip.SipSettings" />

</PreferenceScreen>

<ListPreference
android:key="use_sip_calling_options_key"
android:title="@string/sip_call_options_title"
android:persistent="true"
android:entries="@array/sip_call_options_entries"
android:entryValues="@array/sip_call_options_values"/>

<CheckBoxPreference
android:key="sip_receive_calls_key"
android:title="@string/sip_receive_calls"
android:summary="@string/sip_receive_calls_summary"
android:persistent="true"/>

</PreferenceCategory>

</PreferenceScreen>
6 changes: 0 additions & 6 deletions sip/res/xml/sip_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/sip_accounts">

<CheckBoxPreference
android:key="sip_receive_calls_key"
android:title="@string/sip_receive_calls"
android:summary="@string/sip_receive_calls_summary"
android:persistent="true"/>

<PreferenceCategory android:key="sip_account_list" android:title="@string/sip_account_list"/>

</PreferenceScreen>
37 changes: 0 additions & 37 deletions sip/res/xml/sip_settings_category.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Manages the {@link PhoneAccount} entries for SIP calling.
*/
final class SipAccountRegistry {
public final class SipAccountRegistry {
private final class AccountEntry {
private final SipProfile mProfile;

Expand Down Expand Up @@ -108,7 +108,7 @@ boolean stopSipService(SipManager sipManager) {

private SipAccountRegistry() {}

static SipAccountRegistry getInstance() {
public static SipAccountRegistry getInstance() {
return INSTANCE;
}

Expand Down Expand Up @@ -172,7 +172,7 @@ void stopSipService(Context context, String sipUri) {
*
* @param context The context.
*/
void restartSipService(Context context) {
public void restartSipService(Context context) {
startSipProfiles(context, null);
}

Expand Down
66 changes: 4 additions & 62 deletions sip/src/com/android/services/telephony/sip/SipSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public class SipSettings extends PreferenceActivity {

static final String KEY_SIP_PROFILE = "sip_profile";

private static final String BUTTON_SIP_RECEIVE_CALLS =
"sip_receive_calls_key";
private static final String PREF_SIP_LIST = "sip_account_list";

private static final int REQUEST_ADD_OR_EDIT_SIP_PROFILE = 1;
Expand All @@ -78,7 +76,6 @@ public class SipSettings extends PreferenceActivity {

private SipProfile mProfile; // profile that's being edited

private CheckBoxPreference mButtonSipReceiveCalls;
private PreferenceCategory mSipListContainer;
private Map<String, SipPreference> mSipPreferenceMap;
private List<SipProfile> mSipProfileList;
Expand Down Expand Up @@ -146,7 +143,6 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.sip_settings_ui);
addPreferencesFromResource(R.xml.sip_setting);
mSipListContainer = (PreferenceCategory) findPreference(PREF_SIP_LIST);
registerForReceiveCallsCheckBox();

updateProfilesStatus();

Expand All @@ -159,8 +155,6 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onResume() {
super.onResume();

mButtonSipReceiveCalls.setEnabled(SipUtil.isPhoneIdle(this));
}

@Override
Expand Down Expand Up @@ -195,62 +189,6 @@ public void run() {
}.start();
}

private void registerForReceiveCallsCheckBox() {
mButtonSipReceiveCalls = (CheckBoxPreference) findPreference
(BUTTON_SIP_RECEIVE_CALLS);
mButtonSipReceiveCalls.setChecked(
mSipSharedPreferences.isReceivingCallsEnabled());
mButtonSipReceiveCalls.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
final boolean enabled = ((CheckBoxPreference) preference).isChecked();
new Thread(new Runnable() {
public void run() {
handleSipReceiveCallsOption(enabled);
}
}).start();
return true;
}
});
}

/**
* Handles changes to the "receive calls" option.
*
* @param isReceivingCalls {@code True} if receiving incoming SIP calls.
*/
private synchronized void handleSipReceiveCallsOption(boolean isReceivingCalls) {
mSipSharedPreferences.setReceivingCallsEnabled(isReceivingCalls);

// Mark all profiles as auto-register if we are now receiving calls.
List<SipProfile> sipProfileList = mProfileDb.retrieveSipProfileList();
for (SipProfile p : sipProfileList) {
p = updateAutoRegistrationFlag(p, isReceivingCalls);
}

// Restart all Sip services to ensure we reflect whether we are receiving calls.
SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
sipAccountRegistry.restartSipService(this);

updateProfilesStatus();
}

private SipProfile updateAutoRegistrationFlag(SipProfile p, boolean enabled) {
SipProfile newProfile = new SipProfile.Builder(p)
.setAutoRegistration(enabled)
.build();
try {
// Note: The profile is updated, but the associated PhoneAccount is left alone since
// the only thing that changed is the auto-registration flag, which is not part of the
// PhoneAccount.
mProfileDb.deleteProfile(p);
mProfileDb.saveProfile(newProfile);
} catch (Exception e) {
log("updateAutoRegistrationFlag, exception: " + e);
}
return newProfile;
}

private void updateProfilesStatus() {
new Thread(new Runnable() {
@Override
Expand Down Expand Up @@ -494,6 +432,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
startSipEditor(null);
return true;
}
case android.R.id.home: {
onBackPressed();
return true;
}
}
return super.onOptionsItemSelected(item);
}
Expand Down
34 changes: 33 additions & 1 deletion sip/src/com/android/services/telephony/sip/SipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

public class SipUtil {
static final String LOG_TAG = "SIP";
Expand Down Expand Up @@ -59,7 +61,7 @@ static PendingIntent createIncomingCallPendingIntent(
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

static boolean isPhoneIdle(Context context) {
public static boolean isPhoneIdle(Context context) {
TelecomManager manager = (TelecomManager) context.getSystemService(
Context.TELECOM_SERVICE);
if (manager != null) {
Expand Down Expand Up @@ -131,4 +133,34 @@ private static boolean useSipForPstnCalls(Context context) {
final SipSharedPreferences sipSharedPreferences = new SipSharedPreferences(context);
return sipSharedPreferences.getSipCallOption().equals(Settings.System.SIP_ALWAYS);
}

/**
* Updates SIP accounts to indicate whether they are enabled to receive incoming SIP calls.
*
* @param isEnabled {@code True} if receiving incoming SIP calls.
*/
public static void useSipToReceiveIncomingCalls(Context context, boolean isEnabled) {
SipProfileDb profileDb = new SipProfileDb(context);

// Mark all profiles as auto-register if we are now receiving calls.
List<SipProfile> sipProfileList = profileDb.retrieveSipProfileList();
for (SipProfile p : sipProfileList) {
updateAutoRegistrationFlag(p, profileDb, isEnabled);
}
}

private static void updateAutoRegistrationFlag(
SipProfile p, SipProfileDb db, boolean isEnabled) {
SipProfile newProfile = new SipProfile.Builder(p).setAutoRegistration(isEnabled).build();

try {
// Note: The profile is updated, but the associated PhoneAccount is left alone since
// the only thing that changed is the auto-registration flag, which is not part of the
// PhoneAccount.
db.deleteProfile(p);
db.saveProfile(newProfile);
} catch (Exception e) {
Log.d(LOG_TAG, "updateAutoRegistrationFlag, exception: " + e);
}
}
}
6 changes: 0 additions & 6 deletions src/com/android/phone/CallFeaturesSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -1647,12 +1647,6 @@ protected void onResume() {
updateVoiceNumberField();
mVMProviderSettingsForced = false;

if (SipUtil.isVoipSupported(this)) {
addPreferencesFromResource(
com.android.services.telephony.sip.R.xml.sip_settings_category);
}


if (mButtonDTMF != null) {
int dtmf = Settings.System.getInt(getContentResolver(),
Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, Constants.DTMF_TONE_TYPE_NORMAL);
Expand Down
Loading

0 comments on commit 4d37f52

Please sign in to comment.