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

Commit 5400d131 authored by Jayden Kim's avatar Jayden Kim Committed by Gerrit Code Review
Browse files

Merge "Print package name when binder is dead" into main

parents c8e1d15f 79eb356e
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertisingSetParameters;
import android.bluetooth.le.IAdvertisingSetCallback;
import android.bluetooth.le.PeriodicAdvertisingParameters;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
@@ -122,15 +123,19 @@ public class AdvertiseManager {

    class AdvertisingSetDeathRecipient implements IBinder.DeathRecipient {
        public IAdvertisingSetCallback callback;
        private String mPackageName;

        AdvertisingSetDeathRecipient(IAdvertisingSetCallback callback) {
        AdvertisingSetDeathRecipient(IAdvertisingSetCallback callback, String packageName) {
            this.callback = callback;
            this.mPackageName = packageName;
        }

        @Override
        public void binderDied() {
            if (DBG) {
                Log.d(TAG, "Binder is dead - unregistering advertising set");
                Log.d(
                        TAG,
                        "Binder is dead - unregistering advertising set (" + mPackageName + ")!");
            }
            stopAdvertisingSet(callback);
        }
@@ -228,7 +233,16 @@ public class AdvertiseManager {
            return;
        }

        AdvertisingSetDeathRecipient deathRecipient = new AdvertisingSetDeathRecipient(callback);
        int appUid = Binder.getCallingUid();
        String packageName = null;
        if (mService != null && mService.getPackageManager() != null) {
            packageName = mService.getPackageManager().getNameForUid(appUid);
        }
        if (packageName == null) {
            packageName = "Unknown package name (UID: " + appUid + ")";
        }
        AdvertisingSetDeathRecipient deathRecipient =
                new AdvertisingSetDeathRecipient(callback, packageName);
        IBinder binder = toBinder(callback);
        try {
            binder.linkToDeath(deathRecipient, 0);
+33 −9
Original line number Diff line number Diff line
@@ -504,15 +504,23 @@ public class GattService extends ProfileService {

    class ScannerDeathRecipient implements IBinder.DeathRecipient {
        int mScannerId;
        private String mPackageName;

        ScannerDeathRecipient(int scannerId) {
        ScannerDeathRecipient(int scannerId, String packageName) {
            mScannerId = scannerId;
            mPackageName = packageName;
        }

        @Override
        public void binderDied() {
            if (DBG) {
                Log.d(TAG, "Binder is dead - unregistering scanner (" + mScannerId + ")!");
                Log.d(
                        TAG,
                        "Binder is dead - unregistering scanner ("
                                + mPackageName
                                + " "
                                + mScannerId
                                + ")!");
            }

            ScanClient client = getScanClient(mScannerId);
@@ -539,15 +547,23 @@ public class GattService extends ProfileService {

    class ServerDeathRecipient implements IBinder.DeathRecipient {
        int mAppIf;
        private String mPackageName;

        ServerDeathRecipient(int appIf) {
        ServerDeathRecipient(int appIf, String packageName) {
            mAppIf = appIf;
            mPackageName = packageName;
        }

        @Override
        public void binderDied() {
            if (DBG) {
                Log.d(TAG, "Binder is dead - unregistering server (" + mAppIf + ")!");
                Log.d(
                        TAG,
                        "Binder is dead - unregistering server ("
                                + mPackageName
                                + " "
                                + mAppIf
                                + ")!");
            }
            unregisterServer(mAppIf, getAttributionSource());
        }
@@ -555,15 +571,23 @@ public class GattService extends ProfileService {

    class ClientDeathRecipient implements IBinder.DeathRecipient {
        int mAppIf;
        private String mPackageName;

        ClientDeathRecipient(int appIf) {
        ClientDeathRecipient(int appIf, String packageName) {
            mAppIf = appIf;
            mPackageName = packageName;
        }

        @Override
        public void binderDied() {
            if (DBG) {
                Log.d(TAG, "Binder is dead - unregistering client (" + mAppIf + ")!");
                Log.d(
                        TAG,
                        "Binder is dead - unregistering client ("
                                + mPackageName
                                + " "
                                + mAppIf
                                + ")!");
            }
            unregisterClient(mAppIf, getAttributionSource());
        }
@@ -2061,7 +2085,7 @@ public class GattService extends ProfileService {
                // If app is callback based, setup a death recipient. App will initiate the start.
                // Otherwise, if PendingIntent based, start the scan directly.
                if (cbApp.callback != null) {
                    cbApp.linkToDeath(new ScannerDeathRecipient(scannerId));
                    cbApp.linkToDeath(new ScannerDeathRecipient(scannerId, cbApp.name));
                } else {
                    continuePiStartScan(scannerId, cbApp);
                }
@@ -2122,7 +2146,7 @@ public class GattService extends ProfileService {
        if (app != null) {
            if (status == 0) {
                app.id = clientIf;
                app.linkToDeath(new ClientDeathRecipient(clientIf));
                app.linkToDeath(new ClientDeathRecipient(clientIf, app.name));
            } else {
                mClientMap.remove(uuid);
            }
@@ -4198,7 +4222,7 @@ public class GattService extends ProfileService {
        ServerMap.App app = mServerMap.getByUuid(uuid);
        if (app != null) {
            app.id = serverIf;
            app.linkToDeath(new ServerDeathRecipient(serverIf));
            app.linkToDeath(new ServerDeathRecipient(serverIf, app.name));
            app.callback.onServerRegistered(status, serverIf);
        }
    }