703 Commits

Author SHA1 Message Date
Etienne Ruffieux
7363fc0a38 Added SystemApi annotation to REASON_BLUETOOTH_BROADCAST
As Android Bluetooth becomes a mainline module, we need to
remove all hidden API usages. BluetoothManagerService is
using REASON_BLUETOOTH_BROADCAST so we have to make it
accessible to the Bluetooth module.

Tag: #feature
Bug: 211851706
Test: make
Change-Id: I99ade4673836c068b2e643ce5e56d9ad0454233f
2022-01-13 18:43:50 +00:00
Jacinta Hu
35ecc5886c Fix typo in Javadoc.
A missing end brace was causing Javadoc to fail to parse one of the links.
Change-Id: I8e4ca3721d7d08b7094d142fef394f06a223428e
2021-12-31 00:15:50 +00:00
Treehugger Robot
d1d210762b Merge "Change the wakeup alarms for "light-doze-maintenance step" to non-wakeup alarms" 2021-12-15 23:51:19 +00:00
Raj M
b9d7d27ede Change the wakeup alarms for "light-doze-maintenance step" to non-wakeup alarms
The wakeup alarms for doze-light-maintenance steps are causing battery drain in idle state. In terms of idle state battery optimization, Doze light maintenance step alarms can be changed to non-wakeup alarms as verified it is not critical as well as there is no user impact during our tests over a 50 days of Samsung's internal testing including User Trial.

Once it's changed to a non-wakeup alarm, the time gap between maintenance can be increased. But from our real test data, the gap has not increased as much as we worried, so doze-maintenance is working well.

Merged-In: Ib9bf9e120c806e61eced99fbfb84cdb19d844e69

Bug: b/197216833, b/185466339
Change-Id: Ida62842bdf8019563466fbf79326bc4d52ff3a99
Test: run `atest FrameworksMockingServicesTests:DeviceIdleControllerTest`
2021-12-06 21:02:24 +00:00
Kweku Adams
14841f18ff Partial revert "Wait for unlock to start jobs."
This reverts commit e61cf5125e83b119701228e742f7b2cb3a433cb6
but changes onUserUnlocking to onUserUnlocked.

Reason for revert: Direct-boot-aware jobs should be allowed to run when the user is locked

Bug: 200174299
Bug: 201307089
Test: N/A
Change-Id: Ic5a67a42590e171f0bfed8da0c138096031469d5
(cherry picked from commit 171bf04113154a7e3668e07677701869dfae9eda)
2021-10-12 13:07:14 -07:00
Kweku Adams
7caaf68063 Partial revert "Wait for unlock to start jobs."
This reverts commit e61cf5125e83b119701228e742f7b2cb3a433cb6
but changes onUserUnlocking to onUserUnlocked.

Reason for revert: Direct-boot-aware jobs should be allowed to run when the user is locked

Bug: 201307089
Change-Id: Ic5a67a42590e171f0bfed8da0c138096031469d5
(cherry picked from commit 171bf04113154a7e3668e07677701869dfae9eda)
2021-09-27 21:34:54 +00:00
Hui Yu
0ebc9cd55b tempAllowList duration can be updated if an UID is already temp
allowlisted.

Previously when PowerExemptionManager.addToTemporaryAllowList() is
called for a second time before the first time call's duration expires, the
second call does not update ActivityManagerService's
FgsTempAllowList for the new duration. This CL fixes this problem.

Bug: 199801023
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
Change-Id: Ibb8c6f41740a9b7468b50a4cdabe526ae58550ec
2021-09-20 21:14:23 +00:00
Kweku Adams
a7cb583f3a Use an exact alarm for location timeout.
Use an exact alarm for the location timeout to avoid keeping the GPS
active for too long.

Bug: 194385761
Test: atest DeviceIdleTest
Test: atest FrameworksMockingServicesTests:DeviceIdleControllerTest
Change-Id: I52b7ec6d993705ee605e3780a29a484c0d48e633
2021-08-16 08:49:37 -07:00
Chris Tate
e833132601 Merge "Consistent reporting of failure conditions" into sc-dev 2021-07-28 21:19:45 +00:00
Kweku Adams
0687577f87 Address sorting edge case.
There are times when the enqueue time of two different jobs are exactly
the same. In those cases, if an EJ skipped over one regular job with an
enqueue time X, then it should skip all other regular jobs with enqueue
time X.

