From 5ab1c6cb61523219dd532c3f098f05cf1ecc82ff Mon Sep 17 00:00:00 2001 From: Bonian Chen Date: Mon, 6 Apr 2020 21:43:05 +0800 Subject: [PATCH] [Settings] Changes for supporting replacing ImsManager Wrap IMS related APIs in order to support replacing ImsManager. Bug: 140542283 Test: build pass Merged-In: I10aff50b6f3fc50b2f336ee320740f9f4a81e256 Change-Id: Ibc8c1c36fe031a3d845b99f878ef45ce5db7de28 --- .../settings/network/ims/BooleanConsumer.java | 58 +++++++ .../settings/network/ims/ImsQuery.java | 32 ++++ .../network/ims/ImsQueryController.java | 107 +++++++++++++ .../ImsQueryEnhanced4gLteModeUserSetting.java | 54 +++++++ .../network/ims/ImsQueryProvisioningStat.java | 65 ++++++++ .../network/ims/ImsQueryTtyOnVolteStat.java | 55 +++++++ .../network/ims/ImsQueryVtUserSetting.java | 55 +++++++ .../network/ims/ImsQueryWfcUserSetting.java | 55 +++++++ .../settings/network/ims/IntegerConsumer.java | 58 +++++++ .../network/ims/VolteQueryImsState.java | 136 +++++++++++++++++ .../settings/network/ims/VtQueryImsState.java | 113 ++++++++++++++ .../network/ims/WifiCallingQueryImsState.java | 142 ++++++++++++++++++ .../network/ims/MockVolteQueryImsState.java | 105 +++++++++++++ .../network/ims/MockVtQueryImsState.java | 104 +++++++++++++ .../ims/MockWifiCallingQueryImsState.java | 106 +++++++++++++ 15 files changed, 1245 insertions(+) create mode 100644 src/com/android/settings/network/ims/BooleanConsumer.java create mode 100644 src/com/android/settings/network/ims/ImsQuery.java create mode 100644 src/com/android/settings/network/ims/ImsQueryController.java create mode 100644 src/com/android/settings/network/ims/ImsQueryEnhanced4gLteModeUserSetting.java create mode 100644 src/com/android/settings/network/ims/ImsQueryProvisioningStat.java create mode 100644 src/com/android/settings/network/ims/ImsQueryTtyOnVolteStat.java create mode 100644 src/com/android/settings/network/ims/ImsQueryVtUserSetting.java create mode 100644 src/com/android/settings/network/ims/ImsQueryWfcUserSetting.java create mode 100644 src/com/android/settings/network/ims/IntegerConsumer.java create mode 100644 src/com/android/settings/network/ims/VolteQueryImsState.java create mode 100644 src/com/android/settings/network/ims/VtQueryImsState.java create mode 100644 src/com/android/settings/network/ims/WifiCallingQueryImsState.java create mode 100644 tests/robotests/src/com/android/settings/network/ims/MockVolteQueryImsState.java create mode 100644 tests/robotests/src/com/android/settings/network/ims/MockVtQueryImsState.java create mode 100644 tests/robotests/src/com/android/settings/network/ims/MockWifiCallingQueryImsState.java diff --git a/src/com/android/settings/network/ims/BooleanConsumer.java b/src/com/android/settings/network/ims/BooleanConsumer.java new file mode 100644 index 00000000000..a5dfe6fc867 --- /dev/null +++ b/src/com/android/settings/network/ims/BooleanConsumer.java @@ -0,0 +1,58 @@ +/* + * 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.AtomicBoolean; +import java.util.function.Consumer; + +class BooleanConsumer extends Semaphore implements Consumer { + + private static final String TAG = "BooleanConsumer"; + + BooleanConsumer() { + super(0); + mValue = new AtomicBoolean(); + } + + private volatile AtomicBoolean mValue; + + /** + * Get boolean value reported from callback + * + * @param timeout callback waiting time in milliseconds + * @return boolean value reported + * @throws InterruptedException when thread get interrupted + */ + boolean get(long timeout) throws InterruptedException { + tryAcquire(timeout, TimeUnit.MILLISECONDS); + return mValue.get(); + } + + /** + * Implementation of {@link Consumer#accept(Boolean)} + * + * @param value boolean reported from {@link Consumer#accept(Boolean)} + */ + public void accept(Boolean value) { + if (value != null) { + mValue.set(value.booleanValue()); + } + release(); + } +} diff --git a/src/com/android/settings/network/ims/ImsQuery.java b/src/com/android/settings/network/ims/ImsQuery.java new file mode 100644 index 00000000000..dcb6eeeb648 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQuery.java @@ -0,0 +1,32 @@ +/* + * 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; + + +/** + * An interface for direct querying IMS, and return {@link boolean} + */ +public interface ImsQuery { + + /** + * Interface for performing IMS status/configuration query through public APIs + * + * @return result of query in boolean + */ + boolean query(); + +} diff --git a/src/com/android/settings/network/ims/ImsQueryController.java b/src/com/android/settings/network/ims/ImsQueryController.java new file mode 100644 index 00000000000..3f17da2b360 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQueryController.java @@ -0,0 +1,107 @@ +/* + * 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 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; + +import androidx.annotation.VisibleForTesting; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * Controller class for querying IMS status + */ +abstract class ImsQueryController { + + private static final long TIMEOUT_MILLIS = 2000; + + private volatile int mCapability; + private volatile int mTech; + private volatile int mTransportType; + + /** + * Constructor for query IMS status + * + * @param capability {@link MmTelFeature.MmTelCapabilities#MmTelCapability} + * @param tech {@link ImsRegistrationImplBase#ImsRegistrationTech} + * @param transportType {@link AccessNetworkConstants#TransportType} + */ + ImsQueryController( + @MmTelFeature.MmTelCapabilities.MmTelCapability int capability, + @ImsRegistrationImplBase.ImsRegistrationTech int tech, + @AccessNetworkConstants.TransportType int transportType) { + mCapability = capability; + mTech = tech; + mTransportType = transportType; + } + + abstract boolean isEnabledByUser(int subId); + + @VisibleForTesting + boolean isTtyOnVolteEnabled(int subId) { + return (new ImsQueryTtyOnVolteStat(subId)).query(); + } + + @VisibleForTesting + boolean isEnabledByPlatform(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 BooleanConsumer booleanResult = new BooleanConsumer(); + imsMmTelManager.isSupported(mCapability, mTransportType, executor, booleanResult); + // get() will be blocked until end of execution(isSupported()) within thread(executor) + // or timeout after TIMEOUT_MILLIS milliseconds + return booleanResult.get(TIMEOUT_MILLIS); + } + + @VisibleForTesting + boolean isProvisionedOnDevice(int subId) { + if (!SubscriptionManager.isValidSubscriptionId(subId)) { + return false; + } + 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); + } +} diff --git a/src/com/android/settings/network/ims/ImsQueryEnhanced4gLteModeUserSetting.java b/src/com/android/settings/network/ims/ImsQueryEnhanced4gLteModeUserSetting.java new file mode 100644 index 00000000000..34d8430f57a --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQueryEnhanced4gLteModeUserSetting.java @@ -0,0 +1,54 @@ +/* + * 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 android.telephony.ims.ImsMmTelManager; +import android.util.Log; + + +/** + * An {@link ImsQuery} for accessing IMS user setting for enhanced 4G LTE + */ +public class ImsQueryEnhanced4gLteModeUserSetting implements ImsQuery { + + private static final String LOG_TAG = "QueryEnhanced4gLteModeUserSetting"; + /** + * Constructor + * @param subId subscription id + */ + public ImsQueryEnhanced4gLteModeUserSetting(int subId) { + mSubId = subId; + } + + private volatile int mSubId; + + /** + * Implementation of interface {@link ImsQuery#query()} + * + * @return result of query + */ + public boolean query() { + try { + final ImsMmTelManager imsMmTelManager = + ImsMmTelManager.createForSubscriptionId(mSubId); + return imsMmTelManager.isAdvancedCallingSettingEnabled(); + } catch (IllegalArgumentException exception) { + Log.w(LOG_TAG, "fail to get VoLte settings. subId=" + mSubId, exception); + } + return false; + } +} diff --git a/src/com/android/settings/network/ims/ImsQueryProvisioningStat.java b/src/com/android/settings/network/ims/ImsQueryProvisioningStat.java new file mode 100644 index 00000000000..b52d22c71bf --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQueryProvisioningStat.java @@ -0,0 +1,65 @@ +/* + * 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 android.telephony.ims.ProvisioningManager; +import android.telephony.ims.feature.MmTelFeature; +import android.telephony.ims.stub.ImsRegistrationImplBase; +import android.util.Log; + + +/** + * An {@link ImsQuery} for accessing IMS provision stat + */ +public class ImsQueryProvisioningStat implements ImsQuery { + + private static final String LOG_TAG = "QueryPrivisioningStat"; + + private volatile int mSubId; + private volatile int mCapability; + private volatile int mTech; + + /** + * Constructor + * @param subId subscription id + * @param capability {@link MmTelFeature.MmTelCapabilities#MmTelCapability} + * @param tech {@link ImsRegistrationImplBase#ImsRegistrationTech} + */ + public ImsQueryProvisioningStat(int subId, + @MmTelFeature.MmTelCapabilities.MmTelCapability int capability, + @ImsRegistrationImplBase.ImsRegistrationTech int tech) { + mSubId = subId; + mCapability = capability; + mTech = tech; + } + + /** + * Implementation of interface {@link ImsQuery#query()} + * + * @return result of query + */ + public boolean query() { + try { + final ProvisioningManager privisionManager = + ProvisioningManager.createForSubscriptionId(mSubId); + return privisionManager.getProvisioningStatusForCapability(mCapability, mTech); + } catch (IllegalArgumentException exception) { + Log.w(LOG_TAG, "fail to get Provisioning stat. subId=" + mSubId, exception); + } + return false; + } +} diff --git a/src/com/android/settings/network/ims/ImsQueryTtyOnVolteStat.java b/src/com/android/settings/network/ims/ImsQueryTtyOnVolteStat.java new file mode 100644 index 00000000000..e2719dd27aa --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQueryTtyOnVolteStat.java @@ -0,0 +1,55 @@ +/* + * 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 android.telephony.ims.ImsMmTelManager; +import android.util.Log; + + +/** + * An {@link ImsQuery} for accessing IMS tty on VoLte stat + */ +public class ImsQueryTtyOnVolteStat implements ImsQuery { + + private static final String LOG_TAG = "QueryTtyOnVolteStat"; + + /** + * Constructor + * @param subId subscription id + */ + public ImsQueryTtyOnVolteStat(int subId) { + mSubId = subId; + } + + private volatile int mSubId; + + /** + * Implementation of interface {@link ImsQuery#query()} + * + * @return result of query + */ + public boolean query() { + try { + final ImsMmTelManager imsMmTelManager = + ImsMmTelManager.createForSubscriptionId(mSubId); + return imsMmTelManager.isTtyOverVolteEnabled(); + } catch (IllegalArgumentException exception) { + Log.w(LOG_TAG, "fail to get VoLte Tty Stat. subId=" + mSubId, exception); + } + return false; + } +} diff --git a/src/com/android/settings/network/ims/ImsQueryVtUserSetting.java b/src/com/android/settings/network/ims/ImsQueryVtUserSetting.java new file mode 100644 index 00000000000..6da4a4c07c6 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQueryVtUserSetting.java @@ -0,0 +1,55 @@ +/* + * 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 android.telephony.ims.ImsMmTelManager; +import android.util.Log; + + +/** + * An {@link ImsQuery} for accessing IMS VT enabled settings from user + */ +public class ImsQueryVtUserSetting implements ImsQuery { + + private static final String LOG_TAG = "QueryVtUserSetting"; + + /** + * Constructor + * @param subId subscription id + */ + public ImsQueryVtUserSetting(int subId) { + mSubId = subId; + } + + private volatile int mSubId; + + /** + * Implementation of interface {@link ImsQuery#query()} + * + * @return result of query + */ + public boolean query() { + try { + final ImsMmTelManager imsMmTelManager = + ImsMmTelManager.createForSubscriptionId(mSubId); + return imsMmTelManager.isVtSettingEnabled(); + } catch (IllegalArgumentException exception) { + Log.w(LOG_TAG, "fail to get VT settings. subId=" + mSubId, exception); + } + return false; + } +} diff --git a/src/com/android/settings/network/ims/ImsQueryWfcUserSetting.java b/src/com/android/settings/network/ims/ImsQueryWfcUserSetting.java new file mode 100644 index 00000000000..3407413d3e8 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQueryWfcUserSetting.java @@ -0,0 +1,55 @@ +/* + * 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 android.telephony.ims.ImsMmTelManager; +import android.util.Log; + + +/** + * An {@link ImsQuery} for accessing IMS WFC enabled settings from user + */ +public class ImsQueryWfcUserSetting implements ImsQuery { + + private static final String LOG_TAG = "QueryWfcUserSetting"; + + /** + * Constructor + * @param subId subscription id + */ + public ImsQueryWfcUserSetting(int subId) { + mSubId = subId; + } + + private volatile int mSubId; + + /** + * Implementation of interface {@link ImsQuery#query()} + * + * @return result of query + */ + public boolean query() { + try { + final ImsMmTelManager imsMmTelManager = + ImsMmTelManager.createForSubscriptionId(mSubId); + return imsMmTelManager.isVoWiFiSettingEnabled(); + } catch (IllegalArgumentException exception) { + Log.w(LOG_TAG, "fail to get Wfc settings. subId=" + mSubId, exception); + } + return false; + } +} diff --git a/src/com/android/settings/network/ims/IntegerConsumer.java b/src/com/android/settings/network/ims/IntegerConsumer.java new file mode 100644 index 00000000000..02c82275a86 --- /dev/null +++ b/src/com/android/settings/network/ims/IntegerConsumer.java @@ -0,0 +1,58 @@ +/* + * 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 { + + 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(); + } +} diff --git a/src/com/android/settings/network/ims/VolteQueryImsState.java b/src/com/android/settings/network/ims/VolteQueryImsState.java new file mode 100644 index 00000000000..167b4b13a3e --- /dev/null +++ b/src/com/android/settings/network/ims/VolteQueryImsState.java @@ -0,0 +1,136 @@ +/* + * 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 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; + +/** + * Controller class for querying Volte status + */ +public class VolteQueryImsState extends ImsQueryController { + + private static final String LOG_TAG = "VolteQueryImsState"; + + private Context mContext; + private int mSubId; + + /** + * Constructor + * + * @param context {@link Context} + * @param subId subscription's id + */ + public VolteQueryImsState(Context context, int subId) { + super(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, + ImsRegistrationImplBase.REGISTRATION_TECH_LTE, + AccessNetworkConstants.TRANSPORT_TYPE_WWAN); + mContext = context; + mSubId = subId; + } + + /** + * Implementation of ImsQueryController#isEnabledByUser(int subId) + */ + @VisibleForTesting + boolean isEnabledByUser(int subId) { + if (!SubscriptionManager.isValidSubscriptionId(subId)) { + return false; + } + return (new ImsQueryEnhanced4gLteModeUserSetting(subId)).query(); + } + + /** + * Check whether VoLTE has been provisioned or not on this subscription + * + * @return true when VoLTE has been enabled, otherwise false + */ + public boolean isVoLteProvisioned() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + if (!isProvisionedOnDevice(mSubId)) { + return false; + } + try { + return isEnabledByPlatform(mSubId); + } catch (InterruptedException | IllegalArgumentException | ImsException exception) { + Log.w(LOG_TAG, "fail to get VoLte supporting status. subId=" + mSubId, exception); + } + return false; + } + + /** + * Check whether VoLTE can be perform or not on this subscription + * + * @return true when VoLTE can be performed, otherwise false + */ + public boolean isReadyToVoLte() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + if (!isVoLteProvisioned()) { + return false; + } + try { + return isServiceStateReady(mSubId); + } catch (InterruptedException | IllegalArgumentException | ImsException exception) { + Log.w(LOG_TAG, "fail to get VoLte service status. subId=" + mSubId, exception); + } + return false; + } + + /** + * Get allowance status for user to alter configuration + * + * @return true when changing configuration by user is allowed. + */ + public boolean isAllowUserControl() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + + return ((!isTtyEnabled(mContext)) + || (isTtyOnVolteEnabled(mSubId))); + } + + @VisibleForTesting + boolean isTtyEnabled(Context context) { + final TelecomManager telecomManager = context.getSystemService(TelecomManager.class); + return (telecomManager.getCurrentTtyMode() != TelecomManager.TTY_MODE_OFF); + } + + /** + * Get user's configuration + * + * @return true when user's configuration is ON otherwise false. + */ + public boolean isEnabledByUser() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + return isEnabledByUser(mSubId); + } +} diff --git a/src/com/android/settings/network/ims/VtQueryImsState.java b/src/com/android/settings/network/ims/VtQueryImsState.java new file mode 100644 index 00000000000..5c48ff00380 --- /dev/null +++ b/src/com/android/settings/network/ims/VtQueryImsState.java @@ -0,0 +1,113 @@ +/* + * 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 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; + +/** + * Controller class for querying VT status + */ +public class VtQueryImsState extends ImsQueryController { + + private static final String LOG_TAG = "VtQueryImsState"; + + private Context mContext; + private int mSubId; + + /** + * Constructor + * + * @param context {@link Context} + * @param subId subscription's id + */ + public VtQueryImsState(Context context, int subId) { + super(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO, + ImsRegistrationImplBase.REGISTRATION_TECH_LTE, + AccessNetworkConstants.TRANSPORT_TYPE_WWAN); + mContext = context; + mSubId = subId; + } + + /** + * Implementation of ImsQueryController#isEnabledByUser(int subId) + */ + @VisibleForTesting + boolean isEnabledByUser(int subId) { + if (!SubscriptionManager.isValidSubscriptionId(subId)) { + return false; + } + return (new ImsQueryVtUserSetting(subId)).query(); + } + + /** + * Check whether Video Call can be perform or not on this subscription + * + * @return true when Video Call can be performed, otherwise false + */ + public boolean isReadyToVideoCall() { + if (!isProvisionedOnDevice(mSubId)) { + return false; + } + + try { + return isEnabledByPlatform(mSubId) && isServiceStateReady(mSubId); + } catch (InterruptedException | IllegalArgumentException | ImsException exception) { + Log.w(LOG_TAG, "fail to get Vt ready. subId=" + mSubId, exception); + } + return false; + } + + /** + * Get allowance status for user to alter configuration + * + * @return true when changing configuration by user is allowed. + */ + public boolean isAllowUserControl() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + return ((!isTtyEnabled(mContext)) + || (isTtyOnVolteEnabled(mSubId))); + } + + @VisibleForTesting + boolean isTtyEnabled(Context context) { + final TelecomManager telecomManager = context.getSystemService(TelecomManager.class); + return (telecomManager.getCurrentTtyMode() != TelecomManager.TTY_MODE_OFF); + } + + /** + * Get user's configuration + * + * @return true when user's configuration is ON otherwise false. + */ + public boolean isEnabledByUser() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + return isEnabledByUser(mSubId); + } +} diff --git a/src/com/android/settings/network/ims/WifiCallingQueryImsState.java b/src/com/android/settings/network/ims/WifiCallingQueryImsState.java new file mode 100644 index 00000000000..efa93e5abe5 --- /dev/null +++ b/src/com/android/settings/network/ims/WifiCallingQueryImsState.java @@ -0,0 +1,142 @@ +/* + * 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 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; + +/** + * Controller class for querying Wifi calling status + */ +public class WifiCallingQueryImsState extends ImsQueryController { + + private static final String LOG_TAG = "WifiCallingQueryImsState"; + + private Context mContext; + private int mSubId; + + /** + * Constructor + * + * @param context {@link Context} + * @param subId subscription's id + */ + public WifiCallingQueryImsState(Context context, int subId) { + super(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, + ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN, + AccessNetworkConstants.TRANSPORT_TYPE_WLAN); + mContext = context; + mSubId = subId; + } + + /** + * Implementation of ImsQueryController#isEnabledByUser(int subId) + */ + @VisibleForTesting + boolean isEnabledByUser(int subId) { + if (!SubscriptionManager.isValidSubscriptionId(subId)) { + return false; + } + return (new ImsQueryWfcUserSetting(subId)).query(); + } + + /** + * Check whether Wifi Calling is a supported feature on this subscription + * + * @return true when Wifi Calling is a supported feature, otherwise false + */ + public boolean isWifiCallingSupported() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + try { + return isEnabledByPlatform(mSubId); + } catch (InterruptedException | IllegalArgumentException | ImsException exception) { + Log.w(LOG_TAG, "fail to get WFC supporting status. subId=" + mSubId, exception); + } + return false; + } + + /** + * Check whether Wifi Calling has been provisioned or not on this subscription + * + * @return true when Wifi Calling has been enabled, otherwise false + */ + public boolean isWifiCallingProvisioned() { + return isWifiCallingSupported() && isProvisionedOnDevice(mSubId); + } + + /** + * Check whether Wifi Calling can be perform or not on this subscription + * + * @return true when Wifi Calling can be performed, otherwise false + */ + public boolean isReadyToWifiCalling() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + if (!isWifiCallingProvisioned()) { + return false; + } + try { + return isServiceStateReady(mSubId); + } catch (InterruptedException | IllegalArgumentException | ImsException exception) { + Log.w(LOG_TAG, "fail to get WFC service status. subId=" + mSubId, exception); + } + return false; + } + + /** + * Get allowance status for user to alter configuration + * + * @return true when changing configuration by user is allowed. + */ + public boolean isAllowUserControl() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + + return ((!isTtyEnabled(mContext)) + || (isTtyOnVolteEnabled(mSubId))); + } + + @VisibleForTesting + boolean isTtyEnabled(Context context) { + final TelecomManager telecomManager = context.getSystemService(TelecomManager.class); + return (telecomManager.getCurrentTtyMode() != TelecomManager.TTY_MODE_OFF); + } + + /** + * Get user's configuration + * + * @return true when user's configuration is ON otherwise false. + */ + public boolean isEnabledByUser() { + if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { + return false; + } + return isEnabledByUser(mSubId); + } +} diff --git a/tests/robotests/src/com/android/settings/network/ims/MockVolteQueryImsState.java b/tests/robotests/src/com/android/settings/network/ims/MockVolteQueryImsState.java new file mode 100644 index 00000000000..515ab5b659b --- /dev/null +++ b/tests/robotests/src/com/android/settings/network/ims/MockVolteQueryImsState.java @@ -0,0 +1,105 @@ +/* + * 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 android.content.Context; +import android.telephony.ims.ImsException; + +/** + * Controller class for mock VoLte status + */ +public class MockVolteQueryImsState extends VolteQueryImsState { + + private Boolean mIsTtyOnVolteEnabled; + private Boolean mIsSupported; + private Boolean mIsProvisionedOnDevice; + private Boolean mIsServiceStateReady; + private Boolean mIsEnabledByUser; + + /** + * Constructor + * + * @param context {@link Context} + * @param subId subscription's id + */ + public MockVolteQueryImsState(Context context, int subId) { + super(context, subId); + } + + public void setIsTtyOnVolteEnabled(boolean enabled) { + mIsTtyOnVolteEnabled = enabled; + } + + @Override + boolean isTtyOnVolteEnabled(int subId) { + if (mIsTtyOnVolteEnabled != null) { + return mIsTtyOnVolteEnabled; + } + return super.isTtyOnVolteEnabled(subId); + } + + public void setEnabledByPlatform(boolean isSupported) { + mIsSupported = isSupported; + } + + @Override + boolean isEnabledByPlatform(int subId) throws InterruptedException, ImsException, + IllegalArgumentException { + if (mIsSupported != null) { + return mIsSupported; + } + return super.isEnabledByPlatform(subId); + } + + public void setIsProvisionedOnDevice(boolean isProvisioned) { + mIsProvisionedOnDevice = isProvisioned; + } + + @Override + boolean isProvisionedOnDevice(int subId) { + if (mIsProvisionedOnDevice != null) { + return mIsProvisionedOnDevice; + } + 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; + } + + @Override + boolean isEnabledByUser(int subId) { + if (mIsEnabledByUser != null) { + return mIsEnabledByUser; + } + return super.isEnabledByUser(subId); + } + +} diff --git a/tests/robotests/src/com/android/settings/network/ims/MockVtQueryImsState.java b/tests/robotests/src/com/android/settings/network/ims/MockVtQueryImsState.java new file mode 100644 index 00000000000..0949f1c0262 --- /dev/null +++ b/tests/robotests/src/com/android/settings/network/ims/MockVtQueryImsState.java @@ -0,0 +1,104 @@ +/* + * 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 android.content.Context; +import android.telephony.ims.ImsException; + +/** + * Controller class for mock VT status + */ +public class MockVtQueryImsState extends VtQueryImsState { + + private Boolean mIsTtyOnVolteEnabled; + private Boolean mIsEnabledOnPlatform; + private Boolean mIsProvisionedOnDevice; + private Boolean mIsEnabledByUser; + private Boolean mIsServiceStateReady; + + /** + * Constructor + * + * @param context {@link Context} + * @param subId subscription's id + */ + public MockVtQueryImsState(Context context, int subId) { + super(context, subId); + } + + public void setIsTtyOnVolteEnabled(boolean enabled) { + mIsTtyOnVolteEnabled = enabled; + } + + @Override + boolean isTtyOnVolteEnabled(int subId) { + if (mIsTtyOnVolteEnabled != null) { + return mIsTtyOnVolteEnabled; + } + return super.isTtyOnVolteEnabled(subId); + } + + public void setIsEnabledByPlatform(boolean isEnabled) { + mIsEnabledOnPlatform = isEnabled; + } + + @Override + boolean isEnabledByPlatform(int subId) throws InterruptedException, ImsException, + IllegalArgumentException { + if (mIsEnabledOnPlatform != null) { + return mIsEnabledOnPlatform; + } + return super.isEnabledByPlatform(subId); + } + + public void setIsProvisionedOnDevice(boolean isProvisioned) { + mIsProvisionedOnDevice = isProvisioned; + } + + @Override + boolean isProvisionedOnDevice(int subId) { + if (mIsProvisionedOnDevice != null) { + return mIsProvisionedOnDevice; + } + 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; + } + + @Override + boolean isEnabledByUser(int subId) { + if (mIsEnabledByUser != null) { + return mIsEnabledByUser; + } + return super.isEnabledByUser(subId); + } +} diff --git a/tests/robotests/src/com/android/settings/network/ims/MockWifiCallingQueryImsState.java b/tests/robotests/src/com/android/settings/network/ims/MockWifiCallingQueryImsState.java new file mode 100644 index 00000000000..abea839791e --- /dev/null +++ b/tests/robotests/src/com/android/settings/network/ims/MockWifiCallingQueryImsState.java @@ -0,0 +1,106 @@ +/* + * 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 android.content.Context; +import android.telephony.ims.ImsException; + +/** + * Controller class for mock Wifi calling status + */ +public class MockWifiCallingQueryImsState extends WifiCallingQueryImsState { + + private Boolean mIsTtyOnVolteEnabled; + private Boolean mIsEnabledOnPlatform; + private Boolean mIsProvisionedOnDevice; + private Boolean mIsServiceStateReady; + private Boolean mIsEnabledByUser; + + /** + * Constructor + * + * @param context {@code Context} + * @param subId subscription's id + */ + public MockWifiCallingQueryImsState(Context context, int subId) { + super(context, subId); + } + + public void setIsTtyOnVolteEnabled(boolean enabled) { + mIsTtyOnVolteEnabled = enabled; + } + + @Override + boolean isTtyOnVolteEnabled(int subId) { + if (mIsTtyOnVolteEnabled != null) { + return mIsTtyOnVolteEnabled; + } + return super.isTtyOnVolteEnabled(subId); + } + + + public void setIsEnabledByPlatform(boolean isEnabled) { + mIsEnabledOnPlatform = isEnabled; + } + + @Override + boolean isEnabledByPlatform(int subId) throws InterruptedException, ImsException, + IllegalArgumentException { + if (mIsEnabledOnPlatform != null) { + return mIsEnabledOnPlatform; + } + return super.isEnabledByPlatform(subId); + } + + public void setIsProvisionedOnDevice(boolean isProvisioned) { + mIsProvisionedOnDevice = isProvisioned; + } + + @Override + boolean isProvisionedOnDevice(int subId) { + if (mIsProvisionedOnDevice != null) { + return mIsProvisionedOnDevice; + } + 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; + } + + @Override + boolean isEnabledByUser(int subId) { + if (mIsEnabledByUser != null) { + return mIsEnabledByUser; + } + return super.isEnabledByUser(subId); + } + +}