<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nikheel Vishwas Savant</title>
    <description>The latest articles on DEV Community by Nikheel Vishwas Savant (@nikheelvs).</description>
    <link>https://dev.to/nikheelvs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3164841%2F3bde6299-845c-46f2-bb4f-3d92b4c30976.jpeg</url>
      <title>DEV Community: Nikheel Vishwas Savant</title>
      <link>https://dev.to/nikheelvs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nikheelvs"/>
    <language>en</language>
    <item>
      <title>What’s New in Bluetooth? The 2025 Tech Developers Should Know</title>
      <dc:creator>Nikheel Vishwas Savant</dc:creator>
      <pubDate>Thu, 29 May 2025 05:08:50 +0000</pubDate>
      <link>https://dev.to/nikheelvs/whats-new-in-bluetooth-the-2025-tech-developers-should-know-1h40</link>
      <guid>https://dev.to/nikheelvs/whats-new-in-bluetooth-the-2025-tech-developers-should-know-1h40</guid>
      <description>&lt;p&gt;Bluetooth has undergone significant evolution over the past few years. As of 2025, it is a foundational technology for wearables, smart homes, medical devices, industrial systems, and edge AI applications.&lt;/p&gt;

&lt;p&gt;This article outlines the most impactful developments in Bluetooth technology that every developer working on connected systems should be aware of.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Bluetooth LE Audio and Auracast Broadcast Audio
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu31kkw7az2edd0rvm33k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu31kkw7az2edd0rvm33k.png" alt=" " width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LE Audio, standardized around the LC3 codec, brings high-quality audio at lower power and supports multi-stream audio—ideal for truly wireless earbuds.&lt;/p&gt;

&lt;p&gt;Auracast Broadcast Audio builds on this to enable one-to-many audio sharing. Key use cases include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public address systems in transportation hubs&lt;/li&gt;
&lt;li&gt;Multi-user audio in fitness classes, museums, or schools&lt;/li&gt;
&lt;li&gt;Shared listening experiences for entertainment and accessibility&lt;/li&gt;
&lt;li&gt;For developers building audio apps or products, LE Audio and Auracast are critical technologies to start adopting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Technical Note: LC3 supports bitrates from 160 kbps down to 32 kbps, balancing fidelity and energy consumption.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. High-Precision Location with Bluetooth Direction Finding
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxg4g7t84tdtlkrrd4xj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxg4g7t84tdtlkrrd4xj.png" alt=" " width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recent enhancements in Bluetooth Direction Finding introduce sub-meter accuracy through Angle of Arrival (AoA) and Channel Sounding techniques.&lt;/p&gt;

&lt;p&gt;Use cases include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Indoor navigation&lt;/li&gt;
&lt;li&gt;Warehouse inventory tracking&lt;/li&gt;
&lt;li&gt;Asset location in manufacturing plants&lt;/li&gt;
&lt;li&gt;Spatial audio alignment in AR/VR&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Open SDKs from vendors like u-blox and Nordic make prototyping easier for location-aware applications.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Periodic Advertising with Responses (PAwR)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F92bbwv7txv93s9jidgik.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F92bbwv7txv93s9jidgik.png" alt=" " width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Introduced in Bluetooth 5.4, PAwR enables one-to-many communication with time-synchronized, energy-efficient updates. This is ideal for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Electronic Shelf Labels (ESLs)&lt;/li&gt;
&lt;li&gt;Large-scale sensor networks&lt;/li&gt;
&lt;li&gt;Any scenario with thousands of devices that need brief, periodic interactions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Developers building large BLE networks should explore PAwR and its Encrypted Advertising Data feature for broadcast provisioning.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Bluetooth Mesh Enhancements
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ep012l1dwgmx3hxunb5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ep012l1dwgmx3hxunb5.png" alt=" " width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bluetooth Mesh has matured into a robust option for scalable, interoperable, and vendor-neutral deployments.&lt;/p&gt;

