Commit Graph

3821 Commits

Author SHA1 Message Date
Kweku Adams
b1f303c7a9 Merge "Actually persist network byte values." 2022-11-12 03:01:20 +00:00
Kunal Malhotra
f4c573cc63 Merge "Adding in new metrics for Jobs." 2022-11-11 21:14:54 +00:00
Kweku Adams
46038f2a1c Merge "Add data transfer JobService APIs." 2022-11-11 19:34:24 +00:00
Kweku Adams
4b138af66a Actually persist network byte values.
These numbers are useful in adjusting JS policy, so we should persist
them so we can use them after the device reboots.

Bug: 258701271
Test: atest FrameworksServicesTests:JobStoreTest
Change-Id: Iee8fb699ea5b4c01446ce8fd8f806203effbe4ce
2022-11-11 17:13:30 +00:00
Kweku Adams
7a5d66b557 Add data transfer JobService APIs.
Add new APIs to support the data transfer job project. These APIs allow
the app to update JobScheduler on estimated transfer sizes and the
progress of the transfer.

Bug: 255371817
Test: Android builds
Change-Id: I70c1020d8a8b0956aaff5e2a843cc338bdbe6bf5
2022-11-10 18:03:39 +00:00
Kweku Adams
d20d4fa0c3 Add logic to persist jobs in separate files.
Make it possible to persist jobs in a separate file for each calling
UID. This makes it easier to persist changes to jobs of individual apps
instead of having to write the entire set of jobs every time something
changes.

Read times decrease by 2-5% when there are many jobs for each app but
increase by 33-35% when there are only a few jobs per app.
Write times increase by 5% (for many jobs) to 64% (for few jobs) for a
full write but decrease by 1% (for few jobs) to 38% (for many jobs) when
there are partial writes.

JobScheduler is read-once, write-many system, and apart from migration
from between monolithic and split file architectures, should mostly be
in the partial write scenario.

The code is disabled for now and will be turned on separately.

Performance Test Results:

(With monolithic file):

com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_fewJobs_badRTC
	testPersistedJobReading_fewJobs_badRTC_mean (ns): 4632075
	testPersistedJobReading_fewJobs_badRTC_median (ns): 4568177
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_manyJobs
	testPersistedJobWriting_manyJobs_mean (ns): 38133928
	testPersistedJobWriting_manyJobs_median (ns): 37794691
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_manyJobs_goodRTC
	testPersistedJobReading_manyJobs_goodRTC_mean (ns): 46015412
	testPersistedJobReading_manyJobs_goodRTC_median (ns): 45553494
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_fewJobs
	testPersistedJobWriting_fewJobs_mean (ns): 4903462
	testPersistedJobWriting_fewJobs_median (ns): 4914740
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_fewJobs_goodRTC
	testPersistedJobReading_fewJobs_goodRTC_mean (ns): 4432127
	testPersistedJobReading_fewJobs_goodRTC_median (ns): 4395469
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_delta_manyJobs
	testPersistedJobWriting_delta_manyJobs_mean (ns): 42629601
	testPersistedJobWriting_delta_manyJobs_median (ns): 42282061
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_delta_fewJobs
	testPersistedJobWriting_delta_fewJobs_mean (ns): 5070691
	testPersistedJobWriting_delta_fewJobs_median (ns): 4914688
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_manyJobs_badRTC
	testPersistedJobReading_manyJobs_badRTC_mean (ns): 45184576
	testPersistedJobReading_manyJobs_badRTC_median (ns): 44922660

(With split files):

