[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

@@ -31,10 +31,18 @@
android:selectable="false" android:selectable="false"
settings:isPreferenceVisible="false"/> settings:isPreferenceVisible="false"/>
<!-- The preference to display the second summary -->
<com.android.settings.widget.LinkifySummaryPreference
android:key="second_summary"
android:icon="@drawable/ic_info_outline_24dp"
android:selectable="false"
settings:allowDividerAbove="false"/>
<!-- Buttons --> <!-- Buttons -->
<com.android.settingslib.widget.ActionButtonsPreference <com.android.settingslib.widget.ActionButtonsPreference
android:key="buttons" android:key="buttons"
android:selectable="false" /> android:selectable="false"
settings:allowDividerAbove="true"/>
<!-- General Details Preferences --> <!-- General Details Preferences -->
<Preference <Preference

View File

@@ -374,7 +374,6 @@ public class EntityHeaderController {
} }
} }
private void setText(@IdRes int id, CharSequence text) { private void setText(@IdRes int id, CharSequence text) {
TextView textView = mHeader.findViewById(id); TextView textView = mHeader.findViewById(id);
if (textView != null) { if (textView != null) {

View File

@@ -0,0 +1,60 @@
/*
* 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 android.content.Context;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
/** A preference which supports linkify text in the summary **/
public class LinkifySummaryPreference extends Preference {
public LinkifySummaryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LinkifySummaryPreference(Context context) {
super(context);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
if (summaryView == null || summaryView.getVisibility() != View.VISIBLE) {
return;
}
final CharSequence summary = getSummary();
if (!TextUtils.isEmpty(summary)) {
final SpannableString spannableSummary = new SpannableString(summary);
if (spannableSummary.getSpans(0, spannableSummary.length(), ClickableSpan.class)
.length > 0) {
summaryView.setMovementMethod(LinkMovementMethod.getInstance());
}
}
}
}

View File

@@ -446,10 +446,8 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
if (usingDataUsageHeader(mContext)) { if (usingDataUsageHeader(mContext)) {
mSummaryHeaderController.updateState(mDataUsageSummaryPref); mSummaryHeaderController.updateState(mDataUsageSummaryPref);
} else { } else {
String summary = mWifiEntry.getSummary();
mEntityHeaderController mEntityHeaderController
.setSummary(summary) .setSummary(mWifiEntry.getSummary())
.setSecondSummary(getExpiryTimeSummary()) .setSecondSummary(getExpiryTimeSummary())
.setRecyclerView(mFragment.getListView(), mLifecycle) .setRecyclerView(mFragment.getListView(), mLifecycle)
.done(mFragment.getActivity(), true /* rebind */); .done(mFragment.getActivity(), true /* rebind */);

View File

@@ -140,7 +140,7 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
getContext().getSystemService(Context.DEVICE_POLICY_SERVICE); getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
final UserManager um = (UserManager) final UserManager um = (UserManager)
getContext().getSystemService(Context.USER_SERVICE); getContext().getSystemService(Context.USER_SERVICE);
int profileOwnerUserId = Utils.getManagedProfileId( final int profileOwnerUserId = Utils.getManagedProfileId(
um, UserHandle.myUserId()); um, UserHandle.myUserId());
admin = new EnforcedAdmin(dpm.getProfileOwnerAsUser(profileOwnerUserId), admin = new EnforcedAdmin(dpm.getProfileOwnerAsUser(profileOwnerUserId),
null, UserHandle.of(profileOwnerUserId)); null, UserHandle.of(profileOwnerUserId));
@@ -162,6 +162,11 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
setupNetworksDetailTracker(); setupNetworksDetailTracker();
final WifiEntry wifiEntry = mNetworkDetailsTracker.getWifiEntry(); final WifiEntry wifiEntry = mNetworkDetailsTracker.getWifiEntry();
final WifiSecondSummaryController2 wifiSecondSummaryController2 =
new WifiSecondSummaryController2(context);
wifiSecondSummaryController2.setWifiEntry(wifiEntry);
mControllers.add(wifiSecondSummaryController2);
mWifiDetailPreferenceController2 = WifiDetailPreferenceController2.newInstance( mWifiDetailPreferenceController2 = WifiDetailPreferenceController2.newInstance(
wifiEntry, wifiEntry,
cm, cm,

View File

@@ -0,0 +1,51 @@
/*
* 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 android.content.Context;
import android.text.TextUtils;
import com.android.settings.core.BasePreferenceController;
import com.android.wifitrackerlib.WifiEntry;
/**
* {@link BasePreferenceController} that display the second summary. If users click the preference,
* @link ClickableSpan#onClick} of the first {@link ClickableSpan} in the summary will be called.
*/
public class WifiSecondSummaryController2 extends BasePreferenceController {
private static final String KEY_WIFI_SECOND_SUMMARY = "second_summary";
private CharSequence mSecondSummary;
public WifiSecondSummaryController2(Context context) {
super(context, KEY_WIFI_SECOND_SUMMARY);
}
public void setWifiEntry(WifiEntry wifiEntry) {
mSecondSummary = wifiEntry.getSecondSummary();
}
@Override
public int getAvailabilityStatus() {
return TextUtils.isEmpty(mSecondSummary) ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
}
@Override
public CharSequence getSummary() {
return mSecondSummary;
}
}

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);
}
}