Consolidates the log tag

Bug: 74397597
Test: run on test board
Change-Id: Icce6b3ebe531de06d27a7f23016721a99734d550
diff --git a/TrustAgent/res/values/strings.xml b/TrustAgent/res/values/strings.xml
index 347b8a6..d077262 100644
--- a/TrustAgent/res/values/strings.xml
+++ b/TrustAgent/res/values/strings.xml
@@ -14,7 +14,7 @@
      limitations under the License.
 -->
 <resources>
-    <string name="app_name">CarBleTrustAgent</string>
+    <string name="app_name">CarTrustAgentService</string>
     <string name="trust_granted_explanation">Unlock via escrow token, now granting trust</string>
 
     <!-- service/characteristics uuid for unlocking a device -->
diff --git a/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java b/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java
index 5094c0b..87b268a 100644
--- a/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java
+++ b/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java
@@ -33,7 +33,6 @@
 import android.service.trust.TrustAgentService;
 import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
-import com.android.car.trust.comms.SimpleBleServer;
 
 import java.util.concurrent.TimeUnit;
 
@@ -59,8 +58,6 @@
     public static final String INTENT_EXTRA_TOKEN_HANDLE = "extra-token-handle";
     public static final String INTENT_EXTRA_TOKEN_STATUS = "extra-token-status";
 
-    private static final String TAG = "CarBleTrustAgent";
-
     private static final long TRUST_DURATION_MS = TimeUnit.MINUTES.toMicros(5);
     private static final long BLE_RETRY_MS = TimeUnit.SECONDS.toMillis(1);
 
@@ -75,9 +72,7 @@
         @Override
         public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Received broadcast: " + action);
-            }
+            Log.d(Utils.LOG_TAG, "Received broadcast: " + action);
             if (ACTION_REVOKE_TRUST.equals(action)) {
                 revokeTrust();
             } else if (ACTION_ADD_TOKEN.equals(action)) {
@@ -97,32 +92,25 @@
             = new SimpleBleServer.ConnectionCallback() {
         @Override
         public void onServerStarted() {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "BLE server started");
-            }
+            Log.d(Utils.LOG_TAG, "BLE server started");
         }
 
         @Override
         public void onServerStartFailed(int errorCode) {
-            Log.w(TAG, "BLE server failed to start. Error Code: " + errorCode);
+            Log.e(Utils.LOG_TAG, "BLE server failed to start. Error Code: " + errorCode);
         }
 
         @Override
         public void onDeviceConnected(BluetoothDevice device) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "BLE device connected. Name: " + device.getName()
-                        + " Address: " + device.getAddress());
-            }
+            Log.d(Utils.LOG_TAG, "BLE device connected. Name: " + device.getName()
+                    + " Address: " + device.getAddress());
         }
     };
 
     private final ServiceConnection mServiceConnection = new ServiceConnection() {
         @Override
         public void onServiceConnected(ComponentName className, IBinder service) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "CarUnlockService connected");
-            }
-
+            Log.d(Utils.LOG_TAG, "CarUnlockService connected");
             mBleServiceBound = true;
             CarUnlockService.UnlockServiceBinder binder
                     = (CarUnlockService.UnlockServiceBinder) service;
@@ -143,18 +131,14 @@
     @Override
     public void onTrustTimeout() {
         super.onTrustTimeout();
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "onTrustTimeout(): timeout expired");
-        }
+        Log.d(Utils.LOG_TAG, "onTrustTimeout(): timeout expired");
     }
 
     @Override
     public void onCreate() {
         super.onCreate();
 
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "Bluetooth trust agent starting up");
-        }
+        Log.d(Utils.LOG_TAG, "Bluetooth trust agent starting up");
         IntentFilter filter = new IntentFilter();
         filter.addAction(ACTION_REVOKE_TRUST);
         filter.addAction(ACTION_ADD_TOKEN);
@@ -167,9 +151,7 @@
         // If the user is already unlocked, don't bother starting the BLE service.
         UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
         if (!um.isUserUnlocked()) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "User locked, will now bind CarUnlockService");
