Merge "Move ACTION_SIP_INCOMING_CALL back to Manifest" into oc-mr1-dev am: 5aee651772
am: 1c1021f954

Change-Id: Iedf3f698cacbfc3eefb6615949cf67cf487d56a9
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 554c4d9..69620cd 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -533,6 +533,12 @@
             </intent-filter>
         </service>
 
+        <receiver android:name="com.android.services.telephony.sip.SipIncomingCallReceiver">
+            <intent-filter>
+                <action android:name="com.android.phone.SIP_INCOMING_CALL" />
+            </intent-filter>
+        </receiver>
+
         <activity android:name="com.android.services.telephony.sip.SipPhoneAccountSettingsActivity"
                 android:theme="@android:style/Theme.NoDisplay"
                 android:excludeFromRecents="true">
diff --git a/sip/proguard.flags b/sip/proguard.flags
index 23ae8c1..1c380ed 100644
--- a/sip/proguard.flags
+++ b/sip/proguard.flags
@@ -1,3 +1,3 @@
 -verbose
 -keep class com.android.services.telephony.sip.SipConnectionService
--keep class com.android.services.telephony.sip.SipBroadcastReceiver
+-keep class com.android.services.telephony.sip.SipIncomingCallReceiver
diff --git a/sip/src/com/android/services/telephony/sip/SipAccountRegistry.java b/sip/src/com/android/services/telephony/sip/SipAccountRegistry.java
index 2987ef4..ec77ff1 100644
--- a/sip/src/com/android/services/telephony/sip/SipAccountRegistry.java
+++ b/sip/src/com/android/services/telephony/sip/SipAccountRegistry.java
@@ -111,7 +111,10 @@
         return INSTANCE;
     }
 
