Add a "data during calls" preference
This adds a switch which appears on the SIM details page for any SIMs that aren't the default on for data. It lets the user opt-in to turning on data on this SIM only in the case where there is an active call - this is needed because in some cases the default data SIM may not be able to be used when a call is active on another SIM. Bug: 132114205 Test: make RunSettingsRoboTests Change-Id: Ie44c56e0f486fd93aff411a0ba0e47d3695a4941
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.network.SubscriptionsChangeListener;
|
||||
|
||||
public class DataDuringCallsPreferenceController extends TelephonyTogglePreferenceController
|
||||
implements LifecycleObserver,
|
||||
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
|
||||
|
||||
private SwitchPreference mPreference;
|
||||
private SubscriptionsChangeListener mChangeListener;
|
||||
private TelephonyManager mManager;
|
||||
|
||||
public DataDuringCallsPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mChangeListener = new SubscriptionsChangeListener(mContext, this);
|
||||
}
|
||||
|
||||
public void init(Lifecycle lifecycle, int subId) {
|
||||
this.mSubId = subId;
|
||||
mManager = mContext.getSystemService(TelephonyManager.class).createForSubscriptionId(subId);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_RESUME)
|
||||
public void onResume() {
|
||||
mChangeListener.start();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_PAUSE)
|
||||
public void onPause() {
|
||||
mChangeListener.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mManager.isDataAllowedInVoiceCall();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mManager.setDataAllowedDuringVoiceCall(isChecked);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID ||
|
||||
SubscriptionManager.getDefaultDataSubscriptionId() == mSubId) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
preference.setVisible(isAvailable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {}
|
||||
|
||||
@Override
|
||||
public void onSubscriptionsChanged() {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user