-            }
+            Log.d(Utils.LOG_TAG, "User locked, will now bind CarUnlockService");
             Intent intent = new Intent(this, CarUnlockService.class);
 
             bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
@@ -180,9 +162,7 @@
 
     @Override
     public void onDestroy() {
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "Car Trust agent shutting down");
-        }
+        Log.d(Utils.LOG_TAG, "Car Trust agent shutting down");
         mLocalBroadcastManager.unregisterReceiver(mTrustEventReceiver);
 
         // Unbind the service to avoid leaks from BLE stack.
@@ -193,10 +173,7 @@
     }
 
     private void maybeStartBleUnlockService() {
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "Trying to open a Ble GATT server");
-        }
-
+        Log.d(Utils.LOG_TAG, "Trying to open a Ble GATT server");
         BluetoothManager btManager =
                 (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
         BluetoothGattServer mGattServer
@@ -211,7 +188,7 @@
         // might not be ready just yet. Keep trying until a GattServer can open up before proceeding
         // to start the rest of the BLE services.
         if (mGattServer == null) {
-            Log.e(TAG, "Gatt not available, will try again...in " + BLE_RETRY_MS + "ms");
+            Log.e(Utils.LOG_TAG, "Gatt not available, will try again...in " + BLE_RETRY_MS + "ms");
 
             Handler handler = new Handler();
             handler.postDelayed(new Runnable() {
@@ -222,9 +199,7 @@
             }, BLE_RETRY_MS);
         } else {
             mGattServer.close();
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "GATT available, starting up UnlockService");
-            }
+            Log.d(Utils.LOG_TAG, "GATT available, starting up UnlockService");
             mCarUnlockService.start();
         }
     }
@@ -232,22 +207,16 @@
     private void unlock(byte[] token, long handle) {
         UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
 
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "About to unlock user. Current handle: " + handle
-                    + " Time: " + System.currentTimeMillis());
-        }
+        Log.d(Utils.LOG_TAG, "About to unlock user. Current handle: " + handle
+                + " Time: " + System.currentTimeMillis());
         unlockUserWithToken(handle, token, getCurrentUserHandle());
 
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "Attempted to unlock user, is user unlocked? " + um.isUserUnlocked()
-                    + " Time: " + System.currentTimeMillis());
-        }
+        Log.d(Utils.LOG_TAG, "Attempted to unlock user, is user unlocked? " + um.isUserUnlocked()
+                + " Time: " + System.currentTimeMillis());
         setManagingTrust(true);
 
         if (um.isUserUnlocked()) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, getString(R.string.trust_granted_explanation));
-            }
+            Log.d(Utils.LOG_TAG, getString(R.string.trust_granted_explanation));
             grantTrust("Granting trust from escrow token",
                     TRUST_DURATION_MS, FLAG_GRANT_TRUST_DISMISS_KEYGUARD);
             // Trust has been granted, disable the BLE server. This trust agent service does
@@ -258,17 +227,13 @@
 
     @Override
     public void onEscrowTokenRemoved(long handle, boolean successful) {
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "onEscrowTokenRemoved. Handle: " + handle + " successful? " + successful);
-        }
+        Log.d(Utils.LOG_TAG, "onEscrowTokenRemoved. Handle: " + handle + " successful? " + successful);
     }
 
     @Override
     public void onEscrowTokenStateReceived(long handle, int tokenState) {
         boolean isActive = tokenState == TOKEN_STATE_ACTIVE;
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "Token handle: " + handle + " isActive: " + isActive);
-        }
+        Log.d(Utils.LOG_TAG, "Token handle: " + handle + " isActive: " + isActive);
 
         Intent intent = new Intent();
         intent.setAction(ACTION_TOKEN_STATUS_RESULT);
