diff options
151 files changed, 634 insertions, 696 deletions
diff --git a/Android.bp b/Android.bp index 37c57726ac..89fa45ba46 100644 --- a/Android.bp +++ b/Android.bp @@ -137,6 +137,7 @@ java_defaults { "-Xep:EqualsHashCode:ERROR", "-Xep:EqualsIncompatibleType:ERROR", "-Xep:FallThrough:ERROR", + "-Xep:FieldCanBeFinal:ERROR", "-Xep:FieldCanBeLocal:ERROR", "-Xep:FieldCanBeStatic:ERROR", "-Xep:Finalize:ERROR", diff --git a/android/app/src/com/android/bluetooth/SignedLongLong.java b/android/app/src/com/android/bluetooth/SignedLongLong.java index 023d4b0e8f..ea2e57e559 100644 --- a/android/app/src/com/android/bluetooth/SignedLongLong.java +++ b/android/app/src/com/android/bluetooth/SignedLongLong.java @@ -26,8 +26,8 @@ import java.util.Objects; */ public class SignedLongLong implements Comparable<SignedLongLong> { - private long mMostSigBits; - private long mLeastSigBits; + private final long mMostSigBits; + private final long mLeastSigBits; public SignedLongLong(long leastSigBits, long mostSigBits) { this.mMostSigBits = mostSigBits; diff --git a/android/app/src/com/android/bluetooth/a2dp/A2dpCodecConfig.java b/android/app/src/com/android/bluetooth/a2dp/A2dpCodecConfig.java index bb94277c5a..340827bd09 100644 --- a/android/app/src/com/android/bluetooth/a2dp/A2dpCodecConfig.java +++ b/android/app/src/com/android/bluetooth/a2dp/A2dpCodecConfig.java @@ -40,10 +40,10 @@ import java.util.Objects; class A2dpCodecConfig { private static final String TAG = A2dpCodecConfig.class.getSimpleName(); - private Context mContext; - private A2dpNativeInterface mA2dpNativeInterface; + private final Context mContext; + private final A2dpNativeInterface mA2dpNativeInterface; - private BluetoothCodecConfig[] mCodecConfigPriorities; + private final BluetoothCodecConfig[] mCodecConfigPriorities; private @CodecPriority int mA2dpSourceCodecPrioritySbc = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; private @CodecPriority int mA2dpSourceCodecPriorityAac = diff --git a/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface.java b/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface.java index e26624b614..e3b4c400a3 100644 --- a/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface.java +++ b/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface.java @@ -31,7 +31,7 @@ import com.android.internal.annotations.VisibleForTesting; public class A2dpSinkNativeInterface { private static final String TAG = A2dpSinkNativeInterface.class.getSimpleName(); - private AdapterService mAdapterService; + private final AdapterService mAdapterService; @GuardedBy("INSTANCE_LOCK") private static A2dpSinkNativeInterface sInstance; diff --git a/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java b/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java index 3936929915..44bd62c0ab 100644 --- a/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java +++ b/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java @@ -93,7 +93,7 @@ public class A2dpSinkStreamHandler extends Handler { private MediaPlayer mMediaPlayer = null; // Focus changes when we are currently holding focus. - private OnAudioFocusChangeListener mAudioFocusListener = + private final OnAudioFocusChangeListener mAudioFocusListener = new OnAudioFocusChangeListener() { @Override public void onAudioFocusChange(int focusChange) { diff --git a/android/app/src/com/android/bluetooth/audio_util/BrowsablePlayerConnector.java b/android/app/src/com/android/bluetooth/audio_util/BrowsablePlayerConnector.java index 9092efa879..12908fde53 100644 --- a/android/app/src/com/android/bluetooth/audio_util/BrowsablePlayerConnector.java +++ b/android/app/src/com/android/bluetooth/audio_util/BrowsablePlayerConnector.java @@ -52,10 +52,10 @@ public class BrowsablePlayerConnector extends Handler { private static final int MSG_TIMEOUT = 2; private static BrowsablePlayerConnector sInjectConnector; - private PlayerListCallback mCallback; + private final PlayerListCallback mCallback; - private List<BrowsedPlayerWrapper> mResults = new ArrayList<BrowsedPlayerWrapper>(); - private Set<BrowsedPlayerWrapper> mPendingPlayers = new HashSet<BrowsedPlayerWrapper>(); + private final List<BrowsedPlayerWrapper> mResults = new ArrayList<BrowsedPlayerWrapper>(); + private final Set<BrowsedPlayerWrapper> mPendingPlayers = new HashSet<BrowsedPlayerWrapper>(); interface PlayerListCallback { void run(List<BrowsedPlayerWrapper> result); diff --git a/android/app/src/com/android/bluetooth/audio_util/BrowsedPlayerWrapper.java b/android/app/src/com/android/bluetooth/audio_util/BrowsedPlayerWrapper.java index a54b22afca..02598dae03 100644 --- a/android/app/src/com/android/bluetooth/audio_util/BrowsedPlayerWrapper.java +++ b/android/app/src/com/android/bluetooth/audio_util/BrowsedPlayerWrapper.java @@ -63,7 +63,7 @@ class BrowsedPlayerWrapper { public static final int STATUS_LOOKUP_ERROR = 2; public static final int STATUS_PLAYBACK_TIMEOUT_ERROR = 3; - private MediaBrowser mWrappedBrowser; + private final MediaBrowser mWrappedBrowser; // TODO (apanicke): Store the context in the factories so that we don't need to save this. // As long as the service is alive those factories will have a valid context. diff --git a/android/app/src/com/android/bluetooth/audio_util/MediaPlayerList.java b/android/app/src/com/android/bluetooth/audio_util/MediaPlayerList.java index 26f37f8267..2662901ae7 100644 --- a/android/app/src/com/android/bluetooth/audio_util/MediaPlayerList.java +++ b/android/app/src/com/android/bluetooth/audio_util/MediaPlayerList.java @@ -81,8 +81,8 @@ public class MediaPlayerList { // string. private static final String BROWSE_ID_PATTERN = "\\d\\d.*"; - private Context mContext; - private Looper mLooper; // Thread all media player callbacks and timeouts happen on + private final Context mContext; + private final Looper mLooper; // Thread all media player callbacks and timeouts happen on private MediaSessionManager mMediaSessionManager; private MediaData mCurrMediaData = null; private final AudioManager mAudioManager; @@ -93,13 +93,13 @@ public class MediaPlayerList { new BluetoothEventLogger( AUDIO_PLAYBACK_STATE_LOGGER_SIZE, AUDIO_PLAYBACK_STATE_LOGGER_TITLE); - private Map<Integer, MediaPlayerWrapper> mMediaPlayers = + private final Map<Integer, MediaPlayerWrapper> mMediaPlayers = Collections.synchronizedMap(new HashMap<Integer, MediaPlayerWrapper>()); - private Map<String, Integer> mMediaPlayerIds = + private final Map<String, Integer> mMediaPlayerIds = Collections.synchronizedMap(new HashMap<String, Integer>()); - private Map<Integer, BrowsedPlayerWrapper> mBrowsablePlayers = + private final Map<Integer, BrowsedPlayerWrapper> mBrowsablePlayers = Collections.synchronizedMap(new HashMap<Integer, BrowsedPlayerWrapper>()); - private Map<Integer, MediaBrowserWrapper> mMediaBrowserWrappers = + private final Map<Integer, MediaBrowserWrapper> mMediaBrowserWrappers = Collections.synchronizedMap(new HashMap<Integer, MediaBrowserWrapper>()); private int mActivePlayerId = NO_ACTIVE_PLAYER; private int mBrowsingPlayerId = NO_ACTIVE_PLAYER; diff --git a/android/app/src/com/android/bluetooth/audio_util/MediaPlayerWrapper.java b/android/app/src/com/android/bluetooth/audio_util/MediaPlayerWrapper.java index 079319d07f..cca53936a5 100644 --- a/android/app/src/com/android/bluetooth/audio_util/MediaPlayerWrapper.java +++ b/android/app/src/com/android/bluetooth/audio_util/MediaPlayerWrapper.java @@ -50,7 +50,7 @@ public class MediaPlayerWrapper { final Context mContext; private MediaController mMediaController; - private String mPackageName; + private final String mPackageName; private Looper mLooper; private final BluetoothEventLogger mPlaybackStateChangeEventLogger; diff --git a/android/app/src/com/android/bluetooth/audio_util/helpers/Metadata.java b/android/app/src/com/android/bluetooth/audio_util/helpers/Metadata.java index 63791acb29..bc0de543ec 100644 --- a/android/app/src/com/android/bluetooth/audio_util/helpers/Metadata.java +++ b/android/app/src/com/android/bluetooth/audio_util/helpers/Metadata.java @@ -151,10 +151,10 @@ public class Metadata implements Cloneable { /** A Builder object to populate a Metadata from various different Media Framework objects */ public static class Builder { - private Metadata mMetadata = new Metadata(); + private final Metadata mMetadata = new Metadata(); private Context mContext = null; - /** Set the Media ID fot the Metadata Object */ + /** Set the Media ID for the Metadata Object */ public Builder setMediaId(String id) { mMetadata.mediaId = id; return this; diff --git a/android/app/src/com/android/bluetooth/avrcp/AvrcpCoverArtService.java b/android/app/src/com/android/bluetooth/avrcp/AvrcpCoverArtService.java index 1a015287f4..2351f30fc2 100644 --- a/android/app/src/com/android/bluetooth/avrcp/AvrcpCoverArtService.java +++ b/android/app/src/com/android/bluetooth/avrcp/AvrcpCoverArtService.java @@ -60,7 +60,7 @@ public class AvrcpCoverArtService { private final Object mServerLock = new Object(); // Native interface - private AvrcpNativeInterface mNativeInterface; + private final AvrcpNativeInterface mNativeInterface; // The native interface must be a parameter here in order to be able to mock AvrcpTargetService public AvrcpCoverArtService(AvrcpNativeInterface nativeInterface) { diff --git a/android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java b/android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java index d76e893bf7..1e2e5607cb 100644 --- a/android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java +++ b/android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java @@ -46,7 +46,7 @@ public class AvrcpNativeInterface { private static final Object INSTANCE_LOCK = new Object(); private AvrcpTargetService mAvrcpService; - private AdapterService mAdapterService; + private final AdapterService mAdapterService; private AvrcpNativeInterface() { mAdapterService = requireNonNull(AdapterService.getAdapterService()); diff --git a/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClient.java b/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClient.java index dd5f3bb067..ab89236d84 100644 --- a/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClient.java +++ b/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClient.java @@ -390,7 +390,7 @@ public class AvrcpBipClient { /** Handles this AVRCP BIP Image Pull Client's requests */ private static class AvrcpBipClientHandler extends Handler { - WeakReference<AvrcpBipClient> mInst; + final WeakReference<AvrcpBipClient> mInst; AvrcpBipClientHandler(Looper looper, AvrcpBipClient inst) { super(looper); diff --git a/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtManager.java b/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtManager.java index 9fb548a2bb..64648082fe 100644 --- a/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtManager.java +++ b/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtManager.java @@ -50,7 +50,7 @@ public class AvrcpCoverArtManager { private final AvrcpControllerService mService; protected final Map<BluetoothDevice, AvrcpBipClient> mClients = new ConcurrentHashMap<>(1); - private Map<BluetoothDevice, AvrcpBipSession> mBipSessions = new ConcurrentHashMap<>(1); + private final Map<BluetoothDevice, AvrcpBipSession> mBipSessions = new ConcurrentHashMap<>(1); private final AvrcpCoverArtStorage mCoverArtStorage; private final Callback mCallback; private final String mDownloadScheme; @@ -94,8 +94,8 @@ public class AvrcpCoverArtManager { * <p>Currently contains the mapping of image handles seen to assigned UUIDs. */ private static class AvrcpBipSession { - private Map<String, String> mUuids = new ConcurrentHashMap<>(1); /* handle -> UUID */ - private Map<String, String> mHandles = new ConcurrentHashMap<>(1); /* UUID -> handle */ + private final Map<String, String> mUuids = new ConcurrentHashMap<>(1); // handle -> UUID + private final Map<String, String> mHandles = new ConcurrentHashMap<>(1); // UUID -> handle public String getHandleUuid(String handle) { if (!isValidImageHandle(handle)) return null; diff --git a/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpItem.java b/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpItem.java index 3722796f37..54066e77cd 100644 --- a/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpItem.java +++ b/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpItem.java @@ -311,7 +311,7 @@ public class AvrcpItem { private static final int MEDIA_ATTRIBUTE_PLAYING_TIME = 0x07; private static final int MEDIA_ATTRIBUTE_COVER_ART_HANDLE = 0x08; - private AvrcpItem mAvrcpItem = new AvrcpItem(); + private final AvrcpItem mAvrcpItem = new AvrcpItem(); /** * Initialize all relevant AvrcpItem internals from the AVRCP specification defined set of diff --git a/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayer.java b/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayer.java index 6c68eb33d5..7c90b72a90 100644 --- a/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayer.java +++ b/android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayer.java @@ -53,11 +53,11 @@ class AvrcpPlayer { public static final int FEATURE_BROWSING = 59; public static final int FEATURE_NOW_PLAYING = 65; - private BluetoothDevice mDevice; + private final BluetoothDevice mDevice; private int mPlayStatus = PlaybackStateCompat.STATE_NONE; private long mPlayTime = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; private float mPlaySpeed = 1; - private int mId; + private final int mId; private String mName = ""; private byte[] mPlayerFeatures = new byte[16]; private long mAvailableActions = PlaybackStateCompat.ACTION_PREPARE; diff --git a/android/app/src/com/android/bluetooth/avrcpcontroller/BluetoothMediaBrowserService.java b/android/app/src/com/android/bluetooth/avrcpcontroller/BluetoothMediaBrowserService.java index 8c498f6a7b..e0becffe60 100644 --- a/android/app/src/com/android/bluetooth/avrcpcontroller/BluetoothMediaBrowserService.java +++ b/android/app/src/com/android/bluetooth/avrcpcontroller/BluetoothMediaBrowserService.java @@ -65,7 +65,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { private MediaSessionCompat mSession; // Browsing related structures. - private List<MediaSessionCompat.QueueItem> mMediaQueue = new ArrayList<>(); + private final List<MediaSessionCompat.QueueItem> mMediaQueue = new ArrayList<>(); // Media Framework Content Style constants private static final String CONTENT_STYLE_SUPPORTED = @@ -194,7 +194,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { public static final byte ERROR_MEDIA_ID_INVALID = 0x03; public static final byte ERROR_NO_AVRCP_SERVICE = 0x04; - private List<MediaItem> mResults; + private final List<MediaItem> mResults; private final byte mStatus; List<MediaItem> getResults() { diff --git a/android/app/src/com/android/bluetooth/avrcpcontroller/bip/BipImageDescriptor.java b/android/app/src/com/android/bluetooth/avrcpcontroller/bip/BipImageDescriptor.java index 6777f0fae7..41f3c64d4c 100644 --- a/android/app/src/com/android/bluetooth/avrcpcontroller/bip/BipImageDescriptor.java +++ b/android/app/src/com/android/bluetooth/avrcpcontroller/bip/BipImageDescriptor.java @@ -59,7 +59,7 @@ public class BipImageDescriptor { /** A Builder for an ImageDescriptor object */ public static class Builder { - private BipImageDescriptor mImageDescriptor = new BipImageDescriptor(); + private final BipImageDescriptor mImageDescriptor = new BipImageDescriptor(); /** * Set the encoding for the descriptor you're building using a BipEncoding object diff --git a/android/app/src/com/android/bluetooth/avrcpcontroller/bip/BipImageProperties.java b/android/app/src/com/android/bluetooth/avrcpcontroller/bip/BipImageProperties.java index 7e389ff45f..e049b861d8 100644 --- a/android/app/src/com/android/bluetooth/avrcpcontroller/bip/BipImageProperties.java +++ b/android/app/src/com/android/bluetooth/avrcpcontroller/bip/BipImageProperties.java @@ -66,7 +66,7 @@ public class BipImageProperties { /** A Builder for a BipImageProperties object */ public static class Builder { - private BipImageProperties mProperties = new BipImageProperties(); + private final BipImageProperties mProperties = new BipImageProperties(); /** * Set the image handle field for the object you're building @@ -148,22 +148,16 @@ public class BipImageProperties { private boolean mHasThumbnailFormat = false; /** The various sets of available formats. */ - private List<BipImageFormat> mNativeFormats; + private final List<BipImageFormat> mNativeFormats = new ArrayList<>(); - private List<BipImageFormat> mVariantFormats; - private List<BipAttachmentFormat> mAttachments; + private final List<BipImageFormat> mVariantFormats = new ArrayList<>(); + private final List<BipAttachmentFormat> mAttachments = new ArrayList<>(); private BipImageProperties() { mVersion = sVersion; - mNativeFormats = new ArrayList<BipImageFormat>(); - mVariantFormats = new ArrayList<BipImageFormat>(); - mAttachments = new ArrayList<BipAttachmentFormat>(); } public BipImageProperties(InputStream inputStream) { - mNativeFormats = new ArrayList<BipImageFormat>(); - mVariantFormats = new ArrayList<BipImageFormat>(); - mAttachments = new ArrayList<BipAttachmentFormat>(); parse(inputStream); } diff --git a/android/app/src/com/android/bluetooth/bas/BatteryStateMachine.java b/android/app/src/com/android/bluetooth/bas/BatteryStateMachine.java index abd223648d..991a77cb93 100644 --- a/android/app/src/com/android/bluetooth/bas/BatteryStateMachine.java +++ b/android/app/src/com/android/bluetooth/bas/BatteryStateMachine.java @@ -71,10 +71,10 @@ public class BatteryStateMachine extends StateMachine { @VisibleForTesting static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(30); - private Disconnected mDisconnected; - private Connecting mConnecting; - private Connected mConnected; - private Disconnecting mDisconnecting; + private final Disconnected mDisconnected; + private final Connecting mConnecting; + private final Connected mConnected; + private final Disconnecting mDisconnecting; private int mLastConnectionState = STATE_DISCONNECTED; private final BatteryService mService; diff --git a/android/app/src/com/android/bluetooth/bass_client/BassClientService.java b/android/app/src/com/android/bluetooth/bass_client/BassClientService.java index f68340b53d..b6e99dc2e1 100644 --- a/android/app/src/com/android/bluetooth/bass_client/BassClientService.java +++ b/android/app/src/com/android/bluetooth/bass_client/BassClientService.java @@ -220,7 +220,7 @@ public class BassClientService extends ProfileService { private static final int SCANNER_ID_NOT_INITIALIZED = -2; private static final int SCANNER_ID_INITIALIZING = -1; - private List<ScanFilter> mBaasUuidFilters = new ArrayList<ScanFilter>(); + private final List<ScanFilter> mBaasUuidFilters = new ArrayList<ScanFilter>(); private int mScannerId = SCANNER_ID_NOT_INITIALIZED; void registerAndStartScan(List<ScanFilter> filters) { @@ -582,9 +582,9 @@ public class BassClientService extends ProfileService { }; private static class AddSourceData { - BluetoothDevice mSink; - BluetoothLeBroadcastMetadata mSourceMetadata; - boolean mIsGroupOp; + final BluetoothDevice mSink; + final BluetoothLeBroadcastMetadata mSourceMetadata; + final boolean mIsGroupOp; AddSourceData( BluetoothDevice sink, @@ -4604,8 +4604,8 @@ public class BassClientService extends ProfileService { } private static class ObjParams { - Object mObj1; - Object mObj2; + final Object mObj1; + final Object mObj2; ObjParams(Object o1, Object o2) { mObj1 = o1; diff --git a/android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java b/android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java index d5d532940a..706f886911 100644 --- a/android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java +++ b/android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java @@ -91,6 +91,7 @@ class BassClientStateMachine extends StateMachine { private static final byte OPCODE_SET_BCAST_PIN = 0x04; private static final byte OPCODE_REMOVE_SOURCE = 0x05; private static final int UPDATE_SOURCE_FIXED_LENGTH = 6; + private static final int BROADCAST_SOURCE_ID_LENGTH = 3; static final int CONNECT = 1; static final int DISCONNECT = 2; @@ -109,8 +110,7 @@ class BassClientStateMachine extends StateMachine { static final int CANCEL_PENDING_SOURCE_OPERATION = 15; static final int INITIATE_PA_SYNC_TRANSFER = 16; - // NOTE: the value is not "final" - it is modified in the unit tests - @VisibleForTesting private int mConnectTimeoutMs; + private final int mConnectTimeoutMs; // Type of argument for set broadcast code operation static final int ARGTYPE_METADATA = 1; @@ -154,7 +154,6 @@ class BassClientStateMachine extends StateMachine { private final Map<Integer, Boolean> mPendingRemove = new HashMap(); private boolean mDefNoPAS = false; private boolean mForceSB = false; - private int mBroadcastSourceIdLength = 3; @VisibleForTesting byte mNextSourceId = 0; private boolean mAllowReconnect = false; @VisibleForTesting BluetoothGattTestableWrapper mBluetoothGatt = null; @@ -200,10 +199,10 @@ class BassClientStateMachine extends StateMachine { } private static class LeAudioBroadcastSyncStats { - private BluetoothDevice mDevice; - private boolean mIsLocalBroadcast; - private int mBroadcastId; - private long mSourceAddTime; + private final BluetoothDevice mDevice; + private final boolean mIsLocalBroadcast; + private final int mBroadcastId; + private final long mSourceAddTime; private long mSourcePaSyncedTime; private long mSourceBisSyncedTime; private int mSyncStatus; @@ -747,13 +746,13 @@ class BassClientStateMachine extends StateMachine { metadataList.add(BluetoothLeAudioContentMetadata.fromRawBytes(new byte[0])); } } - byte[] broadcastIdBytes = new byte[mBroadcastSourceIdLength]; + byte[] broadcastIdBytes = new byte[BROADCAST_SOURCE_ID_LENGTH]; System.arraycopy( receiverState, BassConstants.BCAST_RCVR_STATE_SRC_BCAST_ID_START_IDX, broadcastIdBytes, 0, - mBroadcastSourceIdLength); + BROADCAST_SOURCE_ID_LENGTH); int broadcastId = BassUtils.parseBroadcastId(broadcastIdBytes); byte[] sourceAddress = new byte[BassConstants.BCAST_RCVR_STATE_SRC_ADDR_SIZE]; System.arraycopy( @@ -968,13 +967,13 @@ class BassClientStateMachine extends StateMachine { metadataList.add(BluetoothLeAudioContentMetadata.fromRawBytes(new byte[0])); } } - byte[] broadcastIdBytes = new byte[mBroadcastSourceIdLength]; + byte[] broadcastIdBytes = new byte[BROADCAST_SOURCE_ID_LENGTH]; System.arraycopy( receiverState, BassConstants.BCAST_RCVR_STATE_SRC_BCAST_ID_START_IDX, broadcastIdBytes, 0, - mBroadcastSourceIdLength); + BROADCAST_SOURCE_ID_LENGTH); int broadcastId = BassUtils.parseBroadcastId(broadcastIdBytes); byte[] sourceAddress = new byte[BassConstants.BCAST_RCVR_STATE_SRC_ADDR_SIZE]; System.arraycopy( diff --git a/android/app/src/com/android/bluetooth/bass_client/PeriodicAdvertisementResult.java b/android/app/src/com/android/bluetooth/bass_client/PeriodicAdvertisementResult.java index 6a985f6ac0..e36f0de976 100644 --- a/android/app/src/com/android/bluetooth/bass_client/PeriodicAdvertisementResult.java +++ b/android/app/src/com/android/bluetooth/bass_client/PeriodicAdvertisementResult.java @@ -23,7 +23,7 @@ import android.util.Log; public class PeriodicAdvertisementResult { private static final String TAG = PeriodicAdvertisementResult.class.getSimpleName(); - private BluetoothDevice mDevice; + private final BluetoothDevice mDevice; private int mAddressType; private int mAdvSid; private int mSyncHandle; diff --git a/android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java b/android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java index 95c6661be4..61429c8d90 100644 --- a/android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java +++ b/android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java @@ -142,7 +142,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac private final List<BluetoothDevice> mLeHearingAidConnectedDevices = new ArrayList<>(); @GuardedBy("mLock") - private List<BluetoothDevice> mPendingLeHearingAidActiveDevice = new ArrayList<>(); + private final List<BluetoothDevice> mPendingLeHearingAidActiveDevice = new ArrayList<>(); @GuardedBy("mLock") private BluetoothDevice mA2dpActiveDevice = null; diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterProperties.java b/android/app/src/com/android/bluetooth/btservice/AdapterProperties.java index 8166412b0a..9385004747 100644 --- a/android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +++ b/android/app/src/com/android/bluetooth/btservice/AdapterProperties.java @@ -89,7 +89,8 @@ class AdapterProperties { private volatile int mDiscoverableTimeout; private volatile ParcelUuid[] mUuids; - private CopyOnWriteArrayList<BluetoothDevice> mBondedDevices = new CopyOnWriteArrayList<>(); + private final CopyOnWriteArrayList<BluetoothDevice> mBondedDevices = + new CopyOnWriteArrayList<>(); private int mProfilesConnecting, mProfilesConnected, mProfilesDisconnecting; private final HashMap<Integer, Pair<Integer, Integer>> mProfileConnectionState = diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterService.java b/android/app/src/com/android/bluetooth/btservice/AdapterService.java index 3d61a63928..bb560fa8f7 100644 --- a/android/app/src/com/android/bluetooth/btservice/AdapterService.java +++ b/android/app/src/com/android/bluetooth/btservice/AdapterService.java @@ -299,7 +299,7 @@ public class AdapterService extends Service { private long mRxTimeTotalMs; private long mIdleTimeTotalMs; private long mEnergyUsedTotalVoltAmpSecMicro; - private HashSet<String> mLeAudioAllowDevices = new HashSet<>(); + private final HashSet<String> mLeAudioAllowDevices = new HashSet<>(); /* List of pairs of gatt clients which controls AutoActiveMode on the device.*/ @VisibleForTesting @@ -319,7 +319,7 @@ public class AdapterService extends Service { private boolean mNativeAvailable; private boolean mCleaningUp; private boolean mQuietmode = false; - private Map<String, CallerInfo> mBondAttemptCallerInfo = new HashMap<>(); + private final Map<String, CallerInfo> mBondAttemptCallerInfo = new HashMap<>(); private BatteryStatsManager mBatteryStatsManager; private PowerManager mPowerManager; @@ -618,7 +618,7 @@ public class AdapterService extends Service { // The newly requested preferences final Bundle mRequestedPreferences; // Reference counter for how many calls are pending completion in the audio framework - int mRemainingRequestsToAudioFramework; + final int mRemainingRequestsToAudioFramework; // The device with which the request was made. Used for sending the callback. final BluetoothDevice mDeviceRequested; diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterState.java b/android/app/src/com/android/bluetooth/btservice/AdapterState.java index b5ff730b5a..1197e11845 100644 --- a/android/app/src/com/android/bluetooth/btservice/AdapterState.java +++ b/android/app/src/com/android/bluetooth/btservice/AdapterState.java @@ -67,13 +67,13 @@ final class AdapterState extends StateMachine { 4000 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1); private AdapterService mAdapterService; - private TurningOnState mTurningOnState = new TurningOnState(); - private TurningBleOnState mTurningBleOnState = new TurningBleOnState(); - private TurningOffState mTurningOffState = new TurningOffState(); - private TurningBleOffState mTurningBleOffState = new TurningBleOffState(); - private OnState mOnState = new OnState(); - private OffState mOffState = new OffState(); - private BleOnState mBleOnState = new BleOnState(); + private final TurningOnState mTurningOnState = new TurningOnState(); + private final TurningBleOnState mTurningBleOnState = new TurningBleOnState(); + private final TurningOffState mTurningOffState = new TurningOffState(); + private final TurningBleOffState mTurningBleOffState = new TurningBleOffState(); + private final OnState mOnState = new OnState(); + private final OffState mOffState = new OffState(); + private final BleOnState mBleOnState = new BleOnState(); private int mPrevState = BluetoothAdapter.STATE_OFF; diff --git a/android/app/src/com/android/bluetooth/btservice/BondStateMachine.java b/android/app/src/com/android/bluetooth/btservice/BondStateMachine.java index 30be010ae4..b822ae3251 100644 --- a/android/app/src/com/android/bluetooth/btservice/BondStateMachine.java +++ b/android/app/src/com/android/bluetooth/btservice/BondStateMachine.java @@ -85,10 +85,10 @@ final class BondStateMachine extends StateMachine { private AdapterService mAdapterService; private AdapterProperties mAdapterProperties; private RemoteDevices mRemoteDevices; - private BluetoothAdapter mAdapter; + private final BluetoothAdapter mAdapter; - private PendingCommandState mPendingCommandState = new PendingCommandState(); - private StableState mStableState = new StableState(); + private final PendingCommandState mPendingCommandState = new PendingCommandState(); + private final StableState mStableState = new StableState(); public static final String OOBDATAP192 = "oobdatap192"; public static final String OOBDATAP256 = "oobdatap256"; diff --git a/android/app/src/com/android/bluetooth/btservice/Config.java b/android/app/src/com/android/bluetooth/btservice/Config.java index dbed62a154..1cac6b8c8b 100644 --- a/android/app/src/com/android/bluetooth/btservice/Config.java +++ b/android/app/src/com/android/bluetooth/btservice/Config.java @@ -68,7 +68,7 @@ public class Config { private static class ProfileConfig { boolean mSupported; - int mProfileId; + final int mProfileId; ProfileConfig(boolean supported, int profileId) { mSupported = supported; diff --git a/android/app/src/com/android/bluetooth/btservice/DiscoveringPackage.java b/android/app/src/com/android/bluetooth/btservice/DiscoveringPackage.java index e2b7295322..f13bf94a8d 100644 --- a/android/app/src/com/android/bluetooth/btservice/DiscoveringPackage.java +++ b/android/app/src/com/android/bluetooth/btservice/DiscoveringPackage.java @@ -20,9 +20,9 @@ import android.annotation.NonNull; import android.annotation.Nullable; final class DiscoveringPackage { - private @NonNull String mPackageName; - private @Nullable String mPermission; - private boolean mHasDisavowedLocation; + private final @NonNull String mPackageName; + private final @Nullable String mPermission; + private final boolean mHasDisavowedLocation; DiscoveringPackage( @NonNull String packageName, diff --git a/android/app/src/com/android/bluetooth/btservice/MetricsLogger.java b/android/app/src/com/android/bluetooth/btservice/MetricsLogger.java index e8a5df5043..06758cea38 100644 --- a/android/app/src/com/android/bluetooth/btservice/MetricsLogger.java +++ b/android/app/src/com/android/bluetooth/btservice/MetricsLogger.java @@ -127,7 +127,7 @@ public class MetricsLogger { protected boolean mMedicalDeviceBloomFilterInitialized = false; - private AlarmManager.OnAlarmListener mOnAlarmListener = + private final AlarmManager.OnAlarmListener mOnAlarmListener = new AlarmManager.OnAlarmListener() { @Override public void onAlarm() { diff --git a/android/app/src/com/android/bluetooth/btservice/RemoteDevices.java b/android/app/src/com/android/bluetooth/btservice/RemoteDevices.java index cb3331ffce..2f97c879c7 100644 --- a/android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +++ b/android/app/src/com/android/bluetooth/btservice/RemoteDevices.java @@ -77,9 +77,9 @@ public class RemoteDevices { // Maximum number of device properties to remember private static final int MAX_DEVICE_QUEUE_SIZE = 200; - private BluetoothAdapter mAdapter; + private final BluetoothAdapter mAdapter; private AdapterService mAdapterService; - private ArrayList<BluetoothDevice> mSdpTracker; + private final ArrayList<BluetoothDevice> mSdpTracker; private final Object mObject = new Object(); private static final int UUID_INTENT_DELAY = 6000; diff --git a/android/app/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java b/android/app/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java index 9812509ea0..020692ae6f 100644 --- a/android/app/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java +++ b/android/app/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java @@ -62,7 +62,7 @@ public class BluetoothKeystoreService { private static final String TAG = BluetoothKeystoreService.class.getSimpleName(); private static BluetoothKeystoreService sBluetoothKeystoreService; - private boolean mIsCommonCriteriaMode; + private final boolean mIsCommonCriteriaMode; private static final String CIPHER_ALGORITHM = "AES/GCM/NoPadding"; private static final int GCM_TAG_LENGTH = 128; @@ -92,10 +92,10 @@ public class BluetoothKeystoreService { private ComputeDataThread mEncryptDataThread; private ComputeDataThread mDecryptDataThread; - private Map<String, String> mNameEncryptKey = new HashMap<>(); - private Map<String, String> mNameDecryptKey = new HashMap<>(); - private BlockingQueue<String> mPendingDecryptKey = new LinkedBlockingQueue<>(); - private BlockingQueue<String> mPendingEncryptKey = new LinkedBlockingQueue<>(); + private final Map<String, String> mNameEncryptKey = new HashMap<>(); + private final Map<String, String> mNameDecryptKey = new HashMap<>(); + private final BlockingQueue<String> mPendingDecryptKey = new LinkedBlockingQueue<>(); + private final BlockingQueue<String> mPendingEncryptKey = new LinkedBlockingQueue<>(); private final List<String> mEncryptKeyNameList = List.of( "LinkKey", @@ -106,8 +106,8 @@ public class BluetoothKeystoreService { "LE_KEY_LENC", "LE_KEY_LCSRK"); - private Base64.Decoder mDecoder = Base64.getDecoder(); - private Base64.Encoder mEncoder = Base64.getEncoder(); + private final Base64.Decoder mDecoder = Base64.getDecoder(); + private final Base64.Encoder mEncoder = Base64.getEncoder(); public BluetoothKeystoreService( BluetoothKeystoreNativeInterface nativeInterface, boolean isCommonCriteriaMode) { @@ -766,10 +766,10 @@ public class BluetoothKeystoreService { /** A thread that decrypt data if the queue has new decrypt task. */ private class ComputeDataThread extends Thread { - private Map<String, String> mSourceDataMap; - private Map<String, String> mTargetDataMap; - private BlockingQueue<String> mSourceQueue; - private boolean mDoEncrypt; + private final Map<String, String> mSourceDataMap; + private final Map<String, String> mTargetDataMap; + private final BlockingQueue<String> mSourceQueue; + private final boolean mDoEncrypt; private boolean mWaitQueueEmptyForStop; diff --git a/android/app/src/com/android/bluetooth/btservice/storage/Metadata.java b/android/app/src/com/android/bluetooth/btservice/storage/Metadata.java index 2e8aaa625e..28b286280f 100644 --- a/android/app/src/com/android/bluetooth/btservice/storage/Metadata.java +++ b/android/app/src/com/android/bluetooth/btservice/storage/Metadata.java @@ -36,7 +36,7 @@ import java.util.List; @Entity(tableName = "metadata") public class Metadata { - @PrimaryKey @NonNull private String address; + @PrimaryKey @NonNull private final String address; public boolean migrated; diff --git a/android/app/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachine.java b/android/app/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachine.java index 8a9953dbb7..c0413865c6 100644 --- a/android/app/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachine.java +++ b/android/app/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachine.java @@ -54,14 +54,14 @@ public class CsipSetCoordinatorStateMachine extends StateMachine { // NOTE: the value is not "final" - it is modified in the unit tests @VisibleForTesting static int sConnectTimeoutMs = 30000; // 30s - private Disconnected mDisconnected; - private Connecting mConnecting; - private Disconnecting mDisconnecting; - private Connected mConnected; + private final Disconnected mDisconnected; + private final Connecting mConnecting; + private final Disconnecting mDisconnecting; + private final Connected mConnected; private int mLastConnectionState = -1; - private CsipSetCoordinatorService mService; - private CsipSetCoordinatorNativeInterface mNativeInterface; + private final CsipSetCoordinatorService mService; + private final CsipSetCoordinatorNativeInterface mNativeInterface; private final BluetoothDevice mDevice; diff --git a/android/app/src/com/android/bluetooth/gatt/AdvertiseManager.java b/android/app/src/com/android/bluetooth/gatt/AdvertiseManager.java index 0f28f6742c..e6d0d6612a 100644 --- a/android/app/src/com/android/bluetooth/gatt/AdvertiseManager.java +++ b/android/app/src/com/android/bluetooth/gatt/AdvertiseManager.java @@ -131,7 +131,7 @@ public class AdvertiseManager { class AdvertisingSetDeathRecipient implements IBinder.DeathRecipient { public IAdvertisingSetCallback callback; - private String mPackageName; + private final String mPackageName; AdvertisingSetDeathRecipient(IAdvertisingSetCallback callback, String packageName) { this.callback = callback; diff --git a/android/app/src/com/android/bluetooth/gatt/AppAdvertiseStats.java b/android/app/src/com/android/bluetooth/gatt/AppAdvertiseStats.java index 4656976850..faf335e651 100644 --- a/android/app/src/com/android/bluetooth/gatt/AppAdvertiseStats.java +++ b/android/app/src/com/android/bluetooth/gatt/AppAdvertiseStats.java @@ -46,7 +46,7 @@ import java.util.Map; class AppAdvertiseStats { private static final String TAG = AppAdvertiseStats.class.getSimpleName(); - private static DateTimeFormatter sDateFormat = + private static final DateTimeFormatter sDateFormat = DateTimeFormatter.ofPattern("MM-dd HH:mm:ss").withZone(ZoneId.systemDefault()); static final String[] PHY_LE_STRINGS = {"LE_1M", "LE_2M", "LE_CODED"}; @@ -84,9 +84,9 @@ class AppAdvertiseStats { } } - private int mAppUid; + private final int mAppUid; @VisibleForTesting String mAppName; - @Nullable private String mAttributionTag; + private final @Nullable String mAttributionTag; private int mId; private boolean mAdvertisingEnabled = false; private boolean mPeriodicAdvertisingEnabled = false; @@ -98,9 +98,9 @@ class AppAdvertiseStats { private boolean mAnonymous = false; private boolean mConnectable = false; private boolean mScannable = false; - @Nullable private AppAdvertiserData mAdvertisingData = null; - @Nullable private AppAdvertiserData mScanResponseData = null; - @Nullable private AppAdvertiserData mPeriodicAdvertisingData = null; + private @Nullable AppAdvertiserData mAdvertisingData = null; + private @Nullable AppAdvertiserData mScanResponseData = null; + private @Nullable AppAdvertiserData mPeriodicAdvertisingData = null; private boolean mPeriodicIncludeTxPower = false; private int mPeriodicInterval = 0; public ArrayList<AppAdvertiserRecord> mAdvertiserRecords = new ArrayList<AppAdvertiserRecord>(); diff --git a/android/app/src/com/android/bluetooth/gatt/CallbackInfo.java b/android/app/src/com/android/bluetooth/gatt/CallbackInfo.java index 5f38241a30..f104b7ee19 100644 --- a/android/app/src/com/android/bluetooth/gatt/CallbackInfo.java +++ b/android/app/src/com/android/bluetooth/gatt/CallbackInfo.java @@ -26,8 +26,8 @@ public class CallbackInfo { public byte[] value; static class Builder { - private String mAddress; - private int mStatus; + private final String mAddress; + private final int mStatus; private int mHandle; private byte[] mValue; diff --git a/android/app/src/com/android/bluetooth/gatt/ContextMap.java b/android/app/src/com/android/bluetooth/gatt/ContextMap.java index 5aa3529982..039f76976a 100644 --- a/android/app/src/com/android/bluetooth/gatt/ContextMap.java +++ b/android/app/src/com/android/bluetooth/gatt/ContextMap.java @@ -99,7 +99,7 @@ public class ContextMap<C> { public Boolean isCongested = false; /** Internal callback info queue, waiting to be send on congestion clear */ - private List<CallbackInfo> mCongestionQueue = new ArrayList<>(); + private final List<CallbackInfo> mCongestionQueue = new ArrayList<>(); /** Creates a new app context. */ App(UUID uuid, C callback, int appUid, String name, AttributionSource attrSource) { @@ -182,7 +182,7 @@ public class ContextMap<C> { private final Object mAppsLock = new Object(); @GuardedBy("mAppsLock") - private List<App> mApps = new ArrayList<>(); + private final List<App> mApps = new ArrayList<>(); @GuardedBy("mAppsLock") private final List<AppRecord> mOngoingRecords = new ArrayList<>(); @@ -191,7 +191,7 @@ public class ContextMap<C> { private final List<AppRecord> mLastRecords = new ArrayList<>(); /** Internal list of connected devices */ - private List<Connection> mConnections = new ArrayList<>(); + private final List<Connection> mConnections = new ArrayList<>(); private final Object mConnectionsLock = new Object(); diff --git a/android/app/src/com/android/bluetooth/gatt/FilterParams.java b/android/app/src/com/android/bluetooth/gatt/FilterParams.java index d1fddb6147..762e7e8818 100644 --- a/android/app/src/com/android/bluetooth/gatt/FilterParams.java +++ b/android/app/src/com/android/bluetooth/gatt/FilterParams.java @@ -17,18 +17,18 @@ package com.android.bluetooth.gatt; public class FilterParams { - private int mClientIf; - private int mFiltIndex; - private int mFeatSeln; - private int mListLogicType; - private int mFiltLogicType; - private int mRssiHighValue; - private int mRssiLowValue; - private int mDelyMode; - private int mFoundTimeOut; - private int mLostTimeOut; - private int mFoundTimeOutCnt; - private int mNumOfTrackEntries; + private final int mClientIf; + private final int mFiltIndex; + private final int mFeatSeln; + private final int mListLogicType; + private final int mFiltLogicType; + private final int mRssiHighValue; + private final int mRssiLowValue; + private final int mDelyMode; + private final int mFoundTimeOut; + private final int mLostTimeOut; + private final int mFoundTimeOutCnt; + private final int mNumOfTrackEntries; public FilterParams( int clientIf, diff --git a/android/app/src/com/android/bluetooth/gatt/GattService.java b/android/app/src/com/android/bluetooth/gatt/GattService.java index 17fddf788a..947885020a 100644 --- a/android/app/src/com/android/bluetooth/gatt/GattService.java +++ b/android/app/src/com/android/bluetooth/gatt/GattService.java @@ -293,7 +293,7 @@ public class GattService extends ProfileService { class ServerDeathRecipient implements IBinder.DeathRecipient { int mAppIf; - private String mPackageName; + private final String mPackageName; ServerDeathRecipient(int appIf, String packageName) { mAppIf = appIf; @@ -311,7 +311,7 @@ public class GattService extends ProfileService { class ClientDeathRecipient implements IBinder.DeathRecipient { int mAppIf; - private String mPackageName; + private final String mPackageName; ClientDeathRecipient(int appIf, String packageName) { mAppIf = appIf; diff --git a/android/app/src/com/android/bluetooth/hearingaid/HearingAidNativeInterface.java b/android/app/src/com/android/bluetooth/hearingaid/HearingAidNativeInterface.java index ae01feab9f..23ad690a21 100644 --- a/android/app/src/com/android/bluetooth/hearingaid/HearingAidNativeInterface.java +++ b/android/app/src/com/android/bluetooth/hearingaid/HearingAidNativeInterface.java @@ -33,7 +33,7 @@ import com.android.internal.annotations.VisibleForTesting; public class HearingAidNativeInterface { private static final String TAG = HearingAidNativeInterface.class.getSimpleName(); - private BluetoothAdapter mAdapter; + private final BluetoothAdapter mAdapter; @GuardedBy("INSTANCE_LOCK") private static HearingAidNativeInterface sInstance; diff --git a/android/app/src/com/android/bluetooth/hfp/HeadsetNativeInterface.java b/android/app/src/com/android/bluetooth/hfp/HeadsetNativeInterface.java index fc39ba7c43..9606d32cca 100644 --- a/android/app/src/com/android/bluetooth/hfp/HeadsetNativeInterface.java +++ b/android/app/src/com/android/bluetooth/hfp/HeadsetNativeInterface.java @@ -43,7 +43,7 @@ public class HeadsetNativeInterface { private static final Object INSTANCE_LOCK = new Object(); - private AdapterService mAdapterService; + private final AdapterService mAdapterService; private HeadsetNativeInterface() { mAdapterService = requireNonNull(AdapterService.getAdapterService()); diff --git a/android/app/src/com/android/bluetooth/hfp/HeadsetService.java b/android/app/src/com/android/bluetooth/hfp/HeadsetService.java index 84fa8239b1..1116e2f9a6 100644 --- a/android/app/src/com/android/bluetooth/hfp/HeadsetService.java +++ b/android/app/src/com/android/bluetooth/hfp/HeadsetService.java @@ -159,7 +159,7 @@ public class HeadsetService extends ProfileService { private VoiceRecognitionTimeoutEvent mVoiceRecognitionTimeoutEvent; // Timeout when voice recognition is started by remote device @VisibleForTesting static int sStartVrTimeoutMs = 5000; - private ArrayList<StateMachineTask> mPendingClccResponses = new ArrayList<>(); + private final ArrayList<StateMachineTask> mPendingClccResponses = new ArrayList<>(); private final AudioManagerAudioDeviceCallback mAudioManagerAudioDeviceCallback = new AudioManagerAudioDeviceCallback(); private static HeadsetService sHeadsetService; diff --git a/android/app/src/com/android/bluetooth/hfp/HeadsetSystemInterface.java b/android/app/src/com/android/bluetooth/hfp/HeadsetSystemInterface.java index 4a82d74f83..67967e941b 100644 --- a/android/app/src/com/android/bluetooth/hfp/HeadsetSystemInterface.java +++ b/android/app/src/com/android/bluetooth/hfp/HeadsetSystemInterface.java @@ -46,7 +46,7 @@ class HeadsetSystemInterface { private final HeadsetService mHeadsetService; private final AudioManager mAudioManager; private final HeadsetPhoneState mHeadsetPhoneState; - private PowerManager.WakeLock mVoiceRecognitionWakeLock; + private final PowerManager.WakeLock mVoiceRecognitionWakeLock; private final TelephonyManager mTelephonyManager; private final TelecomManager mTelecomManager; diff --git a/android/app/src/com/android/bluetooth/hfpclient/HfpClientConnectionService.java b/android/app/src/com/android/bluetooth/hfpclient/HfpClientConnectionService.java index a697e8e4a2..73f03701d6 100644 --- a/android/app/src/com/android/bluetooth/hfpclient/HfpClientConnectionService.java +++ b/android/app/src/com/android/bluetooth/hfpclient/HfpClientConnectionService.java @@ -51,7 +51,8 @@ public class HfpClientConnectionService extends ConnectionService { private TelecomManager mTelecomManager; - private HeadsetClientServiceInterface mServiceInterface = new HeadsetClientServiceInterface(); + private final HeadsetClientServiceInterface mServiceInterface = + new HeadsetClientServiceInterface(); private final Map<BluetoothDevice, HfpClientDeviceBlock> mDeviceBlocks = new HashMap<>(); diff --git a/android/app/src/com/android/bluetooth/hfpclient/HfpClientDeviceBlock.java b/android/app/src/com/android/bluetooth/hfpclient/HfpClientDeviceBlock.java index d69cdb7d82..b68d4f41f6 100644 --- a/android/app/src/com/android/bluetooth/hfpclient/HfpClientDeviceBlock.java +++ b/android/app/src/com/android/bluetooth/hfpclient/HfpClientDeviceBlock.java @@ -48,7 +48,7 @@ public class HfpClientDeviceBlock { private final TelecomManager mTelecomManager; private final HfpClientConnectionService mConnServ; private HfpClientConference mConference; - private Bundle mScoState; + private final Bundle mScoState; private final HeadsetClientServiceInterface mServiceInterface; HfpClientDeviceBlock( diff --git a/android/app/src/com/android/bluetooth/hid/HidDeviceService.java b/android/app/src/com/android/bluetooth/hid/HidDeviceService.java index 67e9349a28..6e5ea040ea 100644 --- a/android/app/src/com/android/bluetooth/hid/HidDeviceService.java +++ b/android/app/src/com/android/bluetooth/hid/HidDeviceService.java @@ -318,7 +318,7 @@ public class HidDeviceService extends ProfileService { } } - private ActivityManager.OnUidImportanceListener mUidImportanceListener = + private final ActivityManager.OnUidImportanceListener mUidImportanceListener = new ActivityManager.OnUidImportanceListener() { @Override public void onUidImportance(final int uid, final int importance) { diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterface.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterface.java index b34f2a989d..291ed71d94 100644 --- a/android/app/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterface.java +++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterface.java @@ -35,7 +35,7 @@ import com.android.internal.annotations.VisibleForTesting; public class LeAudioBroadcasterNativeInterface { private static final String TAG = LeAudioBroadcasterNativeInterface.class.getSimpleName(); - private BluetoothAdapter mAdapter; + private final BluetoothAdapter mAdapter; @GuardedBy("INSTANCE_LOCK") private static LeAudioBroadcasterNativeInterface sInstance; diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioCodecConfig.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioCodecConfig.java index dcdc56c67e..9de7873510 100644 --- a/android/app/src/com/android/bluetooth/le_audio/LeAudioCodecConfig.java +++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioCodecConfig.java @@ -27,7 +27,7 @@ import android.util.Log; class LeAudioCodecConfig { private static final String TAG = LeAudioCodecConfig.class.getSimpleName(); - private Context mContext; + private final Context mContext; private BluetoothLeAudioCodecConfig[] mCodecConfigOffloading = new BluetoothLeAudioCodecConfig[0]; diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java index e2d1490c9f..4b296ae103 100644 --- a/android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java +++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java @@ -37,7 +37,7 @@ import java.util.Arrays; public class LeAudioNativeInterface { private static final String TAG = LeAudioNativeInterface.class.getSimpleName(); - private BluetoothAdapter mAdapter; + private final BluetoothAdapter mAdapter; @GuardedBy("INSTANCE_LOCK") private static LeAudioNativeInterface sInstance; diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java index 463f55383f..2379ffbd43 100644 --- a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java @@ -322,7 +322,7 @@ public class LeAudioService extends ProfileService { mAutoActiveModeEnabled = true; } - Integer mGroupId; + final Integer mGroupId; Boolean mIsConnected; Boolean mHasFallbackDeviceWhenGettingInactive; Integer mDirection; @@ -456,8 +456,8 @@ public class LeAudioService extends ProfileService { } private static class LeAudioBroadcastSessionStats { - private int[] mAudioQuality; - private long mSessionRequestTime; + private final int[] mAudioQuality; + private final long mSessionRequestTime; private long mSessionCreatedTime; private long mSessionStreamingTime; private int mSessionGroupSize; @@ -579,7 +579,7 @@ public class LeAudioService extends ProfileService { private final Map<Integer, LeAudioBroadcastSessionStats> mBroadcastSessionStats = new LinkedHashMap<>(); - private Handler mHandler = new Handler(Looper.getMainLooper()); + private final Handler mHandler = new Handler(Looper.getMainLooper()); private final AudioManagerAudioDeviceCallback mAudioManagerAudioDeviceCallback = new AudioManagerAudioDeviceCallback(); private final AudioModeChangeListener mAudioModeChangeListener = new AudioModeChangeListener(); @@ -647,7 +647,7 @@ public class LeAudioService extends ProfileService { } } - private AudioManager.AudioRecordingCallback mAudioRecordingCallback = + private final AudioManager.AudioRecordingCallback mAudioRecordingCallback = new AudioManager.AudioRecordingCallback() { /* Audio Framework uses this callback to notify listeners of recording configuration * changes. When a recording scenario starts or its configuration changes, this diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioStateMachine.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioStateMachine.java index fc5c54bbf5..d6145c3799 100644 --- a/android/app/src/com/android/bluetooth/le_audio/LeAudioStateMachine.java +++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioStateMachine.java @@ -75,16 +75,16 @@ final class LeAudioStateMachine extends StateMachine { @VisibleForTesting static int sConnectTimeoutMs = 30000; // 30s - private Disconnected mDisconnected; - private Connecting mConnecting; - private Disconnecting mDisconnecting; - private Connected mConnected; + private final Disconnected mDisconnected; + private final Connecting mConnecting; + private final Disconnecting mDisconnecting; + private final Connected mConnected; private int mConnectionState = STATE_DISCONNECTED; private int mLastConnectionState = -1; - private LeAudioService mService; - private LeAudioNativeInterface mNativeInterface; + private final LeAudioService mService; + private final LeAudioNativeInterface mNativeInterface; private final BluetoothDevice mDevice; diff --git a/android/app/src/com/android/bluetooth/le_scan/AppScanStats.java b/android/app/src/com/android/bluetooth/le_scan/AppScanStats.java index 4b74adfc46..fdf2f334c5 100644 --- a/android/app/src/com/android/bluetooth/le_scan/AppScanStats.java +++ b/android/app/src/com/android/bluetooth/le_scan/AppScanStats.java @@ -75,7 +75,7 @@ class AppScanStats { @GuardedBy("sLock") static long sRadioStartTime = 0; - private static Object sLock = new Object(); + private static final Object sLock = new Object(); private static class LastScan { public long duration; diff --git a/android/app/src/com/android/bluetooth/le_scan/ScanController.java b/android/app/src/com/android/bluetooth/le_scan/ScanController.java index 623e478c54..ef02cb5484 100644 --- a/android/app/src/com/android/bluetooth/le_scan/ScanController.java +++ b/android/app/src/com/android/bluetooth/le_scan/ScanController.java @@ -1512,7 +1512,7 @@ public class ScanController { */ class ScannerDeathRecipient implements IBinder.DeathRecipient { int mScannerId; - private String mPackageName; + private final String mPackageName; ScannerDeathRecipient(int scannerId, String packageName) { mScannerId = scannerId; diff --git a/android/app/src/com/android/bluetooth/le_scan/ScanManager.java b/android/app/src/com/android/bluetooth/le_scan/ScanManager.java index 32e725e123..4422a0f89e 100644 --- a/android/app/src/com/android/bluetooth/le_scan/ScanManager.java +++ b/android/app/src/com/android/bluetooth/le_scan/ScanManager.java @@ -2229,7 +2229,7 @@ public class ScanManager { } }; - private ActivityManager.OnUidImportanceListener mUidImportanceListener = + private final ActivityManager.OnUidImportanceListener mUidImportanceListener = new ActivityManager.OnUidImportanceListener() { @Override public void onUidImportance(final int uid, final int importance) { @@ -2242,7 +2242,7 @@ public class ScanManager { } }; - private BroadcastReceiver mLocationReceiver = + private final BroadcastReceiver mLocationReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapAppObserver.java b/android/app/src/com/android/bluetooth/map/BluetoothMapAppObserver.java index 852ee8375f..abf2fac9c4 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapAppObserver.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapAppObserver.java @@ -43,10 +43,10 @@ public class BluetoothMapAppObserver { private static final String TAG = BluetoothMapAppObserver.class.getSimpleName(); /* */ - private Map<BluetoothMapAccountItem, List<BluetoothMapAccountItem>> mFullList; - private Map<String, ContentObserver> mObserverMap = new LinkedHashMap<>(); - private ContentResolver mResolver; - private Context mContext; + private final Map<BluetoothMapAccountItem, List<BluetoothMapAccountItem>> mFullList; + private final Map<String, ContentObserver> mObserverMap = new LinkedHashMap<>(); + private final ContentResolver mResolver; + private final Context mContext; private BroadcastReceiver mReceiver; private PackageManager mPackageManager = null; BluetoothMapAccountLoader mLoader; diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapContentObserver.java b/android/app/src/com/android/bluetooth/map/BluetoothMapContentObserver.java index 15945c8fc1..8fc58b950e 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapContentObserver.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapContentObserver.java @@ -129,12 +129,12 @@ public class BluetoothMapContentObserver { // cases. private static final long PROVIDER_ANR_TIMEOUT = 20 * DateUtils.SECOND_IN_MILLIS; - private Context mContext; - private ContentResolver mResolver; + private final Context mContext; + private final ContentResolver mResolver; @VisibleForTesting ContentProviderClient mProviderClient = null; - private BluetoothMnsObexClient mMnsClient; + private final BluetoothMnsObexClient mMnsClient; private BluetoothMapMasInstance mMasInstance = null; - private int mMasId; + private final int mMasId; private boolean mEnableSmsMms = false; @VisibleForTesting boolean mObserverRegistered = false; @VisibleForTesting BluetoothMapAccountItem mAccount; @@ -168,7 +168,7 @@ public class BluetoothMapContentObserver { // Text only MMS converted to SMS if sms parts less than or equal to defined count private static final int CONVERT_MMS_TO_SMS_PART_COUNT = 10; - private TYPE mSmsType; + private final TYPE mSmsType; private static final String ACTION_MESSAGE_DELIVERY = "com.android.bluetooth.BluetoothMapContentObserver.action.MESSAGE_DELIVERY"; @@ -183,8 +183,8 @@ public class BluetoothMapContentObserver { public static final String EXTRA_MESSAGE_SENT_TRANSPARENT = "transparent"; public static final String EXTRA_MESSAGE_SENT_TIMESTAMP = "timestamp"; - private SmsBroadcastReceiver mSmsBroadcastReceiver = new SmsBroadcastReceiver(); - private CeBroadcastReceiver mCeBroadcastReceiver = new CeBroadcastReceiver(); + private final SmsBroadcastReceiver mSmsBroadcastReceiver = new SmsBroadcastReceiver(); + private final CeBroadcastReceiver mCeBroadcastReceiver = new CeBroadcastReceiver(); private boolean mStorageUnlocked = false; private boolean mInitialized = false; @@ -3004,7 +3004,7 @@ public class BluetoothMapContentObserver { ; } - private Map<Long, PushMsgInfo> mPushMsgList = + private final Map<Long, PushMsgInfo> mPushMsgList = Collections.synchronizedMap(new HashMap<Long, PushMsgInfo>()); /** @@ -4225,7 +4225,7 @@ public class BluetoothMapContentObserver { } } - private PhoneStateListener mPhoneListener = + private final PhoneStateListener mPhoneListener = new PhoneStateListener() { @Override public void onServiceStateChanged(ServiceState serviceState) { diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapFolderElement.java b/android/app/src/com/android/bluetooth/map/BluetoothMapFolderElement.java index 6430485642..93f9db26e4 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapFolderElement.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapFolderElement.java @@ -41,7 +41,7 @@ import java.util.Locale; public class BluetoothMapFolderElement implements Comparable<BluetoothMapFolderElement> { private static final String TAG = BluetoothMapFolderElement.class.getSimpleName(); - private String mName; + private final String mName; private BluetoothMapFolderElement mParent = null; private long mFolderId = -1; private boolean mHasSmsMmsContent = false; @@ -50,7 +50,7 @@ public class BluetoothMapFolderElement implements Comparable<BluetoothMapFolderE private boolean mIgnore = false; - private HashMap<String, BluetoothMapFolderElement> mSubFolders; + private final HashMap<String, BluetoothMapFolderElement> mSubFolders; public BluetoothMapFolderElement(String name, BluetoothMapFolderElement parent) { this.mName = name; diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapMasInstance.java b/android/app/src/com/android/bluetooth/map/BluetoothMapMasInstance.java index cae3eaaf4e..c337d30a63 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapMasInstance.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapMasInstance.java @@ -90,10 +90,10 @@ public class BluetoothMapMasInstance implements IObexConnectionHandler { private boolean mEnableSmsMms = false; BluetoothMapContentObserver mObserver; private BluetoothMapObexServer mMapServer; - private AtomicLong mDbIdentifier = new AtomicLong(); - private AtomicLong mFolderVersionCounter = new AtomicLong(0); - private AtomicLong mSmsMmsConvoListVersionCounter = new AtomicLong(0); - private AtomicLong mImEmailConvoListVersionCounter = new AtomicLong(0); + private final AtomicLong mDbIdentifier = new AtomicLong(); + private final AtomicLong mFolderVersionCounter = new AtomicLong(0); + private final AtomicLong mSmsMmsConvoListVersionCounter = new AtomicLong(0); + private final AtomicLong mImEmailConvoListVersionCounter = new AtomicLong(0); private Map<Long, Msg> mMsgListSms = null; private Map<Long, Msg> mMsgListMms = null; diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapObexServer.java b/android/app/src/com/android/bluetooth/map/BluetoothMapObexServer.java index b817750d05..bf702a5075 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapObexServer.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapObexServer.java @@ -106,7 +106,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler { private BluetoothMapFolderElement mCurrentFolder; private BluetoothMapContentObserver mObserver = null; private Handler mCallback = null; - private Context mContext; + private final Context mContext; private boolean mIsAborted = false; BluetoothMapContent mOutContent; private String mBaseUriString = null; @@ -114,7 +114,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler { private BluetoothMapAccountItem mAccount = null; private Uri mEmailFolderUri = null; private int mMasId = 0; - private BluetoothMapMasInstance mMasInstance; // TODO: change to interface? + private final BluetoothMapMasInstance mMasInstance; // TODO: change to interface? // updated during connect if remote has alternative value private int mRemoteFeatureMask = BluetoothMapUtils.MAP_FEATURE_DEFAULT_BITMASK; private boolean mEnableSmsMms = false; diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapService.java b/android/app/src/com/android/bluetooth/map/BluetoothMapService.java index 456e052470..19694ab1af 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapService.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapService.java @@ -128,10 +128,10 @@ public class BluetoothMapService extends ProfileService { private BluetoothMnsObexClient mBluetoothMnsObexClient = null; // mMasInstances: A list of the active MasInstances using the MasId for the key - private SparseArray<BluetoothMapMasInstance> mMasInstances = + private final SparseArray<BluetoothMapMasInstance> mMasInstances = new SparseArray<BluetoothMapMasInstance>(1); // mMasInstanceMap: A list of the active MasInstances using the account for the key - private HashMap<BluetoothMapAccountItem, BluetoothMapMasInstance> mMasInstanceMap = + private final HashMap<BluetoothMapAccountItem, BluetoothMapMasInstance> mMasInstanceMap = new HashMap<BluetoothMapAccountItem, BluetoothMapMasInstance>(1); // The remote connected device - protect access diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapSmsPdu.java b/android/app/src/com/android/bluetooth/map/BluetoothMapSmsPdu.java index 04f9d0a2d1..30cfebd1fe 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapSmsPdu.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapSmsPdu.java @@ -68,13 +68,13 @@ public class BluetoothMapSmsPdu { */ public static class SmsPdu { private byte[] mData; - private byte[] mScAddress = {0}; + private final byte[] mScAddress = {0}; // At the moment we do not use the scAddress, hence set the length to 0. private int mUserDataMsgOffset = 0; private int mEncoding; private int mLanguageTable; private int mLanguageShiftTable; - private int mType; + private final int mType; /* Members used for pdu decoding */ private int mUserDataSeptetPadding = INVALID_VALUE; diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapUtils.java b/android/app/src/com/android/bluetooth/map/BluetoothMapUtils.java index bbb5f2ee11..932f4a98d6 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapUtils.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapUtils.java @@ -120,7 +120,7 @@ public class BluetoothMapUtils { SMS_CDMA, MMS, IM; - private static TYPE[] sAllValues = values(); + private static final TYPE[] sAllValues = values(); public static TYPE fromOrdinal(int n) { if (n < sAllValues.length) { diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMapbMessage.java b/android/app/src/com/android/bluetooth/map/BluetoothMapbMessage.java index c79f3eaca9..ad2698b72b 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMapbMessage.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMapbMessage.java @@ -64,14 +64,14 @@ public abstract class BluetoothMapbMessage { public static class VCard { /* VCARD attributes */ - private String mVersion; + private final String mVersion; private String mName = null; private String mFormattedName = null; private String[] mPhoneNumbers = {}; private String[] mEmailAddresses = {}; private int mEnvLevel = 0; private String[] mBtUcis = {}; - private String[] mBtUids = {}; + private final String[] mBtUids = {}; /** * Construct a version 3.0 vCard diff --git a/android/app/src/com/android/bluetooth/map/BluetoothMnsObexClient.java b/android/app/src/com/android/bluetooth/map/BluetoothMnsObexClient.java index 8f37895bfc..5d52b33392 100644 --- a/android/app/src/com/android/bluetooth/map/BluetoothMnsObexClient.java +++ b/android/app/src/com/android/bluetooth/map/BluetoothMnsObexClient.java @@ -55,7 +55,7 @@ public class BluetoothMnsObexClient { private ClientSession mClientSession; private boolean mConnected = false; BluetoothDevice mRemoteDevice; - private SparseBooleanArray mRegisteredMasIds = new SparseBooleanArray(1); + private final SparseBooleanArray mRegisteredMasIds = new SparseBooleanArray(1); private HeaderSet mHsConnect = null; private Handler mCallback = null; diff --git a/android/app/src/com/android/bluetooth/map/MmsFileProvider.java b/android/app/src/com/android/bluetooth/map/MmsFileProvider.java index 22810e182c..62f4af1d75 100644 --- a/android/app/src/com/android/bluetooth/map/MmsFileProvider.java +++ b/android/app/src/com/android/bluetooth/map/MmsFileProvider.java @@ -47,7 +47,7 @@ public class MmsFileProvider extends ContentProvider { private static final String TAG = Utils.TAG_PREFIX_BLUETOOTH + MmsFileProvider.class.getSimpleName(); - private PipeWriter mPipeWriter = new PipeWriter(); + private final PipeWriter mPipeWriter = new PipeWriter(); /*package*/ static final Uri CONTENT_URI = Uri.parse("content://com.android.bluetooth.map.MmsFileProvider"); diff --git a/android/app/src/com/android/bluetooth/mapclient/MapClientContent.java b/android/app/src/com/android/bluetooth/mapclient/MapClientContent.java index eee34a4aa3..5997d468cc 100644 --- a/android/app/src/com/android/bluetooth/mapclient/MapClientContent.java +++ b/android/app/src/com/android/bluetooth/mapclient/MapClientContent.java @@ -87,10 +87,10 @@ class MapClientContent { ContentObserver mContentObserver; String mPhoneNumber = null; private int mSubscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; - private SubscriptionManager mSubscriptionManager; - private TelephonyManager mTelephonyManager; - private HashMap<String, Uri> mHandleToUriMap = new HashMap<>(); - private HashMap<Uri, MessageStatus> mUriToHandleMap = new HashMap<>(); + private final SubscriptionManager mSubscriptionManager; + private final TelephonyManager mTelephonyManager; + private final HashMap<String, Uri> mHandleToUriMap = new HashMap<>(); + private final HashMap<Uri, MessageStatus> mUriToHandleMap = new HashMap<>(); /** Callbacks API to notify about statusChanges as observed from the content provider */ interface Callbacks { @@ -887,11 +887,11 @@ class MapClientContent { } private static class MessageDumpElement implements Comparable<MessageDumpElement> { - private String mMessageHandle; - private long mTimestamp; - private Type mType; - private long mThreadId; - private Uri mUri; + private final String mMessageHandle; + private final long mTimestamp; + private final Type mType; + private final long mThreadId; + private final Uri mUri; MessageDumpElement(String handle, Uri uri, long timestamp, long threadId, Type type) { mMessageHandle = handle; diff --git a/android/app/src/com/android/bluetooth/mapclient/MasClient.java b/android/app/src/com/android/bluetooth/mapclient/MasClient.java index 09072876f3..64b26a96dc 100644 --- a/android/app/src/com/android/bluetooth/mapclient/MasClient.java +++ b/android/app/src/com/android/bluetooth/mapclient/MasClient.java @@ -79,12 +79,12 @@ public class MasClient { | MAP_FEATURE_EXTENDED_EVENT_REPORT_1_1; private final StateMachine mCallback; - private Handler mHandler; + private final Handler mHandler; private BluetoothSocket mSocket; private BluetoothObexTransport mTransport; - private BluetoothDevice mRemoteDevice; + private final BluetoothDevice mRemoteDevice; private ClientSession mSession; - private HandlerThread mThread; + private final HandlerThread mThread; private boolean mConnected = false; SdpMasRecord mSdpMasRecord; @@ -219,7 +219,7 @@ public class MasClient { } private static class MasClientHandler extends Handler { - WeakReference<MasClient> mInst; + final WeakReference<MasClient> mInst; MasClientHandler(Looper looper, MasClient inst) { super(looper); diff --git a/android/app/src/com/android/bluetooth/mapclient/MceStateMachine.java b/android/app/src/com/android/bluetooth/mapclient/MceStateMachine.java index f5f53a7378..457e87c69f 100644 --- a/android/app/src/com/android/bluetooth/mapclient/MceStateMachine.java +++ b/android/app/src/com/android/bluetooth/mapclient/MceStateMachine.java @@ -200,7 +200,7 @@ class MceStateMachine extends StateMachine { private final String mHandle; private final Long mTimestamp; private boolean mRead; - private boolean mSeen; + private final boolean mSeen; MessageMetadata(String handle, Long timestamp, boolean read, boolean seen) { mHandle = handle; diff --git a/android/app/src/com/android/bluetooth/mapclient/obex/MessagesFilter.java b/android/app/src/com/android/bluetooth/mapclient/obex/MessagesFilter.java index b8a7bdfd4a..b5e66faaa4 100644 --- a/android/app/src/com/android/bluetooth/mapclient/obex/MessagesFilter.java +++ b/android/app/src/com/android/bluetooth/mapclient/obex/MessagesFilter.java @@ -91,7 +91,7 @@ public final class MessagesFilter { /** Builder for a {@link MessagesFilter}. */ public static class Builder { - private MessagesFilter mMessagesFilter = new MessagesFilter(); + private final MessagesFilter mMessagesFilter = new MessagesFilter(); /** * Sets the `Message Type` field of the filter. diff --git a/android/app/src/com/android/bluetooth/mapclient/obex/RequestGetMessagesListingForOwnNumber.java b/android/app/src/com/android/bluetooth/mapclient/obex/RequestGetMessagesListingForOwnNumber.java index afca4d5de8..e92f9d6425 100644 --- a/android/app/src/com/android/bluetooth/mapclient/obex/RequestGetMessagesListingForOwnNumber.java +++ b/android/app/src/com/android/bluetooth/mapclient/obex/RequestGetMessagesListingForOwnNumber.java @@ -111,9 +111,9 @@ class RequestGetMessagesListingForOwnNumber extends Request { } } - private MessagesSlidingWindow mMessageListingWindow; + private final MessagesSlidingWindow mMessageListingWindow; - private ObexAppParameters mOap; + private final ObexAppParameters mOap; private int mFolderCounter; private boolean mSearchCompleted; diff --git a/android/app/src/com/android/bluetooth/mcp/MediaControlGattService.java b/android/app/src/com/android/bluetooth/mcp/MediaControlGattService.java index 7de6296193..2dbc1014eb 100644 --- a/android/app/src/com/android/bluetooth/mcp/MediaControlGattService.java +++ b/android/app/src/com/android/bluetooth/mcp/MediaControlGattService.java @@ -144,7 +144,7 @@ public class MediaControlGattService implements MediaControlGattServiceInterface private final int mCcid; private final Map<String, Map<UUID, Short>> mCccDescriptorValues = new HashMap<>(); private long mFeatures; - private Context mContext; + private final Context mContext; private MediaControlServiceCallbacks mCallbacks; private BluetoothGattServerProxy mBluetoothGattServer; private BluetoothGattService mGattService = null; @@ -155,7 +155,7 @@ public class MediaControlGattService implements MediaControlGattServiceInterface new HashMap<>(); private McpService mMcpService; private LeAudioService mLeAudioService; - private AdapterService mAdapterService; + private final AdapterService mAdapterService; private static final int LOG_NB_EVENTS = 200; private final BluetoothEventLogger mEventLogger; @@ -253,14 +253,14 @@ public class MediaControlGattService implements MediaControlGattServiceInterface mValue = null; } - public Operation mOperation; - public int mRequestId; - public BluetoothGattCharacteristic mCharacteristic; - public BluetoothGattDescriptor mDescriptor; - public boolean mPreparedWrite; - public boolean mResponseNeeded; - public int mOffset; - public byte[] mValue; + public final Operation mOperation; + public final int mRequestId; + public final BluetoothGattCharacteristic mCharacteristic; + public final BluetoothGattDescriptor mDescriptor; + public final boolean mPreparedWrite; + public final boolean mResponseNeeded; + public final int mOffset; + public final byte[] mValue; } private final Map<UUID, CharacteristicWriteHandler> mCharWriteCallback = @@ -1222,8 +1222,8 @@ public class MediaControlGattService implements MediaControlGattServiceInterface */ @SuppressLint("AndroidFrameworkRequiresPermission") // TODO: b/350563786 public static class BluetoothGattServerProxy { - private BluetoothGattServer mBluetoothGattServer; - private BluetoothManager mBluetoothManager; + private final BluetoothGattServer mBluetoothGattServer; + private final BluetoothManager mBluetoothManager; public BluetoothGattServerProxy(BluetoothGattServer gatt, BluetoothManager manager) { mBluetoothManager = manager; diff --git a/android/app/src/com/android/bluetooth/mcp/MediaControlProfile.java b/android/app/src/com/android/bluetooth/mcp/MediaControlProfile.java index 86eaabfd69..7e25efec16 100644 --- a/android/app/src/com/android/bluetooth/mcp/MediaControlProfile.java +++ b/android/app/src/com/android/bluetooth/mcp/MediaControlProfile.java @@ -85,7 +85,7 @@ public class MediaControlProfile implements MediaControlServiceCallbacks { // MCP Service requests for state fields needed to fill the characteristic values private List<PlayerStateField> mPendingStateRequest; - private MediaPlayerWrapper mLastActivePlayer = null; + private final MediaPlayerWrapper mLastActivePlayer = null; // Same base feature set as the player item features defined in `avrcp/get_foder_items.cc` private static final long BASE_PLAYER_ACTION_SET = diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java index a6110ffc1f..730c1e9ce2 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java @@ -121,7 +121,7 @@ public class BluetoothOppManager { // A list of devices that may send files over OPP to this device // without user confirmation. Used for connection handover from forex NFC. - private List<Pair<String, Long>> mAcceptlist = new ArrayList<Pair<String, Long>>(); + private final List<Pair<String, Long>> mAcceptlist = new ArrayList<Pair<String, Long>>(); // The time for which the acceptlist entries remain valid. private static final int ACCEPTLIST_DURATION_MS = 15000; diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java index 5279c78f6d..b094c60ae3 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java @@ -134,11 +134,10 @@ class BluetoothOppNotification { public NotificationManager mNotificationMgr; - private NotificationChannel mNotificationChannel; + private final NotificationChannel mNotificationChannel; private static final String OPP_NOTIFICATION_CHANNEL = "opp_notification_channel"; - private Context mContext; - + private final Context mContext; private final HashMap<String, NotificationItem> mNotifications = new HashMap<>(); @VisibleForTesting NotificationUpdateThread mUpdateNotificationThread; @@ -226,7 +225,7 @@ class BluetoothOppNotification { // 3. Handler sends a delayed message to self // 4. Handler checks if there are any more updates after 1 second. // 5. If there is an update, update it else stop. - private Handler mHandler = + private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java index 6d102fec39..2548b9e45c 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -361,7 +361,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti private static final int STOP_LISTENER = 200; - private Handler mHandler = + private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { @@ -1269,14 +1269,10 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti } private static class MediaScannerNotifier implements MediaScannerConnectionClient { - - private MediaScannerConnection mConnection; - - private BluetoothOppShareInfo mInfo; - - private Context mContext; - - private Handler mCallback; + private final MediaScannerConnection mConnection; + private final BluetoothOppShareInfo mInfo; + private final Context mContext; + private final Handler mCallback; MediaScannerNotifier(Context context, BluetoothOppShareInfo info, Handler handler) { mContext = context; diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index 95db09defa..1ff73d1b48 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -76,9 +76,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch private static final String TAG = BluetoothOppTransfer.class.getSimpleName(); @VisibleForTesting static final int TRANSPORT_ERROR = 10; - @VisibleForTesting static final int TRANSPORT_CONNECTED = 11; - @VisibleForTesting static final int SOCKET_ERROR_RETRY = 13; private static final String SOCKET_LINK_KEY_ERROR = "Invalid exchange"; @@ -86,23 +84,15 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch private static final Object INSTANCE_LOCK = new Object(); private final Context mContext; - - private BluetoothAdapter mAdapter; - - @VisibleForTesting BluetoothDevice mDevice; - + private final BluetoothAdapter mAdapter; private final BluetoothOppBatch mBatch; + @VisibleForTesting BluetoothDevice mDevice; private BluetoothOppObexSession mSession; - @VisibleForTesting BluetoothOppShareInfo mCurrentShare; - private ObexTransport mTransport; - private HandlerThread mHandlerThread; - @VisibleForTesting EventHandler mSessionHandler; - private long mTimestamp; @VisibleForTesting diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppTransferAdapter.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppTransferAdapter.java index a4d56b9732..5d5cac10cf 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppTransferAdapter.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppTransferAdapter.java @@ -54,7 +54,7 @@ import java.util.Date; * done by this class is to construct a custom view for the line items. */ public class BluetoothOppTransferAdapter extends ResourceCursorAdapter { - private Context mContext; + private final Context mContext; public BluetoothOppTransferAdapter(Context context, int layout, Cursor c) { super(context, layout, c, true /* autoRequery */); diff --git a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java index c4ca07931b..a9957e7891 100644 --- a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java +++ b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java @@ -187,9 +187,8 @@ public class BluetoothPbapObexServer extends ServerRequestHandler { private Handler mCallback = null; - private Context mContext; - - private BluetoothPbapVcardManager mVcardManager; + private final Context mContext; + private final BluetoothPbapVcardManager mVcardManager; BluetoothPbapSimVcardManager mVcardSimManager; @@ -207,15 +206,13 @@ public class BluetoothPbapObexServer extends ServerRequestHandler { private long mDatabaseIdentifierHigh = INVALID_VALUE_PARAMETER; - private long mFolderVersionCounterbitMask = 0x0008; - - private long mDatabaseIdentifierBitMask = 0x0004; + private static final long FOLDER_VERSION_COUNTER_BIT_MASK = 0x0008; + private static final long DATABASE_IDENTIFIER_BIT_MASK = 0x0004; private AppParamValue mConnAppParamValue; - private PbapStateMachine mStateMachine; - - private BluetoothMethodProxy mPbapMethodProxy; + private final PbapStateMachine mStateMachine; + private final BluetoothMethodProxy mPbapMethodProxy; private enum ContactsType { TYPE_PHONEBOOK, @@ -1108,12 +1105,12 @@ public class BluetoothPbapObexServer extends ServerRequestHandler { || isNameMatchTarget(name, OCH) || isNameMatchTarget(name, CCH)) { needSendCallHistoryVersionCounters = - checkPbapFeatureSupport(mFolderVersionCounterbitMask); + checkPbapFeatureSupport(FOLDER_VERSION_COUNTER_BIT_MASK); } boolean needSendPhonebookVersionCounters = false; if (isNameMatchTarget(name, PB) || isNameMatchTarget(name, FAV)) { needSendPhonebookVersionCounters = - checkPbapFeatureSupport(mFolderVersionCounterbitMask); + checkPbapFeatureSupport(FOLDER_VERSION_COUNTER_BIT_MASK); } // In such case, PCE only want the number of index. @@ -1166,7 +1163,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler { "handleAppParaForResponse(): mNeedNewMissedCallsNum=true, num= " + nmnum); } - if (checkPbapFeatureSupport(mDatabaseIdentifierBitMask)) { + if (checkPbapFeatureSupport(DATABASE_IDENTIFIER_BIT_MASK)) { setDbCounters(ap); } if (needSendPhonebookVersionCounters) { @@ -1236,7 +1233,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler { } } - if (checkPbapFeatureSupport(mDatabaseIdentifierBitMask)) { + if (checkPbapFeatureSupport(DATABASE_IDENTIFIER_BIT_MASK)) { setDbCounters(ap); reply.setHeader(HeaderSet.APPLICATION_PARAMETER, ap.getHeader()); try { diff --git a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManager.java b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManager.java index 5705e9c09f..db427991a2 100644 --- a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManager.java +++ b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManager.java @@ -88,7 +88,7 @@ public class BluetoothPbapSimVcardManager implements AutoCloseable { private static final int NUMBERLABEL_COLUMN_INDEX = 3; private final Context mContext; - private ContentResolver mContentResolver; + private final ContentResolver mContentResolver; private Cursor mCursor; private String mErrorReason = NO_ERROR; diff --git a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapUtils.java b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapUtils.java index 886c6135f0..e70706f84d 100644 --- a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapUtils.java +++ b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapUtils.java @@ -84,9 +84,9 @@ class BluetoothPbapUtils { private static class ContactData { private String mName; - private List<String> mEmail; - private List<String> mPhone; - private List<String> mAddress; + private final List<String> mEmail; + private final List<String> mPhone; + private final List<String> mAddress; ContactData() { mPhone = new ArrayList<>(); diff --git a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java index f3a08ec365..5fa66a785c 100644 --- a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java +++ b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java @@ -59,9 +59,8 @@ import java.util.regex.Pattern; public class BluetoothPbapVcardManager { private static final String TAG = BluetoothPbapVcardManager.class.getSimpleName(); - private ContentResolver mResolver; - - private Context mContext; + private final ContentResolver mResolver; + private final Context mContext; static final String SORT_ORDER_PHONE_NUMBER = CommonDataKinds.Phone.NUMBER + " ASC"; diff --git a/android/app/src/com/android/bluetooth/pbap/PbapStateMachine.java b/android/app/src/com/android/bluetooth/pbap/PbapStateMachine.java index 43ec2bb3a5..d0a756ac0d 100644 --- a/android/app/src/com/android/bluetooth/pbap/PbapStateMachine.java +++ b/android/app/src/com/android/bluetooth/pbap/PbapStateMachine.java @@ -87,19 +87,19 @@ public class PbapStateMachine extends StateMachine { /** Used to limit PBAP OBEX maximum packet size in order to reduce transaction time. */ private static final int PBAP_OBEX_MAXIMUM_PACKET_SIZE = 8192; - private BluetoothPbapService mService; + private final BluetoothPbapService mService; private final WaitingForAuth mWaitingForAuth = new WaitingForAuth(); private final Finished mFinished = new Finished(); private final Connected mConnected = new Connected(); private PbapStateBase mPrevState; - private BluetoothDevice mRemoteDevice; - private Handler mServiceHandler; + private final BluetoothDevice mRemoteDevice; + private final Handler mServiceHandler; private BluetoothSocket mConnSocket; private BluetoothPbapObexServer mPbapServer; private BluetoothPbapAuthenticator mObexAuth; private ServerSession mServerSession; - private int mNotificationId; + private final int mNotificationId; private PbapStateMachine( @NonNull BluetoothPbapService service, diff --git a/android/app/src/com/android/bluetooth/pbapclient/PbapClientStateMachine.java b/android/app/src/com/android/bluetooth/pbapclient/PbapClientStateMachine.java index 3aca289ef4..caa9584445 100644 --- a/android/app/src/com/android/bluetooth/pbapclient/PbapClientStateMachine.java +++ b/android/app/src/com/android/bluetooth/pbapclient/PbapClientStateMachine.java @@ -198,7 +198,7 @@ class PbapClientStateMachine extends StateMachine { private final Context mContext; private PbapSdpRecord mSdpRecord = null; private final Account mAccount; - private Map<String, Phonebook> mPhonebooks = new HashMap<String, Phonebook>(); + private final Map<String, Phonebook> mPhonebooks = new HashMap<String, Phonebook>(); private final PbapClientObexClient mObexClient; private final PbapClientContactsStorage mContactsStorage; diff --git a/android/app/src/com/android/bluetooth/pbapclient/PbapClientStateMachineOld.java b/android/app/src/com/android/bluetooth/pbapclient/PbapClientStateMachineOld.java index bf2cade8ee..20f179579b 100644 --- a/android/app/src/com/android/bluetooth/pbapclient/PbapClientStateMachineOld.java +++ b/android/app/src/com/android/bluetooth/pbapclient/PbapClientStateMachineOld.java @@ -111,14 +111,14 @@ class PbapClientStateMachineOld extends StateMachine { PbapSdpRecord.FEATURE_DEFAULT_IMAGE_FORMAT | PbapSdpRecord.FEATURE_DOWNLOADING; private final Object mLock; - private State mDisconnected; - private State mConnecting; - private State mConnected; - private State mDisconnecting; + private final State mDisconnected; + private final State mConnecting; + private final State mConnected; + private final State mDisconnecting; // mCurrentDevice may only be changed in Disconnected State. private final BluetoothDevice mCurrentDevice; - private PbapClientService mService; + private final PbapClientService mService; private PbapClientConnectionHandler mConnectionHandler; private HandlerThread mHandlerThread = null; private UserManager mUserManager = null; diff --git a/android/app/src/com/android/bluetooth/pbapclient/obex/CallLogPullRequest.java b/android/app/src/com/android/bluetooth/pbapclient/obex/CallLogPullRequest.java index a1e668e311..3d276dd88b 100644 --- a/android/app/src/com/android/bluetooth/pbapclient/obex/CallLogPullRequest.java +++ b/android/app/src/com/android/bluetooth/pbapclient/obex/CallLogPullRequest.java @@ -47,8 +47,8 @@ public class CallLogPullRequest extends PullRequest { private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss"; private final Account mAccount; - private Context mContext; - private Map<String, Integer> mCallCounter; + private final Context mContext; + private final Map<String, Integer> mCallCounter; public CallLogPullRequest( Context context, String path, Map<String, Integer> map, Account account) { diff --git a/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientConnectionHandler.java b/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientConnectionHandler.java index 7d6dbd2b1b..472dc96ac3 100644 --- a/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientConnectionHandler.java +++ b/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientConnectionHandler.java @@ -84,14 +84,14 @@ class PbapClientConnectionHandler extends Handler { 0x66 }; - private Account mAccount; + private final Account mAccount; private BluetoothSocket mSocket; private final BluetoothDevice mDevice; private final int mLocalSupportedFeatures; // PSE SDP Record for current device. private PbapSdpRecord mPseRec = null; private ClientSession mObexSession; - private PbapClientService mService; + private final PbapClientService mService; private PbapClientObexAuthenticator mAuth = null; private final PbapClientStateMachineOld mPbapClientStateMachine; private boolean mAccountCreated; diff --git a/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientObexClient.java b/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientObexClient.java index e8b461b797..dc4034df0e 100644 --- a/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientObexClient.java +++ b/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientObexClient.java @@ -90,8 +90,8 @@ class PbapClientObexClient { private final BluetoothDevice mDevice; private final int mLocalSupportedFeatures; private int mState = STATE_DISCONNECTED; - private AtomicInteger mPsm = new AtomicInteger(L2CAP_INVALID_PSM); - private AtomicInteger mChannelId = new AtomicInteger(RFCOMM_INVALID_CHANNEL_ID); + private final AtomicInteger mPsm = new AtomicInteger(L2CAP_INVALID_PSM); + private final AtomicInteger mChannelId = new AtomicInteger(RFCOMM_INVALID_CHANNEL_ID); private final Handler mHandler; private final HandlerThread mThread; diff --git a/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientObexTransport.java b/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientObexTransport.java index 0d7ce8428c..c9f643331e 100644 --- a/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientObexTransport.java +++ b/android/app/src/com/android/bluetooth/pbapclient/obex/PbapClientObexTransport.java @@ -36,9 +36,6 @@ public class PbapClientObexTransport implements ObexTransport { /** Will default at the maximum packet length. */ public static final int PACKET_SIZE_UNSPECIFIED = -1; - private int mMaxTransmitPacketSize = PACKET_SIZE_UNSPECIFIED; - private int mMaxReceivePacketSize = PACKET_SIZE_UNSPECIFIED; - public PbapClientObexTransport(PbapClientSocket socket) { mSocket = requireNonNull(socket); } @@ -88,7 +85,7 @@ public class PbapClientObexTransport implements ObexTransport { @Override public int getMaxTransmitPacketSize() { if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { - return mMaxTransmitPacketSize; + return PACKET_SIZE_UNSPECIFIED; } return mSocket.getMaxTransmitPacketSize(); } @@ -96,12 +93,12 @@ public class PbapClientObexTransport implements ObexTransport { @Override public int getMaxReceivePacketSize() { if (mSocket.getConnectionType() != BluetoothSocket.TYPE_L2CAP) { - return mMaxReceivePacketSize; + return PACKET_SIZE_UNSPECIFIED; } return mSocket.getMaxReceivePacketSize(); } - /** Get the remote device MAC address associated with the transport, as a tring */ + /** Get the remote device MAC address associated with the transport, as a string */ public String getRemoteAddress() { String identityAddress = Utils.getBrEdrAddress(mSocket.getRemoteDevice()); return mSocket.getConnectionType() == BluetoothSocket.TYPE_RFCOMM diff --git a/android/app/src/com/android/bluetooth/sap/SapServer.java b/android/app/src/com/android/bluetooth/sap/SapServer.java index 97cce16ffb..969ae12d9c 100644 --- a/android/app/src/com/android/bluetooth/sap/SapServer.java +++ b/android/app/src/com/android/bluetooth/sap/SapServer.java @@ -74,7 +74,7 @@ public class SapServer extends Thread implements Handler.Callback { /* flag for when user forces disconnect of rfcomm */ @VisibleForTesting boolean mIsLocalInitDisconnect = false; - private CountDownLatch mDeinitSignal = new CountDownLatch(1); + private final CountDownLatch mDeinitSignal = new CountDownLatch(1); /* Message ID's handled by the message handler */ public static final int SAP_MSG_RFC_REPLY = 0x00; diff --git a/android/app/src/com/android/bluetooth/tbs/BluetoothGattServerProxy.java b/android/app/src/com/android/bluetooth/tbs/BluetoothGattServerProxy.java index a3bbb5f79c..9cb083ae67 100644 --- a/android/app/src/com/android/bluetooth/tbs/BluetoothGattServerProxy.java +++ b/android/app/src/com/android/bluetooth/tbs/BluetoothGattServerProxy.java @@ -41,7 +41,7 @@ import java.util.UUID; public class BluetoothGattServerProxy { private final Context mContext; - private BluetoothManager mBluetoothManager; + private final BluetoothManager mBluetoothManager; private BluetoothGattServer mBluetoothGattServer; public BluetoothGattServerProxy(Context context) { diff --git a/android/app/src/com/android/bluetooth/tbs/BluetoothLeCallControlProxy.java b/android/app/src/com/android/bluetooth/tbs/BluetoothLeCallControlProxy.java index 1a35e290a8..9dde971c42 100644 --- a/android/app/src/com/android/bluetooth/tbs/BluetoothLeCallControlProxy.java +++ b/android/app/src/com/android/bluetooth/tbs/BluetoothLeCallControlProxy.java @@ -37,7 +37,7 @@ import java.util.concurrent.Executor; @SuppressLint("AndroidFrameworkRequiresPermission") // TODO: b/350563786 public class BluetoothLeCallControlProxy { - private BluetoothLeCallControl mBluetoothLeCallControl; + private final BluetoothLeCallControl mBluetoothLeCallControl; public static final int BEARER_TECHNOLOGY_3G = 0x01; public static final int BEARER_TECHNOLOGY_4G = 0x02; diff --git a/android/app/src/com/android/bluetooth/tbs/TbsCall.java b/android/app/src/com/android/bluetooth/tbs/TbsCall.java index 9432643ff6..81990b06e9 100644 --- a/android/app/src/com/android/bluetooth/tbs/TbsCall.java +++ b/android/app/src/com/android/bluetooth/tbs/TbsCall.java @@ -27,9 +27,9 @@ public class TbsCall { public static final int INDEX_MAX = 0xFF; private int mState; - private String mUri; - private int mFlags; - private String mFriendlyName; + private final String mUri; + private final int mFlags; + private final String mFriendlyName; /** * Converts state value to human readable state string diff --git a/android/app/src/com/android/bluetooth/tbs/TbsGatt.java b/android/app/src/com/android/bluetooth/tbs/TbsGatt.java index b5cdddf339..871e6d7b62 100644 --- a/android/app/src/com/android/bluetooth/tbs/TbsGatt.java +++ b/android/app/src/com/android/bluetooth/tbs/TbsGatt.java @@ -223,14 +223,14 @@ public class TbsGatt { mValue = null; } - public Operation mOperation; - public int mRequestId; - public BluetoothGattCharacteristic mCharacteristic; - public BluetoothGattDescriptor mDescriptor; - public boolean mPreparedWrite; - public boolean mResponseNeeded; - public int mOffset; - public byte[] mValue; + public final Operation mOperation; + public final int mRequestId; + public final BluetoothGattCharacteristic mCharacteristic; + public final BluetoothGattDescriptor mDescriptor; + public final boolean mPreparedWrite; + public final boolean mResponseNeeded; + public final int mOffset; + public final byte[] mValue; } TbsGatt(AdapterService adapterService, TbsService tbsService) { @@ -516,7 +516,7 @@ public class TbsGatt { /** Wrapper class for BluetoothGattCharacteristic */ private class GattCharacteristic extends BluetoothGattCharacteristic { - protected BluetoothGattCharacteristicNotifier mNotifier; + protected final BluetoothGattCharacteristicNotifier mNotifier; public GattCharacteristic(UUID uuid, int properties, int permissions) { super(uuid, properties, permissions); diff --git a/android/app/src/com/android/bluetooth/tbs/TbsGeneric.java b/android/app/src/com/android/bluetooth/tbs/TbsGeneric.java index b88f6e7d9c..f0ba866d62 100644 --- a/android/app/src/com/android/bluetooth/tbs/TbsGeneric.java +++ b/android/app/src/com/android/bluetooth/tbs/TbsGeneric.java @@ -65,16 +65,16 @@ public class TbsGeneric { /** Class representing the pending request sent to the application */ private static class Request { - BluetoothDevice device; - List<UUID> callIdList; - int requestedOpcode; - int callIndex; + final BluetoothDevice mDevice; + final List<UUID> mCallIdList; + final int mRequestedOpcode; + final int mCallIndex; public Request(BluetoothDevice device, UUID callId, int requestedOpcode, int callIndex) { - this.device = device; - this.callIdList = Arrays.asList(callId); - this.requestedOpcode = requestedOpcode; - this.callIndex = callIndex; + this.mDevice = device; + this.mCallIdList = Arrays.asList(callId); + this.mRequestedOpcode = requestedOpcode; + this.mCallIndex = callIndex; } public Request( @@ -82,13 +82,13 @@ public class TbsGeneric { List<ParcelUuid> callIds, int requestedOpcode, int callIndex) { - this.device = device; - this.callIdList = new ArrayList<>(); + this.mDevice = device; + this.mCallIdList = new ArrayList<>(); for (ParcelUuid callId : callIds) { - this.callIdList.add(callId.getUuid()); + this.mCallIdList.add(callId.getUuid()); } - this.requestedOpcode = requestedOpcode; - this.callIndex = callIndex; + this.mRequestedOpcode = requestedOpcode; + this.mCallIndex = callIndex; } } @@ -96,13 +96,13 @@ public class TbsGeneric { private static class Bearer { final String token; final IBluetoothLeCallControlCallback callback; - List<String> uriSchemes; + final List<String> mUriSchemes; final int capabilities; final int ccid; String providerName; int technology; Map<UUID, Integer> callIdIndexMap = new HashMap<>(); - Map<Integer, Request> requestMap = new HashMap<>(); + final Map<Integer, Request> mRequestMap = new HashMap<>(); Bearer( String token, @@ -114,7 +114,7 @@ public class TbsGeneric { int ccid) { this.token = token; this.callback = callback; - this.uriSchemes = uriSchemes; + this.mUriSchemes = uriSchemes; this.capabilities = capabilities; this.providerName = providerName; this.technology = technology; @@ -275,7 +275,7 @@ public class TbsGeneric { private synchronized Bearer getBearerSupportingUri(String uri) { for (Bearer bearer : mBearerList) { - for (String s : bearer.uriSchemes) { + for (String s : bearer.mUriSchemes) { if (uri.startsWith(s + ":")) { return bearer; } @@ -398,9 +398,9 @@ public class TbsGeneric { private synchronized void checkRequestComplete(Bearer bearer, UUID callId, TbsCall tbsCall) { // check if there's any pending request related to this call Map.Entry<Integer, Request> requestEntry = null; - if (bearer.requestMap.size() > 0) { - for (Map.Entry<Integer, Request> entry : bearer.requestMap.entrySet()) { - if (entry.getValue().callIdList.contains(callId)) { + if (bearer.mRequestMap.size() > 0) { + for (Map.Entry<Integer, Request> entry : bearer.mRequestMap.entrySet()) { + if (entry.getValue().mCallIdList.contains(callId)) { requestEntry = entry; } } @@ -415,39 +415,39 @@ public class TbsGeneric { Request request = requestEntry.getValue(); int result; - if (request.requestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_TERMINATE) { - if (mCurrentCallsList.get(request.callIndex) == null) { + if (request.mRequestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_TERMINATE) { + if (mCurrentCallsList.get(request.mCallIndex) == null) { result = TbsGatt.CALL_CONTROL_POINT_RESULT_SUCCESS; } else { result = TbsGatt.CALL_CONTROL_POINT_RESULT_OPERATION_NOT_POSSIBLE; } - } else if (request.requestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_ACCEPT) { + } else if (request.mRequestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_ACCEPT) { if (tbsCall.getState() != BluetoothLeCall.STATE_INCOMING) { result = TbsGatt.CALL_CONTROL_POINT_RESULT_SUCCESS; } else { result = TbsGatt.CALL_CONTROL_POINT_RESULT_OPERATION_NOT_POSSIBLE; } - } else if (request.requestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_LOCAL_HOLD) { + } else if (request.mRequestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_LOCAL_HOLD) { if (tbsCall.getState() == BluetoothLeCall.STATE_LOCALLY_HELD || tbsCall.getState() == BluetoothLeCall.STATE_LOCALLY_AND_REMOTELY_HELD) { result = TbsGatt.CALL_CONTROL_POINT_RESULT_SUCCESS; } else { result = TbsGatt.CALL_CONTROL_POINT_RESULT_OPERATION_NOT_POSSIBLE; } - } else if (request.requestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_LOCAL_RETRIEVE) { + } else if (request.mRequestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_LOCAL_RETRIEVE) { if (tbsCall.getState() != BluetoothLeCall.STATE_LOCALLY_HELD && tbsCall.getState() != BluetoothLeCall.STATE_LOCALLY_AND_REMOTELY_HELD) { result = TbsGatt.CALL_CONTROL_POINT_RESULT_SUCCESS; } else { result = TbsGatt.CALL_CONTROL_POINT_RESULT_OPERATION_NOT_POSSIBLE; } - } else if (request.requestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_ORIGINATE) { - if (bearer.callIdIndexMap.get(request.callIdList.get(0)) != null) { + } else if (request.mRequestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_ORIGINATE) { + if (bearer.callIdIndexMap.get(request.mCallIdList.get(0)) != null) { result = TbsGatt.CALL_CONTROL_POINT_RESULT_SUCCESS; } else { result = TbsGatt.CALL_CONTROL_POINT_RESULT_OPERATION_NOT_POSSIBLE; } - } else if (request.requestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_JOIN) { + } else if (request.mRequestedOpcode == TbsGatt.CALL_CONTROL_POINT_OPCODE_JOIN) { /* While joining calls, those that are not in remotely held state should go to active */ if (bearer.callIdIndexMap.get(callId) == null || (tbsCall.getState() != BluetoothLeCall.STATE_ACTIVE @@ -455,7 +455,7 @@ public class TbsGeneric { result = TbsGatt.CALL_CONTROL_POINT_RESULT_OPERATION_NOT_POSSIBLE; } else { /* Check if all of the pending calls transit to required state */ - for (UUID pendingCallId : request.callIdList) { + for (UUID pendingCallId : request.mCallIdList) { Integer callIndex = bearer.callIdIndexMap.get(pendingCallId); TbsCall pendingTbsCall = mCurrentCallsList.get(callIndex); if (pendingTbsCall.getState() != BluetoothLeCall.STATE_ACTIVE @@ -471,9 +471,9 @@ public class TbsGeneric { } mTbsGatt.setCallControlPointResult( - request.device, request.requestedOpcode, request.callIndex, result); + request.mDevice, request.mRequestedOpcode, request.mCallIndex, result); - bearer.requestMap.remove(requestId); + bearer.mRequestMap.remove(requestId); } private synchronized int getTbsResult(int result, int requestedOpcode) { @@ -509,15 +509,15 @@ public class TbsGeneric { } // check if there's any pending request related to this call - Request request = bearer.requestMap.remove(requestId); + Request request = bearer.mRequestMap.remove(requestId); if (request == null) { // already sent response return; } - int tbsResult = getTbsResult(result, request.requestedOpcode); + int tbsResult = getTbsResult(result, request.mRequestedOpcode); mTbsGatt.setCallControlPointResult( - request.device, request.requestedOpcode, request.callIndex, tbsResult); + request.mDevice, request.mRequestedOpcode, request.mCallIndex, tbsResult); } public synchronized void callAdded(int ccid, BluetoothLeCall call) { @@ -779,7 +779,7 @@ public class TbsGeneric { return TbsGatt.CALL_CONTROL_POINT_RESULT_OPERATION_NOT_POSSIBLE; } - bearer.requestMap.put(requestId, request); + bearer.mRequestMap.put(requestId, request); mLastIndexAssigned = requestId; } @@ -924,7 +924,7 @@ public class TbsGeneric { break; } - bearer.requestMap.put(requestId, request); + bearer.mRequestMap.put(requestId, request); mLastRequestIdAssigned = requestId; result = TbsGatt.CALL_CONTROL_POINT_RESULT_SUCCESS; @@ -999,7 +999,7 @@ public class TbsGeneric { break; } - bearer.requestMap.put(requestId, request); + bearer.mRequestMap.put(requestId, request); mLastIndexAssigned = requestId; result = TbsGatt.CALL_CONTROL_POINT_RESULT_SUCCESS; @@ -1184,7 +1184,7 @@ public class TbsGeneric { private synchronized void updateUriSchemesSupported() { List<String> newUriSchemes = new ArrayList<>(); for (Bearer bearer : mBearerList) { - newUriSchemes.addAll(bearer.uriSchemes); + newUriSchemes.addAll(bearer.mUriSchemes); } // filter duplicates diff --git a/android/app/src/com/android/bluetooth/telephony/BluetoothInCallService.java b/android/app/src/com/android/bluetooth/telephony/BluetoothInCallService.java index 88633d61f6..296a8f4281 100644 --- a/android/app/src/com/android/bluetooth/telephony/BluetoothInCallService.java +++ b/android/app/src/com/android/bluetooth/telephony/BluetoothInCallService.java @@ -113,14 +113,13 @@ public class BluetoothInCallService extends InCallService { private int mRingingAddressType = DEFAULT_RINGING_ADDRESS_TYPE; private BluetoothCall mOldHeldCall = null; private boolean mHeadsetUpdatedRecently = false; - private boolean mIsDisconnectedTonePlaying = false; @VisibleForTesting boolean mIsTerminatedByClient = false; private static final Object LOCK = new Object(); @VisibleForTesting BluetoothLeCallControlProxy mBluetoothLeCallControl; - private ExecutorService mExecutor; + private final ExecutorService mExecutor; private TelephonyManager mTelephonyManager; private TelecomManager mTelecomManager; @@ -1341,7 +1340,7 @@ public class BluetoothInCallService extends InCallService { bluetoothCallState = CALL_STATE_INCOMING; } else if (!mCallInfo.isNullCall(dialingCall)) { bluetoothCallState = CALL_STATE_ALERTING; - } else if (hasOnlyDisconnectedCalls || mIsDisconnectedTonePlaying) { + } else if (hasOnlyDisconnectedCalls) { // Keep the DISCONNECTED state until the disconnect tone's playback is done bluetoothCallState = CALL_STATE_DISCONNECTED; } diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java index 943e80f7bf..f336cf6a69 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java @@ -104,7 +104,7 @@ public class A2dpServiceTest { private TestLooper mLooper; private A2dpService mA2dpService; - private CompanionDeviceManager mCompanionDeviceManager = + private final CompanionDeviceManager mCompanionDeviceManager = InstrumentationRegistry.getInstrumentation() .getContext() .getSystemService(CompanionDeviceManager.class); diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java index 368eac6c00..ee30dfa8d1 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java @@ -95,7 +95,7 @@ public class AvrcpControllerStateMachineTest { private final BluetoothDevice mDevice = getTestDevice(43); private final byte[] mTestAddress = getBytesFromAddress(mDevice.getAddress()); - private ArgumentCaptor<Intent> mIntentArgument = ArgumentCaptor.forClass(Intent.class); + private final ArgumentCaptor<Intent> mIntentArgument = ArgumentCaptor.forClass(Intent.class); private AvrcpControllerStateMachine mAvrcpStateMachine; private BrowseTree mBrowseTree; diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/bip/BipImageTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/bip/BipImageTest.java index 8186b45de3..4a8f103ad1 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/bip/BipImageTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/bip/BipImageTest.java @@ -36,7 +36,7 @@ import java.io.InputStream; /** A test suite for the BipImage class */ @RunWith(AndroidJUnit4.class) public class BipImageTest { - private static String sImageHandle = "123456789"; + private static final String sImageHandle = "123456789"; private Resources mTestResources; @Before diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java index abe3891872..13f38272e6 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java @@ -100,7 +100,7 @@ public class ActiveDeviceManagerTest { private ArrayList<BluetoothDevice> mDeviceConnectionStack; private BluetoothDevice mMostRecentDevice; private ActiveDeviceManager mActiveDeviceManager; - private long mHearingAidHiSyncId = 1010; + private static final long HEARING_AID_HI_SYNC_ID = 1010; private static final int A2DP_HFP_SYNC_CONNECTION_TIMEOUT_MS = ActiveDeviceManager.A2DP_HFP_SYNC_CONNECTION_TIMEOUT_MS + 2_000; @@ -173,8 +173,8 @@ public class ActiveDeviceManagerTest { List<BluetoothDevice> connectedHearingAidDevices = new ArrayList<>(); connectedHearingAidDevices.add(mHearingAidDevice); - when(mHearingAidService.getHiSyncId(mHearingAidDevice)).thenReturn(mHearingAidHiSyncId); - when(mHearingAidService.getConnectedPeerDevices(mHearingAidHiSyncId)) + when(mHearingAidService.getHiSyncId(mHearingAidDevice)).thenReturn(HEARING_AID_HI_SYNC_ID); + when(mHearingAidService.getConnectedPeerDevices(HEARING_AID_HI_SYNC_ID)) .thenReturn(connectedHearingAidDevices); when(mA2dpService.getFallbackDevice()) @@ -750,7 +750,8 @@ public class ActiveDeviceManagerTest { Assume.assumeTrue( "Ignore test when HearingAidService is not enabled", HearingAidService.isEnabled()); - when(mHearingAidService.getHiSyncId(mSecondaryAudioDevice)).thenReturn(mHearingAidHiSyncId); + when(mHearingAidService.getHiSyncId(mSecondaryAudioDevice)) + .thenReturn(HEARING_AID_HI_SYNC_ID); hearingAidConnected(mHearingAidDevice); hearingAidConnected(mSecondaryAudioDevice); @@ -1465,8 +1466,8 @@ public class ActiveDeviceManagerTest { List<BluetoothDevice> connectedHearingAidDevices = new ArrayList<>(); connectedHearingAidDevices.add(mSecondaryAudioDevice); when(mHearingAidService.getHiSyncId(mSecondaryAudioDevice)) - .thenReturn(mHearingAidHiSyncId + 1); - when(mHearingAidService.getConnectedPeerDevices(mHearingAidHiSyncId + 1)) + .thenReturn(HEARING_AID_HI_SYNC_ID + 1); + when(mHearingAidService.getConnectedPeerDevices(HEARING_AID_HI_SYNC_ID + 1)) .thenReturn(connectedHearingAidDevices); hearingAidConnected(mSecondaryAudioDevice); @@ -1972,7 +1973,7 @@ public class ActiveDeviceManagerTest { } private class TestDatabaseManager extends DatabaseManager { - ArrayMap<BluetoothDevice, SparseIntArray> mProfileConnectionPolicy; + final ArrayMap<BluetoothDevice, SparseIntArray> mProfileConnectionPolicy; TestDatabaseManager(AdapterService service) { super(service); diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java index f1b99ccd3c..ec8bfd09be 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java @@ -448,7 +448,7 @@ public class DataMigrationTest { private static class FakeCursor extends MockCursor { int mNumItem = 1; - List<Pair<String, Object>> mRows; + final List<Pair<String, Object>> mRows; FakeCursor(List<Pair<String, Object>> rows) { mRows = rows; diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java index 27ca9a3ceb..21f04ff490 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java @@ -88,8 +88,8 @@ public class MetricsLoggerTest { @Mock private RemoteDevices mRemoteDevices; private static class TestableMetricsLogger extends MetricsLogger { - public HashMap<Integer, Long> mTestableCounters = new HashMap<>(); - public HashMap<String, Integer> mTestableDeviceNames = new HashMap<>(); + public final HashMap<Integer, Long> mTestableCounters = new HashMap<>(); + public final HashMap<String, Integer> mTestableDeviceNames = new HashMap<>(); @Override public boolean count(int key, long count) { diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java index ba2fe08153..e44682c266 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java @@ -94,7 +94,7 @@ public final class BluetoothKeystoreServiceTest { private List<String> mConfigData = new ArrayList<>(); - private Map<String, String> mNameDecryptKeyResult = new HashMap<>(); + private final Map<String, String> mNameDecryptKeyResult = new HashMap<>(); @Before public void setUp() { diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java index e05c0a0d26..b020dbf6d8 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java @@ -80,11 +80,11 @@ public final class DatabaseManagerTest { @Mock private AdapterService mAdapterService; - private BluetoothDevice mDevice = getTestDevice(54); - private BluetoothDevice mDevice2 = getTestDevice(55); - private BluetoothDevice mDevice3 = getTestDevice(56); - private BluetoothDevice mDevice4 = getTestDevice(57); - private BluetoothDevice mDevice5 = getTestDevice(58); + private final BluetoothDevice mDevice = getTestDevice(54); + private final BluetoothDevice mDevice2 = getTestDevice(55); + private final BluetoothDevice mDevice3 = getTestDevice(56); + private final BluetoothDevice mDevice4 = getTestDevice(57); + private final BluetoothDevice mDevice5 = getTestDevice(58); private MetadataDatabase mDatabase; private DatabaseManager mDatabaseManager; diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java index 9fadbcb9a7..398ba1c6cd 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java @@ -38,7 +38,7 @@ public class BluetoothHeadsetBinderTest { @Mock private HeadsetService mService; private final AttributionSource mAttributionSource = new AttributionSource.Builder(1).build(); - private BluetoothDevice mDevice = getTestDevice(39); + private final BluetoothDevice mDevice = getTestDevice(39); private HeadsetService.BluetoothHeadsetBinder mBinder; diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java index 22e98262e5..696089931e 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java @@ -105,7 +105,7 @@ public class HeadsetStateMachineTest { private HandlerThread mHandlerThread; private HeadsetStateMachine mHeadsetStateMachine; private final BluetoothDevice mDevice = getTestDevice(87); - private ArgumentCaptor<Intent> mIntentArgument = ArgumentCaptor.forClass(Intent.class); + private final ArgumentCaptor<Intent> mIntentArgument = ArgumentCaptor.forClass(Intent.class); @Rule public final MockitoRule mMockitoRule = new MockitoRule(); diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java index 776d713133..17af0e42bc 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java @@ -48,7 +48,7 @@ public class VendorCommandResponseProcessorTest { @Mock private AdapterService mAdapterService; @Mock private HeadsetClientService mHeadsetClientService; - private static int TEST_VENDOR_ID = BluetoothAssignedNumbers.APPLE; + private static final int TEST_VENDOR_ID = BluetoothAssignedNumbers.APPLE; private final BluetoothDevice mDevice = getTestDevice(65); diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java index 7e8820e6bc..7b898c389e 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java @@ -156,7 +156,7 @@ public class LeAudioServiceTest { private final BluetoothDevice mSingleDevice_2 = getTestDevice(3); private LeAudioService mService; - private int testGroupId = 1; + private static final int TEST_GROUP_ID = 1; private boolean onGroupStatusCallbackCalled = false; private boolean onGroupStreamStatusCallbackCalled = false; private boolean onGroupCodecConfChangedCallbackCalled = false; @@ -945,7 +945,7 @@ public class LeAudioServiceTest { assertThat(mService.setActiveDevice(mSingleDevice)).isFalse(); // Connect device - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); // Add location support injectAudioConfChanged(mSingleDevice, groupId, availableContexts, direction); @@ -985,7 +985,7 @@ public class LeAudioServiceTest { assertThat(mService.setActiveDevice(mSingleDevice)).isFalse(); // Connect device - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); // Add location support injectAudioConfChanged(mSingleDevice, groupId, availableContexts, direction); @@ -1083,7 +1083,7 @@ public class LeAudioServiceTest { assertThat(mService.setActiveDevice(mSingleDevice)).isFalse(); // Connect device - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); // Add location support injectAudioConfChanged(mSingleDevice, groupId, availableContexts, direction); @@ -1244,7 +1244,7 @@ public class LeAudioServiceTest { assertThat(mService.setActiveDevice(mSingleDevice)).isFalse(); // Connect device - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); // Add location support injectAudioConfChanged(mSingleDevice, groupId, availableContexts, direction); @@ -1374,7 +1374,7 @@ public class LeAudioServiceTest { int groupStatus = LeAudioStackEvent.GROUP_STATUS_ACTIVE; // Single active device - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); // Add device to group LeAudioStackEvent nodeStatusChangedEvent = @@ -1454,15 +1454,15 @@ public class LeAudioServiceTest { ArgumentCaptor<BluetoothProfileConnectionInfo> testConnectioInfoCapture = ArgumentCaptor.forClass(BluetoothProfileConnectionInfo.class); - doReturn(testVolume).when(mVolumeControlService).getAudioDeviceGroupVolume(testGroupId); + doReturn(testVolume).when(mVolumeControlService).getAudioDeviceGroupVolume(TEST_GROUP_ID); - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); injectAudioConfChanged( mSingleDevice, - testGroupId, + TEST_GROUP_ID, BluetoothLeAudio.CONTEXT_TYPE_MEDIA | BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL, 3); - injectGroupStatusChange(testGroupId, BluetoothLeAudio.GROUP_STATUS_ACTIVE); + injectGroupStatusChange(TEST_GROUP_ID, BluetoothLeAudio.GROUP_STATUS_ACTIVE); verify(mAudioManager, times(2)) .handleBluetoothActiveDeviceChanged( @@ -1481,7 +1481,7 @@ public class LeAudioServiceTest { // Remove source direction injectAudioConfChanged( mSingleDevice, - testGroupId, + TEST_GROUP_ID, BluetoothLeAudio.CONTEXT_TYPE_MEDIA | BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL, 1); @@ -1503,7 +1503,7 @@ public class LeAudioServiceTest { injectAudioConfChanged( mSingleDevice, - testGroupId, + TEST_GROUP_ID, BluetoothLeAudio.CONTEXT_TYPE_MEDIA | BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL, 2); @@ -1529,13 +1529,13 @@ public class LeAudioServiceTest { /** Test native interface audio configuration changed message handling */ @Test public void testMessageFromNativeAudioConfChangedActiveGroup() { - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); injectAudioConfChanged( mSingleDevice, - testGroupId, + TEST_GROUP_ID, BluetoothLeAudio.CONTEXT_TYPE_MEDIA | BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL, 3); - injectGroupStatusChange(testGroupId, BluetoothLeAudio.GROUP_STATUS_ACTIVE); + injectGroupStatusChange(TEST_GROUP_ID, BluetoothLeAudio.GROUP_STATUS_ACTIVE); /* Expect 2 calls to Audio Manager - one for output and second for input as this is * Conversational use case */ @@ -1551,11 +1551,11 @@ public class LeAudioServiceTest { /** Test native interface audio configuration changed message handling */ @Test public void testMessageFromNativeAudioConfChangedInactiveGroup() { - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); Integer contexts = BluetoothLeAudio.CONTEXT_TYPE_MEDIA | BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL; - injectAudioConfChanged(mSingleDevice, testGroupId, contexts, 3); + injectAudioConfChanged(mSingleDevice, TEST_GROUP_ID, contexts, 3); verifyNoIntentSent(); } @@ -1563,9 +1563,9 @@ public class LeAudioServiceTest { /** Test native interface audio configuration changed message handling */ @Test public void testMessageFromNativeAudioConfChangedNoGroupChanged() { - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); - injectAudioConfChanged(mSingleDevice, testGroupId, 0, 3); + injectAudioConfChanged(mSingleDevice, TEST_GROUP_ID, 0, 3); verifyNoIntentSent(); } @@ -1575,7 +1575,7 @@ public class LeAudioServiceTest { */ @Test public void testHealthBaseDeviceAction() { - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); LeAudioStackEvent healthBaseDevAction = new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_HEALTH_BASED_DEV_RECOMMENDATION); @@ -1587,12 +1587,12 @@ public class LeAudioServiceTest { @Test public void testHealthBasedGroupAction() { - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); LeAudioStackEvent healthBasedGroupAction = new LeAudioStackEvent( LeAudioStackEvent.EVENT_TYPE_HEALTH_BASED_GROUP_RECOMMENDATION); - healthBasedGroupAction.valueInt1 = testGroupId; + healthBasedGroupAction.valueInt1 = TEST_GROUP_ID; healthBasedGroupAction.valueInt2 = LeAudioStackEvent.HEALTH_RECOMMENDATION_ACTION_DISABLE; mService.messageFromNative(healthBasedGroupAction); assertThat(mService.mLeAudioNativeIsInitialized).isTrue(); @@ -1601,13 +1601,13 @@ public class LeAudioServiceTest { @Test public void testHealthBasedGroupAction_recommendDisable() { doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); - connectTestDevice(mLeftDevice, testGroupId); - connectTestDevice(mRightDevice, testGroupId); + connectTestDevice(mLeftDevice, TEST_GROUP_ID); + connectTestDevice(mRightDevice, TEST_GROUP_ID); LeAudioStackEvent healthBasedGroupAction = new LeAudioStackEvent( LeAudioStackEvent.EVENT_TYPE_HEALTH_BASED_GROUP_RECOMMENDATION); - healthBasedGroupAction.valueInt1 = testGroupId; + healthBasedGroupAction.valueInt1 = TEST_GROUP_ID; healthBasedGroupAction.valueInt2 = LeAudioStackEvent.HEALTH_RECOMMENDATION_ACTION_DISABLE; mService.messageFromNative(healthBasedGroupAction); assertThat(mService.mLeAudioNativeIsInitialized).isTrue(); @@ -1667,18 +1667,18 @@ public class LeAudioServiceTest { /** Test native interface group status message handling */ @Test public void testMessageFromNativeGroupStatusChanged() { - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); injectAudioConfChanged( mSingleDevice, - testGroupId, + TEST_GROUP_ID, BluetoothLeAudio.CONTEXT_TYPE_MEDIA | BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL, 3); sendEventAndVerifyIntentForGroupStatusChanged( - testGroupId, LeAudioStackEvent.GROUP_STATUS_ACTIVE); + TEST_GROUP_ID, LeAudioStackEvent.GROUP_STATUS_ACTIVE); sendEventAndVerifyIntentForGroupStatusChanged( - testGroupId, LeAudioStackEvent.GROUP_STATUS_INACTIVE); + TEST_GROUP_ID, LeAudioStackEvent.GROUP_STATUS_INACTIVE); } private void sendEventAndVerifyGroupStreamStatusChanged(int groupId, int groupStreamStatus) { @@ -1728,18 +1728,18 @@ public class LeAudioServiceTest { /** Test native interface group stream status message handling */ @Test public void testMessageFromNativeGroupStreamStatusChanged() { - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); injectAudioConfChanged( mSingleDevice, - testGroupId, + TEST_GROUP_ID, BluetoothLeAudio.CONTEXT_TYPE_MEDIA | BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL, 3); sendEventAndVerifyGroupStreamStatusChanged( - testGroupId, LeAudioStackEvent.GROUP_STREAM_STATUS_IDLE); + TEST_GROUP_ID, LeAudioStackEvent.GROUP_STREAM_STATUS_IDLE); sendEventAndVerifyGroupStreamStatusChanged( - testGroupId, LeAudioStackEvent.GROUP_STREAM_STATUS_STREAMING); + TEST_GROUP_ID, LeAudioStackEvent.GROUP_STREAM_STATUS_STREAMING); } private void injectLocalCodecConfigCapaChanged( @@ -1790,7 +1790,7 @@ public class LeAudioServiceTest { injectLocalCodecConfigCapaChanged(INPUT_CAPABILITIES_CONFIG, OUTPUT_CAPABILITIES_CONFIG); - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); testCodecStatus = new BluetoothLeAudioCodecStatus( @@ -1830,9 +1830,9 @@ public class LeAudioServiceTest { } injectGroupSelectableCodecConfigChanged( - testGroupId, INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG); + TEST_GROUP_ID, INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG); // Inject configuration and check that AF is NOT notified. - injectGroupCurrentCodecConfigChanged(testGroupId, LC3_16KHZ_CONFIG, LC3_48KHZ_CONFIG); + injectGroupCurrentCodecConfigChanged(TEST_GROUP_ID, LC3_16KHZ_CONFIG, LC3_48KHZ_CONFIG); TestUtils.waitForLooperToFinishScheduledTask(Looper.getMainLooper()); assertThat(onGroupCodecConfChangedCallbackCalled).isTrue(); @@ -1853,7 +1853,7 @@ public class LeAudioServiceTest { INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG); - injectGroupCurrentCodecConfigChanged(testGroupId, LC3_16KHZ_CONFIG, LC3_16KHZ_CONFIG); + injectGroupCurrentCodecConfigChanged(TEST_GROUP_ID, LC3_16KHZ_CONFIG, LC3_16KHZ_CONFIG); TestUtils.waitForLooperToFinishScheduledTask(Looper.getMainLooper()); assertThat(onGroupCodecConfChangedCallbackCalled).isTrue(); @@ -1876,7 +1876,7 @@ public class LeAudioServiceTest { injectLocalCodecConfigCapaChanged(INPUT_CAPABILITIES_CONFIG, OUTPUT_CAPABILITIES_CONFIG); - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); testCodecStatus = new BluetoothLeAudioCodecStatus( @@ -1916,17 +1916,17 @@ public class LeAudioServiceTest { } injectGroupSelectableCodecConfigChanged( - testGroupId, INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG); + TEST_GROUP_ID, INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG); - injectGroupCurrentCodecConfigChanged(testGroupId, LC3_16KHZ_CONFIG, LC3_48KHZ_CONFIG); + injectGroupCurrentCodecConfigChanged(TEST_GROUP_ID, LC3_16KHZ_CONFIG, LC3_48KHZ_CONFIG); injectAudioConfChanged( mSingleDevice, - testGroupId, + TEST_GROUP_ID, BluetoothLeAudio.CONTEXT_TYPE_MEDIA | BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL, 3); - injectGroupStatusChange(testGroupId, LeAudioStackEvent.GROUP_STATUS_ACTIVE); + injectGroupStatusChange(TEST_GROUP_ID, LeAudioStackEvent.GROUP_STATUS_ACTIVE); TestUtils.waitForLooperToFinishScheduledTask(Looper.getMainLooper()); assertThat(onGroupCodecConfChangedCallbackCalled).isTrue(); @@ -1948,7 +1948,7 @@ public class LeAudioServiceTest { INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG); - injectGroupCurrentCodecConfigChanged(testGroupId, LC3_16KHZ_CONFIG, LC3_16KHZ_CONFIG); + injectGroupCurrentCodecConfigChanged(TEST_GROUP_ID, LC3_16KHZ_CONFIG, LC3_16KHZ_CONFIG); TestUtils.waitForLooperToFinishScheduledTask(Looper.getMainLooper()); assertThat(onGroupCodecConfChangedCallbackCalled).isTrue(); @@ -1972,7 +1972,7 @@ public class LeAudioServiceTest { injectLocalCodecConfigCapaChanged(INPUT_CAPABILITIES_CONFIG, OUTPUT_CAPABILITIES_CONFIG); - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); testCodecStatus = new BluetoothLeAudioCodecStatus( @@ -2012,8 +2012,8 @@ public class LeAudioServiceTest { } injectGroupSelectableCodecConfigChanged( - testGroupId, INPUT_EMPTY_CONFIG, OUTPUT_SELECTABLE_CONFIG); - injectGroupCurrentCodecConfigChanged(testGroupId, EMPTY_CONFIG, LC3_48KHZ_CONFIG); + TEST_GROUP_ID, INPUT_EMPTY_CONFIG, OUTPUT_SELECTABLE_CONFIG); + injectGroupCurrentCodecConfigChanged(TEST_GROUP_ID, EMPTY_CONFIG, LC3_48KHZ_CONFIG); TestUtils.waitForLooperToFinishScheduledTask(Looper.getMainLooper()); assertThat(onGroupCodecConfChangedCallbackCalled).isTrue(); @@ -2023,7 +2023,7 @@ public class LeAudioServiceTest { mService.mLeAudioCallbacks.unregister(leAudioCallbacks); } - BluetoothLeAudioCodecStatus codecStatus = mService.getCodecStatus(testGroupId); + BluetoothLeAudioCodecStatus codecStatus = mService.getCodecStatus(TEST_GROUP_ID); assertThat(codecStatus.getInputCodecConfig()).isNull(); assertThat(codecStatus.getOutputCodecConfig()).isNotNull(); } @@ -2278,7 +2278,7 @@ public class LeAudioServiceTest { @Test public void testGetAudioLocation() { - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); assertThat(mService.getAudioLocation(null)) .isEqualTo(BluetoothLeAudio.AUDIO_LOCATION_INVALID); @@ -2295,10 +2295,10 @@ public class LeAudioServiceTest { @Test public void testGetConnectedPeerDevices() { - connectTestDevice(mLeftDevice, testGroupId); - connectTestDevice(mRightDevice, testGroupId); + connectTestDevice(mLeftDevice, TEST_GROUP_ID); + connectTestDevice(mRightDevice, TEST_GROUP_ID); - List<BluetoothDevice> peerDevices = mService.getConnectedPeerDevices(testGroupId); + List<BluetoothDevice> peerDevices = mService.getConnectedPeerDevices(TEST_GROUP_ID); assertThat(peerDevices.contains(mLeftDevice)).isTrue(); assertThat(peerDevices.contains(mRightDevice)).isTrue(); } @@ -2356,7 +2356,7 @@ public class LeAudioServiceTest { when(mDatabaseManager.getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(CONNECTION_POLICY_ALLOWED); - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); StringBuilder sb = new StringBuilder(); mService.dump(sb); @@ -2497,7 +2497,7 @@ public class LeAudioServiceTest { int groupStatus = LeAudioStackEvent.GROUP_STATUS_ACTIVE; // Single active device - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); // Add device to group LeAudioStackEvent nodeStatusChangedEvent = @@ -3045,7 +3045,7 @@ public class LeAudioServiceTest { assertThat(mService.setActiveDevice(mSingleDevice)).isFalse(); // Connect device - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); // Add location support injectAudioConfChanged(mSingleDevice, groupId, availableContexts, direction); @@ -3108,7 +3108,7 @@ public class LeAudioServiceTest { // Connect device devices.add(mSingleDevice); - connectTestDevice(mSingleDevice, testGroupId); + connectTestDevice(mSingleDevice, TEST_GROUP_ID); // Group should be updated to default (earliest connected) assertThat(mService.getBroadcastToUnicastFallbackGroup()).isEqualTo(firstGroupId); diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java index 886e0ca3a7..09d946390b 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java @@ -76,9 +76,9 @@ public class MapClientContentTest { private Bmessage mTestMessage1; private Bmessage mTestMessage2; - private Long mTestMessage1Timestamp = 1234L; - private String mTestMessage1Handle = "0001"; - private String mTestMessage2Handle = "0002"; + private static final Long TIMESTAMP = 1234L; + private static final String HANDLE_1 = "0001"; + private static final String HANDLE_2 = "0002"; private static final boolean MESSAGE_SEEN = true; private static final boolean MESSAGE_NOT_SEEN = false; @@ -143,8 +143,7 @@ public class MapClientContentTest { @Test public void testCleanDirtyDatabase() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); verify(mMockSubscriptionManager) .addSubscriptionInfoRecord( any(), @@ -160,8 +159,7 @@ public class MapClientContentTest { @Test public void testStoreTwoSMS() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); verify(mMockSubscriptionManager) .addSubscriptionInfoRecord( any(), @@ -170,8 +168,7 @@ public class MapClientContentTest { eq(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM)); assertThat(mMockSmsContentProvider.mContentValues).hasSize(1); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); assertThat(mMockSmsContentProvider.mContentValues).hasSize(2); assertThat(mMockMmsContentProvider.mContentValues).isEmpty(); @@ -184,8 +181,7 @@ public class MapClientContentTest { @Test public void testStoreTwoMMS() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); verify(mMockSubscriptionManager) .addSubscriptionInfoRecord( any(), @@ -194,8 +190,7 @@ public class MapClientContentTest { eq(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM)); assertThat(mMockMmsContentProvider.mContentValues).hasSize(1); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); assertThat(mMockMmsContentProvider.mContentValues).hasSize(2); mMapClientContent.cleanUp(); @@ -206,8 +201,7 @@ public class MapClientContentTest { @Test public void testStoreOneSMSOneMMS() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); verify(mMockSubscriptionManager) .addSubscriptionInfoRecord( any(), @@ -216,8 +210,7 @@ public class MapClientContentTest { eq(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM)); assertThat(mMockMmsContentProvider.mContentValues).hasSize(1); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage2Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_2, TIMESTAMP, MESSAGE_SEEN); assertThat(mMockMmsContentProvider.mContentValues).hasSize(2); mMapClientContent.cleanUp(); @@ -228,8 +221,7 @@ public class MapClientContentTest { @Test public void testReadStatusChanged() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); verify(mMockSubscriptionManager) .addSubscriptionInfoRecord( any(), @@ -238,11 +230,10 @@ public class MapClientContentTest { eq(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM)); assertThat(mMockMmsContentProvider.mContentValues).hasSize(1); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); assertThat(mMockMmsContentProvider.mContentValues).hasSize(2); - mMapClientContent.markRead(mTestMessage1Handle); + mMapClientContent.markRead(HANDLE_1); mMapClientContent.cleanUp(); assertThat(mMockMmsContentProvider.mContentValues).isEmpty(); @@ -258,20 +249,17 @@ public class MapClientContentTest { @Test public void testLocalReadStatusChanged() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); assertThat(mMockMmsContentProvider.mContentValues).hasSize(1); mMapClientContent.mContentObserver.onChange(false); - verify(mCallbacks) - .onMessageStatusChanged(eq(mTestMessage1Handle), eq(BluetoothMapClient.READ)); + verify(mCallbacks).onMessageStatusChanged(eq(HANDLE_1), eq(BluetoothMapClient.READ)); } /** Test if seen status is set to true in database for SMS */ @Test public void testStoreSmsMessageWithSeenTrue_smsWrittenWithSeenTrue() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); assertThat(mMockSmsContentProvider.mContentValues).hasSize(1); ContentValues storedSMS = @@ -284,8 +272,7 @@ public class MapClientContentTest { @Test public void testStoreSmsMessageWithSeenFalse_smsWrittenWithSeenFalse() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_NOT_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_NOT_SEEN); assertThat(mMockSmsContentProvider.mContentValues).hasSize(1); ContentValues storedSMS = @@ -298,8 +285,7 @@ public class MapClientContentTest { @Test public void testStoreMmsMessageWithSeenTrue_mmsWrittenWithSeenTrue() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); assertThat(mMockMmsContentProvider.mContentValues).hasSize(1); ContentValues storedMMS = @@ -312,8 +298,7 @@ public class MapClientContentTest { @Test public void testStoreMmsMessageWithSeenFalse_mmsWrittenWithSeenFalse() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_NOT_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_1, TIMESTAMP, MESSAGE_NOT_SEEN); assertThat(mMockMmsContentProvider.mContentValues).hasSize(1); ContentValues storedMMS = @@ -331,8 +316,7 @@ public class MapClientContentTest { @Test public void testMessageDeleted() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); verify(mMockSubscriptionManager) .addSubscriptionInfoRecord( any(), @@ -341,11 +325,11 @@ public class MapClientContentTest { eq(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM)); assertThat(mMockSmsContentProvider.mContentValues).hasSize(1); // attempt to delete an invalid handle, nothing should be removed. - mMapClientContent.deleteMessage(mTestMessage2Handle); + mMapClientContent.deleteMessage(HANDLE_2); assertThat(mMockSmsContentProvider.mContentValues).hasSize(1); // delete a valid handle - mMapClientContent.deleteMessage(mTestMessage1Handle); + mMapClientContent.deleteMessage(HANDLE_1); assertThat(mMockSmsContentProvider.mContentValues).isEmpty(); } @@ -358,8 +342,7 @@ public class MapClientContentTest { @Test public void testLocalMessageDeleted() { mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); verify(mMockSubscriptionManager) .addSubscriptionInfoRecord( any(), @@ -369,8 +352,7 @@ public class MapClientContentTest { assertThat(mMockSmsContentProvider.mContentValues).hasSize(1); mMockSmsContentProvider.mContentValues.clear(); mMapClientContent.mContentObserver.onChange(false); - verify(mCallbacks) - .onMessageStatusChanged(eq(mTestMessage1Handle), eq(BluetoothMapClient.DELETED)); + verify(mCallbacks).onMessageStatusChanged(eq(HANDLE_1), eq(BluetoothMapClient.DELETED)); } /** @@ -400,15 +382,13 @@ public class MapClientContentTest { mTestMessage1.setBodyContent("HelloWorld"); mTestMessage1.setType(Bmessage.Type.SMS_GSM); mTestMessage1.setFolder("telecom/msg/sent"); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); mTestMessage2 = new Bmessage(); mTestMessage2.setBodyContent("HelloWorld"); mTestMessage2.setType(Bmessage.Type.MMS); mTestMessage2.setFolder("telecom/msg/inbox"); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage2Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_2, TIMESTAMP, MESSAGE_SEEN); } /** @@ -454,16 +434,15 @@ public class MapClientContentTest { Mockito.spy(new MissingContentProvider(mMockContext)); mMockContentResolver.addProvider("sms", missingContentProvider); mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage1, mTestMessage1Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage1, HANDLE_1, TIMESTAMP, MESSAGE_SEEN); // Because the insert failed, function calls to update or delete this message should not // work either - mMapClientContent.markRead(mTestMessage1Handle); + mMapClientContent.markRead(HANDLE_1); verify(missingContentProvider, never()) .update(any(Uri.class), any(ContentValues.class), any(Bundle.class)); - mMapClientContent.deleteMessage(mTestMessage1Handle); + mMapClientContent.deleteMessage(HANDLE_1); verify(missingContentProvider, never()) .delete(any(Uri.class), anyString(), any(String[].class)); } @@ -476,16 +455,15 @@ public class MapClientContentTest { Mockito.spy(new MissingContentProvider(mMockContext)); mMockContentResolver.addProvider("mms", missingContentProvider); mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mDevice); - mMapClientContent.storeMessage( - mTestMessage2, mTestMessage2Handle, mTestMessage1Timestamp, MESSAGE_SEEN); + mMapClientContent.storeMessage(mTestMessage2, HANDLE_2, TIMESTAMP, MESSAGE_SEEN); // Because the insert failed, function calls to update or delete this message should not // work either - mMapClientContent.markRead(mTestMessage2Handle); + mMapClientContent.markRead(HANDLE_2); verify(missingContentProvider, never()) .update(any(Uri.class), any(ContentValues.class), any(Bundle.class)); - mMapClientContent.deleteMessage(mTestMessage2Handle); + mMapClientContent.deleteMessage(HANDLE_2); verify(missingContentProvider, never()) .delete(any(Uri.class), anyString(), any(String[].class)); } diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java index fbd9bf4201..db55624516 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java @@ -155,7 +155,7 @@ public class MapClientStateMachineTest { private InOrder mInOrder; private static class SentDeliveryReceiver extends BroadcastReceiver { - private CountDownLatch mActionReceivedLatch; + private final CountDownLatch mActionReceivedLatch; SentDeliveryReceiver() { mActionReceivedLatch = new CountDownLatch(1); @@ -943,7 +943,7 @@ public class MapClientStateMachineTest { } private static class MockSmsContentProvider extends MockContentProvider { - Map<Uri, ContentValues> mContentValues = new HashMap<>(); + final Map<Uri, ContentValues> mContentValues = new HashMap<>(); int mInsertOperationCount = 0; @Override diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/RequestGetMessagesListingForOwnNumberTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/RequestGetMessagesListingForOwnNumberTest.java index 0f94753e3e..9ca5a6e3b4 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/RequestGetMessagesListingForOwnNumberTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/RequestGetMessagesListingForOwnNumberTest.java @@ -64,7 +64,8 @@ public class RequestGetMessagesListingForOwnNumberTest { private BluetoothMapMessageListingElement mSMSWithoutOwnNumber; private static class FakeMessageFoldersForListing { - private Map<String, List<BluetoothMapMessageListingElement>> mFolders = new HashMap<>(); + private final Map<String, List<BluetoothMapMessageListingElement>> mFolders = + new HashMap<>(); /** * @param folder - the folder you want to create messages for. diff --git a/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java b/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java index d5117cb896..0aa5f199d5 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java @@ -57,10 +57,6 @@ import java.util.UUID; public class MediaControlProfileTest { private MediaControlProfile mMediaControlProfile; - private String packageName = "TestPackage"; - - private String name = "TestPlayer"; - private CharSequence charSequence = "TestPlayer"; private MediaControlServiceCallbacks mMcpServiceCallbacks; @Rule public final MockitoRule mMockitoRule = new MockitoRule(); @@ -93,9 +89,10 @@ public class MediaControlProfileTest { doReturn(mMockMediaPlayerWrapper).when(mMockMediaPlayerList).getActivePlayer(); doReturn(mMockMcpService).when(mMockMcpService).getApplicationContext(); doReturn(mMockPackageManager).when(mMockMcpService).getPackageManager(); + String packageName = "TestPackage"; doReturn(packageName).when(mMockMcpService).getPackageName(); - doReturn(name).when(mMockMediaPlayerWrapper).getPackageName(); - doReturn(charSequence).when(mMockApplicationInfo).loadLabel(any(PackageManager.class)); + doReturn("TestPlayer").when(mMockMediaPlayerWrapper).getPackageName(); + doReturn("TestPlayer").when(mMockApplicationInfo).loadLabel(any(PackageManager.class)); doReturn(mMockApplicationInfo) .when(mMockPackageManager) .getApplicationInfo(anyString(), anyInt()); diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppShareInfoTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppShareInfoTest.java index 1ec8853e9a..26b987bb0b 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppShareInfoTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppShareInfoTest.java @@ -32,54 +32,42 @@ import org.junit.runner.RunWith; public class BluetoothOppShareInfoTest { private BluetoothOppShareInfo mBluetoothOppShareInfo; - private Uri uri = Uri.parse("file://Idontknow//Justmadeitup"); - private String hintString = "this is a object that take 4 bytes"; - private String filename = "random.jpg"; - private String mimetype = "image/jpeg"; - private int direction = BluetoothShare.DIRECTION_INBOUND; - private String destination = "01:23:45:67:89:AB"; - private int visibility = BluetoothShare.VISIBILITY_VISIBLE; - private int confirm = BluetoothShare.USER_CONFIRMATION_CONFIRMED; - private int status = BluetoothShare.STATUS_PENDING; - private int totalBytes = 1023; - private int currentBytes = 42; - private int timestamp = 123456789; - private boolean mediaScanned = false; - @Before public void setUp() throws Exception { mBluetoothOppShareInfo = new BluetoothOppShareInfo( 0, - uri, - hintString, - filename, - mimetype, - direction, - destination, - visibility, - confirm, - status, - totalBytes, - currentBytes, - timestamp, - mediaScanned); + Uri.parse("file://Idontknow//Justmadeitup"), + "this is a object that take 4 bytes", + "random.jpg", + "image/jpeg", + BluetoothShare.DIRECTION_INBOUND, + "01:23:45:67:89:AB", + BluetoothShare.VISIBILITY_VISIBLE, + BluetoothShare.USER_CONFIRMATION_CONFIRMED, + BluetoothShare.STATUS_PENDING, + 1023, + 42, + 123456789, + false); } @Test public void testConstructor() { - assertThat(mBluetoothOppShareInfo.mUri).isEqualTo(uri); - assertThat(mBluetoothOppShareInfo.mFilename).isEqualTo(filename); - assertThat(mBluetoothOppShareInfo.mMimetype).isEqualTo(mimetype); - assertThat(mBluetoothOppShareInfo.mDirection).isEqualTo(direction); - assertThat(mBluetoothOppShareInfo.mDestination).isEqualTo(destination); - assertThat(mBluetoothOppShareInfo.mVisibility).isEqualTo(visibility); - assertThat(mBluetoothOppShareInfo.mConfirm).isEqualTo(confirm); - assertThat(mBluetoothOppShareInfo.mStatus).isEqualTo(status); - assertThat(mBluetoothOppShareInfo.mTotalBytes).isEqualTo(totalBytes); - assertThat(mBluetoothOppShareInfo.mCurrentBytes).isEqualTo(currentBytes); - assertThat(mBluetoothOppShareInfo.mTimestamp).isEqualTo(timestamp); - assertThat(mBluetoothOppShareInfo.mMediaScanned).isEqualTo(mediaScanned); + assertThat(mBluetoothOppShareInfo.mUri) + .isEqualTo(Uri.parse("file://Idontknow//Justmadeitup")); + assertThat(mBluetoothOppShareInfo.mFilename).isEqualTo("random.jpg"); + assertThat(mBluetoothOppShareInfo.mMimetype).isEqualTo("image/jpeg"); + assertThat(mBluetoothOppShareInfo.mDirection).isEqualTo(BluetoothShare.DIRECTION_INBOUND); + assertThat(mBluetoothOppShareInfo.mDestination).isEqualTo("01:23:45:67:89:AB"); + assertThat(mBluetoothOppShareInfo.mVisibility).isEqualTo(BluetoothShare.VISIBILITY_VISIBLE); + assertThat(mBluetoothOppShareInfo.mConfirm) + .isEqualTo(BluetoothShare.USER_CONFIRMATION_CONFIRMED); + assertThat(mBluetoothOppShareInfo.mStatus).isEqualTo(BluetoothShare.STATUS_PENDING); + assertThat(mBluetoothOppShareInfo.mTotalBytes).isEqualTo(1023); + assertThat(mBluetoothOppShareInfo.mCurrentBytes).isEqualTo(42); + assertThat(mBluetoothOppShareInfo.mTimestamp).isEqualTo(123456789); + assertThat(mBluetoothOppShareInfo.mMediaScanned).isEqualTo(false); } @Test diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/FakeContactsProvider.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/FakeContactsProvider.java index b7865caa26..356c26d2d0 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/FakeContactsProvider.java +++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/FakeContactsProvider.java @@ -203,10 +203,10 @@ public class FakeContactsProvider extends MockContentProvider { } private int mNextDataId = 0; - private SparseArray<FakeAccount> mAccounts = new SparseArray<>(); - private SparseArray<FakeRawContact> mRawContacts = new SparseArray<>(); - private SparseArray<FakeData> mData = new SparseArray<>(); - private SparseArray<FakeCallLog> mCallHistory = new SparseArray<>(); + private final SparseArray<FakeAccount> mAccounts = new SparseArray<>(); + private final SparseArray<FakeRawContact> mRawContacts = new SparseArray<>(); + private final SparseArray<FakeData> mData = new SparseArray<>(); + private final SparseArray<FakeCallLog> mCallHistory = new SparseArray<>(); // ********************************************************************************************* // * Get Data (for validation) diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientContactsStorageTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientContactsStorageTest.java index 66070377ed..ea515ec840 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientContactsStorageTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientContactsStorageTest.java @@ -86,7 +86,7 @@ public class PbapClientContactsStorageTest { ArgumentCaptor.forClass(ArrayList.class); @Mock private File mMockDirectory; @Mock private PbapClientAccountManager mMockAccountManager; - private List<Account> mMockedAccounts = new ArrayList<>(); + private final List<Account> mMockedAccounts = new ArrayList<>(); @Mock private PbapClientContactsStorage.Callback mMockStorageCallback; private PbapClientContactsStorage.PbapClientAccountManagerCallback mAccountManagerCallback; diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java index 93c4004647..0f1550d868 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java @@ -97,7 +97,7 @@ public class PbapClientStateMachineTest { ArgumentCaptor<PbapClientContactsStorage.Callback> mCaptor = ArgumentCaptor.forClass(PbapClientContactsStorage.Callback.class); private PbapClientContactsStorage.Callback mStorageCallback; - private List<Account> mMockedAccounts = new ArrayList<>(); + private final List<Account> mMockedAccounts = new ArrayList<>(); @Mock private PbapClientObexClient mMockObexClient; diff --git a/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java b/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java index 8000d9191b..c2b619ee0b 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java @@ -60,7 +60,8 @@ public class TbsGenericTest { @Captor private ArgumentCaptor<String> mGtbsUciCaptor; @Captor - private ArgumentCaptor<List> mDefaultGtbsUriSchemesCaptor = ArgumentCaptor.forClass(List.class); + private final ArgumentCaptor<List> mDefaultGtbsUriSchemesCaptor = + ArgumentCaptor.forClass(List.class); @Captor private ArgumentCaptor<String> mDefaultGtbsProviderNameCaptor; @Captor private ArgumentCaptor<Integer> mDefaultGtbsTechnologyCaptor; diff --git a/framework/java/android/bluetooth/BluetoothActivityEnergyInfo.java b/framework/java/android/bluetooth/BluetoothActivityEnergyInfo.java index 06336e5b31..1dc5c3bf92 100644 --- a/framework/java/android/bluetooth/BluetoothActivityEnergyInfo.java +++ b/framework/java/android/bluetooth/BluetoothActivityEnergyInfo.java @@ -37,11 +37,11 @@ import java.util.List; @SystemApi(client = SystemApi.Client.PRIVILEGED_APPS) public final class BluetoothActivityEnergyInfo implements Parcelable { private final long mTimestamp; - private int mBluetoothStackState; - private long mControllerTxTimeMs; - private long mControllerRxTimeMs; - private long mControllerIdleTimeMs; - private long mControllerEnergyUsed; + private final int mBluetoothStackState; + private final long mControllerTxTimeMs; + private final long mControllerRxTimeMs; + private final long mControllerIdleTimeMs; + private final long mControllerEnergyUsed; private List<UidTraffic> mUidTraffic; /** @hide */ diff --git a/framework/java/android/bluetooth/BluetoothAvrcpPlayerSettings.java b/framework/java/android/bluetooth/BluetoothAvrcpPlayerSettings.java index ef220e5918..0b031dfd66 100644 --- a/framework/java/android/bluetooth/BluetoothAvrcpPlayerSettings.java +++ b/framework/java/android/bluetooth/BluetoothAvrcpPlayerSettings.java @@ -87,10 +87,10 @@ public final class BluetoothAvrcpPlayerSettings implements Parcelable { public static final int STATE_GROUP = 0x04; /** List of supported settings ORed. */ - private int mSettings; + private final int mSettings; /** Hash map of current capability values. */ - private Map<Integer, Integer> mSettingsValue = new HashMap<Integer, Integer>(); + private final Map<Integer, Integer> mSettingsValue = new HashMap<Integer, Integer>(); @Override public int describeContents() { diff --git a/framework/java/android/bluetooth/BluetoothCsipSetCoordinator.java b/framework/java/android/bluetooth/BluetoothCsipSetCoordinator.java index abec916a24..9ec499d002 100644 --- a/framework/java/android/bluetooth/BluetoothCsipSetCoordinator.java +++ b/framework/java/android/bluetooth/BluetoothCsipSetCoordinator.java @@ -67,7 +67,7 @@ public final class BluetoothCsipSetCoordinator implements BluetoothProfile, Auto private static final boolean DBG = false; private static final boolean VDBG = false; - private CloseGuard mCloseGuard; + private final CloseGuard mCloseGuard; /** @hide */ @SystemApi diff --git a/framework/java/android/bluetooth/BluetoothGatt.java b/framework/java/android/bluetooth/BluetoothGatt.java index 1ef8d2add6..7ba4aa2993 100644 --- a/framework/java/android/bluetooth/BluetoothGatt.java +++ b/framework/java/android/bluetooth/BluetoothGatt.java @@ -64,11 +64,11 @@ public final class BluetoothGatt implements BluetoothProfile { private static final boolean DBG = true; private static final boolean VDBG = false; - @UnsupportedAppUsage private IBluetoothGatt mService; + @UnsupportedAppUsage private final IBluetoothGatt mService; @UnsupportedAppUsage private volatile BluetoothGattCallback mCallback; private Handler mHandler; @UnsupportedAppUsage private int mClientIf; - private BluetoothDevice mDevice; + private final BluetoothDevice mDevice; @UnsupportedAppUsage private boolean mAutoConnect; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) @@ -82,10 +82,10 @@ public final class BluetoothGatt implements BluetoothProfile { private Boolean mDeviceBusy = false; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) - private int mTransport; + private final int mTransport; - private int mPhy; - private boolean mOpportunistic; + private final int mPhy; + private final boolean mOpportunistic; private final AttributionSource mAttributionSource; private static final int AUTH_RETRY_STATE_IDLE = 0; @@ -101,7 +101,7 @@ public final class BluetoothGatt implements BluetoothProfile { // Max length of an attribute value, defined in gatt_api.h private static final int GATT_MAX_ATTR_LEN = 512; - private CopyOnWriteArrayList<BluetoothGattService> mServices; + private final CopyOnWriteArrayList<BluetoothGattService> mServices; /** A GATT operation completed successfully */ public static final int GATT_SUCCESS = 0; diff --git a/framework/java/android/bluetooth/BluetoothGattServer.java b/framework/java/android/bluetooth/BluetoothGattServer.java index 3a86c1d7b3..4c180a30fb 100644 --- a/framework/java/android/bluetooth/BluetoothGattServer.java +++ b/framework/java/android/bluetooth/BluetoothGattServer.java @@ -62,9 +62,9 @@ public final class BluetoothGattServer implements BluetoothProfile { private final Object mServerIfLock = new Object(); private int mServerIf; - private int mTransport; + private final int mTransport; private BluetoothGattService mPendingService; - private List<BluetoothGattService> mServices; + private final List<BluetoothGattService> mServices; private static final int CALLBACK_REG_TIMEOUT = 10000; // Max length of an attribute value, defined in gatt_api.h diff --git a/framework/java/android/bluetooth/BluetoothHapClient.java b/framework/java/android/bluetooth/BluetoothHapClient.java index e551cca8f5..bcbf278260 100644 --- a/framework/java/android/bluetooth/BluetoothHapClient.java +++ b/framework/java/android/bluetooth/BluetoothHapClient.java @@ -63,7 +63,7 @@ import java.util.function.Consumer; public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable { private static final String TAG = BluetoothHapClient.class.getSimpleName(); - private CloseGuard mCloseGuard; + private final CloseGuard mCloseGuard; /** * This class provides callbacks mechanism for the BluetoothHapClient profile. diff --git a/framework/java/android/bluetooth/BluetoothHapPresetInfo.java b/framework/java/android/bluetooth/BluetoothHapPresetInfo.java index cdc69d171b..0744257be0 100644 --- a/framework/java/android/bluetooth/BluetoothHapPresetInfo.java +++ b/framework/java/android/bluetooth/BluetoothHapPresetInfo.java @@ -30,10 +30,10 @@ import android.text.TextUtils; */ @SystemApi public final class BluetoothHapPresetInfo implements Parcelable { - private int mPresetIndex; - private String mPresetName = ""; - private boolean mIsWritable; - private boolean mIsAvailable; + private final int mPresetIndex; + private final String mPresetName; + private final boolean mIsWritable; + private final boolean mIsAvailable; /** * HapPresetInfo constructor diff --git a/framework/java/android/bluetooth/BluetoothInputStream.java b/framework/java/android/bluetooth/BluetoothInputStream.java index 98c3491477..657f6944f3 100644 --- a/framework/java/android/bluetooth/BluetoothInputStream.java +++ b/framework/java/android/bluetooth/BluetoothInputStream.java @@ -30,7 +30,7 @@ import java.io.InputStream; */ @SuppressLint("AndroidFrameworkBluetoothPermission") /*package*/ final class BluetoothInputStream extends InputStream { - private BluetoothSocket mSocket; + private final BluetoothSocket mSocket; /*package*/ BluetoothInputStream(BluetoothSocket s) { mSocket = s; diff --git a/framework/java/android/bluetooth/BluetoothLeAudio.java b/framework/java/android/bluetooth/BluetoothLeAudio.java index 4cc3b604fb..d42670fe9c 100644 --- a/framework/java/android/bluetooth/BluetoothLeAudio.java +++ b/framework/java/android/bluetooth/BluetoothLeAudio.java @@ -74,7 +74,7 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable { private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); private static final boolean VDBG = false; - private CloseGuard mCloseGuard; + private final CloseGuard mCloseGuard; /** * This class provides a callback that is invoked when audio codec config changes on the remote diff --git a/framework/java/android/bluetooth/BluetoothLeBroadcast.java b/framework/java/android/bluetooth/BluetoothLeBroadcast.java index 4023184fee..85c895fa54 100644 --- a/framework/java/android/bluetooth/BluetoothLeBroadcast.java +++ b/framework/java/android/bluetooth/BluetoothLeBroadcast.java @@ -61,7 +61,7 @@ public final class BluetoothLeBroadcast implements AutoCloseable, BluetoothProfi private static final boolean DBG = true; private static final boolean VDBG = false; - private CloseGuard mCloseGuard; + private final CloseGuard mCloseGuard; private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; diff --git a/framework/java/android/bluetooth/BluetoothLeBroadcastAssistant.java b/framework/java/android/bluetooth/BluetoothLeBroadcastAssistant.java index 63ddb8a03a..d72fc1a50f 100644 --- a/framework/java/android/bluetooth/BluetoothLeBroadcastAssistant.java +++ b/framework/java/android/bluetooth/BluetoothLeBroadcastAssistant.java @@ -495,7 +495,7 @@ public final class BluetoothLeBroadcastAssistant implements BluetoothProfile, Au public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.action.CONNECTION_STATE_CHANGED"; - private CloseGuard mCloseGuard; + private final CloseGuard mCloseGuard; private final BluetoothAdapter mBluetoothAdapter; private final AttributionSource mAttributionSource; diff --git a/framework/java/android/bluetooth/BluetoothLeBroadcastMetadata.java b/framework/java/android/bluetooth/BluetoothLeBroadcastMetadata.java index ea77d2684c..562e0b7835 100644 --- a/framework/java/android/bluetooth/BluetoothLeBroadcastMetadata.java +++ b/framework/java/android/bluetooth/BluetoothLeBroadcastMetadata.java @@ -518,7 +518,7 @@ public final class BluetoothLeBroadcastMetadata implements Parcelable { private @AudioConfigQuality int mAudioConfigQuality = AUDIO_CONFIG_QUALITY_NONE; private int mRssi = RSSI_UNKNOWN; private BluetoothLeAudioContentMetadata mPublicBroadcastMetadata = null; - private List<BluetoothLeBroadcastSubgroup> mSubgroups = new ArrayList<>(); + private final List<BluetoothLeBroadcastSubgroup> mSubgroups = new ArrayList<>(); /** * Create an empty builder. diff --git a/framework/java/android/bluetooth/BluetoothLeBroadcastSubgroup.java b/framework/java/android/bluetooth/BluetoothLeBroadcastSubgroup.java index 86580d5fe5..5d150ed78c 100644 --- a/framework/java/android/bluetooth/BluetoothLeBroadcastSubgroup.java +++ b/framework/java/android/bluetooth/BluetoothLeBroadcastSubgroup.java @@ -210,7 +210,7 @@ public final class BluetoothLeBroadcastSubgroup implements Parcelable { private long mCodecId = UNKNOWN_VALUE_PLACEHOLDER; private BluetoothLeAudioCodecConfigMetadata mCodecSpecificConfig = null; private BluetoothLeAudioContentMetadata mContentMetadata = null; - private List<BluetoothLeBroadcastChannel> mChannels = new ArrayList<>(); + private final List<BluetoothLeBroadcastChannel> mChannels = new ArrayList<>(); /** * Create an empty constructor. diff --git a/framework/java/android/bluetooth/BluetoothLeCall.java b/framework/java/android/bluetooth/BluetoothLeCall.java index 355e31161e..9dc6bb03e3 100644 --- a/framework/java/android/bluetooth/BluetoothLeCall.java +++ b/framework/java/android/bluetooth/BluetoothLeCall.java @@ -124,19 +124,19 @@ public final class BluetoothLeCall implements Parcelable { public static final int FLAG_WITHHELD_BY_NETWORK = 0x00000004; /** Unique UUID that identifies this call */ - private UUID mUuid; + private final UUID mUuid; /** Remote Caller URI */ - private String mUri; + private final String mUri; /** Caller friendly name */ - private String mFriendlyName; + private final String mFriendlyName; /** Call state */ - private @State int mState; + private final @State int mState; /** Call flags */ - private int mCallFlags; + private final int mCallFlags; /** @hide */ public BluetoothLeCall(@NonNull BluetoothLeCall that) { diff --git a/framework/java/android/bluetooth/BluetoothLeCallControl.java b/framework/java/android/bluetooth/BluetoothLeCallControl.java index 8d54d56160..a4c3f347b6 100644 --- a/framework/java/android/bluetooth/BluetoothLeCallControl.java +++ b/framework/java/android/bluetooth/BluetoothLeCallControl.java @@ -343,7 +343,7 @@ public final class BluetoothLeCallControl implements BluetoothProfile { } ; - private BluetoothAdapter mAdapter; + private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; private int mCcid = 0; private String mToken; diff --git a/framework/java/android/bluetooth/BluetoothMap.java b/framework/java/android/bluetooth/BluetoothMap.java index 4c44995921..811856666b 100644 --- a/framework/java/android/bluetooth/BluetoothMap.java +++ b/framework/java/android/bluetooth/BluetoothMap.java @@ -57,7 +57,7 @@ public final class BluetoothMap implements BluetoothProfile, AutoCloseable { private static final boolean DBG = true; private static final boolean VDBG = false; - private CloseGuard mCloseGuard; + private final CloseGuard mCloseGuard; /** @hide */ @SuppressLint("ActionValue") diff --git a/framework/java/android/bluetooth/BluetoothOutputStream.java b/framework/java/android/bluetooth/BluetoothOutputStream.java index 4d579ca00d..5fd6681494 100644 --- a/framework/java/android/bluetooth/BluetoothOutputStream.java +++ b/framework/java/android/bluetooth/BluetoothOutputStream.java @@ -30,7 +30,7 @@ import java.io.OutputStream; */ @SuppressLint("AndroidFrameworkBluetoothPermission") /*package*/ final class BluetoothOutputStream extends OutputStream { - private BluetoothSocket mSocket; + private final BluetoothSocket mSocket; /*package*/ BluetoothOutputStream(BluetoothSocket s) { mSocket = s; diff --git a/framework/java/android/bluetooth/BluetoothPbap.java b/framework/java/android/bluetooth/BluetoothPbap.java index 8da64ddb96..52e6fd7c17 100644 --- a/framework/java/android/bluetooth/BluetoothPbap.java +++ b/framework/java/android/bluetooth/BluetoothPbap.java @@ -110,7 +110,7 @@ public class BluetoothPbap implements BluetoothProfile { */ public static final int RESULT_CANCELED = 2; - private BluetoothAdapter mAdapter; + private final BluetoothAdapter mAdapter; private IBluetoothPbap mService; diff --git a/framework/java/android/bluetooth/BluetoothQualityReport.java b/framework/java/android/bluetooth/BluetoothQualityReport.java index 28b2f998af..5cb2625a4d 100644 --- a/framework/java/android/bluetooth/BluetoothQualityReport.java +++ b/framework/java/android/bluetooth/BluetoothQualityReport.java @@ -146,14 +146,14 @@ public final class BluetoothQualityReport implements Parcelable { }) public @interface QualityReportId {} - private String mAddr; - private int mLmpVer; - private int mLmpSubVer; - private int mManufacturerId; - private String mName; - private BluetoothClass mBluetoothClass; - - private BqrCommon mBqrCommon; + private final String mAddr; + private final int mLmpVer; + private final int mLmpSubVer; + private final int mManufacturerId; + private final String mName; + private final BluetoothClass mBluetoothClass; + + private final BqrCommon mBqrCommon; private BqrVsLsto mBqrVsLsto; private BqrVsA2dpChoppy mBqrVsA2dpChoppy; private BqrVsScoChoppy mBqrVsScoChoppy; @@ -192,7 +192,7 @@ public final class BluetoothQualityReport implements Parcelable { TYPE_3DH3, TYPE_3DH5; - private static PacketType[] sAllValues = values(); + private static final PacketType[] sAllValues = values(); static PacketType fromOrdinal(int n) { if (n < sAllValues.length) { @@ -224,7 +224,7 @@ public final class BluetoothQualityReport implements Parcelable { CONN_SEMI_CONN(0x12); private final int mValue; - private static ConnState[] sAllStates = values(); + private static final ConnState[] sAllStates = values(); ConnState(int val) { mValue = val; @@ -248,7 +248,7 @@ public final class BluetoothQualityReport implements Parcelable { LOW, INVALID; - private static LinkQuality[] sAllValues = values(); + private static final LinkQuality[] sAllValues = values(); static LinkQuality fromOrdinal(int n) { if (n < sAllValues.length - 1) { @@ -265,7 +265,7 @@ public final class BluetoothQualityReport implements Parcelable { transparent_msbc, INVALID; - private static AirMode[] sAllValues = values(); + private static final AirMode[] sAllValues = values(); static AirMode fromOrdinal(int n) { if (n < sAllValues.length - 1) { @@ -603,7 +603,7 @@ public final class BluetoothQualityReport implements Parcelable { private int manufacturerId; private String remoteName = ""; private BluetoothClass bluetoothClass = new BluetoothClass(0); - private byte[] rawData; + private final byte[] rawData; /** * Creates a new instance of {@link Builder}. @@ -746,7 +746,7 @@ public final class BluetoothQualityReport implements Parcelable { static final int BQR_COMMON_LEN = 85; - private @QualityReportId int mQualityReportId; + private final @QualityReportId int mQualityReportId; private int mPacketType; private int mConnectionHandle; private int mConnectionRole; @@ -1416,14 +1416,14 @@ public final class BluetoothQualityReport implements Parcelable { private static final String TAG = BluetoothQualityReport.TAG + "." + BqrVsLsto.class.getSimpleName(); - private int mConnState; - private long mBasebandStats; - private long mSlotsUsed; - private int mCxmDenials; - private int mTxSkipped; - private int mRfLoss; - private long mNativeClock; - private long mLastTxAckTimestamp; + private final int mConnState; + private final long mBasebandStats; + private final long mSlotsUsed; + private final int mCxmDenials; + private final int mTxSkipped; + private final int mRfLoss; + private final long mNativeClock; + private final long mLastTxAckTimestamp; private BqrVsLsto(byte[] rawData, int offset) { if (rawData == null || rawData.length <= offset) { @@ -1633,13 +1633,13 @@ public final class BluetoothQualityReport implements Parcelable { private static final String TAG = BluetoothQualityReport.TAG + "." + BqrVsA2dpChoppy.class.getSimpleName(); - private long mArrivalTime; - private long mScheduleTime; - private int mGlitchCount; - private int mTxCxmDenials; - private int mRxCxmDenials; - private int mAclTxQueueLength; - private int mLinkQuality; + private final long mArrivalTime; + private final long mScheduleTime; + private final int mGlitchCount; + private final int mTxCxmDenials; + private final int mRxCxmDenials; + private final int mAclTxQueueLength; + private final int mLinkQuality; private BqrVsA2dpChoppy(byte[] rawData, int offset) { if (rawData == null || rawData.length <= offset) { @@ -1834,24 +1834,24 @@ public final class BluetoothQualityReport implements Parcelable { private static final String TAG = BluetoothQualityReport.TAG + "." + BqrVsScoChoppy.class.getSimpleName(); - private int mGlitchCount; - private int mIntervalEsco; - private int mWindowEsco; - private int mAirFormat; - private int mInstanceCount; - private int mTxCxmDenials; - private int mRxCxmDenials; - private int mTxAbortCount; - private int mLateDispatch; - private int mMicIntrMiss; - private int mLpaIntrMiss; - private int mSprIntrMiss; - private int mPlcFillCount; - private int mPlcDiscardCount; - private int mMissedInstanceCount; - private int mTxRetransmitSlotCount; - private int mRxRetransmitSlotCount; - private int mGoodRxFrameCount; + private final int mGlitchCount; + private final int mIntervalEsco; + private final int mWindowEsco; + private final int mAirFormat; + private final int mInstanceCount; + private final int mTxCxmDenials; + private final int mRxCxmDenials; + private final int mTxAbortCount; + private final int mLateDispatch; + private final int mMicIntrMiss; + private final int mLpaIntrMiss; + private final int mSprIntrMiss; + private final int mPlcFillCount; + private final int mPlcDiscardCount; + private final int mMissedInstanceCount; + private final int mTxRetransmitSlotCount; + private final int mRxRetransmitSlotCount; + private final int mGoodRxFrameCount; private BqrVsScoChoppy(byte[] rawData, int offset) { if (rawData == null || rawData.length <= offset) { @@ -2275,7 +2275,7 @@ public final class BluetoothQualityReport implements Parcelable { }) public @interface ConnectFailId {} - private int mFailReason; + private final int mFailReason; private BqrConnectFail(byte[] rawData, int offset) { if (rawData == null || rawData.length <= offset) { @@ -2391,28 +2391,28 @@ public final class BluetoothQualityReport implements Parcelable { private static final String TAG = BluetoothQualityReport.TAG + "." + BqrEnergyMonitor.class.getSimpleName(); - private int mAvgCurrentConsume; - private long mIdleTotalTime; - private long mIdleStateEnterCount; - private long mActiveTotalTime; - private long mActiveStateEnterCount; - private long mBredrTxTotalTime; - private long mBredrTxStateEnterCount; - private int mBredrTxAvgPowerLevel; - private long mBredrRxTotalTime; - private long mBredrRxStateEnterCount; - private long mLeTxTotalTime; - private long mLeTxStateEnterCount; - private int mLeTxAvgPowerLevel; - private long mLeRxTotalTime; - private long mLeRxStateEnterCount; - private long mReportTotalTime; - private long mRxActiveOneChainTime; - private long mRxActiveTwoChainTime; - private long mTxiPaActiveOneChainTime; - private long mTxiPaActiveTwoChainTime; - private long mTxePaActiveOneChainTime; - private long mTxePaActiveTwoChainTime; + private final int mAvgCurrentConsume; + private final long mIdleTotalTime; + private final long mIdleStateEnterCount; + private final long mActiveTotalTime; + private final long mActiveStateEnterCount; + private final long mBredrTxTotalTime; + private final long mBredrTxStateEnterCount; + private final int mBredrTxAvgPowerLevel; + private final long mBredrRxTotalTime; + private final long mBredrRxStateEnterCount; + private final long mLeTxTotalTime; + private final long mLeTxStateEnterCount; + private final int mLeTxAvgPowerLevel; + private final long mLeRxTotalTime; + private final long mLeRxStateEnterCount; + private final long mReportTotalTime; + private final long mRxActiveOneChainTime; + private final long mRxActiveTwoChainTime; + private final long mTxiPaActiveOneChainTime; + private final long mTxiPaActiveTwoChainTime; + private final long mTxePaActiveOneChainTime; + private final long mTxePaActiveTwoChainTime; private BqrEnergyMonitor(byte[] rawData, int offset) { if (rawData == null || rawData.length <= offset) { @@ -2861,27 +2861,27 @@ public final class BluetoothQualityReport implements Parcelable { private static final String TAG = BluetoothQualityReport.TAG + "." + BqrRfStats.class.getSimpleName(); - private int mExtensionInfo; - private long mReportTimePeriod; - private long mTxPoweriPaBf; - private long mTxPowerePaBf; - private long mTxPoweriPaDiv; - private long mTxPowerePaDiv; - private long mRssiChainOver50; - private long mRssiChain50To55; - private long mRssiChain55To60; - private long mRssiChain60To65; - private long mRssiChain65To70; - private long mRssiChain70To75; - private long mRssiChain75To80; - private long mRssiChain80To85; - private long mRssiChain85To90; - private long mRssiChainUnder90; - private long mRssiDeltaUnder2; - private long mRssiDelta2To5; - private long mRssiDelta5To8; - private long mRssiDelta8To11; - private long mRssiDeltaOver11; + private final int mExtensionInfo; + private final long mReportTimePeriod; + private final long mTxPoweriPaBf; + private final long mTxPowerePaBf; + private final long mTxPoweriPaDiv; + private final long mTxPowerePaDiv; + private final long mRssiChainOver50; + private final long mRssiChain50To55; + private final long mRssiChain55To60; + private final long mRssiChain60To65; + private final long mRssiChain65To70; + private final long mRssiChain70To75; + private final long mRssiChain75To80; + private final long mRssiChain80To85; + private final long mRssiChain85To90; + private final long mRssiChainUnder90; + private final long mRssiDeltaUnder2; + private final long mRssiDelta2To5; + private final long mRssiDelta5To8; + private final long mRssiDelta8To11; + private final long mRssiDeltaOver11; private BqrRfStats(byte[] rawData, int offset) { if (rawData == null || rawData.length <= offset) { diff --git a/framework/java/android/bluetooth/BluetoothSap.java b/framework/java/android/bluetooth/BluetoothSap.java index 5ec412cb39..5894c4f197 100644 --- a/framework/java/android/bluetooth/BluetoothSap.java +++ b/framework/java/android/bluetooth/BluetoothSap.java @@ -65,7 +65,7 @@ public final class BluetoothSap implements BluetoothProfile, AutoCloseable { private static final boolean DBG = true; private static final boolean VDBG = false; - private CloseGuard mCloseGuard; + private final CloseGuard mCloseGuard; /** * Intent used to broadcast the change in connection state of the profile. diff --git a/framework/java/android/bluetooth/BluetoothServerSocket.java b/framework/java/android/bluetooth/BluetoothServerSocket.java index e25805437a..832e48aa3b 100644 --- a/framework/java/android/bluetooth/BluetoothServerSocket.java +++ b/framework/java/android/bluetooth/BluetoothServerSocket.java @@ -85,7 +85,7 @@ public final class BluetoothServerSocket implements Closeable { // BluetoothSocket.getConnectionType() will hide L2CAP_LE. // Therefore a new variable need to be maintained here. - private int mType; + private final int mType; /** * Construct a socket for incoming connections. diff --git a/framework/java/android/bluetooth/BluetoothSocketSettings.java b/framework/java/android/bluetooth/BluetoothSocketSettings.java index b7706d50fe..3f222d4717 100644 --- a/framework/java/android/bluetooth/BluetoothSocketSettings.java +++ b/framework/java/android/bluetooth/BluetoothSocketSettings.java @@ -108,22 +108,22 @@ public final class BluetoothSocketSettings { private static final long INVALID_ENDPOINT_ID = 0; /** Type of the Bluetooth socket */ - @SocketType private int mSocketType; + @SocketType private final int mSocketType; /** Encryption requirement for the Bluetooth socket. */ - private boolean mEncryptionRequired; + private final boolean mEncryptionRequired; /** Authentication requirement for the Bluetooth socket. */ - private boolean mAuthenticationRequired; + private final boolean mAuthenticationRequired; /** L2CAP Protocol/Service Multiplexer (PSM) for the Bluetooth Socket. */ - private int mL2capPsm; + private final int mL2capPsm; /** RFCOMM service name associated with the Bluetooth socket. */ - private String mRfcommServiceName; + private final String mRfcommServiceName; /** RFCOMM service UUID associated with the Bluetooth socket. */ - private UUID mRfcommUuid; + private final UUID mRfcommUuid; /** * Specifies the data path used for this socket, influencing how data is transmitted and @@ -137,7 +137,7 @@ public final class BluetoothSocketSettings { * an offloaded application running on a dedicated low-power processor. * </ul> */ - @SocketDataPath private int mDataPath; + private final @SocketDataPath int mDataPath; /** * A user-friendly name for this socket, primarily for debugging and logging. This name should @@ -147,7 +147,7 @@ public final class BluetoothSocketSettings { * application running on the low-power processor. This allows the offloaded application to * identify and manage the socket. */ - private String mSocketName; + private final String mSocketName; /** * When using {@link #DATA_PATH_HARDWARE_OFFLOAD}, this identifies the hub hosting the endpoint. @@ -155,19 +155,19 @@ public final class BluetoothSocketSettings { * <p>Hub represents a logical/physical representation of multiple endpoints. A pair of {@code * mHubId} and {@code mEndpointId} uniquely identifies the endpoint globally. */ - private long mHubId; + private final long mHubId; /** * When using {@link #DATA_PATH_HARDWARE_OFFLOAD}, this identifies the specific endpoint within * the hub that is associated with this socket. */ - private long mEndpointId; + private final long mEndpointId; /** * The maximum size (in bytes) of a single data packet that can be received from the endpoint * when using {@link #DATA_PATH_HARDWARE_OFFLOAD}. */ - private int mMaximumPacketSize; + private final int mMaximumPacketSize; /** * Returns the type of the Bluetooth socket. diff --git a/framework/java/android/bluetooth/BluetoothVolumeControl.java b/framework/java/android/bluetooth/BluetoothVolumeControl.java index 1cf3cedeba..e8c8446e69 100644 --- a/framework/java/android/bluetooth/BluetoothVolumeControl.java +++ b/framework/java/android/bluetooth/BluetoothVolumeControl.java @@ -69,7 +69,7 @@ import java.util.function.Consumer; public final class BluetoothVolumeControl implements BluetoothProfile, AutoCloseable { private static final String TAG = BluetoothVolumeControl.class.getSimpleName(); - private CloseGuard mCloseGuard; + private final CloseGuard mCloseGuard; @GuardedBy("mCallbackExecutorMap") private final Map<Callback, Executor> mCallbackExecutorMap = new HashMap<>(); @@ -246,7 +246,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.volume-control.profile.action.CONNECTION_STATE_CHANGED"; - private BluetoothAdapter mAdapter; + private final BluetoothAdapter mAdapter; private final AttributionSource mAttributionSource; private IBluetoothVolumeControl mService; diff --git a/framework/java/android/bluetooth/BufferConstraint.java b/framework/java/android/bluetooth/BufferConstraint.java index 936b17dd6c..bd4eb739ae 100644 --- a/framework/java/android/bluetooth/BufferConstraint.java +++ b/framework/java/android/bluetooth/BufferConstraint.java @@ -30,9 +30,9 @@ import android.os.Parcelable; public final class BufferConstraint implements Parcelable { private static final String TAG = BufferConstraint.class.getSimpleName(); - private int mDefaultMillis; - private int mMaxMillis; - private int mMinMillis; + private final int mDefaultMillis; + private final int mMaxMillis; + private final int mMinMillis; public BufferConstraint(int defaultMillis, int maxMillis, int minMillis) { mDefaultMillis = defaultMillis; diff --git a/framework/java/android/bluetooth/BufferConstraints.java b/framework/java/android/bluetooth/BufferConstraints.java index c8a1157849..152976a0e3 100644 --- a/framework/java/android/bluetooth/BufferConstraints.java +++ b/framework/java/android/bluetooth/BufferConstraints.java @@ -38,8 +38,8 @@ public final class BufferConstraints implements Parcelable { public static final int BUFFER_CODEC_MAX_NUM = 32; - private Map<Integer, BufferConstraint> mBufferConstraints; - private List<BufferConstraint> mBufferConstraintList; + private final Map<Integer, BufferConstraint> mBufferConstraints; + private final List<BufferConstraint> mBufferConstraintList; public BufferConstraints(@NonNull List<BufferConstraint> bufferConstraintList) { diff --git a/framework/java/android/bluetooth/OobData.java b/framework/java/android/bluetooth/OobData.java index 48b107c7c0..94cdcdeb9f 100644 --- a/framework/java/android/bluetooth/OobData.java +++ b/framework/java/android/bluetooth/OobData.java @@ -231,7 +231,7 @@ public final class OobData implements Parcelable { * * <p>Used for visual on discovering device to represent icon/string/etc... */ - private byte[] mLeAppearance = null; + private final byte[] mLeAppearance = null; /** * Contains which discoverable mode to use, BR/EDR support and capability. diff --git a/framework/java/android/bluetooth/le/AdvertiseData.java b/framework/java/android/bluetooth/le/AdvertiseData.java index 99335d35d7..6c313d8a71 100644 --- a/framework/java/android/bluetooth/le/AdvertiseData.java +++ b/framework/java/android/bluetooth/le/AdvertiseData.java @@ -247,15 +247,14 @@ public final class AdvertiseData implements Parcelable { /** Builder for {@link AdvertiseData}. */ public static final class Builder { - @Nullable private List<ParcelUuid> mServiceUuids = new ArrayList<ParcelUuid>(); - @NonNull private List<ParcelUuid> mServiceSolicitationUuids = new ArrayList<ParcelUuid>(); + private final List<ParcelUuid> mServiceUuids = new ArrayList<ParcelUuid>(); + private final List<ParcelUuid> mServiceSolicitationUuids = new ArrayList<ParcelUuid>(); - @Nullable - private List<TransportDiscoveryData> mTransportDiscoveryData = + private final List<TransportDiscoveryData> mTransportDiscoveryData = new ArrayList<TransportDiscoveryData>(); - private SparseArray<byte[]> mManufacturerSpecificData = new SparseArray<byte[]>(); - private Map<ParcelUuid, byte[]> mServiceData = new ArrayMap<ParcelUuid, byte[]>(); + private final SparseArray<byte[]> mManufacturerSpecificData = new SparseArray<byte[]>(); + private final Map<ParcelUuid, byte[]> mServiceData = new ArrayMap<ParcelUuid, byte[]>(); private boolean mIncludeTxPowerLevel; private boolean mIncludeDeviceName; diff --git a/framework/java/android/bluetooth/le/AdvertisingSet.java b/framework/java/android/bluetooth/le/AdvertisingSet.java index 2c2fce52e3..dcb5c29740 100644 --- a/framework/java/android/bluetooth/le/AdvertisingSet.java +++ b/framework/java/android/bluetooth/le/AdvertisingSet.java @@ -45,7 +45,7 @@ public final class AdvertisingSet { private final IBluetoothAdvertise mAdvertise; private int mAdvertiserId; - private AttributionSource mAttributionSource; + private final AttributionSource mAttributionSource; AdvertisingSet( IBluetoothAdvertise advertise, diff --git a/framework/java/android/bluetooth/le/ChannelSoundingParams.java b/framework/java/android/bluetooth/le/ChannelSoundingParams.java index b6c9529562..cbaa01d0fb 100644 --- a/framework/java/android/bluetooth/le/ChannelSoundingParams.java +++ b/framework/java/android/bluetooth/le/ChannelSoundingParams.java @@ -146,9 +146,9 @@ public final class ChannelSoundingParams implements Parcelable { */ @SystemApi public static final int CS_SECURITY_LEVEL_FOUR = 4; - private int mSightType; - private int mLocationType; - private int mCsSecurityLevel; + private final int mSightType; + private final int mLocationType; + private final int mCsSecurityLevel; /** @hide */ public ChannelSoundingParams(int sightType, int locationType, int csSecurityLevel) { diff --git a/framework/java/android/bluetooth/le/DistanceMeasurementMethod.java b/framework/java/android/bluetooth/le/DistanceMeasurementMethod.java index eb4032057d..0d9f187889 100644 --- a/framework/java/android/bluetooth/le/DistanceMeasurementMethod.java +++ b/framework/java/android/bluetooth/le/DistanceMeasurementMethod.java @@ -207,7 +207,7 @@ public final class DistanceMeasurementMethod implements Parcelable { */ @SystemApi public static final class Builder { - private int mId; + private final int mId; private boolean mIsAzimuthAngleSupported = false; private boolean mIsAltitudeAngleSupported = false; diff --git a/framework/java/android/bluetooth/le/ScanSettings.java b/framework/java/android/bluetooth/le/ScanSettings.java index e78f46c8d4..9d7f7f2b73 100644 --- a/framework/java/android/bluetooth/le/ScanSettings.java +++ b/framework/java/android/bluetooth/le/ScanSettings.java @@ -177,25 +177,25 @@ public final class ScanSettings implements Parcelable { static final long CHANGE_DEFAULT_TRACKABLE_ADV_NUMBER = 386727721L; // Bluetooth LE scan mode. - private int mScanMode; + private final int mScanMode; // Bluetooth LE scan callback type. - private int mCallbackType; + private final int mCallbackType; // Bluetooth LE scan result type. - private int mScanResultType; + private final int mScanResultType; // Time of delay for reporting the scan result. - private long mReportDelayMillis; + private final long mReportDelayMillis; - private int mMatchMode; + private final int mMatchMode; - private int mNumOfMatchesPerFilter; + private final int mNumOfMatchesPerFilter; // Include only legacy advertising results. - private boolean mLegacy; + private final boolean mLegacy; - private int mPhy; + private final int mPhy; public int getScanMode() { return mScanMode; diff --git a/service/src/com/android/server/bluetooth/BluetoothManagerService.java b/service/src/com/android/server/bluetooth/BluetoothManagerService.java index 6cd63181da..fe63ff1c21 100644 --- a/service/src/com/android/server/bluetooth/BluetoothManagerService.java +++ b/service/src/com/android/server/bluetooth/BluetoothManagerService.java @@ -827,7 +827,7 @@ class BluetoothManagerService { } class ClientDeathRecipient implements IBinder.DeathRecipient { - private String mPackageName; + private final String mPackageName; ClientDeathRecipient(String packageName) { mPackageName = packageName; @@ -1356,7 +1356,7 @@ class BluetoothManagerService { } } - private BluetoothServiceConnection mConnection = new BluetoothServiceConnection(); + private final BluetoothServiceConnection mConnection = new BluetoothServiceConnection(); private int mWaitForEnableRetry; private int mWaitForDisableRetry; diff --git a/service/tests/src/com/android/server/bluetooth/BluetoothServiceBinderTest.java b/service/tests/src/com/android/server/bluetooth/BluetoothServiceBinderTest.java index 07466e59c4..ec4abca34f 100644 --- a/service/tests/src/com/android/server/bluetooth/BluetoothServiceBinderTest.java +++ b/service/tests/src/com/android/server/bluetooth/BluetoothServiceBinderTest.java @@ -96,7 +96,7 @@ public class BluetoothServiceBinderTest { @Mock private AppOpsManager mAppOpsManager; @Mock private DevicePolicyManager mDevicePolicyManager; - private Context mContext = + private final Context mContext = spy( new ContextWrapper( InstrumentationRegistry.getInstrumentation().getTargetContext())); |