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

Commit 56e72705 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6035658 from 81a102b378f5f16c7ec2cf937ced98518421d129 to rvc-release

Change-Id: I2d690a8609aec42f02bcfc87f6079dee0fce3422
parents 33f4bb20 0f99979e
Loading
Loading
Loading
Loading
+38 −5
Original line number Original line Diff line number Diff line
@@ -16,8 +16,13 @@


package android.bluetooth;
package android.bluetooth;


import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.os.Binder;
import android.os.Binder;
@@ -25,6 +30,8 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;


@@ -40,6 +47,7 @@ import java.util.List;
 *
 *
 * @hide
 * @hide
 */
 */
@SystemApi
public final class BluetoothPan implements BluetoothProfile {
public final class BluetoothPan implements BluetoothProfile {
    private static final String TAG = "BluetoothPan";
    private static final String TAG = "BluetoothPan";
    private static final boolean DBG = true;
    private static final boolean DBG = true;
@@ -67,6 +75,7 @@ public final class BluetoothPan implements BluetoothProfile {
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to
     * receive.
     * receive.
     */
     */
    @SuppressLint("ActionValue")
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_CONNECTION_STATE_CHANGED =
    public static final String ACTION_CONNECTION_STATE_CHANGED =
            "android.bluetooth.pan.profile.action.CONNECTION_STATE_CHANGED";
            "android.bluetooth.pan.profile.action.CONNECTION_STATE_CHANGED";
@@ -76,19 +85,32 @@ public final class BluetoothPan implements BluetoothProfile {
     * The local role of the PAN profile that the remote device is bound to.
     * The local role of the PAN profile that the remote device is bound to.
     * It can be one of {@link #LOCAL_NAP_ROLE} or {@link #LOCAL_PANU_ROLE}.
     * It can be one of {@link #LOCAL_NAP_ROLE} or {@link #LOCAL_PANU_ROLE}.
     */
     */
    @SuppressLint("ActionValue")
    public static final String EXTRA_LOCAL_ROLE = "android.bluetooth.pan.extra.LOCAL_ROLE";
    public static final String EXTRA_LOCAL_ROLE = "android.bluetooth.pan.extra.LOCAL_ROLE";


    /** @hide */
    @IntDef({PAN_ROLE_NONE, LOCAL_NAP_ROLE, LOCAL_PANU_ROLE})
    @Retention(RetentionPolicy.SOURCE)
    public @interface LocalPanRole {}

    public static final int PAN_ROLE_NONE = 0;
    public static final int PAN_ROLE_NONE = 0;
    /**
    /**
     * The local device is acting as a Network Access Point.
     * The local device is acting as a Network Access Point.
     */
     */
    public static final int LOCAL_NAP_ROLE = 1;
    public static final int LOCAL_NAP_ROLE = 1;
    public static final int REMOTE_NAP_ROLE = 1;


    /**
    /**
     * The local device is acting as a PAN User.
     * The local device is acting as a PAN User.
     */
     */
    public static final int LOCAL_PANU_ROLE = 2;
    public static final int LOCAL_PANU_ROLE = 2;

    /** @hide */
    @IntDef({PAN_ROLE_NONE, REMOTE_NAP_ROLE, REMOTE_PANU_ROLE})
    @Retention(RetentionPolicy.SOURCE)
    public @interface RemotePanRole {}

    public static final int REMOTE_NAP_ROLE = 1;

    public static final int REMOTE_PANU_ROLE = 2;
    public static final int REMOTE_PANU_ROLE = 2;


    /**
    /**
@@ -134,6 +156,8 @@ public final class BluetoothPan implements BluetoothProfile {
    /**
    /**
     * Create a BluetoothPan proxy object for interacting with the local
     * Create a BluetoothPan proxy object for interacting with the local
     * Bluetooth Service which handles the Pan profile
     * Bluetooth Service which handles the Pan profile
     *
     * @hide
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    /*package*/ BluetoothPan(Context context, ServiceListener listener) {
    /*package*/ BluetoothPan(Context context, ServiceListener listener) {
@@ -235,7 +259,7 @@ public final class BluetoothPan implements BluetoothProfile {
     * {@inheritDoc}
     * {@inheritDoc}
     */
     */
    @Override
    @Override
    public List<BluetoothDevice> getConnectedDevices() {
    public @NonNull List<BluetoothDevice> getConnectedDevices() {
        if (VDBG) log("getConnectedDevices()");
        if (VDBG) log("getConnectedDevices()");
        final IBluetoothPan service = getService();
        final IBluetoothPan service = getService();
        if (service != null && isEnabled()) {
        if (service != null && isEnabled()) {
@@ -252,6 +276,7 @@ public final class BluetoothPan implements BluetoothProfile {


    /**
    /**
     * {@inheritDoc}
     * {@inheritDoc}
     * @hide
     */
     */
    @Override
    @Override
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
@@ -273,7 +298,7 @@ public final class BluetoothPan implements BluetoothProfile {
     * {@inheritDoc}
     * {@inheritDoc}
     */
     */
    @Override
    @Override
    public int getConnectionState(BluetoothDevice device) {
    public int getConnectionState(@Nullable BluetoothDevice device) {
        if (VDBG) log("getState(" + device + ")");
        if (VDBG) log("getState(" + device + ")");
        final IBluetoothPan service = getService();
        final IBluetoothPan service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
        if (service != null && isEnabled() && isValidDevice(device)) {
@@ -288,7 +313,11 @@ public final class BluetoothPan implements BluetoothProfile {
        return BluetoothProfile.STATE_DISCONNECTED;
        return BluetoothProfile.STATE_DISCONNECTED;
    }
    }


    @UnsupportedAppUsage
    /**
     * Turns on/off bluetooth tethering
     *
     * @param value is whether to enable or disable bluetooth tethering
     */
    public void setBluetoothTethering(boolean value) {
    public void setBluetoothTethering(boolean value) {
        String pkgName = mContext.getOpPackageName();
        String pkgName = mContext.getOpPackageName();
        if (DBG) log("setBluetoothTethering(" + value + "), calling package:" + pkgName);
        if (DBG) log("setBluetoothTethering(" + value + "), calling package:" + pkgName);
@@ -302,7 +331,11 @@ public final class BluetoothPan implements BluetoothProfile {
        }
        }
    }
    }


    @UnsupportedAppUsage
    /**
     * Determines whether tethering is enabled
     *
     * @return true if tethering is on, false if not or some error occurred
     */
    public boolean isTetheringOn() {
    public boolean isTetheringOn() {
        if (VDBG) log("isTetheringOn()");
        if (VDBG) log("isTetheringOn()");
        final IBluetoothPan service = getService();
        final IBluetoothPan service = getService();
+4 −2
Original line number Original line Diff line number Diff line
@@ -20,9 +20,9 @@ package android.bluetooth;
import android.Manifest;
import android.Manifest;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage;
import android.annotation.UnsupportedAppUsage;
import android.os.Build;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
@@ -43,6 +43,7 @@ public interface BluetoothProfile {
     * This extra represents the current connection state of the profile of the
     * This extra represents the current connection state of the profile of the
     * Bluetooth device.
     * Bluetooth device.
     */
     */
    @SuppressLint("ActionValue")
    String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
    String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";


    /**
    /**
@@ -51,6 +52,7 @@ public interface BluetoothProfile {
     * This extra represents the previous connection state of the profile of the
     * This extra represents the previous connection state of the profile of the
     * Bluetooth device.
     * Bluetooth device.
     */
     */
    @SuppressLint("ActionValue")
    String EXTRA_PREVIOUS_STATE =
    String EXTRA_PREVIOUS_STATE =
            "android.bluetooth.profile.extra.PREVIOUS_STATE";
            "android.bluetooth.profile.extra.PREVIOUS_STATE";


@@ -106,7 +108,7 @@ public interface BluetoothProfile {
     *
     *
     * @hide
     * @hide
     */
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    @SystemApi
    int PAN = 5;
    int PAN = 5;


    /**
    /**
+27 −21
Original line number Original line Diff line number Diff line
@@ -98,7 +98,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {


    private static final int TIMEOUT_BIND_MS = 3000; //Maximum msec to wait for a bind
    private static final int TIMEOUT_BIND_MS = 3000; //Maximum msec to wait for a bind
    //Maximum msec to wait for service restart
    //Maximum msec to wait for service restart
    private static final int SERVICE_RESTART_TIME_MS = 200;
    private static final int SERVICE_RESTART_TIME_MS = 400;
    //Maximum msec to wait for restart due to error
    //Maximum msec to wait for restart due to error
    private static final int ERROR_RESTART_TIME_MS = 3000;
    private static final int ERROR_RESTART_TIME_MS = 3000;
    //Maximum msec to delay MESSAGE_USER_SWITCHED
    //Maximum msec to delay MESSAGE_USER_SWITCHED
@@ -1635,13 +1635,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                        //     ActivityManager detects it.
                        //     ActivityManager detects it.
                        // The waiting for (b) and (c) is accomplished by
                        // The waiting for (b) and (c) is accomplished by
                        // delaying the MESSAGE_RESTART_BLUETOOTH_SERVICE
                        // delaying the MESSAGE_RESTART_BLUETOOTH_SERVICE
                        // message. On slower devices, that delay needs to be
                        // message. The delay time is backed off if Bluetooth
                        // on the order of (2 * SERVICE_RESTART_TIME_MS).
                        // continuously failed to turn on itself.
                        //
                        //
                        waitForOnOff(false, true);
                        waitForOnOff(false, true);
                        Message restartMsg =
                        Message restartMsg =
                                mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
                                mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
                        mHandler.sendMessageDelayed(restartMsg, 2 * SERVICE_RESTART_TIME_MS);
                        mHandler.sendMessageDelayed(restartMsg, getServiceRestartMs());
                    }
                    }
                    break;
                    break;


@@ -1820,7 +1820,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                            waitForOnOff(false, true);
                            waitForOnOff(false, true);
                            Message restartMsg =
                            Message restartMsg =
                                    mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
                                    mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
                            mHandler.sendMessageDelayed(restartMsg, 2 * SERVICE_RESTART_TIME_MS);
                            mHandler.sendMessageDelayed(restartMsg, getServiceRestartMs());
                        }
                        }
                    }
                    }
                    if (newState == BluetoothAdapter.STATE_ON
                    if (newState == BluetoothAdapter.STATE_ON
@@ -1863,7 +1863,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                        // Send a Bluetooth Restart message
                        // Send a Bluetooth Restart message
                        Message restartMsg =
                        Message restartMsg =
                                mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
                                mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
                        mHandler.sendMessageDelayed(restartMsg, SERVICE_RESTART_TIME_MS);
                        mHandler.sendMessageDelayed(restartMsg, getServiceRestartMs());
                    }
                    }


                    sendBluetoothServiceDownCallback();
                    sendBluetoothServiceDownCallback();
@@ -1886,7 +1886,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                    break;
                    break;
                }
                }
                case MESSAGE_RESTART_BLUETOOTH_SERVICE: {
                case MESSAGE_RESTART_BLUETOOTH_SERVICE: {
                    Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE");
                    mErrorRecoveryRetryCounter++;
                    Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE: retry count="
                            + mErrorRecoveryRetryCounter);
                    if (mErrorRecoveryRetryCounter < MAX_ERROR_RESTART_RETRIES) {
                        /* Enable without persisting the setting as
                        /* Enable without persisting the setting as
                         it doesnt change when IBluetooth
                         it doesnt change when IBluetooth
                         service restarts */
                         service restarts */
@@ -1894,6 +1897,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                        addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_RESTARTED,
                        addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_RESTARTED,
                                mContext.getPackageName(), true);
                                mContext.getPackageName(), true);
                        handleEnable(mQuietEnable);
                        handleEnable(mQuietEnable);
                    } else {
                        Slog.e(TAG, "Reach maximum retry to restart Bluetooth!");
                    }
                    break;
                    break;
                }
                }
                case MESSAGE_TIMEOUT_BIND: {
                case MESSAGE_TIMEOUT_BIND: {
@@ -2332,13 +2338,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {


        mEnable = false;
        mEnable = false;


        if (mErrorRecoveryRetryCounter++ < MAX_ERROR_RESTART_RETRIES) {
        // Send a Bluetooth Restart message to reenable bluetooth
        // Send a Bluetooth Restart message to reenable bluetooth
        Message restartMsg = mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
        Message restartMsg = mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
        mHandler.sendMessageDelayed(restartMsg, ERROR_RESTART_TIME_MS);
        mHandler.sendMessageDelayed(restartMsg, ERROR_RESTART_TIME_MS);
        } else {
            // todo: notify user to power down and power up phone to make bluetooth work.
        }
    }
    }


    private boolean isBluetoothDisallowed() {
    private boolean isBluetoothDisallowed() {
@@ -2374,6 +2376,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        }
        }
    }
    }


    private int getServiceRestartMs() {
        return (mErrorRecoveryRetryCounter + 1) * SERVICE_RESTART_TIME_MS;
    }

    @Override
    @Override
    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
        if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) {
        if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) {