Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9cbca4bc authored by Stanley Wang's avatar Stanley Wang
Browse files

Fix can't find the search result by input "4G Calling"

Add indexable raw data for type 4G_CALLING or ADVANCED_CALL and
set the volte to non-indexable if current type is not volte.

Fixes: 137155154
Test: manual

Change-Id: I0992f9fb95e0b1cc23fb4f38f356ee0569f3b5b1
parent 5f10a9a9
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -53,6 +53,22 @@
        settings:keywords="@string/keywords_enhance_4g_lte"
        settings:controller="com.android.settings.network.telephony.Enhanced4gLtePreferenceController"/>

    <SwitchPreference
        android:key="4g_calling"
        android:title="@string/enhanced_4g_lte_mode_title_4g_calling"
        android:persistent="false"
        android:summary="@string/enhanced_4g_lte_mode_summary_4g_calling"
        settings:keywords="@string/keywords_enhance_4g_lte"
        settings:controller="com.android.settings.network.telephony.Enhanced4gCallingPreferenceController"/>

    <SwitchPreference
        android:key="advance_call"
        android:title="@string/enhanced_4g_lte_mode_title_advanced_calling"
        android:persistent="false"
        android:summary="@string/enhanced_4g_lte_mode_summary"
        settings:keywords="@string/keywords_enhance_4g_lte"
        settings:controller="com.android.settings.network.telephony.Enhanced4gAdvancedCallingPreferenceController"/>

    <ListPreference
        android:key="preferred_network_mode_key"
        android:title="@string/preferred_network_mode_title"
+16 −0
Original line number Diff line number Diff line
@@ -100,6 +100,22 @@
            settings:keywords="@string/keywords_enhance_4g_lte"
            settings:controller="com.android.settings.network.telephony.Enhanced4gLtePreferenceController"/>

        <SwitchPreference
            android:key="4g_calling"
            android:title="@string/enhanced_4g_lte_mode_title_4g_calling"
            android:persistent="false"
            android:summary="@string/enhanced_4g_lte_mode_summary_4g_calling"
            settings:keywords="@string/keywords_enhance_4g_lte"
            settings:controller="com.android.settings.network.telephony.Enhanced4gCallingPreferenceController"/>

        <SwitchPreference
            android:key="advance_call"
            android:title="@string/enhanced_4g_lte_mode_title_advanced_calling"
            android:persistent="false"
            android:summary="@string/enhanced_4g_lte_mode_summary"
            settings:keywords="@string/keywords_enhance_4g_lte"
            settings:controller="com.android.settings.network.telephony.Enhanced4gAdvancedCallingPreferenceController"/>

        <ListPreference
            android:key="preferred_network_mode_key"
            android:title="@string/preferred_network_mode_title"
+35 −0
Original line number Diff line number Diff line
/*
 * 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 android.content.Context;

/**
 * Preference controller for "Advance Calling"
 */
public class Enhanced4gAdvancedCallingPreferenceController extends
        Enhanced4gBasePreferenceController {

    public Enhanced4gAdvancedCallingPreferenceController(Context context, String key) {
        super(context, key);
    }

    @Override
    protected int getMode() {
        return MODE_ADVANCED_CALL;
    }
}
+196 −0
Original line number Diff line number Diff line
/*
 * 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 android.content.Context;
import android.os.Looper;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
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 androidx.preference.SwitchPreference;

import com.android.ims.ImsManager;
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.ArrayList;
import java.util.List;

/**
 * Preference controller for "Enhanced 4G LTE"
 */
