DO NOT MERGE: Disable UWB in airplane mode.
Bug: 199933856 Test: Manual Change-Id: I13c5986e28e7a1a9277518ca96da9a22c5e1c21e
This commit is contained in:
parent
e97b0e8fbb
commit
bd74ef8918
@ -83,6 +83,7 @@ public class UwbServiceImplTest {
|
|||||||
when(mUwbInjector.getVendorService()).thenReturn(mVendorService);
|
when(mUwbInjector.getVendorService()).thenReturn(mVendorService);
|
||||||
when(mUwbInjector.checkUwbRangingPermissionForDataDelivery(any(), any())).thenReturn(true);
|
when(mUwbInjector.checkUwbRangingPermissionForDataDelivery(any(), any())).thenReturn(true);
|
||||||
when(mUwbInjector.isPersistedUwbStateEnabled()).thenReturn(true);
|
when(mUwbInjector.isPersistedUwbStateEnabled()).thenReturn(true);
|
||||||
|
when(mUwbInjector.isAirplaneModeOn()).thenReturn(false);
|
||||||
when(mVendorService.asBinder()).thenReturn(mVendorServiceBinder);
|
when(mVendorService.asBinder()).thenReturn(mVendorServiceBinder);
|
||||||
mUwbServiceImpl = new UwbServiceImpl(mContext, mUwbInjector);
|
mUwbServiceImpl = new UwbServiceImpl(mContext, mUwbInjector);
|
||||||
}
|
}
|
||||||
|
@ -96,4 +96,10 @@ public class UwbInjector {
|
|||||||
return true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,11 @@ package com.android.server.uwb;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.content.AttributionSource;
|
import android.content.AttributionSource;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
@ -238,7 +241,7 @@ public class UwbServiceImpl extends IUwbAdapter.Stub implements IBinder.DeathRec
|
|||||||
Log.i(TAG, "Retrieved vendor service");
|
Log.i(TAG, "Retrieved vendor service");
|
||||||
long token = Binder.clearCallingIdentity();
|
long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
mVendorUwbAdapter.setEnabled(mUwbInjector.isPersistedUwbStateEnabled());
|
mVendorUwbAdapter.setEnabled(isEnabled());
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
@ -249,6 +252,7 @@ public class UwbServiceImpl extends IUwbAdapter.Stub implements IBinder.DeathRec
|
|||||||
UwbServiceImpl(@NonNull Context context, @NonNull UwbInjector uwbInjector) {
|
UwbServiceImpl(@NonNull Context context, @NonNull UwbInjector uwbInjector) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mUwbInjector = uwbInjector;
|
mUwbInjector = uwbInjector;
|
||||||
|
registerAirplaneModeReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceUwbPrivilegedPermission() {
|
private void enforceUwbPrivilegedPermission() {
|
||||||
@ -331,7 +335,7 @@ public class UwbServiceImpl extends IUwbAdapter.Stub implements IBinder.DeathRec
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void setEnabled(boolean enabled) throws RemoteException {
|
public synchronized void setEnabled(boolean enabled) throws RemoteException {
|
||||||
persistUwbState(enabled);
|
persistUwbState(enabled);
|
||||||
getVendorUwbAdapter().setEnabled(enabled);
|
getVendorUwbAdapter().setEnabled(isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persistUwbState(boolean enabled) {
|
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;
|
int state = enabled ? AdapterState.STATE_ENABLED_ACTIVE : AdapterState.STATE_DISABLED;
|
||||||
Settings.Global.putInt(cr, Settings.Global.UWB_ENABLED, state);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user