Merge "Start SIP Service after user unlock on FBE devices" into nyc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 26b897a..3cc535a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -538,8 +538,10 @@
                 <action android:name="android.telecom.ConnectionService" />
             </intent-filter>
         </service>
+
         <receiver android:name="com.android.services.telephony.sip.SipBroadcastReceiver">
             <intent-filter>
+                <action android:name="android.intent.action.BOOT_COMPLETED" />
                 <action android:name="android.net.sip.SIP_SERVICE_UP" />
                 <action android:name="com.android.phone.SIP_INCOMING_CALL" />
                 <action android:name="com.android.phone.SIP_REMOVE_PHONE" />
diff --git a/sip/src/com/android/services/telephony/sip/SipAccountRegistry.java b/sip/src/com/android/services/telephony/sip/SipAccountRegistry.java
index dd76c27..9095373 100644
--- a/sip/src/com/android/services/telephony/sip/SipAccountRegistry.java
+++ b/sip/src/com/android/services/telephony/sip/SipAccountRegistry.java
@@ -23,7 +23,6 @@
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
-import android.text.TextUtils;
 import android.util.Log;
 
 import java.util.List;
@@ -231,9 +230,8 @@
      * @param enableProfile Sip account should be enabled.
      */
     private void startSipProfiles(Context context, String sipProfileName, boolean enableProfile) {
-        final SipSharedPreferences sipSharedPreferences = new SipSharedPreferences(context);
-        boolean isReceivingCalls = sipSharedPreferences.isReceivingCallsEnabled();
-        String primaryProfile = sipSharedPreferences.getPrimaryAccount();
+        final SipPreferences sipPreferences = new SipPreferences(context);
+        boolean isReceivingCalls = sipPreferences.isReceivingCallsEnabled();
         TelecomManager telecomManager = TelecomManager.from(context);
         SipManager sipManager = SipManager.newInstance(context);
         SipProfileDb profileDb = new SipProfileDb(context);
@@ -251,12 +249,6 @@
                 startSipServiceForProfile(profile, sipManager, context, isReceivingCalls);
             }
         }
-
-        if (primaryProfile != null) {
-            // Remove the primary account shared preference, ensuring the migration does not
-            // occur again in the future.
-            sipSharedPreferences.cleanupPrimaryAccountSetting();
-        }
     }
 
     /**
diff --git a/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java b/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
index 545854d..cd45ac1 100644
--- a/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
+++ b/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
@@ -25,6 +25,9 @@
 import android.telecom.TelecomManager;
 import android.util.Log;
 
+import com.android.phone.PhoneGlobals;
+import com.android.server.sip.SipService;
+
 /**
  * Broadcast receiver that handles SIP-related intents.
  */
@@ -42,7 +45,13 @@
         }
 
         SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
-        if (action.equals(SipManager.ACTION_SIP_INCOMING_CALL)) {
+        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
+            Context phoneGlobalsContext = PhoneGlobals.getInstance();
+            // Migrate SIP database from DE->CE storage if the device has just upgraded.
+            SipUtil.possiblyMigrateSipDb(phoneGlobalsContext);
+            // Wait until boot complete to start SIP so that it has access to CE storage.
+            SipService.start(phoneGlobalsContext);
+        } else if (action.equals(SipManager.ACTION_SIP_INCOMING_CALL)) {
             takeCall(context, intent);
         } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP) ||
                 action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
diff --git a/sip/src/com/android/services/telephony/sip/SipConnectionService.java b/sip/src/com/android/services/telephony/sip/SipConnectionService.java
index ab4223a..a5f48d3 100644
--- a/sip/src/com/android/services/telephony/sip/SipConnectionService.java
+++ b/sip/src/com/android/services/telephony/sip/SipConnectionService.java
@@ -27,7 +27,6 @@
 import android.net.sip.SipProfile;
 import android.os.Bundle;
 import android.os.Handler;
-import android.os.ResultReceiver;
 import android.telecom.Connection;
 import android.telecom.ConnectionRequest;
 import android.telecom.ConnectionService;
