DO NOT MERGE: Disable UWB in airplane mode.

Bug: 199933856
Test: Manual
Change-Id: I13c5986e28e7a1a9277518ca96da9a22c5e1c21e
This commit is contained in:
Joy Babafemi 2021-09-23 21:08:58 +00:00
parent e97b0e8fbb
commit bd74ef8918
3 changed files with 34 additions and 2 deletions

View File

@ -83,6 +83,7 @@ public class UwbServiceImplTest {
when(mUwbInjector.getVendorService()).thenReturn(mVendorService);
when(mUwbInjector.checkUwbRangingPermissionForDataDelivery(any(), any())).thenReturn(true);
when(mUwbInjector.isPersistedUwbStateEnabled()).thenReturn(true);
when(mUwbInjector.isAirplaneModeOn()).thenReturn(false);
when(mVendorService.asBinder()).thenReturn(mVendorServiceBinder);
mUwbServiceImpl = new UwbServiceImpl(mContext, mUwbInjector);
}

View File

@ -96,4 +96,10 @@ public class UwbInjector {
return true;
}
}
/** Returns true if airplane mode is turned on. */
public boolean isAirplaneModeOn() {
return Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
}
}

View File

@ -18,8 +18,11 @@ package com.android.server.uwb;
import android.annotation.NonNull;
import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
import android.os.PersistableBundle;
@ -238,7 +241,7 @@ public class UwbServiceImpl extends IUwbAdapter.Stub implements IBinder.DeathRec
Log.i(TAG, "Retrieved vendor service");
long token = Binder.clearCallingIdentity();
try {
mVendorUwbAdapter.setEnabled(mUwbInjector.isPersistedUwbStateEnabled());
mVendorUwbAdapter.setEnabled(isEnabled());
} finally {
Binder.restoreCallingIdentity(token);
}
@ -249,6 +252,7 @@ public class UwbServiceImpl extends IUwbAdapter.Stub implements IBinder.DeathRec
UwbServiceImpl(@NonNull Context context, @NonNull UwbInjector uwbInjector) {
mContext = context;
mUwbInjector = uwbInjector;
registerAirplaneModeReceiver();
}
private void enforceUwbPrivilegedPermission() {
@ -331,7 +335,7 @@ public class UwbServiceImpl extends IUwbAdapter.Stub implements IBinder.DeathRec
@Override
public synchronized void setEnabled(boolean enabled) throws RemoteException {
persistUwbState(enabled);
getVendorUwbAdapter().setEnabled(enabled);
getVendorUwbAdapter().setEnabled(isEnabled());
}
private void persistUwbState(boolean enabled) {
@ -339,4 +343,25 @@ public class UwbServiceImpl extends IUwbAdapter.Stub implements IBinder.DeathRec
int state = enabled ? AdapterState.STATE_ENABLED_ACTIVE : AdapterState.STATE_DISABLED;
Settings.Global.putInt(cr, Settings.Global.UWB_ENABLED, state);
}
private void registerAirplaneModeReceiver() {
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
handleAirplaneModeEvent();
}
}, new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
}
private void handleAirplaneModeEvent() {
try {
getVendorUwbAdapter().setEnabled(isEnabled());
} catch (RemoteException e) {
Log.e(TAG, "Unable to set UWB Adapter state.", e);
}
}
private boolean isEnabled() {
return mUwbInjector.isPersistedUwbStateEnabled() && !mUwbInjector.isAirplaneModeOn();
}
}