Bug: 194324016
Test: atest FrameworksMockingServicesTests:JobSchedulerServiceTest
Test: atest CtsJobSchedulerTestCases
Change-Id: I77e106676238dd3ae198fab619af430e48d433a2
2021-07-27 10:38:28 -07:00
TreeHugger Robot
776fea73bb Merge "Don't crash apps due to race condition." into sc-dev 2021-07-23 04:04:35 +00:00
TreeHugger Robot
fd94d33a17 Merge "Logging the caller uid state with AlarmScheduled atom" into sc-dev 2021-07-23 01:11:41 +00:00
Kweku Adams
ec7103c614 Don't crash apps due to race condition.
When apps are stopped unnaturally (ie. because something stopped the job
and the job itself didn't call jobFinished or dequeueWork with no
remaining work) then we have the chance of small race conditions where
the job may try to complete its work. Since the race condition isn't
really the app's fault, we shouldn't punish the app for it.

Bug: 194358301
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: I3b0edd4f2241172fe97875eb8070cb5188027afb
2021-07-22 14:41:36 -07:00
Suprabh Shukla
ef2636a43a Logging the caller uid state with AlarmScheduled atom
Test: statsd_testdrive 368
Test: atest FrameworksMockingServicesTests:AlarmManagerServiceTest
Test: atest CtsAlarmManagerTestCases
Test: atest CtsStatsdAtomHostTestCases:AlarmStatsTests

Bug: 194249875
Change-Id: Ia55306b3a4839aadc4bc2fdd873878b1a4e591fb
2021-07-20 23:05:22 -07:00
TreeHugger Robot
5b6a2aff21 Merge "Stop removing all APP_STANDBY_BUCKET_CHANGED messages." into sc-dev 2021-07-20 23:34:59 +00:00
Kweku Adams
c2f4752a71 Merge "Fix parameter order." into sc-dev 2021-07-20 11:37:09 +00:00
Kweku Adams
63f5d4b699 Stop removing all APP_STANDBY_BUCKET_CHANGED messages.
APP_STANDBY_BUCKET_CHANGED messages are for single apps, so it doesn't
make sense to remove all messages whenever any app's standby bucket
changes.

Bug: 193918191
Test: N/A
Change-Id: I981cd3be3cd381c6d00f06e3da9f8e67f157a26b
Merged-In: I981cd3be3cd381c6d00f06e3da9f8e67f157a26b
2021-07-20 00:14:27 +00:00
Kweku Adams
dbf042c666 Fix parameter order.
AlarmManager.setWindow's parameter order is type -> window start ->
window length. Actually put the values in the correct order.

Bug: 193866265
Test: atest DeviceIdleTest
Test: atest FrameworksMockingServicesTests:DeviceIdleControllerTest
Change-Id: I5c87dad3015859d68aacb6781166432b615327b9
2021-07-19 16:26:54 -07:00
TreeHugger Robot
977e2adc14 Merge "Separating alarm history for lower quota" into sc-dev 2021-07-14 20:09:15 +00:00
Kweku Adams
b70c941f60 Restrict all jobs when the device is too hot.
Restrict all jobs (and not just connectivity jobs) when the thermal
status is SEVERE+.

Bug: 193269111
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: Id8eed849dfeb26aca1c0743af974c9efadf7fb78
2021-07-13 16:50:54 -07:00
Suprabh Shukla
4e05326a55 Separating alarm history for lower quota
Using a separate container for lower allow-while-idle quota to avoid out
of quota issues. Using the same container means that the lower quota is
out whenever higher quota is used for alarms from the same app.
Lower quota - currently once per 9 minutes - is used in the
following cases:
 - Inexact allow-while-idle alarms. This means the same app can use
 alarms using high quota and low quota simultaneously.
 - When the caller is targeting < S.
 - When the caller is in the power save allowlist, but does not have the
 permission - for exact alarms.

