Restart SipService if it crashes
Currently, if the phone process crashes, the SipService will not restart until
reboot. We will now check to see if the user is unlocked in PhoneGlobals
before attempting to start the SipService (this should only happen if
the process crashes and restarts).
Bug: 28100417
Change-Id: Id512ece318963f7ceb8af5ce9d668a80b21bc98b
diff --git a/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java b/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
index b495917..66ae2da 100644
--- a/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
+++ b/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
@@ -53,11 +53,7 @@
SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
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);
+ SipUtil.startSipService();
} else if (action.equals(SipManager.ACTION_SIP_INCOMING_CALL)) {
takeCall(context, intent);
} else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP) ||
diff --git a/sip/src/com/android/services/telephony/sip/SipSettings.java b/sip/src/com/android/services/telephony/sip/SipSettings.java
index 2044d49..0d87798 100644
--- a/sip/src/com/android/services/telephony/sip/SipSettings.java
+++ b/sip/src/com/android/services/telephony/sip/SipSettings.java
@@ -238,7 +238,12 @@
}
private void processActiveProfilesFromSipService() {
- SipProfile[] activeList = mSipManager.getListOfProfiles();
+ SipProfile[] activeList = {};
+ try {
+ activeList = mSipManager.getListOfProfiles();
+ } catch (SipException e) {
+ log("SipManager could not retrieve SIP profiles: " + e);
+ }
for (SipProfile activeProfile : activeList) {
SipProfile profile = getProfileFromList(activeProfile);
if (profile == null) {
diff --git a/sip/src/com/android/services/telephony/sip/SipUtil.java b/sip/src/com/android/services/telephony/sip/SipUtil.java
index 5076f6f..3678c46 100644
--- a/sip/src/com/android/services/telephony/sip/SipUtil.java
+++ b/sip/src/com/android/services/telephony/sip/SipUtil.java
@@ -31,7 +31,9 @@
import android.text.TextUtils;
import android.util.Log;
+import com.android.phone.PhoneGlobals;
import com.android.phone.R;
+import com.android.server.sip.SipService;
import java.io.IOException;
import java.util.ArrayList;
@@ -142,7 +144,7 @@
* 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) {
+ private static void possiblyMigrateSipDb(Context context) {
SipProfileDb dbDeStorage = new SipProfileDb(context);
dbDeStorage.accessDEStorageForMigration();
List<SipProfile> profilesDeStorage = dbDeStorage.retrieveSipProfileList();
@@ -170,6 +172,17 @@
}
/**
+ * Migrates the DB files over from CE->DE storage and starts the SipService.
+ */
+ public static void startSipService() {
+ Context phoneGlobalsContext = PhoneGlobals.getInstance();
+ // Migrate SIP database from DE->CE storage if the device has just upgraded.
+ possiblyMigrateSipDb(phoneGlobalsContext);
+ // Wait until boot complete to start SIP so that it has access to CE storage.
+ SipService.start(phoneGlobalsContext);
+ }
+
+ /**
* 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.
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index e9f4c25..ec86384 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -34,9 +34,12 @@
import android.os.Message;
import android.os.PersistableBundle;
import android.os.PowerManager;
+import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
+import android.os.SystemService;
import android.os.UpdateLock;
+import android.os.UserManager;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
@@ -56,7 +59,9 @@
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 com.android.services.telephony.sip.SipUtil;
/**
* Global state for the telephony subsystem when running in the primary
@@ -93,6 +98,7 @@
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_RESTART_SIP = 13;
// The MMI codes are also used by the InCallScreen.
public static final int MMI_INITIATE = 51;
@@ -237,6 +243,16 @@
case EVENT_UNSOL_CDMA_INFO_RECORD:
//TODO: handle message here;
break;
+ case EVENT_RESTART_SIP:
+ // This should only run if the Phone process crashed and was restarted. We do
+ // not want this running if the device is still in the FBE encrypted state.
+ // This is the same procedure that is triggered in the SipBroadcastReceiver
+ // upon BOOT_COMPLETED.
+ UserManager userManager = UserManager.get(sMe);
+ if (userManager != null && userManager.isUserUnlocked()) {
+ SipUtil.startSipService();
+ }
+ break;
}
}
};
@@ -278,6 +294,9 @@
// status bar icons and control other status bar behavior.
notificationMgr = NotificationMgr.init(this);
+ // If PhoneGlobals has crashed and is being restarted, then restart.
+ mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
+
// Create an instance of CdmaPhoneCallState and initialize it to IDLE
cdmaPhoneCallState = new CdmaPhoneCallState();
cdmaPhoneCallState.CdmaPhoneCallStateInit();