public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenceController
        implements LifecycleObserver, OnStart, OnStop {

    private Preference mPreference;
    private TelephonyManager mTelephonyManager;
    private CarrierConfigManager mCarrierConfigManager;
    private PersistableBundle mCarrierConfig;
    @VisibleForTesting
    ImsManager mImsManager;
    private PhoneCallStateListener mPhoneStateListener;
    private final List<On4gLteUpdateListener> m4gLteListeners;

    protected static final int MODE_NONE = -1;
    protected static final int MODE_VOLTE = 0;
    protected static final int MODE_ADVANCED_CALL = 1;
    protected static final int MODE_4G_CALLING = 2;
    private int m4gCurrentMode = MODE_NONE;

    public Enhanced4gBasePreferenceController(Context context, String key) {
        super(context, key);
        mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
        m4gLteListeners = new ArrayList<>();
        mPhoneStateListener = new PhoneCallStateListener(Looper.getMainLooper());
    }

    public Enhanced4gBasePreferenceController init(int subId) {
        if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && mSubId == subId) {
            return this;
        }
        mSubId = subId;
        mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
        mCarrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
        if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId));
        }

        final boolean show4GForLTE = mCarrierConfig.getBoolean(
                CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL);
        m4gCurrentMode = mCarrierConfig.getInt(
                CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_INT);
        if (m4gCurrentMode != MODE_ADVANCED_CALL) {
            m4gCurrentMode = show4GForLTE ? MODE_4G_CALLING : MODE_VOLTE;
        }
        return this;
    }

    @Override
    public int getAvailabilityStatus(int subId) {
        init(subId);
        if (!isModeMatched()) {
            return CONDITIONALLY_UNAVAILABLE;
        }
        final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
        final boolean isVisible = subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
                && mImsManager != null && carrierConfig != null
                && mImsManager.isVolteEnabledByPlatform()
                && mImsManager.isVolteProvisionedOnDevice()
                && MobileNetworkUtils.isImsServiceStateReady(mImsManager)
                && !carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL);
        return isVisible
                ? (isPrefEnabled() ? AVAILABLE : AVAILABLE_UNSEARCHABLE)
                : CONDITIONALLY_UNAVAILABLE;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
    }

    @Override
    public void onStart() {
        mPhoneStateListener.register(mSubId);
    }

    @Override
    public void onStop() {
        mPhoneStateListener.unregister();
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        final SwitchPreference switchPreference = (SwitchPreference) preference;

        switchPreference.setEnabled(isPrefEnabled());
        switchPreference.setChecked(mImsManager.isEnhanced4gLteModeSettingEnabledByUser()
                && mImsManager.isNonTtyOrTtyOnVolteEnabled());
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        mImsManager.setEnhanced4gLteModeSetting(isChecked);
        for (final On4gLteUpdateListener lsn : m4gLteListeners) {
            lsn.on4gLteUpdated();
        }
        return true;
    }

    @Override
    public boolean isChecked() {
        return mImsManager.isEnhanced4gLteModeSettingEnabledByUser();
    }

    public Enhanced4gBasePreferenceController addListener(On4gLteUpdateListener lsn) {
        m4gLteListeners.add(lsn);
        return this;
    }

    protected int getMode() {
        return MODE_NONE;
    }

    private boolean isModeMatched() {
        return m4gCurrentMode == getMode();
    }

    private boolean isPrefEnabled() {
        return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
                && mTelephonyManager.getCallState(mSubId) == TelephonyManager.CALL_STATE_IDLE
                && mImsManager != null
                && mImsManager.isNonTtyOrTtyOnVolteEnabled()
                && mCarrierConfig.getBoolean(
                CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
    }

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

    /**
     * Update other preferences when 4gLte state is changed
     */
    public interface On4gLteUpdateListener {
        void on4gLteUpdated();
    }
}
+34 −0
Original line number Diff line number Diff line
/*
 * 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 android.content.Context;

/**
 * Preference controller for "4G Calling"
 */
public class Enhanced4gCallingPreferenceController extends Enhanced4gBasePreferenceController {

    public Enhanced4gCallingPreferenceController(Context context, String key) {
        super(context, key);
    }

    @Override
    protected int getMode() {
        return MODE_4G_CALLING;
    }
}
Loading