Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37de9678 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "AutoOn: Defer broadcast to active app" into main am: dbaa0af2

parents 57ac5db9 dbaa0af2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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",
+1 −1
Original line number Diff line number Diff line
android_app {
    name: "ServiceBluetoothFakeTestApp",
    sdk_version: "Tiramisu",
    sdk_version: "34",
}
+9 −0
Original line number Diff line number Diff line
@@ -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
@@ -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
@@ -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
@@ -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,
@@ -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)
@@ -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
+5 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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();
@@ -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");
+4 −0
Original line number Diff line number Diff line
@@ -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;

@@ -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);