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

Commit d0e097a6 authored by Myles Watson's avatar Myles Watson
Browse files

btservice: Remove unused reference-counting logic

Remove overridden finalize() methods which are now unused.

Bug: 67460963
Test: runtest -j32 bluetooth
Change-Id: I290e4c37faba202e5ddb7d866d331b804357517a
parent 09e3fd6c
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
@@ -84,13 +84,9 @@ public class AdapterService extends Service {
    private static final String TAG = "BluetoothAdapterService";
    private static final boolean DBG = true;
    private static final boolean VERBOSE = false;
    private static final boolean TRACE_REF = false;
    private static final int MIN_ADVT_INSTANCES_FOR_MA = 5;
    private static final int MIN_OFFLOADED_FILTERS = 10;
    private static final int MIN_OFFLOADED_SCAN_STORAGE_BYTES = 1024;
    //For Debugging only
    private static int sRefCount = 0;
    private long mBluetoothStartTime = 0;

    private final Object mEnergyInfoLock = new Object();
    private int mStackReportedState;
@@ -185,16 +181,6 @@ public class AdapterService extends Service {
    private ProfileObserver mProfileObserver;
    private PhonePolicy mPhonePolicy;

    public AdapterService() {
        super();
        if (TRACE_REF) {
            synchronized (AdapterService.class) {
                sRefCount++;
                debugLog("AdapterService() - REFCOUNT: CREATED. INSTANCE_COUNT" + sRefCount);
            }
        }
    }

    public void addProfile(ProfileService profile) {
        synchronized (mProfiles) {
            if (!mProfiles.contains(profile)) {
@@ -1686,7 +1672,6 @@ public class AdapterService extends Service {
        mQuietmode = quietMode;
        Message m = mAdapterStateMachine.obtainMessage(AdapterState.BLE_TURN_ON);
        mAdapterStateMachine.sendMessage(m);
        mBluetoothStartTime = System.currentTimeMillis();
        return true;
    }

@@ -2631,16 +2616,6 @@ public class AdapterService extends Service {

    private native void interopDatabaseAddNative(int feature, byte[] address, int length);

    @Override
    public void finalize() {
        if (TRACE_REF) {
            synchronized (AdapterService.class) {
                sRefCount--;
                debugLog("finalize() - REFCOUNT: FINALIZED. INSTANCE_COUNT= " + sRefCount);
            }
        }
    }

    // Returns if this is a mock object. This is currently used in testing so that we may not call
    // System.exit() while finalizing the object. Otherwise GC of mock objects unfortunately ends up
    // calling finalize() which in turn calls System.exit() and the process crashes.
+0 −35
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@ import android.util.Log;

import com.android.bluetooth.Utils;

import java.util.HashMap;

/**
 * Base class for a background service that runs a Bluetooth profile
 */
@@ -35,9 +33,6 @@ public abstract class ProfileService extends Service {
    private static final boolean DBG = false;
    private static final String TAG = "BluetoothProfileService";

    //For Debugging only
    private static final HashMap<String, Integer> sReferenceCount = new HashMap<String, Integer>();

    public static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN;
    public static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
    public static final String BLUETOOTH_PRIVILEGED =
@@ -100,36 +95,6 @@ public abstract class ProfileService extends Service {

    protected ProfileService() {
        mName = getName();
        if (DBG) {
            synchronized (sReferenceCount) {
                Integer refCount = sReferenceCount.get(mName);
                if (refCount == null) {
                    refCount = 1;
                } else {
                    refCount = refCount + 1;
                }
                sReferenceCount.put(mName, refCount);
                if (DBG) {
                    log("REFCOUNT: CREATED. INSTANCE_COUNT=" + refCount);
                }
            }
        }
    }

    @Override
    protected void finalize() {
        if (DBG) {
            synchronized (sReferenceCount) {
                Integer refCount = sReferenceCount.get(mName);
                if (refCount != null) {
                    refCount = refCount - 1;
                } else {
                    refCount = 0;
                }
                sReferenceCount.put(mName, refCount);
                log("REFCOUNT: FINALIZED. INSTANCE_COUNT=" + refCount);
            }
        }
    }

    @Override