Commit Graph

41 Commits

Author SHA1 Message Date
mxyyiyi
d4965bd5cc Ignore broadcast intent from additional profile.
- Use isAdditionalProfile() to ignore intent from either work or private profile.

Bug: 354828134
Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusage
Flag: EXEMPT bug fix
Change-Id: Ic0c91d956e4bfcd53576629efab4be847c94155e
2024-07-23 19:31:05 +08:00
YK Hung
f5cf54bcc7 Add new database table and proto for battery usage reattribution (2/5)
Bug: 346706894
Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusage
Flag: EXEMPT bug fix
Change-Id: If360246d974abdea7004023aedcf1a4be7b63633
2024-06-17 10:13:34 +00:00
YK Hung
1fe85991e8 Disable explicit gc method invocation in V
Disable the gc() method explicit invocation due to the new policy in the
android to avoid android.os.strictmode.ExplicitGcViolation

Test: presubmit
Fix: 345577704
Flag: EXEMPT strictmode fix
Change-Id: I6ec7dac6735499c40a7ab6d135108e4c5013a4a4
2024-06-11 15:00:26 +00:00
mxyyiyi
d3ce90347b Update database clear & job refresh mechanism for time zone change intent
- Clear database and reset periodic job
- Take a snapshot of current battery usage stats

Bug: 336423923
Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusage
Change-Id: I4aade9db950b508e2190605371f246904f131da3
2024-05-10 11:22:58 +08:00
mxyyiyi
798340fafd Update database clear & job refresh mechanism for time change intent
- Ignore time change intent for time format update
- Clear data after current time in DB and refresh periodic job
- Take a snapshot of current battery usage stats if no periodic job in DB

Bug: 336423923
Bug: 314921894
Fix: 314921894
Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusagei
Change-Id: Iec0f5e8e97f18c4603de711a5884336ba0af23a9
2024-05-10 11:22:47 +08:00
mxyyiyi
2c7ca9f2e7 Fix crash while dumpping database.
Bug: 319905857
Test: manual
Change-Id: If531f1d7416b21d481fc19834e7538567dec7c0c
2024-01-16 15:46:34 +08:00
Zaiyue Xue
d6cc80362c Refactor code according to comments in ag/25767430.
Bug: 318308397
Test: presubmit
Change-Id: Idc42d340508d2c41173ca157aabc452b6b0f6036
2024-01-08 15:12:40 +08:00
Zaiyue Xue
9c06e522bc Fix battery usage chart was unexpectedly cleared
Bug: 318308397
Fix: 318308397
Test: manual
Change-Id: Ia00c0680a563eaffb3609c1372336a6b9ed7fa17
2024-01-02 11:59:16 +08:00
mxyyiyi
a919306d75 Provide foreground_service usage time in BatteryDiffEntry.
- Fetch foreground service info through new api from UidBatteryConsumer.
- Record fgs & bg usage time separately, combine them till ui display.

Bug: 315255868
Test: make RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge.*"
Change-Id: Ic19844db7908a6ae6522c7a72972f44f94dcfca4
2023-12-11 15:57:10 +08:00
ykhung
7007b11228 Replace the isWorkProfile method from the SettingsLib
Replace the isWorkProfile() in the Settings with the common method
defined in the SettingsLib to avoid duplicate code

Bug: 306329984
Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge"
Change-Id: Ic9b18e6b80c23f9d4fc200080224daa27cbf4a4d
2023-11-24 11:08:06 +08:00
Jun Lan
cca804e1ed Format battery java code
After this CL, we can follow Guideline:go/hc-mainline-dev#format-code to keep java format consistent.

Test: manual
Bug: 304439460
Change-Id: I5bb77f81b0bd9be618e34942eaaee8296bc42796
2023-11-06 13:55:48 +08:00
mxyyiyi
ad23b53942 Update battery usage data clear mechanism while time change.
- Accept time updated in the last job schedule range:
  [ max (last-full-charge / last-even-hours) , next-even-hours ]

Bug: 308714066
Fix: 308714066
Test: manual
Change-Id: Id92fffddb7666d63fce66fee696a27d957c8b537
2023-11-03 15:25:17 +08:00
Zaiyue Xue
068adaf153 Enable i18n for battery tips card and fix b/297036263.
Bug: 291689623
Bug: 297036263
Fix: 297036263
Test: manual
Change-Id: I41aff99c73ace995ef9dfa8f1dc28024cd12d236
2023-08-25 20:40:45 +08:00
mxyyiyi
d9360ec326 Impl dismiss action in battery tips cards.
- Use SharedPreferences to record and filter the already dimissed anomaly.

Bug: 291689623
Test: manual
Change-Id: I4fd4a39066591a4a201857f9586b6595b7d5c43b
2023-08-25 20:17:31 +08:00
Zaiyue Xue
50da7feeb9 Battery usage page latency improvement (1-8)
Save battery slot diff data into database in hourly job. Then read the
saved diff data and only calculate the remaining data. This could speed
up the battery usage loading.

