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

Commit 2ba1d5be authored by Marie Janssen's avatar Marie Janssen Committed by android-build-merger
Browse files

Merge "AdapterService: track last discovering timestamp" am: 02b06696

am: 70796e21

Change-Id: I191c55e041ace98b88313d05d0e1b298751c31fb
parents 2aba892f 70796e21
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.util.Pair;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;

import java.lang.System;
import java.util.HashMap;
import java.util.concurrent.CopyOnWriteArrayList;

@@ -43,7 +44,9 @@ class AdapterProperties {
    private static final boolean VDBG = false;
    private static final String TAG = "BluetoothAdapterProperties";

    private static final int BD_ADDR_LEN = 6; // 6 bytes
    private static final long DEFAULT_DISCOVERY_TIMEOUT_MS = 12800;
    private static final int BD_ADDR_LEN = 6; // in bytes

    private volatile String mName;
    private volatile byte[] mAddress;
    private volatile int mBluetoothClass;
@@ -61,6 +64,7 @@ class AdapterProperties {

    private AdapterService mService;
    private boolean mDiscovering;
    private long mDiscoveryEndMs; //< Time (ms since epoch) that discovery ended or will end.
    private RemoteDevices mRemoteDevices;
    private BluetoothAdapter mAdapter;
    //TODO - all hw capabilities to be exposed as a class
@@ -349,6 +353,10 @@ class AdapterProperties {
        }
    }

    long discoveryEndMillis() {
        return mDiscoveryEndMs;
    }

    boolean isDiscovering() {
        return mDiscovering;
    }
@@ -665,10 +673,12 @@ class AdapterProperties {
            Intent intent;
            if (state == AbstractionLayer.BT_DISCOVERY_STOPPED) {
                mDiscovering = false;
                mDiscoveryEndMs = System.currentTimeMillis();
                intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
                mService.sendBroadcast(intent, mService.BLUETOOTH_PERM);
            } else if (state == AbstractionLayer.BT_DISCOVERY_STARTED) {
                mDiscovering = true;
                mDiscoveryEndMs = System.currentTimeMillis() + DEFAULT_DISCOVERY_TIMEOUT_MS;
                intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
                mService.sendBroadcast(intent, mService.BLUETOOTH_PERM);
            }
+18 −0
Original line number Diff line number Diff line
@@ -943,6 +943,7 @@ public class AdapterService extends Service {
            if (service == null) return false;
            return service.cancelDiscovery();
        }

        public boolean isDiscovering() {
            if (!Utils.checkCallerAllowManagedProfiles(mService)) {
                Log.w(TAG, "isDiscovering() - Not allowed for non-active user");
@@ -954,6 +955,17 @@ public class AdapterService extends Service {
            return service.isDiscovering();
        }

        public long getDiscoveryEndMillis() {
            if (!Utils.checkCaller()) {
                Log.w(TAG, "getDiscoveryEndMillis() - Not allowed for non-active user");
                return -1;
            }

            AdapterService service = getService();
            if (service == null) return -1;
            return service.getDiscoveryEndMillis();
        }

        public BluetoothDevice[] getBondedDevices() {
            // don't check caller, may be called from system UI
            AdapterService service = getService();
@@ -1486,6 +1498,12 @@ public class AdapterService extends Service {
        return mAdapterProperties.isDiscovering();
    }

    long getDiscoveryEndMillis() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");

        return mAdapterProperties.discoveryEndMillis();
    }

    public BluetoothDevice[] getBondedDevices() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        return mAdapterProperties.getBondedDevices();