Merge "Fix crash issue when user uses multi-window mode on VoicemailSettings"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a76b372..0afb739 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -500,16 +500,6 @@
             </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" />
-                <action android:name="com.android.phone.SIP_CALL_OPTION_CHANGED" />
-            </intent-filter>
-        </receiver>
-
         <activity android:name="com.android.services.telephony.sip.SipPhoneAccountSettingsActivity"
                 android:theme="@android:style/Theme.NoDisplay"
                 android:excludeFromRecents="true">
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 9677acd..868e571 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -219,11 +219,6 @@
                 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
         telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
 
-        Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
-        if (telephonyManager.isMultiSimEnabled() || !SipUtil.isVoipSupported(mPhone.getContext())) {
-            getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
-        }
-
         PreferenceScreen prefSet = getPreferenceScreen();
         mVoicemailSettingsScreen =
                 (PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
diff --git a/src/com/android/phone/DumpsysHandler.java b/src/com/android/phone/DumpsysHandler.java
index d2ae38f..44b88d5 100644
--- a/src/com/android/phone/DumpsysHandler.java
+++ b/src/com/android/phone/DumpsysHandler.java
@@ -15,6 +15,7 @@
 
     public static void dump(Context context, FileDescriptor fd, PrintWriter writer,
             String[] args) {
+        PhoneGlobals.getInstance().dump(fd, writer, args);
         // Dump OMTP visual voicemail log.
         VvmDumpHandler.dump(context, fd, writer, args);
     }
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index a617b0c..9dc1f50 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -28,6 +28,7 @@
 import android.media.AudioManager;
 import android.net.ConnectivityManager;
 import android.net.Uri;
+import android.net.sip.SipManager;
 import android.os.AsyncResult;
 import android.os.Bundle;
 import android.os.Handler;
@@ -43,6 +44,8 @@
 import android.telephony.CarrierConfigManager;
 import android.telephony.ServiceState;
 import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.util.LocalLog;
 import android.util.Log;
 import android.widget.Toast;
 
@@ -53,18 +56,26 @@
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.PhoneFactory;
+import com.android.internal.telephony.SettingsObserver;
 import com.android.internal.telephony.TelephonyCapabilities;
 import com.android.internal.telephony.TelephonyIntents;
+import com.android.internal.telephony.dataconnection.DataConnectionReasons;
+import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
+import com.android.internal.util.IndentingPrintWriter;
 import com.android.phone.common.CallLogAsync;
 import com.android.phone.settings.SettingsConstants;
+import com.android.services.telephony.sip.SipBroadcastReceiver;
 import com.android.services.telephony.sip.SipUtil;
 
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
 /**
  * Global state for the telephony subsystem when running in the primary
  * phone process.
  */
 public class PhoneGlobals extends ContextWrapper {
-    public static final String LOG_TAG = "PhoneApp";
+    public static final String LOG_TAG = "PhoneGlobals";
 
     /**
      * Phone app-wide debug level:
@@ -95,6 +106,8 @@
     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;
+    private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 14;
+    private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 15;
 
     // The MMI codes are also used by the InCallScreen.
     public static final int MMI_INITIATE = 51;
@@ -145,7 +158,7 @@
     private Activity mPUKEntryActivity;
     private ProgressDialog mPUKEntryProgressDialog;
 
-    private boolean mDataDisconnectedDueToRoaming = false;
+    private boolean mNoDataDueToRoaming = false;
 
     private WakeState mWakeState = WakeState.SLEEP;
 
@@ -156,13 +169,21 @@
 
     private UpdateLock mUpdateLock;
 
+    private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+    private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
+
     // 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 SettingsObserver mSettingsObserver;
 
     Handler mHandler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
             PhoneConstants.State phoneState;
+            if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
             switch (msg.what) {
                 // TODO: This event should be handled by the lock screen, just
                 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
@@ -229,6 +250,10 @@
                         SipUtil.startSipService();
                     }
                     break;
+                case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
+                case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
+                    updateDataRoamingStatus();
+                    break;
             }
         }
     };
@@ -236,6 +261,7 @@
     public PhoneGlobals(Context context) {
         super(context);
         sMe = this;
+        mSettingsObserver = new SettingsObserver(context, mHandler);
     }
 
     public void onCreate() {
@@ -311,7 +337,7 @@
 
             configLoader = CarrierConfigLoader.init(this);
 
-            // Create the CallNotifer singleton, which handles
+            // Create the CallNotifier singleton, which handles
             // asynchronous events from the telephony layer (like
             // launching the incoming-call UI when an incoming call comes
             // in.)
@@ -328,13 +354,21 @@
             // Register for misc other intent broadcasts.
             IntentFilter intentFilter =
                     new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
-            intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
             intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
             intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
             intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
             intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
+            intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
+            intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
             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);
+
             //set the default values for the preferences in the phone.
             PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
 
@@ -408,6 +442,27 @@
         return configLoader.getConfigForSubId(subId);
     }
 
+    private void registerSettingsObserver() {
+        mSettingsObserver.unobserve();
+        String dataRoamingSetting = Settings.Global.DATA_ROAMING;
+        String mobileDataSetting = Settings.Global.MOBILE_DATA;
+        if (TelephonyManager.getDefault().getSimCount() > 1) {
+            int subId = mDefaultDataSubId;
+            if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+                dataRoamingSetting += subId;
+                mobileDataSetting += subId;
+            }
+        }
+
+        // Listen for user data roaming setting changed event
+        mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
+                EVENT_DATA_ROAMING_SETTINGS_CHANGED);
+
+        // Listen for mobile data setting changed event
+        mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
+                EVENT_MOBILE_DATA_SETTINGS_CHANGED);
+    }
+
     /**
      * Sets the activity responsible for un-PUK-blocking the device
      * so that we may close it when we receive a positive result.
@@ -645,48 +700,6 @@
                     airplaneMode = AIRPLANE_ON;
                 }
                 handleAirplaneModeChange(context, airplaneMode);
-            } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
-                int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
-                        SubscriptionManager.INVALID_SUBSCRIPTION_ID);
-                int phoneId = SubscriptionManager.getPhoneId(subId);
-                final String apnType = intent.getStringExtra(PhoneConstants.DATA_APN_TYPE_KEY);
-                final String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
-                final String reason = intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY);
-                if (VDBG) {
-                    Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
-                    Log.d(LOG_TAG, "- state: " + state);
-                    Log.d(LOG_TAG, "- reason: " + reason);
-                    Log.d(LOG_TAG, "- subId: " + subId);
-                }
-                Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
-                        PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
-
-                // If the apn type of data connection state changed event is NOT default,
-                // ignore the broadcast intent and avoid action.
-                if (!PhoneConstants.APN_TYPE_DEFAULT.equals(apnType)) {
-                    if (VDBG) Log.d(LOG_TAG, "Ignore broadcast intent as not default apn type");
-                    return;
-                }
-
-                // The "data disconnected due to roaming" notification is shown
-                // if (a) you have the "data roaming" feature turned off, and
-                // (b) you just lost data connectivity because you're roaming.
-                // (c) if we haven't shown the notification for this disconnection earlier.
-                if (!mDataDisconnectedDueToRoaming
-                        && PhoneConstants.DataState.DISCONNECTED.name().equals(state)
-                        && Phone.REASON_ROAMING_ON.equals(reason)
-                        && !phone.getDataRoamingEnabled()) {
-                    // Notify the user that data call is disconnected due to roaming. Note that
-                    // calling this multiple times will not cause multiple notifications.
-                    mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_DISCONNECTED);
-                    mDataDisconnectedDueToRoaming = true;
-                } else if (mDataDisconnectedDueToRoaming
-                        && PhoneConstants.DataState.CONNECTED.name().equals(state)) {
-                    // Cancel the notification when data is available. Note it is okay to call this
-                    // even if the notification doesn't exist.
-                    mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
-                    mDataDisconnectedDueToRoaming = false;
-                }
             } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
                     (mPUKEntryActivity != null)) {
                 // if an attempt to un-PUK-lock the device was made, while we're
@@ -725,6 +738,19 @@
                 } else {
                     Log.w(LOG_TAG, "phoneInEcm is null.");
                 }
+            } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
+                // Roaming status could be overridden by carrier config, so we need to update it.
+                if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
+                updateDataRoamingStatus();
+            } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
+                // We also need to pay attention when default data subscription changes.
+                if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
+                mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
+                registerSettingsObserver();
+                Phone phone = getPhone(mDefaultDataSubId);
+                if (phone != null) {
+                    updateDataRoamingStatus();
+                }
             }
         }
     }
@@ -737,17 +763,64 @@
          * future.
          */
 
+        if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
         // If service just returned, start sending out the queued messages
         Bundle extras = intent.getExtras();
         if (extras != null) {
             ServiceState ss = ServiceState.newFromBundle(extras);
             if (ss != null) {
                 int state = ss.getState();
+                int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
+                        SubscriptionManager.INVALID_SUBSCRIPTION_ID);
                 notificationMgr.updateNetworkSelection(state);
+
+                if (VDBG) {
+                    Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
+                            + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
+                }
+                if (subId == mDefaultDataSubId) {
+                    updateDataRoamingStatus();
+                }
             }
         }
     }
 