Test: atest CtsAlarmManagerTestCases
Test: atest FrameworkMockingServicesTests:com.android.server.alarm

Bug: 190788800
Change-Id: Iba46fdd36dc04843e9256827b0754d21cfff89c9
2021-07-13 16:19:23 -07:00
Christopher Tate
35f567467e Consistent reporting of failure conditions
Querying for the state of the exact-alarm permission produced
inconsistent results depending on circumstances.  This is now fixed so
the failure reporting is invariant.

Bug: 193032972
Test: manual
Test: atest CtsAlarmManagerTestCases
Change-Id: Ie1cc126cec568b6f53ebe6049e57ed13abdfd5bb
2021-07-13 13:08:54 -07:00
Eric Jeong
919b3ad3d8 Change the logic to check car idleness
- Following the change of device idleness checking, car idleness
tracker considers screen on to determine idleness.
- The condition to get idle in automotive is 1) garage mode is started,
or 2) screen is off and idle is triggered.
- If idleness is forced or garage mode is running, it is considered idle
by car idleness tracker, regardless of screen on/off.

Bug: 182492612
Test: atest android.jobscheduler.cts.IdleConstraintTest
Change-Id: I15e78157c6b1539086e9b39354e5da51186c6535
2021-06-30 15:57:58 -07:00
TreeHugger Robot
d1d3358be9 Merge "Allow power-allowlisted apps to schedule alarm-clocks" into sc-dev 2021-06-30 06:13:59 +00:00
TreeHugger Robot
12ded20343 Merge "Exempt default_input_method from BG-FGS-start restriction." into sc-dev 2021-06-30 03:03:32 +00:00
TreeHugger Robot
4260ce4100 Merge "Improve javadocs for repeating alarms" into sc-dev 2021-06-30 00:55:07 +00:00
Suprabh Shukla
94f5840bed Improve javadocs for repeating alarms
Specifically, mentioning that the alarm count can only be included with
the alarm if the supplied pending intent is mutable.

Test: make offline-sdk-docs

Fixes: 178413211
Change-Id: I2914bceebeed8b52b0de11d70960aa33e6837b13
2021-06-29 17:34:14 -07:00
Suprabh Shukla
96da2e8fae Allow power-allowlisted apps to schedule alarm-clocks
They can already use a lot of APIs to perform work in the background
and it simplifies the logic handling permission state changes and the
return value of canScheduleExactAlarms.

The major changes in behavior are:
1. Allowlisted apps can schedule unlimited alarm-clock alarms. This
should be the same as pre-S behavior.
2. If they happen to get the permission revoked, due to whatever reason:
user revocation, deny list, or app update, their alarm-clock alarms will
stay safe like their other exact alarms.
3. The API canScheduleExactAlarms is now true to its name: It returns
true even if the app is allowlisted.

Test: atest CtsAlarmManagerTestCases:ExactAlarmsTest
atest FrameworksMockingServicesTests:AlarmManagerServiceTest

BYPASS_INCLUSIVE_LANGUAGE_REASON=Existing APIs

Bug: 191716678
Bug: 190625528
Change-Id: I420694455f50aac10cf49cd43ff3b98575d86e9f
2021-06-29 15:32:29 -07:00
Hui Yu
20a8ef3c7f Exempt default_input_method from BG-FGS-start restriction.
Bug: 191702190
Test: atest android.app.cts.ActivityManagerFgsBgStartTest#testFgsStartInputMethod
Change-Id: I3bbe6da7afa8e3f2fce3a7c7d5bc40c3c7fd7758
2021-06-29 13:14:43 -07:00
Jing Ji
160fb766f1 Merge "Revert "Kill process if it's cached & idle and in forced-app-standby mode"" into sc-dev 2021-06-29 19:17:17 +00:00
Jing Ji
453601681d Revert "Kill process if it's cached & idle and in forced-app-standby mode"
This reverts commit 6cf25139a0c4625a753f84183c641e83e89ec8fb.

Reason for revert: It results in thrashing the system in some cases

