aboutsummaryrefslogtreecommitdiff
path: root/TrustAgent/src
diff options
context:
space:
mode:
authorHongwei Wang <hwwang@google.com>2018-03-08 11:52:23 -0800
committerHongwei Wang <hwwang@google.com>2018-03-08 13:16:11 -0800
commitebeea53780b1afe4a1bf765758a28ab8d6766fb3 (patch)
treef68d4517c1269a6aabb0cc569e29c53ea4e4bbc8 /TrustAgent/src
parente11231dc0e4f62907fae5a3f41c774f7fd6d1278 (diff)
downloadCar-ebeea53780b1afe4a1bf765758a28ab8d6766fb3.tar.gz
Consolidates the log tag
Bug: 74397597 Test: run on test board Change-Id: Icce6b3ebe531de06d27a7f23016721a99734d550
Diffstat (limited to 'TrustAgent/src')
-rw-r--r--TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java80
-rw-r--r--TrustAgent/src/com/android/car/trust/CarEnrolmentActivity.java21
-rw-r--r--TrustAgent/src/com/android/car/trust/CarEnrolmentService.java22
-rw-r--r--TrustAgent/src/com/android/car/trust/CarUnlockService.java22
-rw-r--r--TrustAgent/src/com/android/car/trust/SimpleBleServer.java (renamed from TrustAgent/src/com/android/car/trust/comms/SimpleBleServer.java)58
-rw-r--r--TrustAgent/src/com/android/car/trust/Utils.java (renamed from TrustAgent/src/com/android/car/trust/comms/Utils.java)4
6 files changed, 67 insertions, 140 deletions
diff --git a/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java b/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java
index 5094c0b61e..87b268a316 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.os.UserManager;
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 class CarBleTrustAgent extends TrustAgentService {
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 @@ public class CarBleTrustAgent extends TrustAgentService {
@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 @@ public class CarBleTrustAgent extends TrustAgentService {
= 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 @@ public class CarBleTrustAgent extends TrustAgentService {
@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 @@ public class CarBleTrustAgent extends TrustAgentService {
// 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 @@ public class CarBleTrustAgent extends TrustAgentService {
@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 @@ public class CarBleTrustAgent extends TrustAgentService {
}
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 @@ public class CarBleTrustAgent extends TrustAgentService {
// 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 @@ public class CarBleTrustAgent extends TrustAgentService {
}, 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 @@ public class CarBleTrustAgent extends TrustAgentService {
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 @@ public class CarBleTrustAgent extends TrustAgentService {
@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 @@ public class CarBleTrustAgent extends TrustAgentService {
@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 dcf836b755..0575ec5e5f 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.util.Log;
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 @@ public class CarEnrolmentActivity extends Activity {
@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 @@ public class CarEnrolmentActivity extends Activity {
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 @@ public class CarEnrolmentActivity extends Activity {
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 @@ public class CarEnrolmentActivity extends Activity {
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 18fbf84101..e92484ba0f 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.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.HashSet;
import java.util.Set;
import java.util.UUID;
@@ -35,7 +32,6 @@ import java.util.UUID;
* 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 class CarEnrolmentService extends SimpleBleServer {
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 @@ public class CarEnrolmentService extends SimpleBleServer {
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 @@ public class CarEnrolmentService extends SimpleBleServer {
//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 499238151c..89d85d7a8c 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.Binder;
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 @@ public class CarUnlockService extends SimpleBleServer {
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 @@ public class CarUnlockService extends SimpleBleServer {
@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 @@ public class CarUnlockService extends SimpleBleServer {
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 @@ public class CarUnlockService extends SimpleBleServer {
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
index 9b3d648c94..2ed0c8f46c 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.AdvertiseData;
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 @@ import java.util.Set;
*/
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 @@ public abstract class SimpleBleServer extends Service {
@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 @@ public abstract class SimpleBleServer extends Service {
@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 @@ public abstract class SimpleBleServer extends Service {
@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 abstract class SimpleBleServer extends Service {
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 @@ public abstract class SimpleBleServer extends Service {
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 @@ public abstract class SimpleBleServer extends Service {
*/
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 @@ public abstract class SimpleBleServer extends Service {
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 @@ public abstract class SimpleBleServer extends Service {
.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 @@ public abstract class SimpleBleServer extends Service {
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 abstract class SimpleBleServer extends Service {
}
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
index 6742842cd8..9f63cc4a22 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);