&lt;p&gt;Improvements include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Friend-Low Power Node (LPN) performance tuning&lt;/li&gt;
&lt;li&gt;Time-synchronized scene transitions&lt;/li&gt;
&lt;li&gt;Multi-subnet coexistence and bridging&lt;/li&gt;
&lt;li&gt;Reduced relay overhead with managed flooding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Mesh is ideal for smart buildings, lighting systems, and industrial control where reliability and scale are key.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Enhanced Security and OOB Pairing
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fswsn0g0ti6gxtprxaesp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fswsn0g0ti6gxtprxaesp.png" alt=" " width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Security has become a central priority:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mandatory use of LE Secure Connections in sensitive environments&lt;/li&gt;
&lt;li&gt;Out-of-Band (OOB) pairing via NFC or QR codes for headless or secure devices&lt;/li&gt;
&lt;li&gt;Experimental use of post-quantum encryption for long-life medical and industrial devices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;For developers: always choose authenticated pairing methods and use ECDH-based key exchange wherever possible.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. BLE for AI and Edge Devices
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flp7yct379bqamenbzplr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flp7yct379bqamenbzplr.png" alt=" " width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bluetooth is now integrated deeply into AI-based systems. Example applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Smart glasses using BLE to transmit gaze and sensor data to a phone or edge model&lt;/li&gt;
&lt;li&gt;BLE-connected medical sensors for real-time vital classification&lt;/li&gt;
&lt;li&gt;Fitness wearables streaming multi-sensor data to local ML models&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Bluetooth 5.3 and beyond enables consistent throughput and low latency while staying power-efficient, making it a great fit for on-device inference.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Dual-Mode and Multiprotocol SoCs
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiz7qyuf4b6k0z74ig733.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiz7qyuf4b6k0z74ig733.png" alt=" " width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Modern Bluetooth SoCs support multiple radios on a single die:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BLE + Zigbee/Thread (used in Matter)&lt;/li&gt;
&lt;li&gt;BLE + Wi-Fi (for audio and high-bandwidth data)&lt;/li&gt;
&lt;li&gt;BLE + Sub-GHz (for long-range sensor fusion)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Developers building smart hubs, gateways, or wearables should consider these hybrid SoCs to reduce board complexity and improve protocol coordination.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Developer Tools and Testability
&lt;/h2&gt;

&lt;p&gt;Bluetooth developer tools have improved substantially:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android and iOS BLE stacks now support full trace and decode for LE Audio and Direction Finding&lt;/li&gt;
&lt;li&gt;AI-based parsers for HCI logs accelerate debugging and regression analysis&lt;/li&gt;
&lt;li&gt;Tools like Ellisys, Teledyne LeCroy, and Nordic’s nRF Connect now support PAwR and Auracast&lt;/li&gt;
&lt;li&gt;Open-source analyzers like Wireshark + extcap, btmon, and BtleJack continue to mature&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Simulation tools such as BlueSim allow virtual validation of BLE firmware against production HCI traces.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Next?
&lt;/h2&gt;

&lt;p&gt;Looking ahead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bluetooth 6.0 is expected to focus on deterministic latency and time-sensitive applications&lt;/li&gt;
&lt;li&gt;BLE-based IPv6 mesh networks may become viable again with 6LoWPAN enhancements&lt;/li&gt;
&lt;li&gt;Dynamic channel selection and AI-based frequency agility are in early experimentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;The future of Bluetooth is more than wireless communication—it is programmable, secure, and foundational for real-time, intelligent systems.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bluetooth SIG, “LE Audio Overview.” &lt;a href="https://www.bluetooth.com/learn-about-bluetooth/recent-enhancements/le-audio/" rel="noopener noreferrer"&gt;https://www.bluetooth.com/learn-about-bluetooth/recent-enhancements/le-audio/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Bluetooth SIG, “Auracast Broadcast Audio.” &lt;a href="https://www.bluetooth.com/blog/introducing-auracast-broadcast-audio/" rel="noopener noreferrer"&gt;https://www.bluetooth.com/blog/introducing-auracast-broadcast-audio/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Nordic Semiconductor, “nRF Connect SDK.” &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/" rel="noopener noreferrer"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;u-blox, “Bluetooth AoA/AoD Solutions.” &lt;a href="https://www.u-blox.com" rel="noopener noreferrer"&gt;https://www.u-blox.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Bluetooth SIG, “Core Specification 5.4 Summary.” &lt;a href="https://www.bluetooth.com/specifications/specs/" rel="noopener noreferrer"&gt;https://www.bluetooth.com/specifications/specs/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Silicon Labs, “Multiprotocol SoC Architecture.” &lt;a href="https://www.silabs.com" rel="noopener noreferrer"&gt;https://www.silabs.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>bluetooth</category>
      <category>iot</category>
      <category>wireless</category>
      <category>ai</category>
    </item>
    <item>
      <title>🛠️ Debugging AOSP System Software Memory Leaks Using LeakCanary</title>
      <dc:creator>Nikheel Vishwas Savant</dc:creator>
      <pubDate>Fri, 16 May 2025 02:19:31 +0000</pubDate>
      <link>https://dev.to/nikheelvs/debugging-aosp-system-software-memory-leaks-using-leakcanary-5gph</link>
      <guid>https://dev.to/nikheelvs/debugging-aosp-system-software-memory-leaks-using-leakcanary-5gph</guid>
      <description>&lt;p&gt;Memory leaks in AOSP system software—whether in privileged apps like Bluetooth or services like SystemUI—can silently degrade device performance and eventually trigger OOM crashes or ANRs. Traditional debugging tools struggle to catch these subtle, long-lived leaks.&lt;/p&gt;