@@ -279,10 +244,7 @@
 
     @Override
     public void onEscrowTokenAdded(byte[] token, long handle, UserHandle user) {
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "onEscrowTokenAdded, handle: " + handle);
-        }
-
+        Log.d(Utils.LOG_TAG, "onEscrowTokenAdded, handle: " + handle);
         Intent intent = new Intent();
         intent.setAction(ACTION_ADD_TOKEN_RESULT);
         intent.putExtra(INTENT_EXTRA_TOKEN_HANDLE, handle);
diff --git a/TrustAgent/src/com/android/car/trust/CarEnrolmentActivity.java b/TrustAgent/src/com/android/car/trust/CarEnrolmentActivity.java
index dcf836b..0575ec5 100644
--- a/TrustAgent/src/com/android/car/trust/CarEnrolmentActivity.java
+++ b/TrustAgent/src/com/android/car/trust/CarEnrolmentActivity.java
@@ -40,13 +40,12 @@
 import android.widget.TextView;
 
 import com.android.car.trust.CarEnrolmentService.EnrolmentListener;
-import com.android.car.trust.comms.SimpleBleServer.ConnectionCallback;
+import com.android.car.trust.SimpleBleServer.ConnectionCallback;
 
 /**
  * Setup activity that binds {@link CarEnrolmentService} and starts the enrolment process.
  */
 public class CarEnrolmentActivity extends Activity {
-    private static final String TAG = "CarEnrolment";
     private static final String SP_HANDLE_KEY = "sp-test";
     private static final int FINE_LOCATION_REQUEST_CODE = 42;
 
@@ -54,9 +53,7 @@
         @Override
         public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Received broadcast: " + action);
-            }
+            Log.d(Utils.LOG_TAG, "Received broadcast: " + action);
 
             if (ACTION_TOKEN_STATUS_RESULT.equals(action)) {
                 boolean tokenActive = intent.getBooleanExtra(INTENT_EXTRA_TOKEN_STATUS, false);
@@ -66,9 +63,7 @@
 
                 runOnUiThread(() -> {
                     mPrefs.edit().putLong(SP_HANDLE_KEY, handle).apply();
-                    if (Log.isLoggable(TAG, Log.DEBUG)) {
-                        Log.d(TAG, "stored new handle");
-                    }
+                    Log.d(Utils.LOG_TAG, "stored new handle");
                 });
 
                 mEnrolmentService.sendHandle(handle, mDevice);
@@ -110,13 +105,15 @@
             CarEnrolmentService.EnrolmentServiceBinder binder
                     = (CarEnrolmentService.EnrolmentServiceBinder) service;
             mEnrolmentService = binder.getService();
-            mEnrolmentService.addEnrolmentCallback(mEnrolmentListener);
+            mEnrolmentService.registerEnrolmentListener(mEnrolmentListener);
             mEnrolmentService.registerConnectionCallback(mConnectionCallback);
             mEnrolmentService.start();
         }
 
         @Override
         public void onServiceDisconnected(ComponentName arg0) {
+            mEnrolmentService.unregisterEnrolmentListener(mEnrolmentListener);
+            mEnrolmentService.unregisterConnectionCallback(mConnectionCallback);
             mEnrolmentService = null;
             mServiceBound = false;
         }
@@ -175,12 +172,10 @@
 
         try {
             mHandle = mPrefs.getLong(SP_HANDLE_KEY, -1);
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "onResume, checking handle active: " + mHandle);
-            }
+            Log.d(Utils.LOG_TAG, "onResume, checking handle active: " + mHandle);
             isTokenActive(mHandle);
         } catch (RemoteException e) {
-            Log.e(TAG, "Error checking if token is valid");
+            Log.e(Utils.LOG_TAG, "Error checking if token is valid");
             appendOutputText("Error checking if token is valid");
         }
     }
diff --git a/TrustAgent/src/com/android/car/trust/CarEnrolmentService.java b/TrustAgent/src/com/android/car/trust/CarEnrolmentService.java
index 18fbf84..e92484b 100644
--- a/TrustAgent/src/com/android/car/trust/CarEnrolmentService.java
+++ b/TrustAgent/src/com/android/car/trust/CarEnrolmentService.java
@@ -24,9 +24,6 @@
 import android.os.ParcelUuid;
 import android.util.Log;
 
