summaryrefslogtreecommitdiff
path: root/com/android/ims/ImsServiceProxy.java
diff options
context:
space:
mode:
Diffstat (limited to 'com/android/ims/ImsServiceProxy.java')
-rw-r--r--com/android/ims/ImsServiceProxy.java122
1 files changed, 108 insertions, 14 deletions
diff --git a/com/android/ims/ImsServiceProxy.java b/com/android/ims/ImsServiceProxy.java
index f3489194..7fcaac2b 100644
--- a/com/android/ims/ImsServiceProxy.java
+++ b/com/android/ims/ImsServiceProxy.java
@@ -16,11 +16,17 @@
package com.android.ims;
+import android.annotation.Nullable;
import android.app.PendingIntent;
+import android.content.Context;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
+import android.telephony.Rlog;
+import android.telephony.TelephonyManager;
import android.telephony.ims.feature.ImsFeature;
+import android.telephony.SmsMessage;
+import android.telephony.ims.internal.stub.SmsImplBase;
import android.util.Log;
import com.android.ims.internal.IImsCallSession;
@@ -29,8 +35,10 @@ import com.android.ims.internal.IImsConfig;
import com.android.ims.internal.IImsEcbm;
import com.android.ims.internal.IImsMMTelFeature;
import com.android.ims.internal.IImsMultiEndpoint;
+import com.android.ims.internal.IImsRegistration;
import com.android.ims.internal.IImsRegistrationListener;
import com.android.ims.internal.IImsServiceFeatureCallback;
+import com.android.ims.internal.IImsSmsListener;
import com.android.ims.internal.IImsUt;
/**
@@ -41,20 +49,58 @@ import com.android.ims.internal.IImsUt;
public class ImsServiceProxy {
- protected String LOG_TAG = "ImsServiceProxy";
+ protected static final String TAG = "ImsServiceProxy";
protected final int mSlotId;
protected IBinder mBinder;
private final int mSupportedFeature;
+ private Context mContext;
// Start by assuming the proxy is available for usage.
private boolean mIsAvailable = true;
// ImsFeature Status from the ImsService. Cached.
private Integer mFeatureStatusCached = null;
- private ImsServiceProxy.INotifyStatusChanged mStatusCallback;
+ private IFeatureUpdate mStatusCallback;
private final Object mLock = new Object();
- public interface INotifyStatusChanged {
- void notifyStatusChanged();
+ public static ImsServiceProxy create(Context context , int slotId) {
+ ImsServiceProxy serviceProxy = new ImsServiceProxy(context, slotId, ImsFeature.MMTEL);
+
+ TelephonyManager tm = getTelephonyManager(context);
+ if (tm == null) {
+ Rlog.w(TAG, "getServiceProxy: TelephonyManager is null!");
+ // Binder can be unset in this case because it will be torn down/recreated as part of
+ // a retry mechanism until the serviceProxy binder is set successfully.
+ return serviceProxy;
+ }
+
+ IImsMMTelFeature binder = tm.getImsMMTelFeatureAndListen(slotId,
+ serviceProxy.getListener());
+ if (binder != null) {
+ serviceProxy.setBinder(binder.asBinder());
+ // Trigger the cache to be updated for feature status.
+ serviceProxy.getFeatureStatus();
+ } else {
+ Rlog.w(TAG, "getServiceProxy: binder is null! Phone Id: " + slotId);
+ }
+ return serviceProxy;
+ }
+
+ public static TelephonyManager getTelephonyManager(Context context) {
+ return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ }
+
+ public interface IFeatureUpdate {
+ /**
+ * Called when the ImsFeature has changed its state. Use
+ * {@link ImsFeature#getFeatureState()} to get the new state.
+ */
+ void notifyStateChanged();
+
+ /**
+ * Called when the ImsFeature has become unavailable due to the binder switching or app
+ * crashing. A new ImsServiceProxy should be requested for that feature.
+ */
+ void notifyUnavailable();
}
private final IImsServiceFeatureCallback mListenerBinder =
@@ -65,7 +111,7 @@ public class ImsServiceProxy {
// The feature has been re-enabled. This may happen when the service crashes.
synchronized (mLock) {
if (!mIsAvailable && mSlotId == slotId && feature == mSupportedFeature) {
- Log.i(LOG_TAG, "Feature enabled on slotId: " + slotId + " for feature: " +
+ Log.i(TAG, "Feature enabled on slotId: " + slotId + " for feature: " +
feature);
mIsAvailable = true;
}
@@ -76,9 +122,12 @@ public class ImsServiceProxy {
public void imsFeatureRemoved(int slotId, int feature) throws RemoteException {
synchronized (mLock) {
if (mIsAvailable && mSlotId == slotId && feature == mSupportedFeature) {
- Log.i(LOG_TAG, "Feature disabled on slotId: " + slotId + " for feature: " +
+ Log.i(TAG, "Feature disabled on slotId: " + slotId + " for feature: " +
feature);
mIsAvailable = false;
+ if (mStatusCallback != null) {
+ mStatusCallback.notifyUnavailable();
+ }
}
}
}
@@ -86,26 +135,32 @@ public class ImsServiceProxy {
@Override
public void imsStatusChanged(int slotId, int feature, int status) throws RemoteException {
synchronized (mLock) {
- Log.i(LOG_TAG, "imsStatusChanged: slot: " + slotId + " feature: " + feature +
+ Log.i(TAG, "imsStatusChanged: slot: " + slotId + " feature: " + feature +
" status: " + status);
if (mSlotId == slotId && feature == mSupportedFeature) {
mFeatureStatusCached = status;
if (mStatusCallback != null) {
- mStatusCallback.notifyStatusChanged();
+ mStatusCallback.notifyStateChanged();
}
}
}
}
};
- public ImsServiceProxy(int slotId, IBinder binder, int featureType) {
+ public ImsServiceProxy(Context context, int slotId, IBinder binder, int featureType) {
mSlotId = slotId;
mBinder = binder;
mSupportedFeature = featureType;
+ mContext = context;
}
- public ImsServiceProxy(int slotId, int featureType) {
- this(slotId, null, featureType);
+ public ImsServiceProxy(Context context, int slotId, int featureType) {
+ this(context, slotId, null, featureType);
+ }
+
+ public @Nullable IImsRegistration getRegistration() {
+ TelephonyManager tm = getTelephonyManager(mContext);
+ return tm != null ? tm.getImsRegistration(mSlotId, ImsFeature.MMTEL) : null;
}
public IImsServiceFeatureCallback getListener() {
@@ -246,7 +301,7 @@ public class ImsServiceProxy {
public int getFeatureStatus() {
synchronized (mLock) {
if (isBinderAlive() && mFeatureStatusCached != null) {
- Log.i(LOG_TAG, "getFeatureStatus - returning cached: " + mFeatureStatusCached);
+ Log.i(TAG, "getFeatureStatus - returning cached: " + mFeatureStatusCached);
return mFeatureStatusCached;
}
}
@@ -259,7 +314,7 @@ public class ImsServiceProxy {
// Cache only non-null value for feature status.
mFeatureStatusCached = status;
}
- Log.i(LOG_TAG, "getFeatureStatus - returning " + status);
+ Log.i(TAG, "getFeatureStatus - returning " + status);
return status;
}
@@ -280,10 +335,49 @@ public class ImsServiceProxy {
/**
* @param c Callback that will fire when the feature status has changed.
*/
- public void setStatusCallback(INotifyStatusChanged c) {
+ public void setStatusCallback(IFeatureUpdate c) {
mStatusCallback = c;
}
+ public void sendSms(int token, int messageRef, String format, String smsc, boolean isRetry,
+ byte[] pdu) throws RemoteException {
+ synchronized (mLock) {
+ checkServiceIsReady();
+ getServiceInterface(mBinder).sendSms(token, messageRef, format, smsc, isRetry,
+ pdu);
+ }
+ }
+
+ public void acknowledgeSms(int token, int messageRef,
+ @SmsImplBase.SendStatusResult int result) throws RemoteException {
+ synchronized (mLock) {
+ checkServiceIsReady();
+ getServiceInterface(mBinder).acknowledgeSms(token, messageRef, result);
+ }
+ }
+
+ public void acknowledgeSmsReport(int token, int messageRef,
+ @SmsImplBase.StatusReportResult int result) throws RemoteException {
+ synchronized (mLock) {
+ checkServiceIsReady();
+ getServiceInterface(mBinder).acknowledgeSmsReport(token, messageRef, result);
+ }
+ }
+
+ public String getSmsFormat() throws RemoteException {
+ synchronized (mLock) {
+ checkServiceIsReady();
+ return getServiceInterface(mBinder).getSmsFormat();
+ }
+ }
+
+ public void setSmsListener(IImsSmsListener listener) throws RemoteException {
+ synchronized (mLock) {
+ checkServiceIsReady();
+ getServiceInterface(mBinder).setSmsListener(listener);
+ }
+ }
+
/**
* @return Returns true if the ImsService is ready to take commands, false otherwise. If this
* method returns false, it doesn't mean that the Binder connection is not available (use