Refactor wifi calling and video calling
Also add a Callback for 4gLte to notify update to video calling preference controller Bug: 114749736 Test: RunSettingsRoboTests Change-Id: I0b5009733251162327f02ccfae8b10ae56b961bc
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.telephony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Looper;
|
||||
import android.telecom.PhoneAccountHandle;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.ims.ImsConfig;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Preference controller for "Wifi Calling"
|
||||
*/
|
||||
public class WifiCallingPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@VisibleForTesting
|
||||
ImsManager mImsManager;
|
||||
@VisibleForTesting
|
||||
PhoneAccountHandle mSimCallManager;
|
||||
private PhoneCallStateListener mPhoneStateListener;
|
||||
private Preference mPreference;
|
||||
private int mSubId;
|
||||
|
||||
public WifiCallingPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||
mSimCallManager = context.getSystemService(TelecomManager.class).getSimCallManager();
|
||||
mPhoneStateListener = new PhoneCallStateListener(Looper.getMainLooper());
|
||||
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
&& MobileNetworkUtils.isWifiCallingEnabled(mContext,
|
||||
SubscriptionManager.getPhoneId(mSubId))
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mPhoneStateListener.register(mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mPhoneStateListener.unregister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
if (mSimCallManager != null) {
|
||||
Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
||||
mSimCallManager);
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
|
||||
preference.setTitle(resolutions.get(0).loadLabel(pm));
|
||||
preference.setSummary(null);
|
||||
preference.setIntent(intent);
|
||||
} else {
|
||||
int resId = com.android.internal.R.string.wifi_calling_off_summary;
|
||||
if (mImsManager.isWfcEnabledByUser()) {
|
||||
final boolean isRoaming = mTelephonyManager.isNetworkRoaming();
|
||||
int wfcMode = mImsManager.getWfcMode(isRoaming);
|
||||
|
||||
switch (wfcMode) {
|
||||
case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
|
||||
resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
|
||||
break;
|
||||
case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
|
||||
resId = com.android.internal.R.string
|
||||
.wfc_mode_cellular_preferred_summary;
|
||||
break;
|
||||
case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
|
||||
resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
preference.setSummary(resId);
|
||||
}
|
||||
preference.setEnabled(
|
||||
mTelephonyManager.getCallState(mSubId) == TelephonyManager.CALL_STATE_IDLE);
|
||||
}
|
||||
|
||||
public void init(int subId) {
|
||||
mSubId = subId;
|
||||
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
||||
mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId));
|
||||
}
|
||||
|
||||
private class PhoneCallStateListener extends PhoneStateListener {
|
||||
|
||||
public PhoneCallStateListener(Looper looper) {
|
||||
super(looper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCallStateChanged(int state, String incomingNumber) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
public void register(int subId) {
|
||||
mSubId = subId;
|
||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user