Correct the logic for CtsTetheringUtils.isWifiTetheringSupported am: 0acaa74538

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/14840204

Change-Id: I4ea2374e8b1ce0a7bba540ebef93b222687790e9
This commit is contained in:
Chiachang Wang
2021-06-07 04:15:06 +00:00
committed by Automerger Merge Worker
2 changed files with 24 additions and 18 deletions

View File

@@ -15,6 +15,7 @@
*/ */
package android.tethering.mts; package android.tethering.mts;
import static android.Manifest.permission.ACCESS_WIFI_STATE;
import static android.Manifest.permission.MANAGE_TEST_NETWORKS; import static android.Manifest.permission.MANAGE_TEST_NETWORKS;
import static android.Manifest.permission.NETWORK_SETTINGS; import static android.Manifest.permission.NETWORK_SETTINGS;
import static android.Manifest.permission.READ_DEVICE_CONFIG; import static android.Manifest.permission.READ_DEVICE_CONFIG;
@@ -70,7 +71,7 @@ public class TetheringModuleTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mUiAutomation.adoptShellPermissionIdentity(MANAGE_TEST_NETWORKS, NETWORK_SETTINGS, mUiAutomation.adoptShellPermissionIdentity(MANAGE_TEST_NETWORKS, NETWORK_SETTINGS,
WRITE_SETTINGS, READ_DEVICE_CONFIG, TETHER_PRIVILEGED); WRITE_SETTINGS, READ_DEVICE_CONFIG, TETHER_PRIVILEGED, ACCESS_WIFI_STATE);
mContext = InstrumentationRegistry.getContext(); mContext = InstrumentationRegistry.getContext();
mTm = mContext.getSystemService(TetheringManager.class); mTm = mContext.getSystemService(TetheringManager.class);
mCtsTetheringUtils = new CtsTetheringUtils(mContext); mCtsTetheringUtils = new CtsTetheringUtils(mContext);
@@ -102,7 +103,7 @@ public class TetheringModuleTest {
TestNetworkTracker tnt = null; TestNetworkTracker tnt = null;
try { try {
tetherEventCallback.assumeTetheringSupported(); tetherEventCallback.assumeTetheringSupported();
assumeTrue(isWifiTetheringSupported(tetherEventCallback)); assumeTrue(isWifiTetheringSupported(mContext, tetherEventCallback));
tetherEventCallback.expectNoTetheringActive(); tetherEventCallback.expectNoTetheringActive();
final TetheringInterface tetheredIface = final TetheringInterface tetheredIface =

View File

@@ -388,20 +388,7 @@ public final class CtsTetheringUtils {
assumeTetheringSupported(); assumeTetheringSupported();
assumeTrue(!getTetheringInterfaceRegexps().getTetherableWifiRegexs().isEmpty()); assumeTrue(!getTetheringInterfaceRegexps().getTetherableWifiRegexs().isEmpty());
assumeTrue(isPortableHotspotSupported(ctx));
final PackageManager pm = ctx.getPackageManager();
assumeTrue(pm.hasSystemFeature(PackageManager.FEATURE_WIFI));
WifiManager wm = ctx.getSystemService(WifiManager.class);
// Wifi feature flags only work when wifi is on.
final boolean previousWifiEnabledState = wm.isWifiEnabled();
try {
if (!previousWifiEnabledState) SystemUtil.runShellCommand("svc wifi enable");
waitForWifiEnabled(ctx);
assumeTrue(wm.isPortableHotspotSupported());
} finally {
if (!previousWifiEnabledState) SystemUtil.runShellCommand("svc wifi disable");
}
} }
public TetheringInterfaceRegexps getTetheringInterfaceRegexps() { public TetheringInterfaceRegexps getTetheringInterfaceRegexps() {
@@ -453,8 +440,26 @@ public final class CtsTetheringUtils {
return callback.getTetheringInterfaceRegexps().getTetherableWifiRegexs(); return callback.getTetheringInterfaceRegexps().getTetherableWifiRegexs();
} }
public static boolean isWifiTetheringSupported(final TestTetheringEventCallback callback) { public static boolean isWifiTetheringSupported(final Context ctx,
return !getWifiTetherableInterfaceRegexps(callback).isEmpty(); final TestTetheringEventCallback callback) throws Exception {
return !getWifiTetherableInterfaceRegexps(callback).isEmpty()
&& isPortableHotspotSupported(ctx);
}
/* Returns if wifi supports hotspot. */
private static boolean isPortableHotspotSupported(final Context ctx) throws Exception {
final PackageManager pm = ctx.getPackageManager();
if (!pm.hasSystemFeature(PackageManager.FEATURE_WIFI)) return false;
final WifiManager wm = ctx.getSystemService(WifiManager.class);
// Wifi feature flags only work when wifi is on.
final boolean previousWifiEnabledState = wm.isWifiEnabled();
try {
if (!previousWifiEnabledState) SystemUtil.runShellCommand("svc wifi enable");
waitForWifiEnabled(ctx);
return wm.isPortableHotspotSupported();
} finally {
if (!previousWifiEnabledState) SystemUtil.runShellCommand("svc wifi disable");
}
} }
public TetheringInterface startWifiTethering(final TestTetheringEventCallback callback) public TetheringInterface startWifiTethering(final TestTetheringEventCallback callback)