Snap for 8035399 from a18933a2d1 to tm-release

Change-Id: I20f522b61d0674b8e8f4d822ec2bb262a1e8682e
This commit is contained in:
Android Build Coastguard Worker
2021-12-30 02:09:09 +00:00
6 changed files with 128 additions and 39 deletions

View File

@@ -25,6 +25,7 @@
<uses-permission android:name="android.permission.HARDWARE_TEST" /> <uses-permission android:name="android.permission.HARDWARE_TEST" />
<uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.QUERY_AUDIO_STATE" />
<uses-permission android:name="android.permission.MASTER_CLEAR" /> <uses-permission android:name="android.permission.MASTER_CLEAR" />
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" /> <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" /> <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />

View File

@@ -53,6 +53,7 @@
</LinearLayout> </LinearLayout>
<ListView <ListView
android:id="@+id/cert_list" android:id="@+id/cert_list"
android:nestedScrollingEnabled="true"
style="@style/TrustedCredentialsList"> style="@style/TrustedCredentialsList">
</ListView> </ListView>
</LinearLayout> </LinearLayout>

View File

@@ -18,11 +18,14 @@ package com.android.settings.wifi.dpp;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Intent; import android.content.Intent;
import android.util.EventLog;
import android.util.Log; import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import com.android.settings.R; import com.android.settings.R;
import com.android.settingslib.wifi.WifiRestrictionsCache;
/** /**
* To provision "this" device with specified Wi-Fi network. * To provision "this" device with specified Wi-Fi network.
@@ -37,6 +40,9 @@ public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements
static final String ACTION_ENROLLEE_QR_CODE_SCANNER = static final String ACTION_ENROLLEE_QR_CODE_SCANNER =
"android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER"; "android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER";
@VisibleForTesting
protected WifiRestrictionsCache mWifiRestrictionsCache;
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
return SettingsEnums.SETTINGS_WIFI_DPP_ENROLLEE; return SettingsEnums.SETTINGS_WIFI_DPP_ENROLLEE;
@@ -50,6 +56,14 @@ public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements
return; return;
} }
if (!isWifiConfigAllowed()) {
Log.e(TAG, "The user is not allowed to configure Wi-Fi.");
finish();
EventLog.writeEvent(0x534e4554, "202017876", getApplicationContext().getUserId(),
"The user is not allowed to configure Wi-Fi.");
return;
}
switch (action) { switch (action) {
case ACTION_ENROLLEE_QR_CODE_SCANNER: case ACTION_ENROLLEE_QR_CODE_SCANNER:
String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID); String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);
@@ -61,7 +75,15 @@ public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements
} }
} }
private void showQrCodeScannerFragment(String ssid) { private boolean isWifiConfigAllowed() {
if (mWifiRestrictionsCache == null) {
mWifiRestrictionsCache = WifiRestrictionsCache.getInstance(getApplicationContext());
}
return mWifiRestrictionsCache.isConfigWifiAllowed();
}
@VisibleForTesting
protected void showQrCodeScannerFragment(String ssid) {
WifiDppQrCodeScannerFragment fragment = WifiDppQrCodeScannerFragment fragment =
(WifiDppQrCodeScannerFragment) mFragmentManager.findFragmentByTag( (WifiDppQrCodeScannerFragment) mFragmentManager.findFragmentByTag(
WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER); WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);

View File

@@ -33,6 +33,7 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause; import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume; import com.android.settingslib.core.lifecycle.events.OnResume;
import com.android.settingslib.wifi.WifiEnterpriseRestrictionUtils;
/** /**
* {@link PreferenceControllerMixin} to toggle Wifi Direct preference on Wi-Fi state. * {@link PreferenceControllerMixin} to toggle Wifi Direct preference on Wi-Fi state.
@@ -51,27 +52,17 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
} }
}; };
private final IntentFilter mFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); private final IntentFilter mFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
private final LocationManager mLocationManager;
@VisibleForTesting
final BroadcastReceiver mLocationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (mWifiDirectPref != null) {
updateState(mWifiDirectPref);
}
}
};
private final IntentFilter mLocationFilter =
new IntentFilter(LocationManager.MODE_CHANGED_ACTION);
private Preference mWifiDirectPref; private Preference mWifiDirectPref;
@VisibleForTesting
boolean mIsWifiDirectAllow;
public WifiP2pPreferenceController( public WifiP2pPreferenceController(
Context context, Lifecycle lifecycle, WifiManager wifiManager) { Context context, Lifecycle lifecycle, WifiManager wifiManager) {
super(context); super(context);
mWifiManager = wifiManager; mWifiManager = wifiManager;
mIsWifiDirectAllow = WifiEnterpriseRestrictionUtils.isWifiDirectAllowed(context);
lifecycle.addObserver(this); lifecycle.addObserver(this);
mLocationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE);
} }
@Override @Override
@@ -84,19 +75,17 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
preference.setEnabled(mLocationManager.isLocationEnabled() && mWifiManager.isWifiEnabled()); preference.setEnabled(isWifiP2pAvailable());
} }
@Override @Override
public void onResume() { public void onResume() {
mContext.registerReceiver(mReceiver, mFilter); mContext.registerReceiver(mReceiver, mFilter);
mContext.registerReceiver(mLocationReceiver, mLocationFilter);
} }
@Override @Override
public void onPause() { public void onPause() {
mContext.unregisterReceiver(mReceiver); mContext.unregisterReceiver(mReceiver);
mContext.unregisterReceiver(mLocationReceiver);
} }
@Override @Override
@@ -111,9 +100,11 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
private void togglePreferences() { private void togglePreferences() {
if (mWifiDirectPref != null) { if (mWifiDirectPref != null) {
mWifiDirectPref.setEnabled( mWifiDirectPref.setEnabled(isWifiP2pAvailable());
mWifiManager.isWifiEnabled()
&& mLocationManager.isLocationEnabled());
} }
} }
private boolean isWifiP2pAvailable() {
return mWifiManager.isWifiEnabled() && mIsWifiDirectAllow;
}
} }

View File

@@ -16,16 +16,82 @@
package com.android.settings.wifi.dpp; package com.android.settings.wifi.dpp;
import static com.android.settings.wifi.dpp.WifiDppEnrolleeActivity.ACTION_ENROLLEE_QR_CODE_SCANNER;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Intent;
import com.android.settingslib.wifi.WifiRestrictionsCache;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class WifiDppEnrolleeActivityTest { public class WifiDppEnrolleeActivityTest {
private static final String WIFI_SSID = "wifi-ssid";
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Mock
WifiRestrictionsCache mWifiRestrictionsCache;
@Mock
Intent mIntent;
WifiDppEnrolleeActivity mActivity;
@Before
public void setUp() {
when(mWifiRestrictionsCache.isConfigWifiAllowed()).thenReturn(true);
when(mIntent.getAction()).thenReturn(ACTION_ENROLLEE_QR_CODE_SCANNER);
when(mIntent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID)).thenReturn(WIFI_SSID);
mActivity = spy(Robolectric.setupActivity(WifiDppEnrolleeActivity.class));
mActivity.mWifiRestrictionsCache = mWifiRestrictionsCache;
}
@Test @Test
public void launchActivity_noIntentAction_shouldNotFatalException() { public void launchActivity_noIntentAction_shouldNotFatalException() {
WifiDppEnrolleeActivity wifiDppEnrolleeActivity = WifiDppEnrolleeActivity wifiDppEnrolleeActivity =
Robolectric.setupActivity(WifiDppEnrolleeActivity.class); Robolectric.setupActivity(WifiDppEnrolleeActivity.class);
} }
@Test
public void handleIntent_noIntentAction_shouldFinish() {
when(mIntent.getAction()).thenReturn(null);
mActivity.handleIntent(mIntent);
verify(mActivity).finish();
}
@Test
public void handleIntent_notAllowedConfigWifi_shouldFinish() {
when(mWifiRestrictionsCache.isConfigWifiAllowed()).thenReturn(false);
mActivity.handleIntent(mIntent);
verify(mActivity).finish();
}
@Test
public void handleIntent_hasIntentDataAndAllowedConfigWifi_shouldShowFragment() {
when(mWifiRestrictionsCache.isConfigWifiAllowed()).thenReturn(true);
doNothing().when(mActivity).showQrCodeScannerFragment(WIFI_SSID);
mActivity.handleIntent(mIntent);
verify(mActivity).showQrCodeScannerFragment(WIFI_SSID);
}
} }

View File

@@ -32,8 +32,9 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.location.LocationManager;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -56,12 +57,15 @@ public class WifiP2PPreferenceControllerTest {
private Context mContext; private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS) @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private WifiManager mWifiManager; private WifiManager mWifiManager;
@Mock
private UserManager mUserManager;
@Mock
private Bundle mBundle;
@Mock @Mock
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
@Mock @Mock
private Preference mWifiDirectPreference; private Preference mWifiDirectPreference;
@Mock
private LocationManager mLocationManager;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
@@ -74,8 +78,11 @@ public class WifiP2PPreferenceControllerTest {
mLifecycle = new Lifecycle(mLifecycleOwner); mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager); when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
when(mScreen.findPreference(anyString())).thenReturn(mWifiDirectPreference); when(mScreen.findPreference(anyString())).thenReturn(mWifiDirectPreference);
when(mContext.getSystemService(eq(Service.LOCATION_SERVICE))).thenReturn(mLocationManager); when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.getUserRestrictions()).thenReturn(mBundle);
when(mWifiManager.isWifiEnabled()).thenReturn(true);
mController = new WifiP2pPreferenceController(mContext, mLifecycle, mWifiManager); mController = new WifiP2pPreferenceController(mContext, mLifecycle, mWifiManager);
mController.mIsWifiDirectAllow = true;
} }
@Test @Test
@@ -86,21 +93,19 @@ public class WifiP2PPreferenceControllerTest {
@Test @Test
public void testOnResume_shouldRegisterListener() { public void testOnResume_shouldRegisterListener() {
mLifecycle.handleLifecycleEvent(ON_RESUME); mLifecycle.handleLifecycleEvent(ON_RESUME);
verify(mContext, times(2)).registerReceiver( verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
any(BroadcastReceiver.class), any(IntentFilter.class));
} }
@Test @Test
public void testOnPause_shouldUnregisterListener() { public void testOnPause_shouldUnregisterListener() {
mLifecycle.handleLifecycleEvent(ON_RESUME); mLifecycle.handleLifecycleEvent(ON_RESUME);
mLifecycle.handleLifecycleEvent(ON_PAUSE); mLifecycle.handleLifecycleEvent(ON_PAUSE);
verify(mContext, times(2)).unregisterReceiver(any(BroadcastReceiver.class)); verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
} }
@Test @Test
public void testWifiStateChange_shouldToggleEnabledState() { public void testWifiStateChange_shouldToggleEnabledState() {
when(mWifiManager.isWifiEnabled()).thenReturn(true); when(mWifiManager.isWifiEnabled()).thenReturn(true);
when(mLocationManager.isLocationEnabled()).thenReturn(true);
//Sets the preferences. //Sets the preferences.
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -118,7 +123,6 @@ public class WifiP2PPreferenceControllerTest {
@Test @Test
public void testDisplayPreference_shouldToggleEnabledState() { public void testDisplayPreference_shouldToggleEnabledState() {
when(mWifiManager.isWifiEnabled()).thenReturn(true); when(mWifiManager.isWifiEnabled()).thenReturn(true);
when(mLocationManager.isLocationEnabled()).thenReturn(true);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
verify(mWifiDirectPreference).setEnabled(true); verify(mWifiDirectPreference).setEnabled(true);
@@ -127,21 +131,25 @@ public class WifiP2PPreferenceControllerTest {
verify(mWifiDirectPreference).setEnabled(false); verify(mWifiDirectPreference).setEnabled(false);
when(mWifiManager.isWifiEnabled()).thenReturn(true); when(mWifiManager.isWifiEnabled()).thenReturn(true);
when(mLocationManager.isLocationEnabled()).thenReturn(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
verify(mWifiDirectPreference, times(2)).setEnabled(false); verify(mWifiDirectPreference).setEnabled(false);
} }
@Test @Test
public void updateState_withLocationDisabled_preferenceShouldBeDisable() { public void displayPreference_wifiDirectNotAllowed_shouldDisable() {
when(mWifiManager.isWifiEnabled()).thenReturn(true); mController.mIsWifiDirectAllow = false;
when(mLocationManager.isLocationEnabled()).thenReturn(true);
Intent fakeIntent = new Intent(); mController.displayPreference(mScreen);
mController.displayPreference(mScreen);
verify(mWifiDirectPreference).setEnabled(true);
when(mLocationManager.isLocationEnabled()).thenReturn(false);
mController.mLocationReceiver.onReceive(mContext, fakeIntent);
verify(mWifiDirectPreference).setEnabled(false); verify(mWifiDirectPreference).setEnabled(false);
} }
@Test
public void displayPreference_wifiDirectNotAllowed_shouldEnable() {
mController.mIsWifiDirectAllow = true;
mController.displayPreference(mScreen);
verify(mWifiDirectPreference).setEnabled(true);
}
} }