com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_fewJobs_badRTC
	testPersistedJobReading_fewJobs_badRTC_mean (ns): 6350549
	testPersistedJobReading_fewJobs_badRTC_median (ns): 6232605
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_manyJobs
	testPersistedJobWriting_manyJobs_mean (ns): 39963524
	testPersistedJobWriting_manyJobs_median (ns): 39628389
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_manyJobs_goodRTC
	testPersistedJobReading_manyJobs_goodRTC_mean (ns): 43956702
	testPersistedJobReading_manyJobs_goodRTC_median (ns): 43569874
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_fewJobs
	testPersistedJobWriting_fewJobs_mean (ns): 8250152
	testPersistedJobWriting_fewJobs_median (ns): 8090939
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_fewJobs_goodRTC
	testPersistedJobReading_fewJobs_goodRTC_mean (ns): 6006753
	testPersistedJobReading_fewJobs_goodRTC_median (ns): 5869193
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_delta_manyJobs
	testPersistedJobWriting_delta_manyJobs_mean (ns): 26459508
	testPersistedJobWriting_delta_manyJobs_median (ns): 26147607
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_delta_fewJobs
	testPersistedJobWriting_delta_fewJobs_mean (ns): 4958038
	testPersistedJobWriting_delta_fewJobs_median (ns): 4881588
com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_manyJobs_badRTC
	testPersistedJobReading_manyJobs_badRTC_mean (ns): 44476839
	testPersistedJobReading_manyJobs_badRTC_median (ns): 43993285

Bug: 255352252
Test: atest JobSchedulerPerfTests:JobStorePerfTests
Test: atest FrameworksServicesTests:JobStoreTest
Change-Id: Ib7bfa2c974f7663dea79d707c9e1b2bd53ef89b3
2022-11-10 16:37:55 +00:00
Kweku Adams
e33d4b520d Merge "Switch from Pair to UserPackage." 2022-11-09 15:51:22 +00:00
Kweku Adams
68d0689f84 Merge "Remove satisfied timed jobs from the tracked list." 2022-11-08 17:05:24 +00:00
Kweku Adams
97329fbdc7 Merge "Add additional lanes if current jobs will run too long." 2022-11-07 22:19:58 +00:00
Kweku Adams
3c3e645dd5 Remove satisfied timed jobs from the tracked list.
Remove jobs whose timing constraints have been deemed as satisfied
outside of the normal alarm checking flow from the tracked job list.
They would have eventually be removed, but there's no reason to keep
them in the list longer than necessary.

Bug: 141645789
Test: Android builds
Change-Id: I9d5a78f747a9195621205e62279f92c6c9bba8cc
2022-11-07 17:14:46 +00:00
Kweku Adams
03d7508067 Switch from Pair to UserPackage.
UserPackage is designed to reduce object creation and memory
duplication for the userId+packageName pair use case.

Bug: 247127880
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/devicepolicy
Test: atest FrameworksMockingServicesTests:AlarmManagerServiceTest
Change-Id: Iab0e1169a7f81c12054995836a07b3fa960ee8e6
2022-11-07 17:12:07 +00:00
Sudheer Shanka
df26ea80c8 Merge "Deliver DEVICE_IDLE_MODE_CHANGED broadcasts as non-ordered." 2022-11-07 06:58:54 +00:00
Vova Sharaienko
c2710373b7 Merge "ExpressLog integration for JobScheduler" am: dc7b608720 am: fe1ec1044c am: 6586c76ce7
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2269493

Change-Id: I633913b0fee5b59a6f5eda4fcd6aa2d3f6327db4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-11-04 21:06:09 +00:00
Vova Sharaienko
fe1ec1044c Merge "ExpressLog integration for JobScheduler" am: dc7b608720
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2269493

Change-Id: I295a9a01f1f11c46d3df887bfeb4d5ba5b791d2c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-11-04 20:26:54 +00:00
Kunal Malhotra
457599d9d6 Adding in new metrics for Jobs.
Test: manual
Change-Id: I1bc0cabb50accfad7c2fb1a32aef8a8cfa7b2193
Bug: b/257339302
2022-11-04 20:02:51 +00:00
Sudheer Shanka
c7e66035bb Deliver DEVICE_IDLE_MODE_CHANGED broadcasts as non-ordered.
They are currently being sent as ordered in order to receive
the finish callback. Since the modern broadcast queue supports
a finish callback with the need for the broadcasts to be ordered,
don't send these broadcasts as ordered anymore.

