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

Commit 80478ea7 authored by Brad Ebinger's avatar Brad Ebinger Committed by Gerrit Code Review
Browse files

Merge changes from topic "redo_ims_poll"

* changes:
  Increase ImsManager efficiency when using getInstance
  Move to a push model of querying ImsFeature Binders
parents 18a29292 751c047c
Loading
Loading
Loading
Loading
+29 −146
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.ims;


import android.annotation.Nullable;
import android.annotation.Nullable;
import android.content.Context;
import android.content.Context;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Looper;
import android.os.Looper;
import android.os.RemoteException;
import android.os.RemoteException;
@@ -29,11 +28,7 @@ import android.telephony.ims.feature.ImsFeature;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.util.Log;
import android.util.Log;


import com.android.ims.internal.IImsServiceFeatureCallback;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.util.HandlerExecutor;

import java.util.concurrent.Executor;


/**
/**
 * Base class of MmTelFeatureConnection and RcsFeatureConnection.
 * Base class of MmTelFeatureConnection and RcsFeatureConnection.
@@ -41,51 +36,26 @@ import java.util.concurrent.Executor;
public abstract class FeatureConnection {
public abstract class FeatureConnection {
    protected static final String TAG = "FeatureConnection";
    protected static final String TAG = "FeatureConnection";


    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();
    }

    protected static boolean sImsSupportedOnDevice = true;
    protected static boolean sImsSupportedOnDevice = true;


    protected final int mSlotId;
    protected final int mSlotId;
    protected Context mContext;
    protected Context mContext;
    protected IBinder mBinder;
    protected IBinder mBinder;
    @VisibleForTesting
    public Executor mExecutor;


    // We are assuming the feature is available when started.
    // We are assuming the feature is available when started.
    protected volatile boolean mIsAvailable = true;
    protected volatile boolean mIsAvailable = true;
    // ImsFeature Status from the ImsService. Cached.
    // ImsFeature Status from the ImsService. Cached.
    protected Integer mFeatureStateCached = null;
    protected Integer mFeatureStateCached = null;
    protected IFeatureUpdate mStatusCallback;
    protected long mFeatureCapabilities;
    protected IImsRegistration mRegistrationBinder;
    private final IImsRegistration mRegistrationBinder;
    protected IImsConfig mConfigBinder;
    private final IImsConfig mConfigBinder;
    protected final Object mLock = new Object();
    protected final Object mLock = new Object();


    public FeatureConnection(Context context, int slotId) {
    public FeatureConnection(Context context, int slotId, IImsConfig c, IImsRegistration r) {
        mSlotId = slotId;
        mSlotId = slotId;
        mContext = context;
        mContext = context;

        mRegistrationBinder = r;
        // Callbacks should be scheduled on the main thread.
        mConfigBinder = c;
        if (context.getMainLooper() != null) {
            mExecutor = context.getMainExecutor();
        } else {
            // Fallback to the current thread.
            if (Looper.myLooper() == null) {
                Looper.prepare();
            }
            mExecutor = new HandlerExecutor(new Handler(Looper.myLooper()));
        }
    }
    }


    protected TelephonyManager getTelephonyManager() {
    protected TelephonyManager getTelephonyManager() {
@@ -128,57 +98,12 @@ public abstract class FeatureConnection {
        synchronized (mLock) {
        synchronized (mLock) {
            if (mIsAvailable) {
            if (mIsAvailable) {
                mIsAvailable = false;
                mIsAvailable = false;
                mRegistrationBinder = null;
                if (mBinder != null) {
                if (mBinder != null) {
                    mBinder.unlinkToDeath(mDeathRecipient, 0);
                    mBinder.unlinkToDeath(mDeathRecipient, 0);
                }
                }
                if (mStatusCallback != null) {
                    Log.d(TAG, "onRemovedOrDied: notifyUnavailable");
                    mStatusCallback.notifyUnavailable();
                    // Unlink because this FeatureConnection should no longer send callbacks.
                    mStatusCallback = null;
                }
            }
        }
    }

    /**
     * The listener for ImsManger and RcsFeatureManager to receive IMS feature status changed.
     * @param callback Callback that will fire when the feature status has changed.
     */
    public void setStatusCallback(IFeatureUpdate callback) {
        mStatusCallback = callback;
            }
            }

    @VisibleForTesting
    public IImsServiceFeatureCallback getListener() {
        return mListenerBinder;
        }
        }

    /**
     * The callback to receive ImsFeature status changed.
     */
    private final IImsServiceFeatureCallback mListenerBinder =
        new IImsServiceFeatureCallback.Stub() {
            @Override
            public void imsFeatureCreated(int slotId, int feature) {
                mExecutor.execute(() -> {
                    handleImsFeatureCreatedCallback(slotId, feature);
                });
            }
            @Override
            public void imsFeatureRemoved(int slotId, int feature) {
                mExecutor.execute(() -> {
                    handleImsFeatureRemovedCallback(slotId, feature);
                });
            }
            @Override
            public void imsStatusChanged(int slotId, int feature, int status) {
                mExecutor.execute(() -> {
                    handleImsStatusChangedCallback(slotId, feature, status);
                });
    }
    }
        };


    public @ImsRegistrationImplBase.ImsRegistrationTech int getRegistrationTech()
    public @ImsRegistrationImplBase.ImsRegistrationTech int getRegistrationTech()
            throws RemoteException {
            throws RemoteException {
@@ -192,41 +117,10 @@ public abstract class FeatureConnection {
    }
    }


    public @Nullable IImsRegistration getRegistration() {
    public @Nullable IImsRegistration getRegistration() {
        synchronized (mLock) {
            // null if cache is invalid;
            if (mRegistrationBinder != null) {
                return mRegistrationBinder;
            }
        }
        // We don't want to synchronize on a binder call to another process.
        IImsRegistration regBinder = getRegistrationBinder();
        synchronized (mLock) {
            // mRegistrationBinder may have changed while we tried to get the registration
            // interface.
            if (mRegistrationBinder == null) {
                mRegistrationBinder = regBinder;
            }
        }
        return mRegistrationBinder;
        return mRegistrationBinder;
    }
    }


    public @Nullable
    public @Nullable IImsConfig getConfig() {
    IImsConfig getConfig() {
        synchronized (mLock) {
            // null if cache is invalid;
            if (mConfigBinder != null) {
                return mConfigBinder;
            }
        }
        // We don't want to synchronize on a binder call to another process.
        IImsConfig configBinder = getConfigBinder();
        synchronized (mLock) {
            // mRegistrationBinder may have changed while we tried to get the registration
            // interface.
            if (mConfigBinder == null) {
                mConfigBinder = configBinder;
            }
        }
        return mConfigBinder;
        return mConfigBinder;
    }
    }


@@ -260,6 +154,27 @@ public abstract class FeatureConnection {
        return mIsAvailable && mBinder != null && mBinder.isBinderAlive();
        return mIsAvailable && mBinder != null && mBinder.isBinderAlive();
    }
    }


    public void updateFeatureState(int state) {
        synchronized (mLock) {
            mFeatureStateCached = state;
        }
    }

    public long getFeatureCapabilties() {
        synchronized (mLock) {
            return mFeatureCapabilities;
        }
    }

    public void updateFeatureCapabilities(long caps) {
        synchronized (mLock) {
            if (mFeatureCapabilities != caps) {
                mFeatureCapabilities = caps;
                onFeatureCapabilitiesUpdated(caps);
            }
        }
    }

    /**
    /**
     * @return an integer describing the current Feature Status, defined in
     * @return an integer describing the current Feature Status, defined in
     * {@link ImsFeature.ImsState}.
     * {@link ImsFeature.ImsState}.
@@ -284,42 +199,10 @@ public abstract class FeatureConnection {
        return state;
        return state;
    }
    }


    /**
     * An ImsFeature has been created for this FeatureConnection for the associated
     * {@link ImsFeature.FeatureType}.
     * @param slotId The slot ID associated with the event.
     * @param feature The {@link ImsFeature.FeatureType} associated with the event.
     */
    protected abstract void handleImsFeatureCreatedCallback(int slotId, int feature);

    /**
     * An ImsFeature has been removed for this FeatureConnection for the associated
     * {@link ImsFeature.FeatureType}.
     * @param slotId The slot ID associated with the event.
     * @param feature The {@link ImsFeature.FeatureType} associated with the event.
     */
    protected abstract void handleImsFeatureRemovedCallback(int slotId, int feature);

    /**
     * The status of an ImsFeature has changed for the associated {@link ImsFeature.FeatureType}.
     * @param slotId The slot ID associated with the event.
     * @param feature The {@link ImsFeature.FeatureType} associated with the event.
     * @param status The new {@link ImsFeature.ImsState} associated with the ImsFeature
     */
    protected abstract void handleImsStatusChangedCallback(int slotId, int feature, int status);

    /**
    /**
     * Internal method used to retrieve the feature status from the corresponding ImsService.
     * Internal method used to retrieve the feature status from the corresponding ImsService.
     */
     */
    protected abstract Integer retrieveFeatureState();
    protected abstract Integer retrieveFeatureState();


    /**
    protected abstract void onFeatureCapabilitiesUpdated(long capabilities);
     * @return The ImsRegistration instance associated with the FeatureConnection.
     */
    protected abstract IImsRegistration getRegistrationBinder();

    /**
     * @return The ImsRegistration instance associated with the FeatureConnection.
     */
    protected abstract IImsConfig getConfigBinder();
}
}
Loading