+    /**
+     * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
+     * to notify the user so they can enable it through settings. Vise versa if the condition
+     * changes, we need to dismiss the notification.
+     */
+    private void updateDataRoamingStatus() {
+        if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
+        Phone phone = getPhone(mDefaultDataSubId);
+        if (phone == null) {
+            Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
+            return;
+        }
+
+        DataConnectionReasons reasons = new DataConnectionReasons();
+        boolean dataAllowed = phone.isDataAllowed(reasons);
+        mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
+        if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
+        if (!mNoDataDueToRoaming
+                && !dataAllowed
+                && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
+            // If the only reason of no data is data roaming disabled, then we notify the user
+            // so the user can turn on data roaming.
+            mNoDataDueToRoaming = true;
+            Log.d(LOG_TAG, "Show roaming disconnected notification");
+            mDataRoamingNotifLog.log("Show");
+            mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_DISCONNECTED);
+        } else if (mNoDataDueToRoaming && (dataAllowed
+                || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) {
+            // Otherwise dismiss the notification we showed earlier.
+            mNoDataDueToRoaming = false;
+            Log.d(LOG_TAG, "Dismiss roaming disconnected notification");
+            mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
+            mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
+        }
+    }
+
     public Phone getPhoneInEcm() {
         return phoneInEcm;
     }
