summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java37
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java28
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java63
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/ForegroundServiceDismissalFeatureController.kt2
-rw-r--r--services/core/java/com/android/server/BluetoothManagerService.java175
-rw-r--r--services/core/java/com/android/server/wm/TaskOrganizerController.java21
6 files changed, 211 insertions, 115 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index 4aad3cbb2116..f216db6fc717 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -917,23 +917,11 @@ public final class BluetoothAdapter {
if (!isBleScanAlwaysAvailable()) {
return false;
}
-
- int state = getLeState();
- if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_BLE_ON) {
- String packageName = ActivityThread.currentPackageName();
- if (DBG) {
- Log.d(TAG, "disableBLE(): de-registering " + packageName);
- }
- try {
- mManagerService.updateBleAppCount(mToken, false, packageName);
- } catch (RemoteException e) {
- Log.e(TAG, "", e);
- }
- return true;
- }
-
- if (DBG) {
- Log.d(TAG, "disableBLE(): Already disabled");
+ String packageName = ActivityThread.currentPackageName();
+ try {
+ return mManagerService.disableBle(packageName, mToken);
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
}
return false;
}
@@ -974,20 +962,9 @@ public final class BluetoothAdapter {
if (!isBleScanAlwaysAvailable()) {
return false;
}
-
+ String packageName = ActivityThread.currentPackageName();
try {
- String packageName = ActivityThread.currentPackageName();
- mManagerService.updateBleAppCount(mToken, true, packageName);
- if (isLeEnabled()) {
- if (DBG) {
- Log.d(TAG, "enableBLE(): Bluetooth already enabled");
- }
- return true;
- }
- if (DBG) {
- Log.d(TAG, "enableBLE(): Calling enable");
- }
- return mManagerService.enable(packageName);
+ return mManagerService.enableBle(packageName, mToken);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java b/packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java
index cf1662409efc..19c8b20b7822 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java
@@ -338,7 +338,8 @@ public class InfoMediaManager extends MediaManager {
private void buildAllRoutes() {
for (MediaRoute2Info route : mRouterManager.getAllRoutes()) {
if (DEBUG) {
- Log.d(TAG, "buildAllRoutes() route : " + route.getName());
+ Log.d(TAG, "buildAllRoutes() route : " + route.getName() + ", volume : "
+ + route.getVolume());
}
if (route.isSystemRoute()) {
addMediaDevice(route);
@@ -414,18 +415,7 @@ public class InfoMediaManager extends MediaManager {
@Override
public void onRoutesChanged(List<MediaRoute2Info> routes) {
- mMediaDevices.clear();
- mCurrentConnectedDevice = null;
- if (TextUtils.isEmpty(mPackageName)) {
- buildAllRoutes();
- } else {
- buildAvailableRoutes();
- }
-
- final String id = mCurrentConnectedDevice != null
- ? mCurrentConnectedDevice.getId()
- : null;
- dispatchConnectedDeviceChanged(id);
+ refreshDevices();
}
@Override
@@ -439,6 +429,18 @@ public class InfoMediaManager extends MediaManager {
Log.d(TAG, "onTransferred() oldSession : " + oldSession.getName()
+ ", newSession : " + newSession.getName());
}
+ mMediaDevices.clear();
+ mCurrentConnectedDevice = null;
+ if (TextUtils.isEmpty(mPackageName)) {
+ buildAllRoutes();
+ } else {
+ buildAvailableRoutes();
+ }
+
+ final String id = mCurrentConnectedDevice != null
+ ? mCurrentConnectedDevice.getId()
+ : null;
+ dispatchConnectedDeviceChanged(id);
}
@Override
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java
index d0c37a0bd8c1..c21582cdf203 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java
@@ -173,8 +173,6 @@ public class InfoMediaManagerTest {
mShadowRouter2Manager.setRoutingSessions(routingSessionInfos);
final MediaRoute2Info info = mock(MediaRoute2Info.class);
- mInfoMediaManager.registerCallback(mCallback);
-
when(info.getId()).thenReturn(TEST_ID);
when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME);
@@ -191,14 +189,11 @@ public class InfoMediaManagerTest {
assertThat(infoDevice.getId()).isEqualTo(TEST_ID);
assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice);
assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size());
- verify(mCallback).onConnectedDeviceChanged(TEST_ID);
}
@Test
public void onRoutesChanged_buildAllRoutes_shouldAddMediaDevice() {
final MediaRoute2Info info = mock(MediaRoute2Info.class);
- mInfoMediaManager.registerCallback(mCallback);
-
when(info.getId()).thenReturn(TEST_ID);
when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME);
when(info.isSystemRoute()).thenReturn(true);
@@ -216,7 +211,6 @@ public class InfoMediaManagerTest {
final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0);
assertThat(infoDevice.getId()).isEqualTo(TEST_ID);
assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size());
- verify(mCallback).onConnectedDeviceChanged(null);
}
@Test
@@ -550,4 +544,61 @@ public class InfoMediaManagerTest {
verify(mCallback).onRequestFailed(REASON_NETWORK_ERROR);
}
+
+ @Test
+ public void onTransferred_getAvailableRoutes_shouldAddMediaDevice() {
+ final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>();
+ final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class);
+ routingSessionInfos.add(sessionInfo);
+ final List<String> selectedRoutes = new ArrayList<>();
+ selectedRoutes.add(TEST_ID);
+ when(sessionInfo.getSelectedRoutes()).thenReturn(selectedRoutes);
+ mShadowRouter2Manager.setRoutingSessions(routingSessionInfos);
+
+ final MediaRoute2Info info = mock(MediaRoute2Info.class);
+ mInfoMediaManager.registerCallback(mCallback);
+
+ when(info.getId()).thenReturn(TEST_ID);
+ when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME);
+
+ final List<MediaRoute2Info> routes = new ArrayList<>();
+ routes.add(info);
+ mShadowRouter2Manager.setAvailableRoutes(routes);
+
+ final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID);
+ assertThat(mediaDevice).isNull();
+
+ mInfoMediaManager.mMediaRouterCallback.onTransferred(null, null);
+
+ final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0);
+ assertThat(infoDevice.getId()).isEqualTo(TEST_ID);
+ assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice);
+ assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size());
+ verify(mCallback).onConnectedDeviceChanged(TEST_ID);
+ }
+
+ @Test
+ public void onTransferred_buildAllRoutes_shouldAddMediaDevice() {
+ final MediaRoute2Info info = mock(MediaRoute2Info.class);
+ mInfoMediaManager.registerCallback(mCallback);
+
+ when(info.getId()).thenReturn(TEST_ID);
+ when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME);
+ when(info.isSystemRoute()).thenReturn(true);
+
+ final List<MediaRoute2Info> routes = new ArrayList<>();
+ routes.add(info);
+ mShadowRouter2Manager.setAllRoutes(routes);
+
+ final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID);
+ assertThat(mediaDevice).isNull();
+
+ mInfoMediaManager.mPackageName = "";
+ mInfoMediaManager.mMediaRouterCallback.onTransferred(null, null);
+
+ final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0);
+ assertThat(infoDevice.getId()).isEqualTo(TEST_ID);
+ assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size());
+ verify(mCallback).onConnectedDeviceChanged(null);
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ForegroundServiceDismissalFeatureController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ForegroundServiceDismissalFeatureController.kt
index 571a85440b89..dfc2fc1c4584 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ForegroundServiceDismissalFeatureController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ForegroundServiceDismissalFeatureController.kt
@@ -42,7 +42,7 @@ class ForegroundServiceDismissalFeatureController @Inject constructor(
private fun isEnabled(proxy: DeviceConfigProxy): Boolean {
if (sIsEnabled == null) {
sIsEnabled = proxy.getBoolean(
- DeviceConfig.NAMESPACE_SYSTEMUI, NOTIFICATIONS_ALLOW_FGS_DISMISSAL, true)
+ DeviceConfig.NAMESPACE_SYSTEMUI, NOTIFICATIONS_ALLOW_FGS_DISMISSAL, false)
}
return sIsEnabled!!
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index 1bf559a17021..192ea72224b1 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -828,13 +828,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
}
- public int updateBleAppCount(IBinder token, boolean enable, String packageName) {
- // Check if packageName belongs to callingUid
- final int callingUid = Binder.getCallingUid();
- final boolean isCallerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
- if (!isCallerSystem) {
- checkPackage(callingUid, packageName);
- }
+ private int updateBleAppCount(IBinder token, boolean enable, String packageName) {
ClientDeathRecipient r = mBleApps.get(token);
if (r == null && enable) {
ClientDeathRecipient deathRec = new ClientDeathRecipient(packageName);
@@ -859,13 +853,94 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (DBG) {
Slog.d(TAG, appCount + " registered Ble Apps");
}
- if (appCount == 0 && mEnable) {
- disableBleScanMode();
+ return appCount;
+ }
+
+ private boolean checkBluetoothPermissions(String packageName, boolean requireForeground) {
+ if (isBluetoothDisallowed()) {
+ if (DBG) {
+ Slog.d(TAG, "checkBluetoothPermissions: bluetooth disallowed");
+ }
+ return false;
}
- if (appCount == 0 && !mEnableExternal) {
- sendBrEdrDownCallback();
+ // Check if packageName belongs to callingUid
+ final int callingUid = Binder.getCallingUid();
+ final boolean isCallerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
+ if (!isCallerSystem) {
+ checkPackage(callingUid, packageName);
+
+ if (requireForeground && !checkIfCallerIsForegroundUser()) {
+ Slog.w(TAG, "Not allowed for non-active and non system user");
+ return false;
+ }
+
+ mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH ADMIN permission");
}
- return appCount;
+ return true;
+ }
+
+ public boolean enableBle(String packageName, IBinder token) throws RemoteException {
+ if (!checkBluetoothPermissions(packageName, false)) {
+ if (DBG) {
+ Slog.d(TAG, "enableBle(): bluetooth disallowed");
+ }
+ return false;
+ }
+
+ if (DBG) {
+ Slog.d(TAG, "enableBle(" + packageName + "): mBluetooth =" + mBluetooth
+ + " mBinding = " + mBinding + " mState = "
+ + BluetoothAdapter.nameForState(mState));
+ }
+ updateBleAppCount(token, true, packageName);
+
+ if (mState == BluetoothAdapter.STATE_ON
+ || mState == BluetoothAdapter.STATE_BLE_ON
+ || mState == BluetoothAdapter.STATE_TURNING_ON
+ || mState == BluetoothAdapter.STATE_TURNING_OFF) {
+ Log.d(TAG, "enableBLE(): Bluetooth already enabled");
+ return true;
+ }
+ synchronized (mReceiver) {
+ // waive WRITE_SECURE_SETTINGS permission check
+ sendEnableMsg(false,
+ BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST, packageName);
+ }
+ return true;
+ }
+
+ public boolean disableBle(String packageName, IBinder token) throws RemoteException {
+ if (!checkBluetoothPermissions(packageName, false)) {
+ if (DBG) {
+ Slog.d(TAG, "disableBLE(): bluetooth disallowed");
+ }
+ return false;
+ }
+
+ if (DBG) {
+ Slog.d(TAG, "disableBle(" + packageName + "): mBluetooth =" + mBluetooth
+ + " mBinding = " + mBinding + " mState = "
+ + BluetoothAdapter.nameForState(mState));
+ }
+
+ if (mState == BluetoothAdapter.STATE_OFF) {
+ Slog.d(TAG, "disableBLE(): Already disabled");
+ return false;
+ }
+ updateBleAppCount(token, false, packageName);
+
+ if (mState == BluetoothAdapter.STATE_BLE_ON && !isBleAppPresent()) {
+ if (mEnable) {
+ disableBleScanMode();
+ }
+ if (!mEnableExternal) {
+ addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST,
+ packageName, false);
+ sendBrEdrDownCallback();
+ }
+ }
+ return true;
}
// Clear all apps using BLE scan only mode.
@@ -894,6 +969,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
Slog.e(TAG, "onBluetoothServiceUp: mBluetooth is null!");
return;
}
+ if (!mEnableExternal && !isBleAppPresent() && isAirplaneModeOn()) {
+ // Airplane mode is turned on while enabling BLE only mode, disable
+ // BLE now.
+ disableBleScanMode();
+ sendBrEdrDownCallback();
+ return;
+ }
if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) {
// This triggers transition to STATE_ON
mBluetooth.onLeServiceUp();
@@ -943,29 +1025,19 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
public boolean enableNoAutoConnect(String packageName) {
- if (isBluetoothDisallowed()) {
+ if (!checkBluetoothPermissions(packageName, false)) {
if (DBG) {
Slog.d(TAG, "enableNoAutoConnect(): not enabling - bluetooth disallowed");
}
return false;
}
- // Check if packageName belongs to callingUid
- final int callingUid = Binder.getCallingUid();
- final boolean isCallerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
- if (!isCallerSystem) {
- checkPackage(callingUid, packageName);
- }
-
- mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
- "Need BLUETOOTH ADMIN permission");
-
if (DBG) {
Slog.d(TAG, "enableNoAutoConnect(): mBluetooth =" + mBluetooth + " mBinding = "
+ mBinding);
}
- int callingAppId = UserHandle.getAppId(callingUid);
+ int callingAppId = UserHandle.getAppId(Binder.getCallingUid());
if (callingAppId != Process.NFC_UID) {
throw new SecurityException("no permission to enable Bluetooth quietly");
}
@@ -980,32 +1052,19 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
public boolean enable(String packageName) throws RemoteException {
- final int callingUid = Binder.getCallingUid();
- final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
-
- if (isBluetoothDisallowed()) {
+ if (!checkBluetoothPermissions(packageName, true)) {
if (DBG) {
Slog.d(TAG, "enable(): not enabling - bluetooth disallowed");
}
return false;
}
- if (!callerSystem) {
- // Check if packageName belongs to callingUid
- checkPackage(callingUid, packageName);
-
- if (!checkIfCallerIsForegroundUser()) {
- Slog.w(TAG, "enable(): not allowed for non-active and non system user");
- return false;
- }
-
- mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
- "Need BLUETOOTH ADMIN permission");
-
- if (!isEnabled() && mWirelessConsentRequired && startConsentUiIfNeeded(packageName,
- callingUid, BluetoothAdapter.ACTION_REQUEST_ENABLE)) {
- return false;
- }
+ final int callingUid = Binder.getCallingUid();
+ final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
+ if (!callerSystem && !isEnabled() && mWirelessConsentRequired
+ && startConsentUiIfNeeded(packageName,
+ callingUid, BluetoothAdapter.ACTION_REQUEST_ENABLE)) {
+ return false;
}
if (DBG) {
@@ -1027,25 +1086,19 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
public boolean disable(String packageName, boolean persist) throws RemoteException {
- final int callingUid = Binder.getCallingUid();
- final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
-
- if (!callerSystem) {
- // Check if packageName belongs to callingUid
- checkPackage(callingUid, packageName);
-
- if (!checkIfCallerIsForegroundUser()) {
- Slog.w(TAG, "disable(): not allowed for non-active and non system user");
- return false;
+ if (!checkBluetoothPermissions(packageName, true)) {
+ if (DBG) {
+ Slog.d(TAG, "disable(): not disabling - bluetooth disallowed");
}
+ return false;
+ }
- mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
- "Need BLUETOOTH ADMIN permission");
-
- if (isEnabled() && mWirelessConsentRequired && startConsentUiIfNeeded(packageName,
- callingUid, BluetoothAdapter.ACTION_REQUEST_DISABLE)) {
- return false;
- }
+ final int callingUid = Binder.getCallingUid();
+ final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
+ if (!callerSystem && isEnabled() && mWirelessConsentRequired
+ && startConsentUiIfNeeded(packageName,
+ callingUid, BluetoothAdapter.ACTION_REQUEST_DISABLE)) {
+ return false;
}
if (DBG) {
diff --git a/services/core/java/com/android/server/wm/TaskOrganizerController.java b/services/core/java/com/android/server/wm/TaskOrganizerController.java
index 8edcd2fb7765..8e95ca7ef961 100644
--- a/services/core/java/com/android/server/wm/TaskOrganizerController.java
+++ b/services/core/java/com/android/server/wm/TaskOrganizerController.java
@@ -78,7 +78,9 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
synchronized (mGlobalLock) {
final TaskOrganizerState state = mTaskOrganizerStates.remove(
mTaskOrganizer.asBinder());
- state.dispose();
+ if (state != null) {
+ state.dispose();
+ }
}
}
};
@@ -222,9 +224,20 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
@Override
public void unregisterTaskOrganizer(ITaskOrganizer organizer) {
- final TaskOrganizerState state = mTaskOrganizerStates.remove(organizer.asBinder());
- state.unlinkDeath();
- state.dispose();
+ enforceStackPermission("unregisterTaskOrganizer()");
+ final long origId = Binder.clearCallingIdentity();
+ try {
+ synchronized (mGlobalLock) {
+ final TaskOrganizerState state = mTaskOrganizerStates.remove(organizer.asBinder());
+ if (state == null) {
+ return;
+ }
+ state.unlinkDeath();
+ state.dispose();
+ }
+ } finally {
+ Binder.restoreCallingIdentity(origId);
+ }
}
ITaskOrganizer getTaskOrganizer(int windowingMode) {