Bug: 256597397
Bug: 256597171
Bug: 253226131
Test: treehugger
Change-Id: I00a0dec0df99892b2d0f4a023efcc965a2061379
2022-11-04 03:58:11 -07:00
Nikhil Kumar
3f98c7d7c8 Merge "Allow admin user's app with system UID to access blob store." 2022-11-04 10:15:14 +00:00
Peter Collingbourne
fd99d08d90 Merge "Fix division by zero in maybeAdjustDesiredStockLevelLocked()." 2022-11-03 22:17:26 +00:00
Nikhil Kumar
b53c1158e4 Allow admin user's app with system UID to access blob store.
BlobStore APIs are restricted to be only consumed by the admin user's
app with system uid. Right now there is only one admin user
which is user 0 and for user 0 both the appId and callingUid are same.
So even with callingUid, the existing check works well.

With the new headless mode, there can be several Admin users,
and any Admin user's app with a system uid can call BlobStoreManager APIs. But the appId and callingUid have different values on other(except user 0) amdin users' apps.
callingUid = userId + "0" + appId

Refactored the restriction to use appId instead of callingUid to match with SYSTEM_UID and added an additional check to ensure that the calling user is an admin user.

Removed unused callingUid param in internal method.

Bug: 256119753

Test: atest --test-mapping apex/blobstore
Change-Id: I6717cb8ebeb263c911e3caae924b7c3935e58778
2022-11-03 21:34:51 +00:00
Kweku Adams
6e3b4d4fe1 Merge "Do best effort network estimate calculation." 2022-11-03 20:38:42 +00:00
Vova Sharaienko
194d719fa4 ExpressLog integration for JobScheduler
- logging counter for deadline jobs

Bug: 247803110
Test: build & statsd_testdrive
Change-Id: I9637554ae80454e60aac9e7b14e391250a6ed980
2022-11-03 20:02:48 +00:00
Peter Collingbourne
9bb7cb8af1 Fix division by zero in maybeAdjustDesiredStockLevelLocked().
If getBatteryScreenOffDischargeMah() returns zero that will lead to
a division by zero when computing estimatedLifeHours that will
bring down the entire system server. Guard against this by returning
from the function early if it returns zero.

Change-Id: I4905d7184e5185a07e4185fa0e263559d85cff49
2022-11-03 10:52:44 -07:00
TreeHugger Robot
e2ce20253b Merge "Consolidate UserID+Package classes." 2022-11-02 01:12:23 +00:00
Michał Brzeziński
0046945ce9 Merge changes from topic "revert-20329504-KNAMDEHGHL"
* changes:
  Revert "BroadcastQueue: return reasons from skip policy."
  Revert "BroadcastQueue: better state transition logging."
  Revert "BroadcastQueue: skip ANRs when assuming success."
2022-11-01 13:47:11 +00:00
Michał Brzeziński
8ef5a2e3ae Revert "BroadcastQueue: better state transition logging."
Revert submission 20329504

Reason for revert: Broken SystemServicesTestRuleTest
Bug: 256741859 
Reverted Changes:
I1a74109e7:BroadcastQueue: return reasons from skip policy.
I7fe33cd17:BroadcastQueue: better state transition logging.
I9899e805f:BroadcastQueue: skip ANRs when assuming success.

Change-Id: I31ad4804cde2e16d5ecffb8ea8c9cfa9fec4f23d
2022-11-01 11:58:36 +00:00
TreeHugger Robot
3e17e51fca Merge "Remove unused parameter and innocuous bug." 2022-11-01 10:13:02 +00:00
TreeHugger Robot
bb210c0fdd Merge "Executor version of setWindow() and setExactAndAllowWhileIdle()" 2022-11-01 07:44:22 +00:00
Jeff Sharkey
73ffa86985 Merge changes from topic "oct28b"
* changes:
  BroadcastQueue: skip ANRs when assuming success.
  BroadcastQueue: better state transition logging.
  BroadcastQueue: return reasons from skip policy.
2022-11-01 03:31:41 +00:00
Soonil Nagarkar
00790871c0 Executor version of setWindow() and setExactAndAllowWhileIdle()
We need executor APIs.

Test: atest CtsAlarmManagerTestCases:BasicApiTests

