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

Commit 49211ec3 authored by Bonian Chen's avatar Bonian Chen Committed by Automerger Merge Worker
Browse files

Merge "[Settings] Replace ImsManager#getImsServiceState()" into rvc-dev am:...

Merge "[Settings] Replace ImsManager#getImsServiceState()" into rvc-dev am: c073abaf am: 70830926

Change-Id: Ic8fe75bd65d72e7008857405163d0fa35d5820f0
parents 56cd70f1 70830926
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.telephony.AccessNetworkConstants;
import android.telephony.SubscriptionManager;
import android.telephony.ims.ImsException;
import android.telephony.ims.ImsMmTelManager;
import android.telephony.ims.feature.ImsFeature;
import android.telephony.ims.feature.MmTelFeature;
import android.telephony.ims.stub.ImsRegistrationImplBase;

@@ -84,4 +85,20 @@ abstract class ImsQueryController {
    boolean isProvisionedOnDevice(int subId) {
        return (new ImsQueryProvisioningStat(subId, mCapability, mTech)).query();
    }

    @VisibleForTesting
    boolean isServiceStateReady(int subId) throws InterruptedException, ImsException,
            IllegalArgumentException {
        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
            return false;
        }

        final ImsMmTelManager imsMmTelManager = ImsMmTelManager.createForSubscriptionId(subId);
        // TODO: have a shared thread pool instead of create ExecutorService
        //       everytime to improve performance.
        final ExecutorService executor = Executors.newSingleThreadExecutor();
        final IntegerConsumer intResult = new IntegerConsumer();
        imsMmTelManager.getFeatureState(executor, intResult);
        return (intResult.get(TIMEOUT_MILLIS) == ImsFeature.STATE_READY);
    }
}
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.network.ims;

import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

class IntegerConsumer extends Semaphore implements Consumer<Integer> {

    private static final String TAG = "IntegerConsumer";

    IntegerConsumer() {
        super(0);
        mValue = new AtomicInteger();
    }

    private volatile AtomicInteger mValue;

    /**
     * Get boolean value reported from callback
     *
     * @param timeout callback waiting time in milliseconds
     * @return int value reported
     * @throws InterruptedException when thread get interrupted
     */
    int get(long timeout) throws InterruptedException {
        tryAcquire(timeout, TimeUnit.MILLISECONDS);
        return mValue.get();
    }

    /**
     * Implementation of {@link Consumer#accept(Integer)}
     *
     * @param value int reported from {@link Consumer#accept(Integer)}
     */
    public void accept(Integer value) {
        if (value != null) {
            mValue.set(value.intValue());
        }
        release();
    }
}
+18 −4
Original line number Diff line number Diff line
@@ -20,20 +20,23 @@ import android.content.Context;
import android.telecom.TelecomManager;
import android.telephony.AccessNetworkConstants;
import android.telephony.SubscriptionManager;
import android.telephony.ims.ImsException;
import android.telephony.ims.feature.MmTelFeature;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.util.Log;

import androidx.annotation.VisibleForTesting;

import com.android.ims.ImsManager;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.network.telephony.MobileNetworkUtils;

/**
 * Controller class for querying VT status
 */
public class VtQueryImsState extends ImsQueryController {

    private static final String LOG_TAG = "VtQueryImsState";

    private Context mContext;
    private int mSubId;

@@ -71,14 +74,25 @@ public class VtQueryImsState extends ImsQueryController {
     * @return true when Video Call can be performed, otherwise false
     */
    public boolean isReadyToVideoCall() {
        if (!isProvisionedOnDevice(mSubId)) {
            return false;
        }

        final ImsManager imsManager = getImsManager(mSubId);
        if (imsManager == null) {
            return false;
        }

        return imsManager.isVtEnabledByPlatform()
                && isProvisionedOnDevice(mSubId)
                && MobileNetworkUtils.isImsServiceStateReady(imsManager);
        if (!imsManager.isVtEnabledByPlatform()) {
            return false;
        }

        try {
            return isServiceStateReady(mSubId);
        } catch (InterruptedException | IllegalArgumentException | ImsException exception) {
            Log.w(LOG_TAG, "fail to get Vt service status. subId=" + mSubId, exception);
        }
        return false;
    }

    /**
+15 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.network.ims;

import android.content.Context;
import android.telephony.ims.ImsException;

import com.android.ims.ImsManager;

@@ -29,6 +30,7 @@ public class MockVtQueryImsState extends VtQueryImsState {
    private Boolean mIsTtyOnVolteEnabled;
    private Boolean mIsProvisionedOnDevice;
    private Boolean mIsEnabledByUser;
    private Boolean mIsServiceStateReady;

    /**
     * Constructor
@@ -68,6 +70,19 @@ public class MockVtQueryImsState extends VtQueryImsState {
        return super.isProvisionedOnDevice(subId);
    }

    public void setServiceStateReady(boolean isReady) {
        mIsServiceStateReady = isReady;
    }

    @Override
    boolean isServiceStateReady(int subId) throws InterruptedException, ImsException,
            IllegalArgumentException {
        if (mIsServiceStateReady != null) {
            return mIsServiceStateReady;
        }
        return super.isServiceStateReady(subId);
    }

    public void setIsEnabledByUser(boolean enabled) {
        mIsEnabledByUser = enabled;
    }
+1 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager;
import android.telephony.ims.ProvisioningManager;
import android.telephony.ims.feature.ImsFeature;

import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
@@ -98,7 +97,7 @@ public class VideoCallingPreferenceControllerTest {

        doReturn(true).when(mImsManager).isVtEnabledByPlatform();
        mQueryImsState.setIsProvisionedOnDevice(true);
        doReturn(ImsFeature.STATE_READY).when(mImsManager).getImsServiceState();
        mQueryImsState.setServiceStateReady(true);
        doReturn(true).when(mTelephonyManager).isDataEnabled();

        mController.mCallState = TelephonyManager.CALL_STATE_IDLE;