[RCS] Imeplement IImsRcsController apis related to ImsRcsManager
Bug: 139260826
Test: atest RcsFeatureManagerTest
Change-Id: I8a7eb8984720958eb3a8dd4b29db8e52c797117f
diff --git a/src/com/android/phone/ImsRcsController.java b/src/com/android/phone/ImsRcsController.java
index d1ff56f..06d2367 100644
--- a/src/com/android/phone/ImsRcsController.java
+++ b/src/com/android/phone/ImsRcsController.java
@@ -18,13 +18,22 @@
import android.content.Context;
import android.net.Uri;
+import android.os.Binder;
+import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.ServiceSpecificException;
+import android.telephony.ims.ImsException;
import android.telephony.ims.aidl.IImsCapabilityCallback;
import android.telephony.ims.aidl.IImsRcsController;
import android.telephony.ims.aidl.IRcsUceControllerCallback;
import android.telephony.ims.feature.RcsFeature;
+import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.util.Log;
+import com.android.ims.RcsFeatureManager;
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.imsphone.ImsPhone;
+
import java.util.List;
/**
@@ -60,28 +69,94 @@
ServiceManager.addService(Context.TELEPHONY_IMS_SERVICE, this);
}
+ /**
+ * Register a capability callback which will provide RCS availability updates for the
+ * subscription specified.
+ *
+ * @param subId the subscription ID
+ * @param callback The ImsCapabilityCallback to be registered.
+ */
@Override
- public void registerRcsAvailabilityCallback(IImsCapabilityCallback c) {
+ public void registerRcsAvailabilityCallback(int subId, IImsCapabilityCallback callback)
+ throws RemoteException {
enforceReadPrivilegedPermission("registerRcsAvailabilityCallback");
+ final long token = Binder.clearCallingIdentity();
+ try {
+ getRcsFeatureManager(subId).registerRcsAvailabilityCallback(callback);
+ } catch (com.android.ims.ImsException e) {
+ Log.e(TAG, "registerRcsAvailabilityCallback: sudId=" + subId + ", " + e.getMessage());
+ throw new ServiceSpecificException(e.getCode());
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
+ /**
+ * Remove the registered capability callback.
+ *
+ * @param subId the subscription ID
+ * @param callback The ImsCapabilityCallback to be removed.
+ */
@Override
- public void unregisterRcsAvailabilityCallback(IImsCapabilityCallback c) {
+ public void unregisterRcsAvailabilityCallback(int subId, IImsCapabilityCallback callback) {
enforceReadPrivilegedPermission("unregisterRcsAvailabilityCallback");
+ final long token = Binder.clearCallingIdentity();
+ try {
+ getRcsFeatureManager(subId).unregisterRcsAvailabilityCallback(callback);
+ } catch (com.android.ims.ImsException e) {
+ Log.e(TAG, "unregisterRcsAvailabilityCallback: sudId=" + subId + "," + e.getMessage());
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
+ /**
+ * Query for the capability of an IMS RCS service
+ *
+ * @param subId the subscription ID
+ * @param capability the RCS capability to query.
+ * @param radioTech the radio tech that this capability failed for
+ * @return true if the RCS capability is capable for this subscription, false otherwise.
+ */
@Override
public boolean isCapable(int subId,
- @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability) {
+ @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability,
+ @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) {
enforceReadPrivilegedPermission("isCapable");
- return false;
+ final long token = Binder.clearCallingIdentity();
+ try {
+ return getRcsFeatureManager(subId).isCapable(capability, radioTech);
+ } catch (com.android.ims.ImsException e) {
+ Log.e(TAG, "isCapable: sudId=" + subId
+ + ", capability=" + capability + ", " + e.getMessage());
+ return false;
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
+ /**
+ * Query the availability of an IMS RCS capability.
+ *
+ * @param subId the subscription ID
+ * @param capability the RCS capability to query.
+ * @return true if the RCS capability is currently available for the associated subscription,
+ * false otherwise.
+ */
@Override
public boolean isAvailable(int subId,
@RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability) {
enforceReadPrivilegedPermission("isAvailable");
- return false;
+ final long token = Binder.clearCallingIdentity();
+ try {
+ return getRcsFeatureManager(subId).isAvailable(capability);
+ } catch (com.android.ims.ImsException e) {
+ Log.e(TAG, "isAvailable: sudId=" + subId
+ + ", capability=" + capability + ", " + e.getMessage());
+ return false;
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
@Override
@@ -125,4 +200,30 @@
private void enforceModifyPermission() {
mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
}
+
+ /**
+ * Retrieve RcsFeatureManager instance.
+ *
+ * @param subId the subscription ID
+ * @return The RcsFeatureManager instance
+ * @throws SecurityException if getting Phone or RcsFeatureManager instance failed.
+ */
+ private RcsFeatureManager getRcsFeatureManager(int subId) {
+ Phone phone = PhoneGlobals.getPhone(subId);
+ if (phone == null) {
+ throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
+ "Invalid subscription Id: " + subId);
+ }
+ ImsPhone imsPhone = (ImsPhone) phone.getImsPhone();
+ if (imsPhone == null) {
+ throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
+ "Cannot find ImsPhone instance: " + subId);
+ }
+ RcsFeatureManager rcsFeatureManager = imsPhone.getRcsManager();
+ if (rcsFeatureManager == null) {
+ throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
+ "Cannot find RcsFeatureManager instance: " + subId);
+ }
+ return rcsFeatureManager;
+ }
}