-import com.android.car.trust.comms.SimpleBleServer;
-import com.android.car.trust.comms.Utils;
-
 import java.util.HashSet;
 import java.util.Set;
 import java.util.UUID;
@@ -35,7 +32,6 @@
  * A service that receives escrow token enrollment requests from remote devices.
  */
 public class CarEnrolmentService extends SimpleBleServer {
-    private static final String TAG = "CarEnrolmentService";
 
     public interface EnrolmentListener {
         void onEnrolmentDataReceived(byte[] token);
@@ -57,6 +53,7 @@
     public void start() {
         ParcelUuid uuid = new ParcelUuid(
                 UUID.fromString(getString(R.string.enrollment_service_uuid)));
+        Log.e(Utils.LOG_TAG, "CarEnrolmentService start with uuid: " + uuid);
         start(uuid, mEnrolmentService);
     }
 
@@ -70,10 +67,7 @@
             int requestId, BluetoothGattCharacteristic characteristic,
             boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
         if (characteristic.getUuid().equals(mEnrolmentEscrowToken.getUuid())) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Enrolment token received, value: " + Utils.getLong(value));
-            }
-
+            Log.d(Utils.LOG_TAG, "Enrolment token received, value: " + Utils.getLong(value));
             for (EnrolmentListener callback : mEnrolmentListeners) {
                 callback.onEnrolmentDataReceived(value);
             }
@@ -86,16 +80,18 @@
         //Enrolment service should not have any read requests.
     }
 
-    public void addEnrolmentCallback(EnrolmentListener callback) {
-        mEnrolmentListeners.add(callback);
+    public void registerEnrolmentListener(EnrolmentListener listener) {
+        mEnrolmentListeners.add(listener);
+    }
+
+    public void unregisterEnrolmentListener(EnrolmentListener listener) {
+        mEnrolmentListeners.remove(listener);
     }
 
     public void sendHandle(long handle, BluetoothDevice device) {
         mEnrolmentTokenHandle.setValue(Utils.getBytes(handle));
 
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "Sending notification for EscrowToken Handle");
-        }
+        Log.d(Utils.LOG_TAG, "Sending notification for EscrowToken Handle");
         mGattServer.notifyCharacteristicChanged(device,
                 mEnrolmentTokenHandle, false /* confirm */);
     }
diff --git a/TrustAgent/src/com/android/car/trust/CarUnlockService.java b/TrustAgent/src/com/android/car/trust/CarUnlockService.java
index 4992381..89d85d7 100644
--- a/TrustAgent/src/com/android/car/trust/CarUnlockService.java
+++ b/TrustAgent/src/com/android/car/trust/CarUnlockService.java
@@ -23,8 +23,6 @@
 import android.os.IBinder;
 import android.os.ParcelUuid;
 import android.util.Log;
-import com.android.car.trust.comms.SimpleBleServer;
-import com.android.car.trust.comms.Utils;
 
 import java.util.UUID;
 
@@ -39,8 +37,6 @@
         void unlockDevice(byte[] token, long handle);
     }
 
-    private static final String TAG = "CarUnlockService";
-
     private BluetoothGattService mUnlockService;
     private BluetoothGattCharacteristic mUnlockEscrowToken;
     private BluetoothGattCharacteristic mUnlockTokenHandle;
@@ -61,9 +57,7 @@
     @Override
     public void onCreate() {
         super.onCreate();
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "CarUnlockService starting up, creating BLE service");
-        }
+        Log.d(Utils.LOG_TAG, "CarUnlockService starting up, creating BLE service");
         setupUnlockService();
     }
 
@@ -92,15 +86,11 @@
         UUID uuid = characteristic.getUuid();
 
         if (uuid.equals(mUnlockTokenHandle.getUuid())) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Unlock handle received, value: " + Utils.getLong(value));
