From 72717cb53746c04ac67869b4be456ca469ef2c9d Mon Sep 17 00:00:00 2001 From: Bonian Chen Date: Tue, 21 Jan 2020 20:35:30 +0800 Subject: [PATCH] [Settings] replace isNonTtyOrTtyOnVolteEnabled() in WFC 1. Code refactor 2. Replace ImsManager#isNonTtyOrTtyOnVolteEnabled() by combination of TelecomManager#getCurrentTtyMode() and ImsMmTelManager#isTtyOverVolteEnabled() Bug: 140542283 Test: manual Change-Id: Ia5179ee1a23f054899bc74c796542bae40cdc8d5 --- .../settings/network/ims/ImsDirectQuery.java | 32 +++++++++++ .../network/ims/ImsDirectQueryImpl.java | 56 +++++++++++++++++++ .../settings/network/ims/ImsQuery.java | 38 +++++++++++++ .../network/ims/ImsQueryController.java | 37 ++++++++++++ .../network/ims/ImsQuerySystemTtyStat.java | 47 ++++++++++++++++ .../network/ims/ImsQueryTtyOnVolteStat.java | 46 +++++++++++++++ .../network/ims/WifiCallingQueryImsState.java | 16 +++++- .../WifiCallingSuggestionActivity.java | 7 ++- 8 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 src/com/android/settings/network/ims/ImsDirectQuery.java create mode 100644 src/com/android/settings/network/ims/ImsDirectQueryImpl.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/ImsQuerySystemTtyStat.java create mode 100644 src/com/android/settings/network/ims/ImsQueryTtyOnVolteStat.java diff --git a/src/com/android/settings/network/ims/ImsDirectQuery.java b/src/com/android/settings/network/ims/ImsDirectQuery.java new file mode 100644 index 00000000000..4c6a932e125 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsDirectQuery.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 {@code boolean} + */ +public interface ImsDirectQuery { + + /** + * Interface for performing IMS status/configuration query through public APIs + * + * @return result of query in boolean + */ + boolean directQuery(); + +} diff --git a/src/com/android/settings/network/ims/ImsDirectQueryImpl.java b/src/com/android/settings/network/ims/ImsDirectQueryImpl.java new file mode 100644 index 00000000000..cff8461f500 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsDirectQueryImpl.java @@ -0,0 +1,56 @@ +/* + * 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.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.RejectedExecutionException; + + +/** + * An implementation of {@code ImsQuery} and {@code ImsDirectQuery}. + */ +abstract class ImsDirectQueryImpl implements ImsQuery, ImsDirectQuery, Callable { + + /** + * Implementation of interface {@code ImsQuery} + * + * @param executors {@code ExecutorService} which allows to submit {@code ImsQuery} when + * required + * @return result of query in format of {@code Future} + */ + public Future query(ExecutorService executors) throws RejectedExecutionException { + return executors.submit(this); + } + + /** + * Implementation of interface {@code ImsDirectQuery} + * + * @return result of query + */ + public boolean directQuery() { + return call(); + } + + /** + * Query running within a {@code Callable} + * + * @return result of query + */ + public abstract Boolean call(); +} 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..1462718971a --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQuery.java @@ -0,0 +1,38 @@ +/* + * 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.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.RejectedExecutionException; + + +/** + * An interface for querying IMS, and return {@code Future} + */ +public interface ImsQuery { + + /** + * Interface for performing IMS status/configuration query through ExecutorService + * + * @param executors {@code ExecutorService} which allows to submit {@code ImsQuery} when + * required + * @return result of query in format of {@code Future} + */ + Future query(ExecutorService executors) throws RejectedExecutionException; + +} 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..651c4222366 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQueryController.java @@ -0,0 +1,37 @@ +/* + * 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 androidx.annotation.VisibleForTesting; + +/** + * Controller class for querying IMS status + */ +abstract class ImsQueryController { + + @VisibleForTesting + ImsDirectQuery isSystemTtyEnabled(Context context) { + return new ImsQuerySystemTtyStat(context); + } + + @VisibleForTesting + ImsDirectQuery isTtyOnVolteEnabled(int subId) { + return new ImsQueryTtyOnVolteStat(subId); + } +} diff --git a/src/com/android/settings/network/ims/ImsQuerySystemTtyStat.java b/src/com/android/settings/network/ims/ImsQuerySystemTtyStat.java new file mode 100644 index 00000000000..4239b16e220 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQuerySystemTtyStat.java @@ -0,0 +1,47 @@ +/* + * 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; + + +/** + * An {@code ImsQuery} for accessing system TTY stat + */ +public class ImsQuerySystemTtyStat extends ImsDirectQueryImpl { + + /** + * Constructor + * @param context context of activity + */ + public ImsQuerySystemTtyStat(Context context) { + mContext = context; + } + + private volatile Context mContext; + + /** + * Query running within a {@code Callable} + * + * @return result of query + */ + public Boolean call() { + final TelecomManager telecomManager = mContext.getSystemService(TelecomManager.class); + return (telecomManager.getCurrentTtyMode() != TelecomManager.TTY_MODE_OFF); + } +} 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..a371ce7d080 --- /dev/null +++ b/src/com/android/settings/network/ims/ImsQueryTtyOnVolteStat.java @@ -0,0 +1,46 @@ +/* + * 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; + + +/** + * An {@code ImsQuery} for accessing IMS tty on VoLte stat + */ +public class ImsQueryTtyOnVolteStat extends ImsDirectQueryImpl { + + /** + * Constructor + * @param subId subscription id + */ + public ImsQueryTtyOnVolteStat(int subId) { + mSubId = subId; + } + + private volatile int mSubId; + + /** + * Query running within a {@code Callable} + * + * @return result of query + */ + public Boolean call() { + final ImsMmTelManager imsMmTelManager = ImsMmTelManager.createForSubscriptionId(mSubId); + return imsMmTelManager.isTtyOverVolteEnabled(); + } +} diff --git a/src/com/android/settings/network/ims/WifiCallingQueryImsState.java b/src/com/android/settings/network/ims/WifiCallingQueryImsState.java index 99009153615..b41cb260fd0 100644 --- a/src/com/android/settings/network/ims/WifiCallingQueryImsState.java +++ b/src/com/android/settings/network/ims/WifiCallingQueryImsState.java @@ -25,7 +25,7 @@ import com.android.settings.network.SubscriptionUtil; /** * Controller class for querying Wifi calling status */ -public class WifiCallingQueryImsState { +public class WifiCallingQueryImsState extends ImsQueryController { private Context mContext; private int mSubId; @@ -41,6 +41,20 @@ public class WifiCallingQueryImsState { mSubId = subId; } + /** + * 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 ((!isSystemTtyEnabled(mContext).directQuery()) + || (isTtyOnVolteEnabled(mSubId).directQuery())); + } + /** * Get user's configuration * diff --git a/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java b/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java index 526e9c3c71e..0e3b8872d27 100644 --- a/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java +++ b/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java @@ -21,17 +21,20 @@ import android.telephony.SubscriptionManager; import com.android.ims.ImsManager; import com.android.settings.SettingsActivity; +import com.android.settings.network.ims.WifiCallingQueryImsState; import com.android.settings.network.telephony.MobileNetworkUtils; public class WifiCallingSuggestionActivity extends SettingsActivity { public static boolean isSuggestionComplete(Context context) { + final WifiCallingQueryImsState queryState = + new WifiCallingQueryImsState(context, + SubscriptionManager.getDefaultVoiceSubscriptionId()); if (!ImsManager.isWfcEnabledByPlatform(context) || !MobileNetworkUtils.isWfcProvisionedOnDevice( SubscriptionManager.getDefaultVoiceSubscriptionId())) { return true; } - return ImsManager.isWfcEnabledByUser(context) - && ImsManager.isNonTtyOrTtyOnVolteEnabled(context); + return queryState.isEnabledByUser() && queryState.isAllowUserControl(); } }