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

Commit e8e3f41d authored by Nikki Moteva's avatar Nikki Moteva Committed by Android (Google) Code Review
Browse files

Merge "Settings: add a new Location off footer string" into main

parents fe537f1b 4c9f1135
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -792,11 +792,15 @@
        Apps with the nearby devices permission can determine the
        relative position of connected devices.
    </string>
    <!-- Location settings footer warning text when location is off [CHAR LIMIT=NONE] -->
    <string name="location_settings_footer_location_off">
    <!-- Location settings footer warning text when location is off and calling and messaging are supported [CHAR LIMIT=NONE] -->
    <string name="location_settings_footer_location_off_with_telephony">
        Location access is off for apps and services. Your device location may still be sent to
        emergency responders when you contact an emergency number.
    </string>
    <!-- Location settings footer warning text when location is off and calling and messaging are not supported [CHAR LIMIT=NONE] -->
    <string name="location_settings_footer_location_off_no_telephony">
        Location access is off for apps and services.
    </string>
    <!-- Location settings footer link to support page [CHAR LIMIT=NONE] -->
    <string name="location_settings_footer_learn_more_link" translatable="false">
        https://support.google.com/android/answer/3467281
+18 −7
Original line number Diff line number Diff line
@@ -93,19 +93,30 @@ public class LocationSettingsFooterPreferenceController extends LocationBasePref
    }

    private void updateFooterPreference() {
        String footerString = mContext.getString(R.string.location_settings_footer_general);
        StringBuilder footerString = new StringBuilder();
        if (mLocationEnabled) {
            if (!TextUtils.isEmpty(mInjectedFooterString)) {
                footerString = Html.escapeHtml(mInjectedFooterString) + PARAGRAPH_SEPARATOR
                        + footerString;
                footerString.append(Html.escapeHtml(mInjectedFooterString) + PARAGRAPH_SEPARATOR);
            }
        } else {
            footerString = mContext.getString(R.string.location_settings_footer_location_off)
                    + PARAGRAPH_SEPARATOR
                    + footerString;
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CALLING)
                    || mPackageManager.hasSystemFeature(
                            PackageManager.FEATURE_TELEPHONY_MESSAGING)) {
                footerString.append(
                        mContext.getString(
                                R.string.location_settings_footer_location_off_with_telephony));
            } else {
                footerString.append(
                        mContext.getString(
                                R.string.location_settings_footer_location_off_no_telephony));
            }
            footerString.append(PARAGRAPH_SEPARATOR);
        }

        footerString.append(mContext.getString(R.string.location_settings_footer_general));

        if (mFooterPreference != null) {
            mFooterPreference.setTitle(Html.fromHtml(footerString));
            mFooterPreference.setTitle(Html.fromHtml(footerString.toString()));
            mFooterPreference.setLearnMoreAction(v -> openLocationLearnMoreLink());
            mFooterPreference.setLearnMoreText(mContext.getString(
                    R.string.location_settings_footer_learn_more_content_description));
+74 −19
Original line number Diff line number Diff line
@@ -149,38 +149,64 @@ public class LocationSettingsFooterPreferenceControllerTest {
    }

    @Test
    public void onLocationModeChanged_off_setTitle() {
        final List<ResolveInfo> testResolveInfos = new ArrayList<>();
        testResolveInfos.add(
                getTestResolveInfo(/*isSystemApp*/ true, /*hasRequiredMetadata*/ true));
        when(mPackageManager.queryBroadcastReceivers(any(Intent.class), anyInt()))
                .thenReturn(testResolveInfos);
        mController.updateState(mFooterPreference);
        verify(mFooterPreference).setTitle(any());
        mController.onLocationModeChanged(/* mode= */ 0, /* restricted= */ false);
    public void onLocationModeChanged_off_withTelephonyMessagingOn_setTitle() {
        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING))
                .thenReturn(true);

        setUpLocationModeChanged(false);
        assertLocationFooter(R.string.location_settings_footer_location_off_with_telephony);
    }

    @Test
    public void onLocationModeChanged_off_withTelephonyCallingOn_setTitle() {
        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CALLING))
                .thenReturn(true);

        setUpLocationModeChanged(false);
        assertLocationFooter(R.string.location_settings_footer_location_off_with_telephony);
    }

    @Test
    public void onLocationModeChanged_off_noTelephony_setTitle() {
        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY))
                .thenReturn(false);

        setUpLocationModeChanged(false);
        assertLocationFooter(R.string.location_settings_footer_location_off_no_telephony);
    }

    @Test
    public void onLocationModeChanged_on_setTitle() {
        setUpLocationModeChanged(true);

        ArgumentCaptor<CharSequence> title = ArgumentCaptor.forClass(CharSequence.class);
        verify(mFooterPreference, times(2)).setTitle(title.capture());

        assertThat(title.getValue().toString()).contains(
        assertThat(title.getValue().toString()).doesNotContain(
                Html.fromHtml(mContext.getString(
                        R.string.location_settings_footer_location_off)).toString());
                        R.string.location_settings_footer_location_off_with_telephony)).toString());
        assertThat(title.getValue().toString()).doesNotContain(
                Html.fromHtml(mContext.getString(
                        R.string.location_settings_footer_location_off_no_telephony)).toString());
    }

    @Test
    public void onLocationModeChanged_on_setTitle() {
    public void onLocationModeChanged_on_withoutInjectedString_setTitle() {
        final List<ResolveInfo> testResolveInfos = new ArrayList<>();
        testResolveInfos.add(
                getTestResolveInfo(/*isSystemApp*/ true, /*hasRequiredMetadata*/ true));
                getTestResolveInfo(/*isSystemApp*/ false, /*hasRequiredMetadata*/ true));
        when(mPackageManager.queryBroadcastReceivers(any(Intent.class), anyInt()))
                .thenReturn(testResolveInfos);
        assertThat(mController.isAvailable()).isTrue();
        mController.updateState(mFooterPreference);
        verify(mFooterPreference).setTitle(any());
        mController.onLocationModeChanged(/* mode= */ 1, /* restricted= */ false);
        mController.onLocationModeChanged(1, /* restricted= */ false);

        ArgumentCaptor<CharSequence> title = ArgumentCaptor.forClass(CharSequence.class);
        verify(mFooterPreference, times(2)).setTitle(title.capture());
        assertThat(title.getValue().toString()).doesNotContain(
                Html.fromHtml(mContext.getString(
                        R.string.location_settings_footer_location_off)).toString());
        verify(mFooterPreference, times(1)).setTitle(title.capture());
        assertThat(title.getValue().toString())
                .isEqualTo(
                        Html.fromHtml(mContext.getString(R.string.location_settings_footer_general))
                                .toString());
    }

    @Test
