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

Commit 9df42c36 authored by Hall Liu's avatar Hall Liu Committed by Tyler Gunn
Browse files

Tweaks to the call blocking options.

1. Add option for device to hide the "block callers not in contacts" option;
there was a large potential for the user to accidentally block too many
calls.  The dialer app would need to do some work to ensure it makes the
user aware of the fact that they're blocking large numbers of calls.
Since this is not mandatory per the CDD requirements, making this a
configurable option.  This way a device can choose to use this feature and
provide a good user experience around exposing the blocked calls.
2. Add an option for a device to combine the block options for "restricted" and
"unknown" callers options.  Conceptually most users won't recognize the
difference between the two types of calls, so it makes sense to combine
them in a generic sense unless there is a strong desire for a device to
support separating these options.

Test: Manual; verified that "not in contacts" option is hidden.
Test: Manual; verified that toggling the option to combine the unknown
and restricted options updates the shared prefs for both.
Fixes: 129353233

Merged-In: I3561c9fdfebad9719bb80e6c6b8fa661ec18f32c
Change-Id: I3561c9fdfebad9719bb80e6c6b8fa661ec18f32c
(cherry picked from commit abbe75d6)
parent 6f344256
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -66,4 +66,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;