-            }
+            Log.d(Utils.LOG_TAG, "Unlock handle received, value: " + Utils.getLong(value));
             mCurrentHandle = Utils.getLong(value);
             unlockDataReceived();
         } else if (uuid.equals(mUnlockEscrowToken.getUuid())) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Unlock escrow token received, value: " + Utils.getLong(value));
-            }
+            Log.d(Utils.LOG_TAG, "Unlock escrow token received, value: " + Utils.getLong(value));
             mCurrentToken = value;
             unlockDataReceived();
         }
@@ -118,10 +108,8 @@
             return;
         }
 
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "Handle and token both received, requesting unlock. Time: "
-                    + System.currentTimeMillis());
-        }
+        Log.d(Utils.LOG_TAG, "Handle and token both received, requesting unlock. Time: "
+                + System.currentTimeMillis());
         // Both the handle and token has been received, try to unlock the device.
 
 
diff --git a/TrustAgent/src/com/android/car/trust/comms/SimpleBleServer.java b/TrustAgent/src/com/android/car/trust/SimpleBleServer.java
similarity index 83%
rename from TrustAgent/src/com/android/car/trust/comms/SimpleBleServer.java
rename to TrustAgent/src/com/android/car/trust/SimpleBleServer.java
index 9b3d648..2ed0c8f 100644
--- a/TrustAgent/src/com/android/car/trust/comms/SimpleBleServer.java
+++ b/TrustAgent/src/com/android/car/trust/SimpleBleServer.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License
  */
-package com.android.car.trust.comms;
+package com.android.car.trust;
 
 import android.app.Service;
 import android.bluetooth.BluetoothAdapter;
@@ -30,9 +30,7 @@
 import android.bluetooth.le.AdvertiseSettings;
 import android.bluetooth.le.BluetoothLeAdvertiser;
 import android.content.Context;
-import android.content.Intent;
 import android.content.pm.PackageManager;
-import android.os.IBinder;
 import android.os.ParcelUuid;
 import android.util.Log;
 
@@ -44,15 +42,11 @@
  */
 public abstract class SimpleBleServer extends Service {
 
-    private static final String TAG = "SimpleBleServer";
-
     private final AdvertiseCallback mAdvertisingCallback = new AdvertiseCallback() {
         @Override
         public void onStartSuccess(AdvertiseSettings settingsInEffect) {
             super.onStartSuccess(settingsInEffect);
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Successfully started advertising service");
-            }
+            Log.d(Utils.LOG_TAG, "Successfully started advertising service");
             for (ConnectionCallback callback : mConnectionCallbacks) {
                 callback.onServerStarted();
             }
@@ -61,9 +55,7 @@
         @Override
         public void onStartFailure(int errorCode) {
             super.onStartFailure(errorCode);
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Failed to advertise, errorCode: " + errorCode);
-            }
+            Log.e(Utils.LOG_TAG, "Failed to advertise, errorCode: " + errorCode);
             for (ConnectionCallback callback : mConnectionCallbacks) {
                 callback.onServerStartFailed(errorCode);
             }
@@ -75,11 +67,9 @@
         @Override
         public void onConnectionStateChange(BluetoothDevice device,
                 final int status, final int newState) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "GattServer connection change status: "
-                        + newState + " newState: "
-                        + newState + " device name: " + device.getName());
-            }
+            Log.d(Utils.LOG_TAG, "GattServer connection change status: " + status
+                    + " newState: " + newState
+                    + " device name: " + device.getName());
             if (newState == BluetoothProfile.STATE_CONNECTED) {
                 for (ConnectionCallback callback : mConnectionCallbacks) {
                     callback.onDeviceConnected(device);
@@ -89,17 +79,13 @@
 
         @Override
         public void onServiceAdded(final int status, BluetoothGattService service) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Service added status: " + status + " uuid: " + service.getUuid());
-            }
+            Log.d(Utils.LOG_TAG, "Service added status: " + status + " uuid: " + service.getUuid());
         }
 
         @Override
         public void onCharacteristicReadRequest(BluetoothDevice device,
                 int requestId, int offset, final BluetoothGattCharacteristic characteristic) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Read request for characteristic: " + characteristic.getUuid());
