Make tethering APIs unsupported synchronously when disallowed

To backward compatible existing behavior, make tethering APIs
unsupported synchronously when tethering is disallowed. There
are two APIs register/unregisterTetheringEventCallback still
supported even tethering is disallowed.
This could avoid some existing tests flaky. The test assume
startTethering would fail right away after tethering restricted
apply.

Bug: 184996041
Bug: 239500515
Test: atest TetheringTests
Change-Id: I41ae1d61647c9baf69bcb246965e8d9b4a89b497
This commit is contained in:
Mark
2022-07-27 08:27:06 +00:00
parent 874a3e273e
commit cf230301e3
3 changed files with 107 additions and 9 deletions

View File

@@ -2525,7 +2525,7 @@ public class Tethering {
// if ro.tether.denied = true we default to no tethering
// gservices could set the secure setting to 1 though to enable it on a build where it
// had previously been turned off.
private boolean isTetheringAllowed() {
boolean isTetheringAllowed() {
final int defaultVal = mDeps.isTetheringDenied() ? 0 : 1;
final boolean tetherSupported = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.TETHER_SUPPORTED, defaultVal) != 0;

View File

@@ -237,7 +237,7 @@ public class TetheringService extends Service {
listener.onResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
return true;
}
if (!mTethering.isTetheringSupported()) {
if (!mTethering.isTetheringSupported() || !mTethering.isTetheringAllowed()) {
listener.onResult(TETHER_ERROR_UNSUPPORTED);
return true;
}
@@ -255,7 +255,7 @@ public class TetheringService extends Service {
receiver.send(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION, null);
return true;
}
if (!mTethering.isTetheringSupported()) {
if (!mTethering.isTetheringSupported() || !mTethering.isTetheringAllowed()) {
receiver.send(TETHER_ERROR_UNSUPPORTED, null);
return true;
}