Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7da31960 authored by Brad Ebinger's avatar Brad Ebinger Committed by android-build-merger
Browse files

Only allow ImsManager to work with FEATURE_TELEPHONY_IMS

am: aa43f578

Change-Id: Iba30720262b072992327b2e9c0a99a35a6e68191
parents 4379ee0f aa43f578
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.ims;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerExecutor;
@@ -308,8 +309,14 @@ public class ImsManager {
         * Start the creation of a connection to the underlying ImsService implementation. When the
         * service is connected, {@link Listener#connectionReady(ImsManager)} will be called with
         * an active ImsManager instance.
         *
         * If this device does not support an ImsStack (i.e. doesn't support
         * {@link PackageManager#FEATURE_TELEPHONY_IMS} feature), this method will do nothing.
         */
        public void connect() {
            if (!ImsManager.isImsSupportedOnDevice(mContext)) {
                return;
            }
            mRetryCount = 0;
            // Send a message to connect to the Ims Service and open a connection through
            // getImsService().
@@ -448,6 +455,10 @@ public class ImsManager {
        }
    }

    public static boolean isImsSupportedOnDevice(Context context) {
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS);
    }

    /**
     * Returns the user configuration of Enhanced 4G LTE Mode setting.
     *
@@ -2369,6 +2380,10 @@ public class ImsManager {
     */
    private void checkAndThrowExceptionIfServiceUnavailable()
            throws ImsException {
        if (!isImsSupportedOnDevice(mContext)) {
            throw new ImsException("IMS not supported on device.",
                    ImsReasonInfo.CODE_LOCAL_IMS_NOT_SUPPORTED_ON_DEVICE);
        }
        if (mMmTelFeatureConnection == null || !mMmTelFeatureConnection.isBinderAlive()) {
            createImsService();

@@ -2758,6 +2773,7 @@ public class ImsManager {

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("ImsManager:");
        pw.println("  device supports IMS = " + isImsSupportedOnDevice(mContext));
        pw.println("  mPhoneId = " + mPhoneId);
        pw.println("  mConfigUpdated = " + mConfigUpdated);
        pw.println("  mImsServiceProxy = " + mMmTelFeatureConnection);
+14 −10
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.ims;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.os.Handler;
@@ -297,7 +298,7 @@ public class MmTelFeatureConnection {
            IImsRegistration imsRegistration = getRegistration();
            if (imsRegistration != null) {
                try {
                    getRegistration().addRegistrationCallback(localCallback);
                    imsRegistration.addRegistrationCallback(localCallback);
                } catch (RemoteException e) {
                    throw new IllegalStateException("ImsRegistrationCallbackAdapter: MmTelFeature"
                            + " binder is dead.");
@@ -314,7 +315,7 @@ public class MmTelFeatureConnection {
            IImsRegistration imsRegistration = getRegistration();
            if (imsRegistration != null) {
                try {
                    getRegistration().removeRegistrationCallback(localCallback);
                    imsRegistration.removeRegistrationCallback(localCallback);
                } catch (RemoteException e) {
                    Log.w(TAG, "ImsRegistrationCallbackAdapter - unregisterCallback: couldn't"
                            + " remove registration callback");
@@ -429,6 +430,7 @@ public class MmTelFeatureConnection {
    private final Object mLock = new Object();
    // Updated by IImsServiceFeatureCallback when FEATURE_EMERGENCY_MMTEL is sent.
    private boolean mSupportsEmergencyCalling = false;
    private static boolean sImsSupportedOnDevice = true;

    // Cache the Registration and Config interfaces as long as the MmTel feature is connected. If
    // it becomes disconnected, invalidate.
@@ -451,8 +453,13 @@ public class MmTelFeatureConnection {
    private final CapabilityCallbackManager mCapabilityCallbackManager;
    private final ProvisioningCallbackManager mProvisioningCallbackManager;

    public static MmTelFeatureConnection create(Context context , int slotId) {
    public static @NonNull MmTelFeatureConnection create(Context context , int slotId) {
        MmTelFeatureConnection serviceProxy = new MmTelFeatureConnection(context, slotId);
        if (!ImsManager.isImsSupportedOnDevice(context)) {
            // Return empty service proxy in the case that IMS is not supported.
            sImsSupportedOnDevice = false;
            return serviceProxy;
        }

        TelephonyManager tm  = getTelephonyManager(context);
        if (tm == null) {
@@ -946,7 +953,10 @@ public class MmTelFeatureConnection {
        return mIsAvailable && mBinder != null && mBinder.isBinderAlive();
    }

    protected void checkServiceIsReady() throws RemoteException {
    private void checkServiceIsReady() throws RemoteException {
        if (!sImsSupportedOnDevice) {
            throw new RemoteException("IMS is not supported on this device.");
        }
        if (!isBinderReady()) {
            throw new RemoteException("ImsServiceProxy is not ready to accept commands.");
        }
@@ -955,10 +965,4 @@ public class MmTelFeatureConnection {
    private IImsMmTelFeature getServiceInterface(IBinder b) {
        return IImsMmTelFeature.Stub.asInterface(b);
    }

    protected void checkBinderConnection() throws RemoteException {
        if (!isBinderAlive()) {
            throw new RemoteException("ImsServiceProxy is not available for that feature.");
        }
    }
}