diff --git a/sip/src/com/android/services/telephony/sip/SipEditor.java b/sip/src/com/android/services/telephony/sip/SipEditor.java
index 6ba78c9..8bc7734 100644
--- a/sip/src/com/android/services/telephony/sip/SipEditor.java
+++ b/sip/src/com/android/services/telephony/sip/SipEditor.java
@@ -18,7 +18,6 @@
 
 import android.app.AlertDialog;
 import android.content.Intent;
-import android.net.sip.SipManager;
 import android.net.sip.SipProfile;
 import android.os.Bundle;
 import android.os.Parcelable;
@@ -58,7 +57,7 @@
     private static final int NA = 0;
 
     private AdvancedSettings mAdvancedSettings;
-    private SipSharedPreferences mSharedPreferences;
+    private SipPreferences mSipPreferences;
     private boolean mDisplayNameSet;
     private boolean mHomeButtonClicked;
     private boolean mUpdateRequired;
@@ -151,7 +150,7 @@
         if (VERBOSE) log("onCreate, start profile editor");
         super.onCreate(savedInstanceState);
 
-        mSharedPreferences = new SipSharedPreferences(this);
+        mSipPreferences = new SipPreferences(this);
         mProfileDb = new SipProfileDb(this);
         mSipAccountRegistry = SipAccountRegistry.getInstance();
 
@@ -404,7 +403,7 @@
                 .setPort(Integer.parseInt(PreferenceKey.Port.getValue()))
                 .setSendKeepAlive(isAlwaysSendKeepAlive())
                 .setAutoRegistration(
-                        mSharedPreferences.isReceivingCallsEnabled())
+                        mSipPreferences.isReceivingCallsEnabled())
                 .setAuthUserName(PreferenceKey.AuthUserName.getValue())
                 .build();
     }
diff --git a/sip/src/com/android/services/telephony/sip/SipSharedPreferences.java b/sip/src/com/android/services/telephony/sip/SipPreferences.java
similarity index 63%
rename from sip/src/com/android/services/telephony/sip/SipSharedPreferences.java
rename to sip/src/com/android/services/telephony/sip/SipPreferences.java
index bad7dd5..f344497 100644
--- a/sip/src/com/android/services/telephony/sip/SipSharedPreferences.java
+++ b/sip/src/com/android/services/telephony/sip/SipPreferences.java
@@ -18,57 +18,27 @@
 
 import android.content.Context;
 import android.content.Intent;
-import android.content.SharedPreferences;
 import android.net.sip.SipManager;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
 import android.util.Log;
 
 /**
- * Wrapper for SIP's shared preferences.
+ * Wrapper for SIP's preferences.
  */