@@ -795,4 +868,25 @@
     public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
         notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled);
     }
+
+    /**
+     * Dump the state of the object, add calls to other objects as desired.
+     *
+     * @param fd File descriptor
+     * @param printWriter Print writer
+     * @param args Arguments
+     */
+    public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
+        IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, "  ");
+        pw.println("------- PhoneGlobals -------");
+        pw.increaseIndent();
+        pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming);
+        pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
+        pw.println("mDataRoamingNotifLog:");
+        pw.increaseIndent();
+        mDataRoamingNotifLog.dump(fd, pw, args);
+        pw.decreaseIndent();
+        pw.decreaseIndent();
+        pw.println("------- End PhoneGlobals -------");
+    }
 }
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index d92d349..0bc8c01 100644
--- a/src/com/android/phone/PhoneUtils.java
+++ b/src/com/android/phone/PhoneUtils.java
@@ -952,7 +952,7 @@
                             .create();
 
                     sUssdDialog.getWindow().setType(
-                            WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
+                            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                     sUssdDialog.getWindow().addFlags(
                             WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                 }
diff --git a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/AppActiveStreams.java b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/AppActiveStreams.java
index dfc7ac9..4d2c62c 100644
--- a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/AppActiveStreams.java
+++ b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/AppActiveStreams.java
@@ -17,8 +17,8 @@
 package com.android.phone.testapps.embmsmw;
 
 import android.os.RemoteException;
-import android.telephony.mbms.IStreamingServiceCallback;
 import android.telephony.mbms.StreamingService;
+import android.telephony.mbms.StreamingServiceCallback;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -28,18 +28,18 @@
 public class AppActiveStreams {
     // Wrapper for a pair (StreamingServiceCallback, streaming state)
     private static class StreamCallbackWithState {
-        private final IStreamingServiceCallback mCallback;
+        private final StreamingServiceCallback mCallback;
         private int mState;
         private int mMethod;
         private boolean mMethodSet = false;
 
-        StreamCallbackWithState(IStreamingServiceCallback callback, int state, int method) {
+        StreamCallbackWithState(StreamingServiceCallback callback, int state, int method) {
             mCallback = callback;
             mState = state;
             mMethod = method;
         }
 
-        public IStreamingServiceCallback getCallback() {
+        public StreamingServiceCallback getCallback() {
             return mCallback;
         }
 
@@ -80,7 +80,7 @@
                 StreamingService.STATE_STOPPED : callbackWithState.getState();
     }
 
-    public void startStreaming(String serviceId, IStreamingServiceCallback callback, int reason) {
+    public void startStreaming(String serviceId, StreamingServiceCallback callback, int reason) {
         if (mStreamStates.get(serviceId) != null) {
             // error - already started
             return;
diff --git a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
index 150460a..afac316 100644
--- a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
+++ b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
@@ -34,7 +34,7 @@
 import android.telephony.mbms.DownloadRequest;
 import android.telephony.mbms.FileInfo;
 import android.telephony.mbms.FileServiceInfo;
-import android.telephony.mbms.IDownloadCallback;
+import android.telephony.mbms.IDownloadProgressListener;
 import android.telephony.mbms.IMbmsDownloadManagerCallback;
 import android.telephony.mbms.MbmsException;
 import android.telephony.mbms.UriPathPair;
@@ -68,29 +68,15 @@
 
     private final IMbmsDownloadService mBinder = new MbmsDownloadServiceBase() {
         @Override
-        public void initialize(int subId, IMbmsDownloadManagerCallback listener) {
+        public int initialize(int subId, IMbmsDownloadManagerCallback listener) {
             int packageUid = Binder.getCallingUid();
             String[] packageNames = getPackageManager().getPackagesForUid(packageUid);
             if (packageNames == null) {
-                try {
-                    listener.error(
-                            MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED,
-                            "No matching packages found for your UID");
-                } catch (RemoteException e) {
-                    // ignore
-                }
-                return;
+                return MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED;
             }
             boolean isUidAllowed = Arrays.stream(packageNames).anyMatch(ALLOWED_PACKAGES::contains);
             if (!isUidAllowed) {
-                try {
-                    listener.error(
-                            MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED,
-                            "No packages for your UID are allowed to use this service.");
-                } catch (RemoteException e) {
-                    // ignore
-                }
-                return;
+                return MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED;
             }
 
             // Do initialization with a bit of a delay to simulate work being done.
@@ -116,6 +102,8 @@
                     // TODO: call dispose
                 }
             }, INITIALIZATION_DELAY);
+
+            return MbmsException.SUCCESS;
         }
 
         @Override
@@ -155,7 +143,7 @@
         }
 
         @Override
-        public int download(DownloadRequest downloadRequest, IDownloadCallback listener) {
+        public int download(DownloadRequest downloadRequest, IDownloadProgressListener listener) {
             FrontendAppIdentifier appKey = new FrontendAppIdentifier(
                     Binder.getCallingUid(), downloadRequest.getSubscriptionId());
             checkInitialized(appKey);
diff --git a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsTestStreamingService.java b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsTestStreamingService.java
index 0373597..73a13e9 100644
--- a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsTestStreamingService.java
+++ b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsTestStreamingService.java
@@ -25,9 +25,10 @@
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.telephony.mbms.IMbmsStreamingManagerCallback;
-import android.telephony.mbms.IStreamingServiceCallback;
 import android.telephony.mbms.MbmsException;
+import android.telephony.mbms.MbmsStreamingManagerCallback;
 import android.telephony.mbms.StreamingService;
+import android.telephony.mbms.StreamingServiceCallback;
 import android.telephony.mbms.StreamingServiceInfo;
 import android.telephony.mbms.vendor.IMbmsStreamingService;
 import android.telephony.mbms.vendor.MbmsStreamingServiceBase;
@@ -81,29 +82,15 @@
 
     private final IMbmsStreamingService.Stub mBinder = new MbmsStreamingServiceBase() {
         @Override
-        public void initialize(IMbmsStreamingManagerCallback listener, int subId) {
+        public int initialize(MbmsStreamingManagerCallback listener, int subId) {
             int packageUid = Binder.getCallingUid();
             String[] packageNames = getPackageManager().getPackagesForUid(packageUid);
             if (packageNames == null) {
-                try {
-                    listener.error(
-                            MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED,
-                            "No matching packages found for your UID");
-                } catch (RemoteException e) {
-                    // ignore
-                }
-                return;
+                return MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED;
             }
             boolean isUidAllowed = Arrays.stream(packageNames).anyMatch(ALLOWED_PACKAGES::contains);
             if (!isUidAllowed) {
-                try {
-                    listener.error(
-                            MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED,
-                            "No packages for your UID are allowed to use this service.");
-                } catch (RemoteException e) {
-                    // ignore
-                }
-                return;
+                return MbmsException.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED;
             }
 
             mHandler.postDelayed(() -> {
@@ -126,6 +113,7 @@
                     mAppCallbacks.remove(appKey);
                 }
             }, INITIALIZATION_DELAY);
+            return MbmsException.SUCCESS;
         }
 
         @Override
@@ -150,7 +138,7 @@
 
         @Override
         public int startStreaming(int subscriptionId, String serviceId,
-                IStreamingServiceCallback callback) {
+                StreamingServiceCallback callback) {
             FrontendAppIdentifier appKey =
                     new FrontendAppIdentifier(Binder.getCallingUid(), subscriptionId);
             checkInitialized(appKey);
diff --git a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/StreamStateTracker.java b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/StreamStateTracker.java
index de81359..6fde02b 100644
--- a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/StreamStateTracker.java
+++ b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/StreamStateTracker.java
@@ -16,8 +16,8 @@
 
 package com.android.phone.testapps.embmsmw;
 
-import android.telephony.mbms.IStreamingServiceCallback;
 import android.telephony.mbms.StreamingService;
+import android.telephony.mbms.StreamingServiceCallback;
 import android.util.Log;
 
 import java.util.HashMap;
@@ -39,7 +39,7 @@
     }
 
     public static void startStreaming(FrontendAppIdentifier appIdentifier, String serviceId,
-            IStreamingServiceCallback callback, int reason) {
+            StreamingServiceCallback callback, int reason) {
         AppActiveStreams appStreams = sPerAppStreamStates.get(appIdentifier);
         if (appStreams == null) {
             appStreams = new AppActiveStreams(appIdentifier);