# android-measure-current **Repository Path**: drawfeel/android-measure-current ## Basic Information - **Project Name**: android-measure-current - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-30 - **Last Updated**: 2026-08-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Measure Current ADB Commands (Windows cmd) Complete command set for Windows cmd. Notes: - The script waits `PRE_WAIT_SEC` (default 15s) before the first measurement. - In volume sweep mode, the script waits `RANGE_WAIT_SEC` (currently 3s) between later volume levels. - Default duration is 180 seconds when no arguments are provided. - Default method is sample mode (`--method=sample`), so you do not need to pass it explicitly. - `--method=sample` runs the per-interval sampling path (`current_now`/`voltage_now`). - `--interval=SEC` is only meaningful in sampling mode (`sample`). - In charge-counter mode (`charge-counter`), periodic polling uses internal `CHARGE_COUNTER_SAMPLE_SEC` (currently 5s), not `--interval`. - Only `--name=value` arguments are supported. Legacy positional arguments (such as `180 1`) are not supported. - Optional `--volume-range=[X,Y]` enables a per-volume sweep from X to Y (inclusive). - The script creates `/sdcard/measure-current_log_YYYYMMDDHHMM/` automatically and writes `current_run.log` plus all result files into that directory. - In volume sweep mode, result files are written as `current_vol_.txt` in the measurement log directory. - If a target volume is unreachable (for example target 16 while max is 15), the run prints a `SKIP` message and continues. ## Measurement Principles ### `sample` method The `sample` method is a per-interval polling implementation. On every loop, the script reads: - `/sys/class/power_supply/battery/current_now` - `/sys/class/power_supply/battery/current_avg` - `/sys/class/power_supply/battery/voltage_now` - `/sys/class/power_supply/usb/current_now` - `/sys/class/power_supply/usb/voltage_now` The loop sleeps for `--interval=SEC` between samples, so this mode is suitable when you want finer time resolution, for example 1-second snapshots during a short behavior change. After the run, the script averages all collected rows and derives these values: - Battery current and battery power from battery current and battery voltage. - USB current and USB power from USB current and USB voltage. - Estimated device power as `usb_power - battery_power`. - Estimated device current as `device_power / battery_voltage`. In short, `sample` is an instantaneous sampling approach. It is better for observing short-term variation, but the result depends more on sample interval and transient noise. ### `charge-counter` method The `charge-counter` method is an accumulated-charge implementation. Instead of using `--interval`, it polls `/sys/class/power_supply/battery/charge_counter` every internal `CHARGE_COUNTER_SAMPLE_SEC` seconds (currently 5 seconds). The script waits until the counter changes, uses one changed value as the start anchor, then keeps polling until it has another changed value that is more than the requested duration away from that anchor. The final average current is computed from charge delta over actual elapsed time: $$ ext{avg\_signed\_mA} = \frac{\Delta \text{charge\_uAh} \times 3.6}{\text{elapsed\_sec}} $$ Positive signed current means charging, negative signed current means discharging. The report also prints `avg current draw`, which flips the sign so a positive value means battery drain. If battery voltage is available, the script also estimates average battery power by averaging the start and end `voltage_now` readings and multiplying by the computed average current. In short, `charge-counter` is an interval-average approach. It is usually better for long-duration average current or power measurement, and less sensitive to short spikes, but it does not provide per-second waveform-style detail. ### When to use which - Use `sample` when you want time-granular snapshots and trend observation. - Use `charge-counter` when you want a more stable whole-period average current or average power result. - For longer runs, `charge-counter` is usually the better default if the device exposes a reliable `charge_counter` node. ## 1) Push Script to Device ~~~bat adb devices adb push D:\audio-tech\git\bose-android-audio-effect\measure-current.sh /data/local/tmp/ adb shell chmod 755 /data/local/tmp/measure-current.sh ~~~ ## 2) Optional: Set SELinux to Permissive Requires root/eng/userdebug build: ~~~bat adb root adb shell setenforce 0 adb shell getenforce ~~~ If `adb root` is not available, try: ~~~bat adb shell su 0 setenforce 0 adb shell su 0 getenforce ~~~ ## 3) Run in Foreground No arguments (defaults: `duration=180`, sample mode): ~~~bat adb shell sh /data/local/tmp/measure-current.sh adb shell ls /sdcard/measure-current_log_*/ ~~~ Set duration to 180 seconds: ~~~bat adb shell sh /data/local/tmp/measure-current.sh --duration=180 adb shell ls /sdcard/measure-current_log_*/ ~~~ Set duration to 300 seconds: ~~~bat adb shell sh /data/local/tmp/measure-current.sh --duration=300 adb shell ls /sdcard/measure-current_log_*/ ~~~ Recommended for period-average current (charge-counter mode, explicit): ~~~bat adb shell sh /data/local/tmp/measure-current.sh --duration=600 --method=charge-counter adb shell ls /sdcard/measure-current_log_*/ ~~~ Run per-interval sampling mode (1 second interval): ~~~bat adb shell sh /data/local/tmp/measure-current.sh --duration=300 --method=sample --interval=1 adb shell ls /sdcard/measure-current_log_*/ ~~~ Run a volume sweep from 0 to 16: ~~~bat adb shell sh /data/local/tmp/measure-current.sh --duration=180 --volume-range=[0,16] adb shell ls /sdcard/measure-current_log_*/current_vol_*.txt ~~~ ## 4) Run in Background Example: run for 180 seconds in background (default sample mode): ~~~bat adb shell "sh /data/local/tmp/measure-current.sh --duration=180 &" ~~~ Example: run charge-counter method in background (explicit): ~~~bat adb shell "sh /data/local/tmp/measure-current.sh --duration=600 --method=charge-counter &" ~~~ Example: run per-interval sampling mode in background: ~~~bat adb shell "sh /data/local/tmp/measure-current.sh --duration=180 --method=sample --interval=1 &" ~~~ Example: run a volume sweep in background: ~~~bat adb shell "sh /data/local/tmp/measure-current.sh --duration=300 --method=sample --interval=1 --volume-range=[0,8] &" adb shell "sh /data/local/tmp/measure-current.sh --duration=300 --method=charge-counter --volume-range=[0,8] &" ~~~ ## 5) Check Background Process ~~~bat adb shell ps -A | grep measure-current.sh ~~~ If `grep` is not available on the device: ~~~bat adb shell ps -A ~~~ ## 6) View Logs and Results ~~~bat adb shell tail -n 120 /sdcard/measure-current_log_YYYYMMDDHHMM/current_run.log adb shell cat /sdcard/measure-current_log_YYYYMMDDHHMM/current.txt ~~~ For charge-counter method: ~~~bat adb shell tail -n 120 /sdcard/measure-current_log_YYYYMMDDHHMM/current_run.log adb shell cat /sdcard/measure-current_log_YYYYMMDDHHMM/current.txt ~~~ In volume sweep mode, check generated per-volume files: ~~~bat adb shell ls /sdcard/measure-current_log_YYYYMMDDHHMM/current_vol_*.txt adb shell cat /sdcard/measure-current_log_YYYYMMDDHHMM/current_vol_0.txt ~~~ ## 7) Pull Results to PC ~~~bat adb pull /sdcard/measure-current_log_YYYYMMDDHHMM/current.txt .\current.txt adb pull /sdcard/measure-current_log_YYYYMMDDHHMM/current_run.log .\current_run.log ~~~ Pull per-volume results (volume sweep mode): ~~~bat adb pull /sdcard/measure-current_log_YYYYMMDDHHMM/current_vol_0.txt .\current_vol_0.txt adb pull /sdcard/measure-current_log_YYYYMMDDHHMM/current_vol_1.txt .\current_vol_1.txt ~~~ ## 8) If /sdcard Is Not Writable The script writes its measurement directory under /sdcard/measure-current_log_YYYYMMDDHHMM/. If /sdcard is not writable on your device, fix storage permissions first or copy the results after the run. ## 9) Multi-Device Scenario (Using -s Serial) First, list devices and copy the target serial (for example, `ABC123XYZ`): ~~~bat adb devices ~~~ Set a variable and reuse it in all commands (Windows cmd): ~~~bat set SERIAL=ABC123XYZ ~~~ Push and grant execute permission: ~~~bat adb -s %SERIAL% push D:\audio-tech\git\bose-android-audio-effect\measure-current.sh /data/local/tmp/ adb -s %SERIAL% shell chmod 755 /data/local/tmp/measure-current.sh ~~~ Check process and view logs: ~~~bat adb -s %SERIAL% shell ps -A | grep measure-current.sh adb -s %SERIAL% shell tail -n 120 /sdcard/measure-current_log_YYYYMMDDHHMM/current_run.log adb -s %SERIAL% shell ls /sdcard/measure-current_log_YYYYMMDDHHMM/current_vol_*.txt ~~~ Pull results to PC: ~~~bat adb -s %SERIAL% pull /sdcard/measure-current_log_YYYYMMDDHHMM/current_run.log .\current_run_%SERIAL%.log adb -s %SERIAL% pull /sdcard/measure-current_log_YYYYMMDDHHMM/current_vol_0.txt .\current_vol_0_%SERIAL%.txt ~~~