Bug: 255004822
Change-Id: I64cd8330a4874e7652ef043a67942da2907a7ab1
2022-10-31 19:26:04 -07:00
TreeHugger Robot
8c75791bb4 Merge "Rework backoff policy calculation." 2022-10-31 21:22:24 +00:00
Kweku Adams
819087f4a9 Remove unused parameter and innocuous bug.
1. Remove the forUpdate boolean since no controller was using it.
2. Stop returning a boolean from JobStore.add(). It was always returning
   false because the remove() method would remove the added JobStatus
   object, not anything similar to the object. Thankfully, we were
   removing old JobStatus objects via another codepath, so the bug never
   surfaced as an issue.

Bug: 141645789
Test: Android builds
Change-Id: I17c7a4a629f033c574e4fbd625211c0fc476fcc9
2022-10-31 21:13:02 +00:00
Kweku Adams
a8372dac3c Merge "Separate minimum from initial consumption limit." 2022-10-31 18:54:20 +00:00
Kweku Adams
c6a6194824 Consolidate UserID+Package classes.
https://xkcd.com/927/

Many different components have created their own classes to represent a
userID+packageName combination. This means 1) duplicate code, 2)
duplicate objects in memory representing the same thing. Creating a
common class that limits itself to one object per userID+packageName
combo addresses those two concerns.

There are still others with similar classes. They're not included in
this CL because they have slight differences and would require a little
bit more work to consolidate.

Bug: 141645789
Bug: 247127880
Test: atest CtsAccountManagerTestCases
Test: atest CtsContentTestCases:OverlayManagerTest
Test: atest CtsShortcutManagerTestCases
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/tare
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/om
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/pm
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/tare
Test: atest FrameworksMockingServicesTests:PrefetchControllerTest
Test: atest FrameworksMockingServicesTests:QuotaControllerTest
Change-Id: I63d5bc946cc7b24a0536e8b2051da07a801b3a8a
2022-10-31 14:57:28 +00:00
Kweku Adams
9bfcae02d0 Add additional lanes if current jobs will run too long.
With the incoming long-running job feature comes the possibility that
all usable slots are occupied for long periods of time (eg. for hours),
so if we detect that other jobs would be stuck waiting in the queue for
too long then we'll create at most 2 extra slots (one for EJs, one for
regular jobs) so that we can make forward progress with the other jobs.

Bug: 248386641
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Test: atest CtsJobSchedulerTestCases
Change-Id: I7a41a5c8371714a0285bb2dcfe115c762c0d8ed7
2022-10-31 14:57:10 +00:00
Kweku Adams
7549e3d5f7 Separate minimum from initial consumption limit.
Create separate fields for minimum and initial consumption limits so
that they can be modified independently.

Bug: 255321890
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/tare
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/tare
Test: manually change in Developer Options UI
Change-Id: I2d3e17be2fd6d6913782fcfdbbe4452cfd484c2c
2022-10-31 14:18:30 +00:00
Jeff Sharkey
2533f9a7c7 BroadcastQueue: better state transition logging.
To aid future debugging of the modern stack, include a "reason"
behind each state transition.

Register Loopers that are well-known to be used for broadcast
dispatch so that we fully drain them before "wait-for-broadcast".

Remove outdated TODOs that are either finished or tracked elsewhere,
add misc annotations.

Bug: 254521331
Test: atest FrameworksMockingServicesTests:BroadcastRecordTest
Test: atest FrameworksMockingServicesTests:BroadcastQueueTest
Test: atest FrameworksMockingServicesTests:BroadcastQueueModernImplTest
Change-Id: I7fe33cd173919f98c062c488598f81ac732c52a3
2022-10-28 19:41:27 -06:00
Kweku Adams
1ff568de49 Rename "long running" to "overtime".
Use "overtime job" instead of "long running" to refer to jobs that
have been running longer than their minimum execution timeout and
are thus running in overtime to avoid naming collision with new long
running job features.

Bug: 141645789
Test: Android builds
Change-Id: I7298f69aa16a422c9887b07a51d1f53314635978
2022-10-27 19:07:45 +00:00
Kweku Adams
976d0a98d4 Rework backoff policy calculation.
Don't penalize jobs in the backoff calculation when they were stopped
for reasons that were likely outside of the app's control (eg. the
device entering Doze or battery saver or constraints no longer being
satisfied). Jobs calling jobFinished() on their own or timing out are
both deemed as being within the app's control.

