[Wi-Fi] Add IMSI privacy protection warning summary

If a SIM based Wi-Fi network is not provided with IMSI
protection, Wi-Fi detail UI shows the warning summary if
the Wi-Fi network is connected.

Bug: 148283447
Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiSecondSummaryController2Test
      make RunSettingsRoboTests ROBOTEST_FILTER=LinkifySummaryPreferenceTest

Change-Id: I689a75d2f0a2ae6196b2ed5985b8ff141fbac8b4
This commit is contained in:
Arc Wang
2020-04-17 11:13:34 +08:00
parent f11da4c787
commit c6c4d036da
8 changed files with 289 additions and 6 deletions

View File

@@ -0,0 +1,99 @@
/*
* Copyright (C) 2020 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.widget;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.view.View;
import android.widget.TextView;
import androidx.preference.PreferenceViewHolder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class LinkifySummaryPreferenceTest {
@Spy
private PreferenceViewHolder mViewHolder;
@Mock
private TextView mSummaryTextView;
private LinkifySummaryPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final Context context = RuntimeEnvironment.application;
mPreference = new LinkifySummaryPreference(context, null /* attrs */);
final View view = spy(View.inflate(context, mPreference.getLayoutResource(),
null /* root */));
mViewHolder = spy(PreferenceViewHolder.createInstanceForTests(view));
doReturn(mSummaryTextView).when(mViewHolder).findViewById(android.R.id.summary);
}
@Test
public void onBindViewHolder_summaryTextViewGone_shouldNotSetMovementMethod() {
when(mSummaryTextView.getVisibility()).thenReturn(View.GONE);
mPreference.onBindViewHolder(mViewHolder);
verify(mSummaryTextView, never()).setMovementMethod(LinkMovementMethod.getInstance());
}
@Test
public void onBindViewHolder_noLinkSummary_shouldNotSetMovementMethod() {
when(mSummaryTextView.getVisibility()).thenReturn(View.VISIBLE);
final CharSequence seondSummary = "secondSummary";
mPreference.setSummary(seondSummary);
mPreference.onBindViewHolder(mViewHolder);
verify(mSummaryTextView, never()).setMovementMethod(LinkMovementMethod.getInstance());
}
@Test
public void onBindViewHolder_linkedSummary_shouldSetMovementMethod() {
when(mSummaryTextView.getVisibility()).thenReturn(View.VISIBLE);
final CharSequence seondSummary = "secondSummary";
final SpannableStringBuilder summaryBuilder = new SpannableStringBuilder();
summaryBuilder.append(seondSummary, new URLSpan("" /* url */),
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
mPreference.setSummary(summaryBuilder);
mPreference.onBindViewHolder(mViewHolder);
verify(mSummaryTextView).setMovementMethod(any(LinkMovementMethod.class));
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (C) 2020 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.wifi.details2;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import com.android.wifitrackerlib.WifiEntry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class WifiSecondSummaryController2Test {
private WifiSecondSummaryController2 mController;
@Mock
private WifiEntry mWifiEntry;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new WifiSecondSummaryController2(RuntimeEnvironment.application);
}
@Test
public void getAvailabilityStatus_showWhenSummaryAvailable() {
// Visible when summary is not empty.
when(mWifiEntry.getSecondSummary()).thenReturn("test");
mController.setWifiEntry(mWifiEntry);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
// Invisible when summary is empty.
when(mWifiEntry.getSecondSummary()).thenReturn("");
mController.setWifiEntry(mWifiEntry);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
}