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

Commit 0a66946d authored by Doris Ling's avatar Doris Ling
Browse files

Use a different string for vpn summary.

- for legacy vpn config, we do not get the vpn name to show in the
preference summary, and we used to simply show "Connected" as the summary
text. However, the string was changed to include the connected device
name as the parameter. Change to use connected summary string that does
not requires any parameter.

Change-Id: Ia6191eb315f5f23e0e6bf8da2a9537c211e8188e
Fixes: 77618408
Test: make RunSettingsRoboTests
parent e6750d6c
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -159,9 +159,10 @@ public class VpnPreferenceController extends AbstractPreferenceController
        ThreadUtils.postOnMainThread(() -> mPreference.setSummary(summary));
    }

    private String getNameForVpnConfig(VpnConfig cfg, UserHandle user) {
    @VisibleForTesting
    String getNameForVpnConfig(VpnConfig cfg, UserHandle user) {
        if (cfg.legacy) {
            return mContext.getString(R.string.bluetooth_connected);
            return mContext.getString(R.string.wifi_display_status_connected);
        }
        // The package name for an active VPN is stored in the 'user' field of its VpnConfig
        final String vpnPackage = cfg.user;
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.network;

import static com.google.common.truth.Truth.assertThat;
import static android.arch.lifecycle.Lifecycle.Event.ON_PAUSE;
import static android.arch.lifecycle.Lifecycle.Event.ON_RESUME;
import static org.mockito.Matchers.any;
@@ -31,9 +32,11 @@ import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.NetworkRequest;
import android.os.IBinder;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.internal.net.VpnConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;

@@ -42,6 +45,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowServiceManager;

@RunWith(SettingsRobolectricTestRunner.class)
@@ -99,4 +103,16 @@ public class VpnPreferenceControllerTest {
        verify(mConnectivityManager).unregisterNetworkCallback(
                any(ConnectivityManager.NetworkCallback.class));
    }

    @Test
    public void getNameForVpnConfig_legacyVPNConfig_shouldSetSummaryToConnected() {
        final VpnConfig config = new VpnConfig();
        config.legacy = true;
        final VpnPreferenceController controller =
                new VpnPreferenceController(RuntimeEnvironment.application);

        final String summary = controller.getNameForVpnConfig(config, UserHandle.CURRENT);

        assertThat(summary).isEqualTo("Connected");
    }
}