@@ -218,4 +244,33 @@ public class LocationSettingsFooterPreferenceControllerTest {
        testResolveInfo.activityInfo = testActivityInfo;
        return testResolveInfo;
    }

    /**
     * Sets up the location mode to the given status.
     * @param locationEnabled Whether the location mode is on or off.
     */
    private void setUpLocationModeChanged(boolean locationEnabled) {
        final List<ResolveInfo> testResolveInfos = new ArrayList<>();
        testResolveInfos.add(
                getTestResolveInfo(/*isSystemApp*/ true, /*hasRequiredMetadata*/ true));
        when(mPackageManager.queryBroadcastReceivers(any(Intent.class), anyInt()))
                .thenReturn(testResolveInfos);
        mController.updateState(mFooterPreference);
        verify(mFooterPreference).setTitle(any());
        mController.onLocationModeChanged(locationEnabled ? 1 : 0, /* restricted= */ false);
    }

    /**
     * Asserts that the location footer exists and contains the given string.
     * @param footerStringId The string resource id to assert.
     */
    private void assertLocationFooter(int footerStringId) {
        ArgumentCaptor<CharSequence> title = ArgumentCaptor.forClass(CharSequence.class);
        verify(mFooterPreference, times(2)).setTitle(title.capture());
        assertThat(title.getValue().toString())
                .isEqualTo(
                        Html.fromHtml(mContext.getString(footerStringId)).toString()
                                + "\n\n"
                                + mContext.getString(R.string.location_settings_footer_general));
    }
}