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

Commit d9ac861a authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Merge "Tweaks to the call blocking options."

am: 49b3bc6f

Change-Id: I17e0fb64282f573e62a49b2bc208ed410df103d3
parents 4a3c8602 49b3bc6f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -69,4 +69,12 @@
         classified as being on a user's ear. If the Y-component is less than this negative value,
         the device is probably upside-down and therefore not on a ear -->
    <item name="device_on_ear_y_gravity_negative_threshold" format="float" type="dimen">-1</item>

    <!-- When true, an option is shown in the call blocking screen which allows the user to block
         all incoming calls from callers not in their contacts. -->
    <bool name="show_option_to_block_callers_not_in_contacts">false</bool>

    <!-- When true, the options in the call blocking settings to block restricted and unknown
         callers are combined into a single toggle. -->
    <bool name="combine_options_to_block_restricted_and_unknown_callers">true</bool>
</resources>
+36 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.preference.SwitchPreference;
import android.provider.BlockedNumberContract.SystemContract;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telecom.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@@ -35,12 +36,21 @@ import com.android.server.telecom.R;

public class EnhancedCallBlockingFragment extends PreferenceFragment
        implements Preference.OnPreferenceChangeListener {
    private static final String BLOCK_NUMBERS_NOT_IN_CONTACTS_KEY =
            "block_numbers_not_in_contacts_setting";
    private static final String BLOCK_RESTRICTED_NUMBERS_KEY =
            "block_private_number_calls_setting";
    private static final String BLOCK_UNKNOWN_NUMBERS_KEY =
            "block_unknown_calls_setting";
    private boolean mIsCombiningRestrictedAndUnknownOption = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.enhanced_call_blocking_settings);

        maybeConfigureCallBlockingOptions();

        setOnPreferenceChangeListener(SystemContract.ENHANCED_SETTING_KEY_BLOCK_UNREGISTERED);
        setOnPreferenceChangeListener(SystemContract.ENHANCED_SETTING_KEY_BLOCK_PRIVATE);
        setOnPreferenceChangeListener(SystemContract.ENHANCED_SETTING_KEY_BLOCK_PAYPHONE);
@@ -67,6 +77,25 @@ public class EnhancedCallBlockingFragment extends PreferenceFragment
        return b.getBoolean(CarrierConfigManager.KEY_SHOW_BLOCKING_PAY_PHONE_OPTION_BOOL);
    }

    private void maybeConfigureCallBlockingOptions() {
        PreferenceScreen screen = getPreferenceScreen();
        boolean isShowingNotInContactsOption =
                getResources().getBoolean(R.bool.show_option_to_block_callers_not_in_contacts);
        if (!isShowingNotInContactsOption) {
            Preference pref = findPreference(BLOCK_NUMBERS_NOT_IN_CONTACTS_KEY);
            screen.removePreference(pref);
            Log.i(this, "onCreate: removed block not in contacts preference.");
        }

        mIsCombiningRestrictedAndUnknownOption = getResources().getBoolean(
                        R.bool.combine_options_to_block_restricted_and_unknown_callers);
        if (mIsCombiningRestrictedAndUnknownOption) {
            Preference pref = findPreference(BLOCK_RESTRICTED_NUMBERS_KEY);
            screen.removePreference(pref);
            Log.i(this, "onCreate: removed block restricted preference.");
        }
    }

    /**
     * Set OnPreferenceChangeListener for the preference.
     */
@@ -101,6 +130,13 @@ public class EnhancedCallBlockingFragment extends PreferenceFragment

    @Override
    public boolean onPreferenceChange(Preference preference, Object objValue) {
        if (mIsCombiningRestrictedAndUnknownOption
                && preference.getKey().equals(BLOCK_UNKNOWN_NUMBERS_KEY)) {
            Log.i(this, "onPreferenceChange: changing %s and %s to %b",
                    preference.getKey(), BLOCK_RESTRICTED_NUMBERS_KEY, (boolean) objValue);
            BlockedNumbersUtil.setEnhancedBlockSetting(getActivity(), BLOCK_RESTRICTED_NUMBERS_KEY,
                    (boolean) objValue);
        }
        BlockedNumbersUtil.setEnhancedBlockSetting(getActivity(), preference.getKey(),
                (boolean) objValue);
        return true;