Loading service/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,8 @@ android_robolectric_test { "src/satellite/ModeListenerTest.kt", ], jarjar_rules: ":bluetooth-jarjar-rules", static_libs: [ "androidx.test.core", "androidx.test.ext.truth", Loading service/fake_app/Android.bp +1 −1 Original line number Diff line number Diff line android_app { name: "ServiceBluetoothFakeTestApp", sdk_version: "Tiramisu", sdk_version: "34", } service/src/AutoOnFeature.kt +9 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.bluetooth import android.app.AlarmManager import android.app.BroadcastOptions import android.bluetooth.BluetoothAdapter.ACTION_AUTO_ON_STATE_CHANGED import android.bluetooth.BluetoothAdapter.AUTO_ON_STATE_DISABLED import android.bluetooth.BluetoothAdapter.AUTO_ON_STATE_ENABLED Loading @@ -30,10 +31,12 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.database.ContentObserver import android.os.Build import android.os.Handler import android.os.Looper import android.os.SystemClock import android.provider.Settings import androidx.annotation.RequiresApi import androidx.annotation.VisibleForTesting import com.android.modules.expresslog.Counter import com.android.server.bluetooth.airplane.hasUserToggledApm as hasUserToggledApm Loading Loading @@ -95,6 +98,7 @@ public fun pause() { timer = null } @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) public fun notifyBluetoothOn(context: Context) { timer?.cancel() timer = null Loading @@ -118,6 +122,7 @@ public fun isUserEnabled(context: Context): Boolean { return isFeatureEnabledForUser(context.contentResolver) } @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) public fun setUserEnabled( looper: Looper, context: Context, Loading Loading @@ -287,6 +292,7 @@ private fun isFeatureSupportedForUser(resolver: ContentResolver): Boolean { * * @return whether the auto on feature is enabled for this user */ @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) private fun setFeatureEnabledForUserUnchecked(context: Context, status: Boolean): Boolean { val ret = Settings.Secure.putInt(context.contentResolver, USER_SETTINGS_KEY, if (status) 1 else 0) Loading @@ -299,6 +305,9 @@ private fun setFeatureEnabledForUserUnchecked(context: Context, status: Boolean) if (status) AUTO_ON_STATE_ENABLED else AUTO_ON_STATE_DISABLED ), android.Manifest.permission.BLUETOOTH_PRIVILEGED, BroadcastOptions.makeBasic() .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE) .toBundle(), ) } return ret Loading service/src/com/android/server/bluetooth/BluetoothManagerService.java +5 −1 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.ContentObserver; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; Loading @@ -72,6 +73,8 @@ import android.provider.Settings.SettingNotFoundException; import android.sysprop.BluetoothProperties; import android.util.proto.ProtoOutputStream; import androidx.annotation.RequiresApi; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.flags.FeatureFlags; import com.android.bluetooth.flags.Flags; Loading Loading @@ -2164,7 +2167,7 @@ class BluetoothManagerService { // Notify all proxy objects first of adapter state change if (newState == STATE_ON) { if (mDeviceConfigAllowAutoOn) { if (isAtLeastV() && mDeviceConfigAllowAutoOn) { AutoOnFeature.notifyBluetoothOn(mCurrentUserContext); } sendBluetoothOnCallback(); Loading Loading @@ -2729,6 +2732,7 @@ class BluetoothManagerService { return postAndWait(() -> AutoOnFeature.isUserEnabled(mCurrentUserContext)); } @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) void setAutoOnEnabled(boolean status) { if (!mDeviceConfigAllowAutoOn) { throw new IllegalStateException("AutoOnFeature is not supported in current config"); Loading service/src/com/android/server/bluetooth/BluetoothServiceBinder.java +4 −0 Original line number Diff line number Diff line Loading @@ -38,12 +38,15 @@ import android.bluetooth.IBluetoothManager; import android.bluetooth.IBluetoothManagerCallback; import android.content.AttributionSource; import android.content.Context; import android.os.Build; import android.os.IBinder; import android.os.Looper; import android.os.ParcelFileDescriptor; import android.os.UserManager; import android.permission.PermissionManager; import androidx.annotation.RequiresApi; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -337,6 +340,7 @@ class BluetoothServiceBinder extends IBluetoothManager.Stub { @Override @RequiresPermission(BLUETOOTH_PRIVILEGED) @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) public void setAutoOnEnabled(boolean status) { BtPermissionUtils.enforcePrivileged(mContext); mBluetoothManagerService.setAutoOnEnabled(status); Loading Loading
service/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,8 @@ android_robolectric_test { "src/satellite/ModeListenerTest.kt", ], jarjar_rules: ":bluetooth-jarjar-rules", static_libs: [ "androidx.test.core", "androidx.test.ext.truth", Loading
service/fake_app/Android.bp +1 −1 Original line number Diff line number Diff line android_app { name: "ServiceBluetoothFakeTestApp", sdk_version: "Tiramisu", sdk_version: "34", }
service/src/AutoOnFeature.kt +9 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.bluetooth import android.app.AlarmManager import android.app.BroadcastOptions import android.bluetooth.BluetoothAdapter.ACTION_AUTO_ON_STATE_CHANGED import android.bluetooth.BluetoothAdapter.AUTO_ON_STATE_DISABLED import android.bluetooth.BluetoothAdapter.AUTO_ON_STATE_ENABLED Loading @@ -30,10 +31,12 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.database.ContentObserver import android.os.Build import android.os.Handler import android.os.Looper import android.os.SystemClock import android.provider.Settings import androidx.annotation.RequiresApi import androidx.annotation.VisibleForTesting import com.android.modules.expresslog.Counter import com.android.server.bluetooth.airplane.hasUserToggledApm as hasUserToggledApm Loading Loading @@ -95,6 +98,7 @@ public fun pause() { timer = null } @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) public fun notifyBluetoothOn(context: Context) { timer?.cancel() timer = null Loading @@ -118,6 +122,7 @@ public fun isUserEnabled(context: Context): Boolean { return isFeatureEnabledForUser(context.contentResolver) } @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) public fun setUserEnabled( looper: Looper, context: Context, Loading Loading @@ -287,6 +292,7 @@ private fun isFeatureSupportedForUser(resolver: ContentResolver): Boolean { * * @return whether the auto on feature is enabled for this user */ @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) private fun setFeatureEnabledForUserUnchecked(context: Context, status: Boolean): Boolean { val ret = Settings.Secure.putInt(context.contentResolver, USER_SETTINGS_KEY, if (status) 1 else 0) Loading @@ -299,6 +305,9 @@ private fun setFeatureEnabledForUserUnchecked(context: Context, status: Boolean) if (status) AUTO_ON_STATE_ENABLED else AUTO_ON_STATE_DISABLED ), android.Manifest.permission.BLUETOOTH_PRIVILEGED, BroadcastOptions.makeBasic() .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE) .toBundle(), ) } return ret Loading
service/src/com/android/server/bluetooth/BluetoothManagerService.java +5 −1 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.ContentObserver; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; Loading @@ -72,6 +73,8 @@ import android.provider.Settings.SettingNotFoundException; import android.sysprop.BluetoothProperties; import android.util.proto.ProtoOutputStream; import androidx.annotation.RequiresApi; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.flags.FeatureFlags; import com.android.bluetooth.flags.Flags; Loading Loading @@ -2164,7 +2167,7 @@ class BluetoothManagerService { // Notify all proxy objects first of adapter state change if (newState == STATE_ON) { if (mDeviceConfigAllowAutoOn) { if (isAtLeastV() && mDeviceConfigAllowAutoOn) { AutoOnFeature.notifyBluetoothOn(mCurrentUserContext); } sendBluetoothOnCallback(); Loading Loading @@ -2729,6 +2732,7 @@ class BluetoothManagerService { return postAndWait(() -> AutoOnFeature.isUserEnabled(mCurrentUserContext)); } @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) void setAutoOnEnabled(boolean status) { if (!mDeviceConfigAllowAutoOn) { throw new IllegalStateException("AutoOnFeature is not supported in current config"); Loading
service/src/com/android/server/bluetooth/BluetoothServiceBinder.java +4 −0 Original line number Diff line number Diff line Loading @@ -38,12 +38,15 @@ import android.bluetooth.IBluetoothManager; import android.bluetooth.IBluetoothManagerCallback; import android.content.AttributionSource; import android.content.Context; import android.os.Build; import android.os.IBinder; import android.os.Looper; import android.os.ParcelFileDescriptor; import android.os.UserManager; import android.permission.PermissionManager; import androidx.annotation.RequiresApi; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -337,6 +340,7 @@ class BluetoothServiceBinder extends IBluetoothManager.Stub { @Override @RequiresPermission(BLUETOOTH_PRIVILEGED) @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) public void setAutoOnEnabled(boolean status) { BtPermissionUtils.enforcePrivileged(mContext); mBluetoothManagerService.setAutoOnEnabled(status); Loading