Bug: 261163071
Fix: 261163071
Test: manual
Change-Id: Icd4868ca9326b64b17ddbccdb0311e755dc68026
2023-08-16 15:12:04 +08:00
Kuan Wang
20ec9893d2 Move static UsageStatsManager from DatabaseUtils to DataProcessor to
avoid reference from DataProcessor.

This is to fix the Accessibility tests hang issue.
Tested on main branch (https://android-build.googleplex.com/builds/abtd/run/L40400000962473343).

Test: make RunSettingsRoboTests
Bug: 293366011
Bug: 295026588
Bug: 295123907
Change-Id: I345e0c060165e4d06f98ada6b2e1ca3cbb4f911a
2023-08-11 06:30:59 +00:00
Kuan Wang
64177774e2 Add cache strategy for getUsageSource().
Cache usage source into SharedPreferences when phone is booting to avoid
calling it too frequently.
It should be safe because the usage source can only change on reboot.

Bug: 293366011
Test: make RunSettingsRoboTests
Change-Id: I35c07539d294737c5764b03b746cfb39f4ce008d
2023-08-01 14:36:58 +08:00
ykhung
ef66549e64 Add a mechanism to log battery usage periodic job events
Example history log:
      	Jul 07, 2023, 15:28:51 SCHEDULE_JOB triggerTime=Jul 07, 2023, 16:00:00
      	Jul 07, 2023, 15:32:16 FETCH_USAGE_DATA
      	Jul 07, 2023, 15:32:17 INSERT_USAGE_DATA size=37
      	Jul 07, 2023, 15:43:45 FETCH_USAGE_DATA
      	Jul 07, 2023, 15:43:48 INSERT_USAGE_DATA size=47
      	Jul 07, 2023, 15:43:49 SCHEDULE_JOB triggerTime=Jul 07, 2023, 16:00:00

Bug: 284893240
Test: make test RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.fuelgauge
Change-Id: I45a1ce0ce9b70f095702727e53d7b7ce8824abdb
2023-07-07 17:47:19 +08:00
Zaiyue Xue
a2ab3ae5b3 Small refactor battery usage code according to the comments in previous cls.
Bug: 262802531
Test: presubmit
Change-Id: I0d496fc6a41af5964311dafe8dd89f8b8058de82
2023-04-12 17:24:16 +08:00
Zaiyue Xue
ff11b8e307 Exclude screen on time in battery usage page when the device is in charging.
Bug: 265751163
Fix: 265751163
Test: manual
Change-Id: I4ed71e1d6fad56a7cbfc9cd47ed4d791f45261ce
2023-03-30 20:23:33 +08:00
Zaiyue Xue
9723490f63 Unify logging timestamp string.
Bug: 275278933
Fix: 275278933
Test: presubmit
Change-Id: Ifc67b9bf841f018465ee4a7b38b3a8605f60212b
2023-03-27 19:11:13 +08:00
ykhung
1f3cf084c8 Record important battery usage event into SharedPreference for dump()
Fix: 268300677
Test: presubmit
Change-Id: If03106c265b984bc2608528bdf45386973e3a14f
2023-03-26 01:24:50 +08:00
Zaiyue Xue
a528f1e382 Fix b/273175976: Screen time counts the time before full charge.
Use the raw start timestamp instead of the first timestamp in the level
map to query app usage time.

Bug: 273175976
Fix: 273175976
Test: manual
Change-Id: Idb43b2bd5378e2f34ec722354408754f4a439c6d
2023-03-13 15:59:05 +08:00
Nikhil Kumar
846d1d26f4 Get profile parent's context in case of work profile
In the headless system user mode a non-system user can also have
a work profile.
Refactor DatabaseUtils to get the profile parent's context when
the user is a work profile.

Bug: 270039752
Test: make RunSettingsRoboTests
Change-Id: I1fb78c9d91d59d50880a1ea0dd5f83a3d11dd08f
2023-02-20 18:38:13 +00:00
Kuan Wang
4a6b26558d Query usage event for a longer time period and then trim the usage
events outside the expected period to make sure the app usage calculation near the boundaries are correct.

Test: make RunSettingsRoboTests + manual
Bug: 264858898
Change-Id: I9f6aa5a09a537f48a26a08b7dff8ae81e8a16e2a
2023-01-13 15:17:27 +08:00
Kuan Wang
6da66f9a5c Use (the last existing timestamp in DB + 1) as the start time of usage
event query to avoid loading the same events repeatedly.

queryEvents API will return the events within [start, end). In the
hourly job, if we query the events from the latest existing time, the
events happening at the latest time will be saved for multiple times
into database. This aims to avoid this issue.

Test: make RunSettingsRoboTests
Bug: 265110147
Fix: 265110147
Change-Id: I408e88b0e15fe22585906261935854cf47707f9c
2023-01-11 16:18:55 +08:00
Kuan Wang
97924455ff Implement the app usage data loading from database function.
Bug: 260964903
Test: make RunSettingsRoboTests + manual
Change-Id: I459dbdebe53e6b7421642955f36976b3e7c95fcb
2022-12-20 02:31:50 +00:00
Kuan Wang
8d2a26caed Add DataProcessManager to manage the async tasks of battery usage data
processing.

Test: make RunSettingsRoboTests + manually
Bug: 260964903
Change-Id: Id3b2772a98ec2ab3b03910c8a5e81adf7ccd5646
2022-12-19 03:40:48 +00:00
Kuan Wang
6c4f83f33d Load app usage events data in the hourly job.
Test: make RunSettingsRoboTests + manual
Bug: 260964679
Change-Id: Iaccaa77bd52fb7356cdcb786c64523f21040b128
2022-12-15 06:32:54 +00:00
Kuan Wang
ec1c9d94f2 Remove foreground_service_usage_time_in_ms field which has been merged
into background_usage_time_in_ms in the BatteryUsageStats (b/257392992).

Test: make RunSettingsRoboTests + manual
Bug: 258124768
Bug: 253553141
Change-Id: I0967eec0cbe6d0cb7a0535d744a1046dec1d267b
2022-12-06 01:04:48 +00:00
ykhung
e77b5bbecb Replace the getBatteryLevel() method from SettingsLib API
Bug: 260524172
Test: presubmit
Change-Id: Icb56abd3dc258dde142a956124dc12bbfd9ae889
2022-11-30 00:22:19 +08:00
Kuan Wang
20f6b1faaa Merge "Populate new fields foreground_service_usage_time_in_ms, foreground_usage_consume_power, foreground_service_usage_consume_power, background_usage_consume_power and cached_usage_consume_power into database and pass them to UI." 2022-11-29 06:52:08 +00:00
Kuan Wang
53a761f55b Populate new fields foreground_service_usage_time_in_ms,
foreground_usage_consume_power, foreground_service_usage_consume_power,
background_usage_consume_power and cached_usage_consume_power into
database and pass them to UI.

Test: make RunSettingsRoboTests + manual
Bug: 256123455
Bug: 258124768
Change-Id: Ic46032f67eff5898f9d4182c517bbebe478eca01
2022-11-29 11:42:26 +08:00
Kuan Wang
5285597dee Invoke the cursor.close() after loading data from database.
Test: make RunSettingsRoboTests + manual
Bug: 258099535
Change-Id: Ie8d8f5294fff6e44b7151e22f9ae7b5b53cd5d6d
2022-11-28 16:37:53 +08:00
Kuan Wang
2b93d40683 Use the field isFullChargeCycleStart in database to get the last full
charge cycle start and remove the unused SharedPreference.

Test: make RunSettingsRoboTests + manual
Bug: 253553141
Change-Id: I74ef71775fa5d4871077f6d5573467aa5843bc6b
2022-11-28 11:27:24 +08:00
Zaiyue Xue
bc1f4798a6 Refoactor 2 util functions from DatabaseUtil to BatteyUtils.
Bug: 252407178
Test: presubmit
Change-Id: I393777186cc308298f0a8b76af4672b9012ed681
2022-11-17 14:25:10 +08:00
Kuan Wang
45be6bae05 Listen ACTION_BATTERY_LEVEL_CHANGED in Settings and fetch usage data
when battery is full charged.

Bug: 253395332
Test: make RunSettingsRoboTests + manually
Change-Id: Ie83e5f319074ff404a600c4eb375fbecad651b6d
2022-11-01 06:39:21 +00:00
Kuan Wang
df05a1378b Add hourly period job to fetch battery usage data in Settings.
Bug: 253395332
Test: make RunSettingsRoboTests + manually
Change-Id: I342066a30fed202e5013b8c2554f36d991975c3e
2022-11-01 02:05:14 +00:00
Kuan Wang
cbaffa34bc Add functions of SI DatabaseUtils into Settings DatabaseUtils and remove
unused functions.

Bug: 253395332
Test: make RunSettingsRoboTests
Change-Id: I61feee3386d7291f9174acb884d09d7ab8733511
2022-10-21 04:48:14 +00:00
Kuan Wang
547df61667 Copy DatabaseUtils from SettingsGoogle to Settings and use the new
Settings database.

Bug: 253395332
Test: make RunSettingsRoboTests
Change-Id: Idbe6d71b69b28d344db146d139b4b60e2e7434da
2022-10-19 02:20:00 +00:00
Kuan Wang
0a0ba915ca Copy BatterySettingsContentProvider from SettingsIntelligence to Settings and rename it to BatteryUsageContentProvider.
Bug: 253395332
Test: make RunSettingsRoboTests + manually
Change-Id: Ib6c2240cd065f6e29393e13b7231bba7afd2d850
2022-10-18 02:26:23 +00:00