Merge "[Settings] Changes for supporting replacing ImsManager"

This commit is contained in:
Bonian Chen
2020-04-08 03:20:43 +00:00
committed by Gerrit Code Review
15 changed files with 1245 additions and 0 deletions

View File

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

View File

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

View File

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

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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