-            }
+            Log.d(Utils.LOG_TAG, "Read request for characteristic: " + characteristic.getUuid());
             mGattServer.sendResponse(device, requestId,
                     BluetoothGatt.GATT_SUCCESS, offset, characteristic.getValue());
             SimpleBleServer.
@@ -110,9 +96,7 @@
         public void onCharacteristicWriteRequest(final BluetoothDevice device, int requestId,
                 BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean
                 responseNeeded, int offset, byte[] value) {
-            if (Log.isLoggable(TAG, Log.DEBUG)) {
-                Log.d(TAG, "Write request for characteristic: " + characteristic.getUuid());
-            }
+            Log.d(Utils.LOG_TAG, "Write request for characteristic: " + characteristic.getUuid());
             mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS,
                     offset, value);
 
@@ -127,12 +111,6 @@
     private BluetoothLeAdvertiser mAdvertiser;
     protected BluetoothGattServer mGattServer;
 
-    @Override
-    public IBinder onBind(Intent intent) {
-        // Override in child classes.
-        return null;
-    }
-
     /**
      * Starts the GATT server with the given {@link BluetoothGattService} and begins
      * advertising with the {@link ParcelUuid}.
@@ -141,7 +119,7 @@
      */
     protected void start(ParcelUuid advertiseUuid, BluetoothGattService service) {
         if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
-            Log.e(TAG, "System does not support BLE");
+            Log.e(Utils.LOG_TAG, "System does not support BLE");
             return;
         }
 
@@ -150,7 +128,7 @@
 
         mGattServer = btManager.openGattServer(this, mGattServerCallback);
         if (mGattServer == null) {
-            Log.e(TAG, "Gatt Server not created");
+            Log.e(Utils.LOG_TAG, "Gatt Server not created");
             return;
         }
 
@@ -171,6 +149,10 @@
                 .build();
 
         mAdvertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();
+        if (mAdvertiser == null) {
+            Log.e(Utils.LOG_TAG, "Failed to get BLE advertiser");
+            return;
+        }
         mAdvertiser.startAdvertising(settings, data, mAdvertisingCallback);
     }
 
@@ -190,7 +172,7 @@
                     mGattServer.cancelConnection(d);
                 }
             } catch (UnsupportedOperationException e) {
-                Log.e(TAG, "Error getting connected devices", e);
+                Log.e(Utils.LOG_TAG, "Error getting connected devices", e);
             } finally {
                 mGattServer.close();
             }
@@ -206,12 +188,14 @@
     }
 
     public void registerConnectionCallback(ConnectionCallback callback) {
-        if (Log.isLoggable(TAG, Log.DEBUG)) {
-            Log.d(TAG, "Adding connection listener");
-        }
+        Log.d(Utils.LOG_TAG, "Adding connection listener");
         mConnectionCallbacks.add(callback);
     }
 
+    public void unregisterConnectionCallback(ConnectionCallback callback) {
+        mConnectionCallbacks.remove(callback);
+    }
+
     /**
      * Triggered when this BleService receives a write request from a remote
      * device. Sub-classes should implement how to handle requests.
diff --git a/TrustAgent/src/com/android/car/trust/comms/Utils.java b/TrustAgent/src/com/android/car/trust/Utils.java
similarity index 91%
rename from TrustAgent/src/com/android/car/trust/comms/Utils.java
rename to TrustAgent/src/com/android/car/trust/Utils.java
index 6742842..9f63cc4 100644
--- a/TrustAgent/src/com/android/car/trust/comms/Utils.java
+++ b/TrustAgent/src/com/android/car/trust/Utils.java
@@ -13,12 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License
  */
-package com.android.car.trust.comms;
+package com.android.car.trust;
 
 import java.nio.ByteBuffer;
 
 public class Utils {
 
+    public static final String LOG_TAG = "CarTrustAgentService";
+
     public static byte[] getBytes(long l) {
         ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE);
         buffer.putLong(0, l);