-public class SipSharedPreferences {
-    private static final String PREFIX = "[SipSharedPreferences] ";
+public class SipPreferences {
+    private static final String PREFIX = "[SipPreferences] ";
     private static final boolean VERBOSE = false; /* STOP SHIP if true */
 
+    // Used to clear out old SharedPreferences file during SipProfile Database Migration
     private static final String SIP_SHARED_PREFERENCES = "SIP_PREFERENCES";
 
-    /**
-     * @deprecated Primary account selection for SIP accounts is no longer relevant.
-     */
-    @Deprecated
-    private static final String KEY_PRIMARY_ACCOUNT = "primary";
-
-    private static final String KEY_NUMBER_OF_PROFILES = "profiles";
-
-    private SharedPreferences mPreferences;
     private Context mContext;
 
-    public SipSharedPreferences(Context context) {
-        mPreferences = context.getSharedPreferences(
-                SIP_SHARED_PREFERENCES, Context.MODE_WORLD_READABLE);
+    public SipPreferences(Context context) {
         mContext = context;
     }
 
-    /**
-     * Returns the primary account URI or null if it does not exist.
-     * @deprecated The primary account setting is no longer used.
-     */
-    @Deprecated
-    public String getPrimaryAccount() {
-        return mPreferences.getString(KEY_PRIMARY_ACCOUNT, null);
-    }
-
-    public void setProfilesCount(int number) {
-        SharedPreferences.Editor editor = mPreferences.edit();
-        editor.putInt(KEY_NUMBER_OF_PROFILES, number);
-        editor.apply();
-    }
-
-    public int getProfilesCount() {
-        return mPreferences.getInt(KEY_NUMBER_OF_PROFILES, 0);
-    }
-
     public void setSipCallOption(String option) {
         Settings.System.putString(mContext.getContentResolver(),
                 Settings.System.SIP_CALL_OPTIONS, option);
@@ -103,15 +73,10 @@
     }
 
     /**
-     * Performs cleanup of the shared preferences, removing the deprecated primary account key if
-     * it exists.
+     * Remove obsolete SharedPreferences File upon upgrade from M->N.
      */
-    public void cleanupPrimaryAccountSetting() {
-        if (mPreferences.contains(KEY_PRIMARY_ACCOUNT)) {
-            SharedPreferences.Editor editor = mPreferences.edit();
-            editor.remove(KEY_PRIMARY_ACCOUNT);
-            editor.apply();
-        }
+    public void clearSharedPreferences() {
+        mContext.deleteSharedPreferences(SIP_SHARED_PREFERENCES);
     }
 
     // TODO: back up to Android Backup
diff --git a/sip/src/com/android/services/telephony/sip/SipProfileDb.java b/sip/src/com/android/services/telephony/sip/SipProfileDb.java
index 578c683..fed8438 100644
--- a/sip/src/com/android/services/telephony/sip/SipProfileDb.java
+++ b/sip/src/com/android/services/telephony/sip/SipProfileDb.java
@@ -24,7 +24,6 @@
 import android.util.Log;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -45,20 +44,32 @@
 
     private static final String SCHEME_PREFIX = "sip:";
 
+    private Context mContext;
     private String mProfilesDirectory;
-    private SipSharedPreferences mSipSharedPreferences;
+    private SipPreferences mSipPreferences;
     private int mProfilesCount = -1;
 
     public SipProfileDb(Context context) {
-        mProfilesDirectory = context.getFilesDir().getAbsolutePath() + PROFILES_DIR;
-        mSipSharedPreferences = new SipSharedPreferences(context);
+        // Sip Profile Db should always reference CE storage.
+        mContext = context.createCredentialEncryptedStorageContext();
+        setupDatabase();
+    }
+
+    // Only should be used during migration from M->N to move database
+    public void accessDEStorageForMigration() {
+        mContext = mContext.createDeviceEncryptedStorageContext();
+        setupDatabase();
+    }
+
+    private void setupDatabase() {
+        mProfilesDirectory = mContext.getFilesDir().getAbsolutePath() + PROFILES_DIR;
+        mSipPreferences = new SipPreferences(mContext);
     }
 
     public void deleteProfile(SipProfile p) {
         synchronized(SipProfileDb.class) {
             deleteProfile(new File(mProfilesDirectory + p.getProfileName()));
             if (mProfilesCount < 0) retrieveSipProfileListInternal();
-            mSipSharedPreferences.setProfilesCount(--mProfilesCount);
         }
     }
 
@@ -69,6 +80,16 @@
         file.delete();
     }
 
+    public void cleanupUponMigration() {
+        // Remove empty .../profiles/ directory
+        File dbDir = new File(mProfilesDirectory);
+        if(dbDir.isDirectory()) {
+            dbDir.delete();
+        }
+        // Remove SharedPreferences file as well
+        mSipPreferences.clearSharedPreferences();
+    }
+
     public void saveProfile(SipProfile p) throws IOException {
         synchronized(SipProfileDb.class) {
             if (mProfilesCount < 0) retrieveSipProfileListInternal();
@@ -82,7 +103,6 @@
                 oos = new ObjectOutputStream(fos);
                 oos.writeObject(p);
                 oos.flush();
-                mSipSharedPreferences.setProfilesCount(++mProfilesCount);
                 atomicFile.finishWrite(fos);
             } catch (IOException e) {
                 atomicFile.failWrite(fos);
@@ -93,10 +113,6 @@
         }
     }
 
-    public int getProfilesCount() {
-        return (mProfilesCount < 0) ?  mSipSharedPreferences.getProfilesCount() : mProfilesCount;
-    }
-
     public List<SipProfile> retrieveSipProfileList() {
         synchronized(SipProfileDb.class) {
             return retrieveSipProfileListInternal();
@@ -116,7 +132,6 @@
             sipProfileList.add(p);
         }
         mProfilesCount = sipProfileList.size();
-        mSipSharedPreferences.setProfilesCount(mProfilesCount);
         return sipProfileList;
     }
 
diff --git a/sip/src/com/android/services/telephony/sip/SipSettings.java b/sip/src/com/android/services/telephony/sip/SipSettings.java
index 76470e5..2044d49 100644
--- a/sip/src/com/android/services/telephony/sip/SipSettings.java
+++ b/sip/src/com/android/services/telephony/sip/SipSettings.java
@@ -16,9 +16,6 @@
 
 package com.android.services.telephony.sip;
 
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneConstants;
-
 import android.app.ActionBar;
 import android.app.AlertDialog;
 import android.content.Context;
@@ -34,13 +31,9 @@
 import android.os.Bundle;
 import android.os.Parcelable;
 import android.os.Process;
-import android.preference.CheckBoxPreference;
 import android.preference.Preference;
-import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceCategory;
-import android.telecom.PhoneAccount;
-import android.telecom.TelecomManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Menu;
@@ -76,7 +69,7 @@
     private PreferenceCategory mSipListContainer;
     private Map<String, SipPreference> mSipPreferenceMap;
     private List<SipProfile> mSipProfileList;
-    private SipSharedPreferences mSipSharedPreferences;
+    private SipPreferences mSipPreferences;
     private int mUid = Process.myUid();
 
     private class SipPreference extends Preference {
@@ -93,7 +86,7 @@
         void setProfile(SipProfile p) {
             mProfile = p;
             setTitle(getProfileName(p));
-            updateSummary(mSipSharedPreferences.isReceivingCallsEnabled()
+            updateSummary(mSipPreferences.isReceivingCallsEnabled()
                     ? getString(R.string.registration_status_checking_status)
                     : getString(R.string.registration_status_not_receiving));
         }
@@ -133,7 +126,7 @@
         super.onCreate(savedInstanceState);
 
         mSipManager = SipManager.newInstance(this);
-        mSipSharedPreferences = new SipSharedPreferences(this);
+        mSipPreferences = new SipPreferences(this);
         mProfileDb = new SipProfileDb(this);
 
         mPackageManager = getPackageManager();
@@ -231,7 +224,7 @@
             }
         }
 
-        if (!mSipSharedPreferences.isReceivingCallsEnabled()) return;
+        if (!mSipPreferences.isReceivingCallsEnabled()) return;
         for (SipProfile p : mSipProfileList) {
             if (mUid == p.getCallingUid()) {
                 try {
diff --git a/sip/src/com/android/services/telephony/sip/SipUtil.java b/sip/src/com/android/services/telephony/sip/SipUtil.java
index e885fad..42e8116 100644
--- a/sip/src/com/android/services/telephony/sip/SipUtil.java
+++ b/sip/src/com/android/services/telephony/sip/SipUtil.java
@@ -33,6 +33,7 @@
 
 import com.android.phone.R;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -133,13 +134,49 @@
     }
 
     /**
+     * Upon migration from M->N, the SIP Profile database will be moved into DE storage. This will
+     * not be a problem for non-FBE enabled devices, since DE and CE storage is available at the
+     * same time. This will be a problem for backup/restore, however if the SIP Profile DB is
+     * restored onto a new FBE enabled device.
+     *
+     * Checks if the Sip Db is in DE storage. If it is, the Db is moved to CE storage and
+     * deleted.
+     */
+    public static void possiblyMigrateSipDb(Context context) {
+        SipProfileDb dbDeStorage = new SipProfileDb(context);
+        dbDeStorage.accessDEStorageForMigration();
+        List<SipProfile> profilesDeStorage = dbDeStorage.retrieveSipProfileList();
+        if(profilesDeStorage.size() != 0) {
+            Log.i(LOG_TAG, "Migrating SIP Profiles over!");
+            SipProfileDb dbCeStorage = new SipProfileDb(context);
+            //Perform Profile Migration
+            for (SipProfile profileToMove : profilesDeStorage) {
+                if (dbCeStorage.retrieveSipProfileFromName(
+                        profileToMove.getProfileName()) == null) {
+                    try {
+                        dbCeStorage.saveProfile(profileToMove);
+                    } catch (IOException e) {
+                        Log.w(LOG_TAG, "Error Migrating file to CE: " +
+                                profileToMove.getProfileName(), e);
+                    }
+                }
+                Log.i(LOG_TAG, "(Migration) Deleting SIP profile: " +
+                        profileToMove.getProfileName());
+                dbDeStorage.deleteProfile(profileToMove);
+            }
+        }
+        // Delete supporting structures if they exist
+        dbDeStorage.cleanupUponMigration();
+    }
+
+    /**
      * Determines if the user has chosen to use SIP for PSTN calls as well as SIP calls.
      * @param context The context.
      * @return {@code True} if SIP should be used for PSTN calls.
      */
     private static boolean useSipForPstnCalls(Context context) {
-        final SipSharedPreferences sipSharedPreferences = new SipSharedPreferences(context);
-        return sipSharedPreferences.getSipCallOption().equals(Settings.System.SIP_ALWAYS);
+        final SipPreferences sipPreferences = new SipPreferences(context);
+        return sipPreferences.getSipCallOption().equals(Settings.System.SIP_ALWAYS);
     }
 
     /**
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 88e8272..c2ec719 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -18,62 +18,44 @@
 
 import android.app.Activity;
 import android.app.KeyguardManager;
-import android.app.PendingIntent;
 import android.app.ProgressDialog;
-import android.app.TaskStackBuilder;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.IBluetoothHeadsetPhone;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.ContextWrapper;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.ServiceConnection;
 import android.media.AudioManager;
 import android.net.Uri;
 import android.os.AsyncResult;
 import android.os.Bundle;
 import android.os.Handler;
-import android.os.IBinder;
-import android.os.IPowerManager;
 import android.os.Message;
 import android.os.PersistableBundle;
 import android.os.PowerManager;
-import android.os.RemoteException;
-import android.os.ServiceManager;
 import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.os.UpdateLock;
-import android.os.UserHandle;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
 import android.telephony.CarrierConfigManager;
 import android.telephony.ServiceState;
-import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.util.Log;
 
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallManager;
-import com.android.internal.telephony.IccCard;
 import com.android.internal.telephony.IccCardConstants;
 import com.android.internal.telephony.MmiCode;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.PhoneFactory;
-import com.android.internal.telephony.SubscriptionController;
 import com.android.internal.telephony.TelephonyCapabilities;
 import com.android.internal.telephony.TelephonyIntents;
 import com.android.phone.common.CallLogAsync;
 import com.android.phone.settings.SettingsConstants;
-import com.android.server.sip.SipService;
 import com.android.services.telephony.activation.SimActivationManager;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * Global state for the telephony subsystem when running in the primary
  * phone process.
@@ -109,7 +91,6 @@
     private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
     private static final int EVENT_DATA_ROAMING_OK = 11;
     private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
-    private static final int EVENT_START_SIP_SERVICE = 13;
 
     // The MMI codes are also used by the InCallScreen.
     public static final int MMI_INITIATE = 51;
@@ -196,15 +177,6 @@
         public void handleMessage(Message msg) {
             PhoneConstants.State phoneState;
             switch (msg.what) {
-                // Starts the SIP service. It's a no-op if SIP API is not supported
-                // on the deivce.
-                // TODO: Having the phone process host the SIP service is only
-                // temporary. Will move it to a persistent communication process
-                // later.
-                case EVENT_START_SIP_SERVICE:
-                    SipService.start(getApplicationContext());
-                    break;
-
                 // TODO: This event should be handled by the lock screen, just
                 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
                 case EVENT_SIM_NETWORK_LOCKED:
@@ -301,8 +273,6 @@
             // status bar icons and control other status bar behavior.
             notificationMgr = NotificationMgr.init(this);
 
-            mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
-
             // Create an instance of CdmaPhoneCallState and initialize it to IDLE
             cdmaPhoneCallState = new CdmaPhoneCallState();
             cdmaPhoneCallState.CdmaPhoneCallStateInit();
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index 27de57c..53f9567 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -27,7 +27,7 @@
 import com.android.phone.R;
 import com.android.phone.SubscriptionInfoHelper;
 import com.android.services.telephony.sip.SipAccountRegistry;
-import com.android.services.telephony.sip.SipSharedPreferences;
+import com.android.services.telephony.sip.SipPreferences;
 import com.android.services.telephony.sip.SipUtil;
 
 import java.util.ArrayList;
@@ -74,7 +74,7 @@
 
     private ListPreference mUseSipCalling;
     private CheckBoxPreference mSipReceiveCallsPreference;
-    private SipSharedPreferences mSipSharedPreferences;
+    private SipPreferences mSipPreferences;
 
     @Override
     public void onCreate(Bundle icicle) {
@@ -152,7 +152,7 @@
         }
 
         if (isPrimaryUser() && SipUtil.isVoipSupported(getActivity())) {
-            mSipSharedPreferences = new SipSharedPreferences(getActivity());
+            mSipPreferences = new SipPreferences(getActivity());
 
             mUseSipCalling = (ListPreference)
                     getPreferenceScreen().findPreference(USE_SIP_PREF_KEY);
@@ -162,13 +162,13 @@
             mUseSipCalling.setOnPreferenceChangeListener(this);
 
             int optionsValueIndex =
-                    mUseSipCalling.findIndexOfValue(mSipSharedPreferences.getSipCallOption());
+                    mUseSipCalling.findIndexOfValue(mSipPreferences.getSipCallOption());
             if (optionsValueIndex == -1) {
                 // If the option is invalid (eg. deprecated value), default to SIP_ADDRESS_ONLY.
-                mSipSharedPreferences.setSipCallOption(
+                mSipPreferences.setSipCallOption(
                         getResources().getString(R.string.sip_address_only));
                 optionsValueIndex =
-                        mUseSipCalling.findIndexOfValue(mSipSharedPreferences.getSipCallOption());
+                        mUseSipCalling.findIndexOfValue(mSipPreferences.getSipCallOption());
             }
             mUseSipCalling.setValueIndex(optionsValueIndex);
             mUseSipCalling.setSummary(mUseSipCalling.getEntry());
@@ -177,7 +177,7 @@
                     getPreferenceScreen().findPreference(SIP_RECEIVE_CALLS_PREF_KEY);
             mSipReceiveCallsPreference.setEnabled(SipUtil.isPhoneIdle(getActivity()));
             mSipReceiveCallsPreference.setChecked(
-                    mSipSharedPreferences.isReceivingCallsEnabled());
+                    mSipPreferences.isReceivingCallsEnabled());
             mSipReceiveCallsPreference.setOnPreferenceChangeListener(this);
         } else {
             getPreferenceScreen().removePreference(
@@ -196,7 +196,7 @@
     public boolean onPreferenceChange(Preference pref, Object objValue) {
         if (pref == mUseSipCalling) {
             String option = objValue.toString();
-            mSipSharedPreferences.setSipCallOption(option);
+            mSipPreferences.setSipCallOption(option);
             mUseSipCalling.setValueIndex(mUseSipCalling.findIndexOfValue(option));
             mUseSipCalling.setSummary(mUseSipCalling.getEntry());
             return true;
@@ -250,7 +250,7 @@
             return;
         }
 
-        mSipSharedPreferences.setReceivingCallsEnabled(isEnabled);
+        mSipPreferences.setReceivingCallsEnabled(isEnabled);
 
         SipUtil.useSipToReceiveIncomingCalls(context, isEnabled);