-    void setup(Context context) {
+    /**
+     * Sets up the Account registry and performs any upgrade operations before it is used.
+     */
+    public void setup(Context context) {
         verifyAndPurgeInvalidPhoneAccounts(context);
         startSipProfilesAsync(context, (String) null, false);
     }
@@ -157,7 +160,7 @@
      *
      * @param sipProfileName Name of the SIP profile.
      */
-    void removeSipProfile(String sipProfileName) {
+    public void removeSipProfile(String sipProfileName) {
         AccountEntry accountEntry = getAccountEntry(sipProfileName);
 
         if (accountEntry != null) {
diff --git a/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java b/sip/src/com/android/services/telephony/sip/SipIncomingCallReceiver.java
similarity index 69%
rename from sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
rename to sip/src/com/android/services/telephony/sip/SipIncomingCallReceiver.java
index 66ae2da..c754ae4 100644
--- a/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
+++ b/sip/src/com/android/services/telephony/sip/SipIncomingCallReceiver.java
@@ -27,14 +27,11 @@
 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.
+ * Broadcast receiver that handles explicit incoming call intents
  */
-public class SipBroadcastReceiver extends BroadcastReceiver {
-    private static final String PREFIX = "[SipBroadcastReceiver] ";
+public class SipIncomingCallReceiver extends BroadcastReceiver {
+    private static final String PREFIX = "[SipIncomingCallReceiver] ";
     private static final boolean VERBOSE = false; /* STOP SHIP if true */
 
     @Override
@@ -42,7 +39,7 @@
         String action = intent.getAction();
 
         if (!isRunningInSystemUser()) {
-            if (VERBOSE) log("SipBroadcastReceiver only run in system user, ignore " + action);
+            if (VERBOSE) log("SipIncomingCallReceiver only run in system user, ignore " + action);
             return;
         }
 
@@ -51,18 +48,8 @@
             return;
         }
 
-        SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
-        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
-            SipUtil.startSipService();
-        } else if (action.equals(SipManager.ACTION_SIP_INCOMING_CALL)) {
+        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)) {
-            sipAccountRegistry.setup(context);
-        } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
-            if (VERBOSE) log("SIP_REMOVE_PHONE " +
-                            intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
-            sipAccountRegistry.removeSipProfile(intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
         } else {
             if (VERBOSE) log("onReceive, action not processed: " + action);
         }
@@ -82,7 +69,7 @@
             extras.putParcelable(SipUtil.EXTRA_INCOMING_CALL_INTENT, intent);
             TelecomManager tm = TelecomManager.from(context);
             PhoneAccount phoneAccount = tm.getPhoneAccount(accountHandle);
-            if(phoneAccount != null && phoneAccount.isEnabled()) {
+            if (phoneAccount != null && phoneAccount.isEnabled()) {
                 tm.addNewIncomingCall(accountHandle, extras);
             } else {
                 log("takeCall, PhoneAccount is disabled. Not accepting incoming call...");
diff --git a/sip/src/com/android/services/telephony/sip/SipUtil.java b/sip/src/com/android/services/telephony/sip/SipUtil.java
index a804e3d..d674225 100644
--- a/sip/src/com/android/services/telephony/sip/SipUtil.java
+++ b/sip/src/com/android/services/telephony/sip/SipUtil.java
@@ -60,7 +60,7 @@
 
     static PendingIntent createIncomingCallPendingIntent(
             Context context, String sipProfileName) {
-        Intent intent = new Intent(context, SipBroadcastReceiver.class);
+        Intent intent = new Intent(context, SipIncomingCallReceiver.class);
         intent.setAction(SipManager.ACTION_SIP_INCOMING_CALL);
         intent.putExtra(EXTRA_PHONE_ACCOUNT, SipUtil.createAccountHandle(context, sipProfileName));
         return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 20eedeb..98b94cc 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -65,7 +65,7 @@
 import com.android.phone.common.CallLogAsync;
 import com.android.phone.settings.SettingsConstants;
 import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
-import com.android.services.telephony.sip.SipBroadcastReceiver;
+import com.android.services.telephony.sip.SipAccountRegistry;
 import com.android.services.telephony.sip.SipUtil;
 
 import java.io.FileDescriptor;
@@ -176,7 +176,7 @@
     // Broadcast receiver for various intent broadcasts (see onCreate())
     private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
     // Broadcast receiver for SIP based intents (see onCreate())
-    private final SipBroadcastReceiver mSipBroadcastReceiver = new SipBroadcastReceiver();
+    private final SipReceiver mSipReceiver = new SipReceiver();
 
     private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
             new CarrierVvmPackageInstalledReceiver();
@@ -247,7 +247,7 @@
                 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
+                    // This is the same procedure that is triggered in the SipIncomingCallReceiver
                     // upon BOOT_COMPLETED.
                     UserManager userManager = UserManager.get(sMe);
                     if (userManager != null && userManager.isUserUnlocked()) {
@@ -367,11 +367,10 @@
             registerReceiver(mReceiver, intentFilter);
 
             IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
-            sipIntentFilter.addAction(SipManager.ACTION_SIP_INCOMING_CALL);
             sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
             sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
             sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
-            registerReceiver(mSipBroadcastReceiver, sipIntentFilter);
+            registerReceiver(mSipReceiver, sipIntentFilter);
 
             mCarrierVvmPackageInstalledReceiver.register(this);
 
@@ -763,6 +762,31 @@
         }
     }
 
+    private class SipReceiver extends BroadcastReceiver {
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+
+            SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
+            if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
+                SipUtil.startSipService();
+            } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
+                    || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
+                sipAccountRegistry.setup(context);
+            } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
+                if (DBG) {
+                    Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
+                            + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
+                }
+                sipAccountRegistry.removeSipProfile(intent.getStringExtra(
+                        SipManager.EXTRA_LOCAL_URI));
+            } else {
+                if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
+            }
+        }
+    }
+
     private void handleServiceStateChanged(Intent intent) {
         /**
          * This used to handle updating EriTextWidgetProvider this routine