&lt;p&gt;In this article, I’ll show you how to instrument LeakCanary into AOSP system components—even services not designed for app-level inspection—and use it to detect memory leaks in system software like Bluetooth.apk, Settings, or even your own custom privileged services.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;🧠 Why LeakCanary for System Software?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;LeakCanary is primarily designed for Android app developers. But it becomes even more powerful in AOSP system-level debugging:&lt;/p&gt;

&lt;p&gt;Catches leaks in framework-facing services&lt;br&gt;
Tracks long-lived Handler threads or leaked Context in privileged apps&lt;br&gt;
Offers real-time leak traces even when no UI is involved&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;☝️ It’s especially useful for debugging Bluetooth, Telephony, or Connectivity services where services are restarted often or context mismanagement is common.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;🔧 Step-by-Step: Integrate LeakCanary into AOSP&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s take a system app or service like com.android.bluetooth as our example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📁 1. Clone and Embed LeakCanary in AOSP&lt;/strong&gt;&lt;br&gt;
LeakCanary is not prebuilt into AOSP. You need to vendor it yourself.&lt;/p&gt;

&lt;p&gt;Clone LeakCanary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/square/leakcanary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy its source into your AOSP tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp -r leakcanary/leakcanary-android-core/src/main/java/* \
    packages/apps/Bluetooth/src/com/squareup/leakcanary/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🛠️ 2. Modify Android.bp in Your System App&lt;/strong&gt;&lt;br&gt;
Update the Android.bp file of your system app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java_library {
    name: "bluetooth-leakcanary",
    srcs: ["src/**/*.java"],
    static_libs: ["leakcanary-core"],
    sdk_version: "current",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case your module uses platform_compat or system_current, set appropriate sdk_version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📲 3. Inject LeakCanary in Your Service Process&lt;/strong&gt;&lt;br&gt;