Bug: 209979687
Test: atest FrameworksMockingServicesTests:JobSchedulerServiceTest
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Change-Id: I3cffd676c81cb461df39e68999b1a97cf4d5521a
2022-10-27 15:28:05 +00:00
Kweku Adams
d3e900e38c Do best effort network estimate calculation.
Ignore invalid negative values in the network payload estimate
calculations and use known/available values to get a best effort
estimate of the total payload size.

Bug: 253665015
Bug: 255828754
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Change-Id: Ie986ac8a4b46a920c6d57b6925e72f8d62e1ce68
2022-10-26 21:22:14 +00:00
Hai Zhang
5611f58784 Merge "Move TypedXml{Parser,Serializer} to modules utils package." 2022-10-25 02:44:29 +00:00
Kweku Adams
3d5d56f871 Prevent apps from setting negative estimated bytes.
Bug: 253665015
Test: atest CtsJobSchedulerTestCases:JobInfoTest
Test: atest CtsJobSchedulerTestCases:JobWorkItemTest
Change-Id: I4f8185b4f6abbe872d8944448de629ed0d903634
2022-10-24 18:37:00 +00:00
Kweku Adams
60a827fa4a Merge "Reject inconsistent Job-JobWorkItem scheduling." 2022-10-24 16:31:32 +00:00
Hai Zhang
e55b8eeb28 Move TypedXml{Parser,Serializer} to modules utils package.
A subsequent change will actually move the files to the other git
project.

Bug: 243194720
Test: presubmit
Change-Id: If126bb68f74852528c4da8df79831b49b5129983
2022-10-21 04:28:13 -07:00
Kweku Adams
bc72f48fb4 Reject inconsistent Job-JobWorkItem scheduling.
Reject scheduling of JobWorkItems that imply network usage but are
scheduled using a JobInfo that doesn't have a network constraint.

Bug: 241104082
Test: atest CtsJobSchedulerTestCases:JobWorkItemTest
Change-Id: I0c74eae37d9cb60f0e671dda252a0d4f15c83070
2022-10-18 22:06:23 +00:00
Treehugger Robot
3932482d40 Merge "Fix bug for user removed case" am: 1db4d8b36a
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2256888

Change-Id: I07057020ecf4e151926d831d8782f18327553a36
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-10-18 21:12:51 +00:00
yong8.huang
667237ea5b Fix bug for user removed case
For user removed case, need to remove all data
which is related with theremoved userId.

Bug: N/A
Test: N/A
Change-Id: Icad92b86d37154134117a0c6035d95617df352d1
Merged-In: I400e2d9d3ec8b76a293856c44375bb1d302c530f
2022-10-18 09:52:40 +08:00
Kweku Adams
bce9f378ba Use the correct UID for proc state evaluation.
JS policy is primarily based on the source UID, not the calling UID.
Update the code and tests to evaluate the source UID state.

Bug: 253815639
Bug: 253820921
Test: atest FrameworksMockingServicesTests:FlexibilityControllerTest
Change-Id: I193b69e0809f10f38e11fe956f8dbb9c325d993b
2022-10-17 22:53:55 +00:00
Kweku Adams
7fceefa1bb Merge "Cancel all jobs associated with a UID when appropriate." 2022-10-15 18:50:25 +00:00
Kweku Adams
c28117e1d9 Try to avoid IndexOutOfBoundsException.
Add a limit to the number of dropped constraints and stop modifying the
number of required and dropped constraints independently to prevent the
code from creating invalid indices at random times. Also fix some of the
tests and make them more robust.

Bug: 253237201
Test: atest --rerun-until-failure 25 CtsJobSchedulerTestCases:FlexibilityConstraintTest
Test: atest --rerun-until-failure 25 FrameworksMockingServicesTests:FlexibilityControllerTest
Change-Id: I072da5c6271eecc3e8a7e3983f414c752d40cba8
2022-10-14 16:38:49 +00:00
Kweku Adams
0e9b531408 Merge "Make concurrency manager code more testable." 2022-10-14 14:42:35 +00:00