Bug: 192082833
Bug: 152573287
Test: atest FrameworksMockingServicesTests
Test: atest FrameworksServicesTests
Change-Id: I0ca09655b7911857cded5da74169b0c3bd332bda
2021-06-28 16:30:33 -07:00
Kweku Adams
881da35724 Merge "Fix pending job sorting." into sc-dev 2021-06-28 16:29:42 +00:00
Kweku Adams
a309167072 Avoid unnecessary work.
Only requested-expedited-jobs could have their run-in-bg constraint
change (because of EJ quota) without a corresponding call coming through
the ForceAppStandbyListener. Restrict job evaluation to requested-EJ
jobs to avoid making unnecessary/redundant calls for regular jobs.

Bug: 192105110
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: I9acc45e109c32fb77c79df4fe126a9b1845163ff
2021-06-25 16:43:45 -07:00
Kweku Adams
2700aba1c5 Fix pending job sorting.
We want to always run an app's expedited jobs before its own regular
jobs. This means that we order an app's EJs before its regular jobs. In
order to satisfy the transitivity constraint, we must also order one
app's EJs ahead of a differing app's jobs iff we had to order the first
app's EJ ahead of a job that was earlier than the second app's jobs.

The current sorting system fails the transitivity requirement.

Test case: regJob1 enqueued at t1 for UID A, regJob2 enqueued at t2 for
UID B, EJ3 enqueued at t3 for UID A. Because we expedite EJs, EJ3 is
ordered before regJob1. Because we sort jobs of differing apps by enqueue
time, regJob1 comes before regJob2 and regJob2 comes before EJ3. This
violates transitivity.

The new sorting system will order a later EJ ahead of a differing app's
jobs iff the first app has a regular job that is earlier than the
differing app's first regular job.

Bug: 191592712
Test: atest FrameworksMockingServicesTests:JobSchedulerServiceTest
Test: atest CtsJobSchedulerTestCases
Change-Id: I5391a4f35269d7d43eefc1954788f9df160b1d22
2021-06-24 12:25:33 -07:00
TreeHugger Robot
41e40c69f2 Merge "Tighten up Doze alarm timing." into sc-dev 2021-06-22 22:53:03 +00:00
Suprabh Shukla
a7807022fe canScheduleExactAlarms returns true for older apps
Callers that don't target S can schedule exact alarms so should get a
return value of true when they call canScheduleExactAlarm.

Test: atest FrameworksMockingServicesTests:AlarmManagerServiceTest

Bug: 191328951
Change-Id: I1cd1d0fb3d3d922360494552e653ed540bfe5227
2021-06-21 18:09:35 -07:00
Kweku Adams
aa8f6da7d4 Merge "Allow bucket elevation for timed-out restricted apps." into sc-dev 2021-06-21 20:20:17 +00:00
Frank Li
2fcda2f9f4 Improve the net-capabilities scheme for backward compatibility
- Create a new XML tag for the new format. The new format should
  persist the arrays of values without assuming they necessarily
  have different bits.

- Upon reading, if the new tag is present, use that. If the new
  tag is not present but the old tag is present, then limit the
  contents to the capabilities/transports that existed in R.

- Catch all exceptions and ignore the requests if they can't be
  re-read from disk. This is a measure to avoid any mistake where
  the device couldn't boot when JS tries to restore state.

Bug: 183071974
Test: atest JobStoreTest
Original-Change: https://android-review.googlesource.com/1679762
Merged-In: I56cde50d2adab81134c8be4f6996d68018f4212a
Change-Id: I56cde50d2adab81134c8be4f6996d68018f4212a
2021-06-17 13:44:17 +00:00
Kweku Adams
bcea3814fd Tighten up Doze alarm timing.
Set explicit alarm window sizes so we can control the maximum alarm
delay for Doze alarms.

Bug: 187947479
Bug: 188468510
Test: atest DeviceIdleTest
Test: atest FrameworksMockingServicesTests:DeviceIdleControllerTest
Change-Id: I40c0e1a0fce18886ea817245d9a064a509eb6e08
2021-06-16 16:54:18 -07:00
Kweku Adams
183ec609e8 Allow bucket elevation for timed-out restricted apps.
Ensure SYSTEM_INTERACTION can bring an app out of the RESTRICTED bucket
(temporarily) if the app is only in the bucket due to timeout.