Let’s assume you are instrumenting AdapterService in the Bluetooth stack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class AdapterService extends Service {

    @Override
    public void onCreate() {
        super.onCreate();
        if (LeakCanary.isInAnalyzerProcess(this)) {
            return;
        }
        LeakCanary.install(getApplication());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure that the Application class is properly used in the system manifest or override ContextImpl if needed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🔐 Note: You must have read/write permission to /data/leakcanary/ or use rooted devices/emulators.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;🧪 Run, Leak, Repeat: AOSP Bluetooth Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s a real example from debugging the AOSP Bluetooth stack:&lt;/p&gt;

&lt;p&gt;Scenario:&lt;br&gt;
Toggle Bluetooth multiple times. Eventually, you notice increased memory usage.&lt;/p&gt;

&lt;p&gt;LeakCanary output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┬───
│ GC ROOT static android.bluetooth.BluetoothAdapter.sService
│ leaks AdapterService instance
│ ↓ AdapterService.mHandler
│   ↓ Callback retained Context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🔍 Analysis:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;sService holds onto an old AdapterService instance.&lt;br&gt;
The Handler inside retains the previous Context.&lt;br&gt;
That context is no longer valid post-service restart.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Fix:&lt;/strong&gt;&lt;br&gt;
Clear or nullify references in onDestroy():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Override
public void onDestroy() {
    mHandler.removeCallbacksAndMessages(null);
    sService = null;
    super.onDestroy();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;📉 Dumping Heap for Offline Analysis&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LeakCanary automatically creates heap dumps (.hprof). You can push them to your host:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adb pull /sdcard/leakcanary-&amp;lt;timestamp&amp;gt;.hprof
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧾 Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Memory leaks in AOSP system software are often hard to spot and harder to debug. LeakCanary can be retrofitted into system components, giving you visibility that otherwise would require JNI dumps or heavy profiling.&lt;/p&gt;

&lt;p&gt;Whether you're optimizing Bluetooth, investigating SystemUI bloat, or improving your custom HAL-based service—LeakCanary gives you the tools to debug like a pro.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔗 Resources&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/square/leakcanary" rel="noopener noreferrer"&gt;LeakCanary GitHub&lt;/a&gt;&lt;br&gt;
&lt;a href="https://source.android.com/setup/start" rel="noopener noreferrer"&gt;AOSP Source Tree Setup&lt;/a&gt;&lt;br&gt;
&lt;a href="https://chatgpt.com/c/68269e91-5038-8001-a957-d752fa376442" rel="noopener noreferrer"&gt;Eclipse MAT&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>AOSP Handler vs synchronized: Choosing the Right Tool for Thread Safety</title>
      <dc:creator>Nikheel Vishwas Savant</dc:creator>
      <pubDate>Thu, 15 May 2025 04:54:27 +0000</pubDate>
      <link>https://dev.to/nikheelvs/aosp-handler-vs-synchronized-choosing-the-right-tool-for-thread-safety-p4l</link>
      <guid>https://dev.to/nikheelvs/aosp-handler-vs-synchronized-choosing-the-right-tool-for-thread-safety-p4l</guid>
      <description>&lt;p&gt;In Android development, particularly within the AOSP (Android Open Source Project), managing concurrency is critical when designing reliable and thread-safe components. Two core techniques often used for this are:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Handler (and its related Looper mechanism)&lt;/li&gt;
&lt;li&gt;The synchronized keyword (Java-level mutual exclusion)&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;While both can help manage shared state across threads, they serve very different purposes. Understanding when to use each can be the difference between clean concurrency and subtle deadlocks.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What is a Handler?
&lt;/h2&gt;

&lt;p&gt;A Handler in Android is a mechanism to post messages or runnables to a thread’s message queue. When backed by a Looper, a Handler provides asynchronous task scheduling on the thread it’s associated with — typically the main/UI thread or a dedicated background thread.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Handler handler = new Handler(Looper.getMainLooper());
handler.post(() -&amp;gt; {
    // Run code on the main thread
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In AOSP system components (like BluetoothManagerService or ActivityManagerService), Handlers are frequently bound to a dedicated thread (HandlerThread) to serialize operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is synchronized?
&lt;/h2&gt;

&lt;p&gt;The synchronized keyword is a Java primitive that provides mutual exclusion, ensuring that only one thread can enter a critical section of code at a time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;synchronized(lockObject) {
    // Critical section
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s low-level, blocking, and does not switch threads or schedule operations. It simply protects data from concurrent access issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. When to Use Handler in AOSP?
&lt;/h2&gt;

&lt;p&gt;Use Handler when you want to serialize work on a specific thread. For example, if you're managing Bluetooth connections from a central thread:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private final Object mLock = new Object();
void addClient(String id) {
    synchronized (mLock) {
        mClientIds.add(id);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This avoids needing synchronized at all, as long as all access to mConnectionMap goes through this handler.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. When to Use synchronized?
&lt;/h2&gt;

&lt;p&gt;Use synchronized when the access to shared data is sporadic or does not justify a dedicated thread.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private final Object mLock = new Object();
void addClient(String id) {
    synchronized (mLock) {
        mClientIds.add(id);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, avoid long operations inside a synchronized block, especially those that can trigger callbacks or I/O.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Best Practices
&lt;/h2&gt;

&lt;p&gt;🧵 Prefer Handlers for Thread Affinity&lt;br&gt;
If your logic has a natural affinity to a thread (e.g., UI or Bluetooth handler thread), use Handler. It allows non-blocking, serialized execution.&lt;/p&gt;

&lt;p&gt;⚠️ Use synchronized for Fine-Grained Locks&lt;br&gt;
If data is accessed from multiple threads and there's no dedicated handler thread, then synchronized is still appropriate — but limit scope.&lt;/p&gt;

&lt;p&gt;☠️ Avoid Mixing Carelessly&lt;br&gt;
A common pitfall is combining synchronized and Handler-based designs, which can lead to deadlocks if not carefully ordered.&lt;/p&gt;
&lt;h2&gt;
  
  
  6. Real Example in AOSP
&lt;/h2&gt;

&lt;p&gt;In AdapterService.java (Bluetooth stack), you’ll often find:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mHandler.post(() -&amp;gt; handleConnectionStateChange(device, state));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Internally, handleConnectionStateChange() may access shared maps or state without synchronization — because the handler ensures thread confinement.&lt;/p&gt;

&lt;p&gt;In contrast, parts of BatteryService or InputManagerService use synchronized to guard against race conditions due to multiple calling threads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Both Handler and synchronized are powerful concurrency tools in AOSP. Use Handler when working with components tied to thread-specific behavior, especially when serial execution is required. Use synchronized for fine-grained mutual exclusion without needing message queuing overhead.&lt;/p&gt;

&lt;p&gt;Understanding and applying them properly results in safer, cleaner, and more maintainable Android system code.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