Bug: 191297958
Test: atest AppStandbyControllerTests
Change-Id: Ie76d224710228a8654d4d57ee0c73bb9441ef28f
2021-06-16 15:39:20 -07:00
TreeHugger Robot
916a356f71 Merge "Exempt some callers from min-window restrictions" into sc-dev 2021-06-16 20:30:44 +00:00
Suprabh Shukla
980954b86c Exempt some callers from min-window restrictions
Callers that have power exemption should be allowed to set smaller
windows for their alarms.

Test: atest FrameworksMockingServicesTests:AlarmManagerServiceTest

Bug: 185199076
Change-Id: I5f6515a917da7f87891f79fb637d48a3d7862a1b
2021-06-15 17:50:04 -07:00
TreeHugger Robot
f797f40bcc Merge "Update AlarmManager javadoc for S Beta 3" into sc-dev 2021-06-15 00:31:25 +00:00
Makoto Onuki
44fba3a53f Update AlarmManager javadoc for S Beta 3
Sample partial output: https://screenshot.googleplex.com/4wey3a3y3jsoGcP

Bug: 190625528
Test: build
Test: m offline-sdk-docs && \
  cd /android/sc-dev/out/target/common/docs/offline-sdk/ && \
  python3 -m http.server 8000 && \
  google-chrome http://localhost:8000/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)
Change-Id: Ie106b03a1c20fa62b0023f82d2c3997b4e425d95
2021-06-14 15:44:04 -07:00
TreeHugger Robot
cd140900ed Merge "Handle exact alarm permission state changes" into sc-dev 2021-06-14 21:43:49 +00:00
Suprabh Shukla
c3f067c103 Handle exact alarm permission state changes
The permission SCHEDULE_EXACT_ALARM state changes at the following
boundaries:
 1. App-op: This gets toggled by the user via Settings.
 2. Deny-list: Packages can be added to the deny list via DeviceConfig
 APIs.
 3. Package changes: A package's manifest may changes when it gets
 updated.

In both cases 1 and 2, if alarm manager detects a permission change
from revoked to granted, it sends the
ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED broadcast to the
app.
If it detects a permission change from granted to revoked, it kills
all the processes within the hosting uid.
In all three cases, when the permssion changes from granted to revoked,
all the exact alarms scheduled by the relevant package are removed.
Package updates are treated differently as they require processes to
restart anyway. The broadcast is not needed in this case as there
are no alarms expected to have been lost by a previous revocation, and
apps can always use ACTION_MY_PACKAGE_REPLACED for post-update setup as
usual.

All this only applies to packages that have the change
REQUIRE_EXACT_ALARM_PERMISSION enabled.

Also changed canScheduleExactAlarms to return false if the change is not
enabled for the calling package.

Test: atest FrameworksMockingServicesTests:AlarmManagerServiceTest
atest CtsAlarmManagerTestCases

Bug: 179541791
Bug: 187206399
Change-Id: Icd68275701f2804be65b3a10a7dd81bbf6e2a0bb
2021-06-13 16:55:21 -07:00
Sudheer Shanka
724c2aa056 Propagate the temp allowlist reason to NPMS.
Bug: 189291729
Test: atest ./tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
BYPASS_INCLUSIVE_LANGUAGE_REASON=Existing public API
Change-Id: I7e26eaef4fe9d7d7b4b3a1740608e0fe821537d2
2021-06-09 18:03:57 +00:00
TreeHugger Robot
e487bd115f Merge "cmd deviceidle tempwhitelist -r should clear FGS tempallowlist too" into sc-dev 2021-05-26 22:28:50 +00:00
TreeHugger Robot
3d9400e2dc Merge "Turn off device-idle alarm history" into sc-dev 2021-05-26 21:03:42 +00:00
Suprabh Shukla
18cdcb663e Merge "Unlink listener death recipient on alarms" into sc-dev 2021-05-26 20:52:55 +00:00