196 Commits

Author SHA1 Message Date
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
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
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
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
Kweku Adams
093a6dc517 Run "insane" network jobs when charging + unmetered.
When we're charging and on an unmetered network, run jobs that we
calcluate won't complete within the max execution time due to the
network speed, just so they have a chance of running.

Also update documentation to guide to only providing size of
non-interruptible transfers.

Bug: 188429037
Test: Run `m offline-sdk-docs` and check site at out/target/common/docs/offline-sdk/reference/android/app/job/JobInfo.html
Test: atest FrameworksMockingServicesTests:ConnectivityControllerTest
Change-Id: Ic69e85a7e0eae51b3dd3ea89bd00255a734c1472
2021-05-26 11:29:51 -07:00
TreeHugger Robot
60b32709f0 Merge "Relaxing minimum alarm window requirements" into sc-dev 2021-05-14 21:15:53 +00:00
Suprabh Shukla
0d3bf483bc Relaxing minimum alarm window requirements
Minimum allowed window is now a function of the futurity of the alarm.
So for alarms in the near future, it is smaller and it increases as time
to alarm increases maxing out at 10 minutes.

Test: atest AlarmManagerServiceTest

Bug: 185199076
Change-Id: I57f275adab7f9bcc7f0f7535bb810aa9b359287b
2021-05-13 22:25:16 -07:00
Makoto Onuki
1cd708bb0b Clarify the semantics of ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED
Bug: 187206399
Test: build
Change-Id: Ibe450f0d7c29ada5848508b6ac6a585bfabad72b
2021-05-12 09:53:15 -07:00
Makoto Onuki
987f904072 Merge "Implement requestForegroundServiceExemption, without enabling it" into sc-dev 2021-05-11 15:55:14 +00:00
Makoto Onuki
26f28d4a29 Merge "Send a broadcast when an app is granted SCHEDULE_EXACT_ALARM" into sc-dev 2021-05-10 22:14:48 +00:00
Makoto Onuki
619c5a46d8 Implement requestForegroundServiceExemption, without enabling it
Bug: 187429663
Test: Checked ApplicationInfo.hasRequestForegroundServiceExemption()
  of a test app, with and without the new attribute set.

Change-Id: I98342a35a82e44327db896c9820806eb3eda5b4c
2021-05-10 11:50:32 -07:00
Makoto Onuki
306ed287f4 Send a broadcast when an app is granted SCHEDULE_EXACT_ALARM
Bug: 187206399
Test: atest AlarmManagerServiceTest
Test: Manual test with a test app.
- Grant the permission to test app and make sure it can start FGS.
Log:
```
05-07 10:12:08.671  1000  1579  9475 I ActivityManager: Background started FGS: Allowed [callingPackage: com.google.omakoto.testapp; callingUid: 10294; uidState: RCVR; intent: Intent { act=fgs cmp=com.google.omakoto.testapp/.MyFgs }; code:(unknown:207); tempAllowListReason:<broadcast:1000:android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED,reason:,reasonCode:(unknown:207),duration:10000,callingUid:1000>; targetSdkVersion:30; callerTargetSdkVersion:30; startForegroundCount:0]
```
- Grant the permission to a different app and make sure the test app
  won't receive the broadcast.

Test: CTS -- Incoming

Change-Id: Iefe3e12dcf51318d8433532ba3048caa69b1edcd
2021-05-07 17:34:12 -07:00
Jing Ji
6cf25139a0 Kill process if it's cached & idle and in forced-app-standby mode
This behavior could be turned OFF via the flag kill_fas_cached_idle
in device_config.

Bug: 152573287
Test: atest FrameworksServicesTests:ActivityManagerTest
Test: atest FrameworksMockingServicesTests:AppStateTrackerTest
Change-Id: Ifa6950582fbf6a24595b36163810f3c7e9345394
2021-05-07 14:27:30 -07:00
Hui Yu
32bf836de3 Merge "Exempt some broadcasts from FGS start restriction." into sc-dev 2021-05-06 03:33:18 +00:00
Hui Yu
0daa76ed40 Exempt some broadcasts from FGS start restriction.
1. Exempt broadcasts ACTION_TIMEZONE_CHANGED, ACTION_TIME_CHANGED, ACTION_LOCALE_CHANGED
from FGS start restriction.
2. Add test case AlarmManagerServiceTest#setTimeZoneImpl.

Bug: 184111171
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/alarm/AlarmManagerServiceTest.java
Change-Id: I80ce830d1bd98d69f35fdc6bcc041de173083fba
2021-05-05 14:33:35 -07:00
Kweku Adams
0ec65b00b6 Merge "Fix EJ syncs." into sc-dev 2021-05-04 23:05:21 +00:00
Kweku Adams
d23ce9610b Fix EJ syncs.
1. Only downgrade an EJ that doesn't have the IGNORE_BACKOFF extra when
   we are actually attempting to back off the job.
2. Allow EJs to have the FLAG_EXEMPT_FROM_APP_STANDBY flag since that
   can only be set by the system and won't cause issues.

Also propagate the scheduleEjAsRegularJob bit through the job extras to
help with debugging.

Bug: 178852366
Test: atest ContentResolverTest (all)
Test: atest CtsJobSchedulerTestCases:JobInfoTest
Test: atest CtsSyncManagerTest
Test: atest SyncOperationTest
Test: atest SyncManagerTest
Test: atest SyncRequestTest
Change-Id: I133d089a4d770a3cc37df72f8b38d234b24077df
2021-05-04 14:37:02 -07:00
Kweku Adams
9c3d74f7e0 Merge "Expand JS documentation." into sc-dev 2021-04-30 16:10:42 +00:00
Hui Yu
a6b92260d3 Do not allow FGS start when temp allowlist reasonCode is REASON_PUSH_MESSAGING_OVER_QUOTA
If temp allowlist reasonCode is REASON_PUSH_MESSAGING_OVER_QUOTA, check
DeviceConfig key "push_messaging_over_quota_behavior" to decide if
temp allowlist and FGS start are allowed. Three options:
1. -1, temp allowlist not allowed, FGS start not allowed.
2. 0, temp allowlist allowed, FGS start allowed.
3. 1, temp allowlist allowed, FGS start not allowed. This is default.

The device config command to change the behavior:
adb shell device_config set activity_manager push_messaging_over_quota_behavior <-1|0|1>

If temp allowlist reasonCode is REASON_DENIED, do not allow temp allowlist
at all.

Also, in DeviceIdleController.addPowerSaveTempAllowlistAppInternal(),
there used to be a check if the callingUid is on the mPowerSaveWhitelistSystemAppIds list,
this is unnecessary because upstream callers already checked if callingUid has
 permission CHANGE_DEVICE_IDLE_TEMP_WHITELIST, and this permission is a privileged permission,
so removing the check of mPowerSaveWhitelistSystemAppIds should be safe.

Bug: 182796372
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java#testPushMessagingOverQuota
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java#testTempAllowListReasonCode

Change-Id: Id34b1c26c819dc4fe07838eb2e3a8f0138cbcf8f
2021-04-29 16:27:41 -07:00
Kweku Adams
fbab1fcc18 Expand JS documentation.
1. Make it clear that "minimum latency" != "run ASAP after latency"
2. Note that deadline constraints are dropped from rescheduled jobs
3. Clarify that jobFinished does not need to be called if onStopJob is called

Bug: 19536175
Test: Run `m offline-sdk-docs` and check site at out/target/common/docs/offline-sdk/reference/android/app/job/JobInfo.html
Change-Id: I051feb0ebfcb0a24c452a38b91a751bbeef581f8
2021-04-29 17:47:49 +00:00
Kweku Adams
c49760fc63 Merge "Updating proto enums." into sc-dev 2021-04-28 16:09:35 +00:00
Kweku Adams
88cf226a2d Merge "Remove isForegroundJob." into sc-dev 2021-04-28 16:08:38 +00:00
Kweku Adams
b2fa0cabc1 Note that user engagement replenishes EJ quota.
Make sure developers are aware that user interaction will replenish EJ
quota so they are less concerned about running out of quota for valid
use cases.

Bug: 171305774
Test: N/A
Change-Id: Iec231522dbc7fe83c65956b59ca3e4fbda072b97
2021-04-27 17:10:55 -07:00
Kweku Adams
01319777d1 Remove isForegroundJob.
This was supposed to be removed at the same we removed the related APIs
in JobInfo.Builder. It's not being used by anyone.

Bug: 186475837
Test: Android builds
Change-Id: Ib57029b7ba7e0c7b3f5bd36ba29a96e89eefb270
2021-04-27 09:46:48 -07:00
Hui Yu
9757955874 Merge "Temp allowlist bluetooth broadcast to start FGS for 10 seconds." into sc-dev 2021-04-22 23:41:30 +00:00
Kweku Adams
574b4199a1 Updating proto enums.
Updating proto enums to differentiate between the internal job stop
reasons and the public stop reasons.

Bug: 138239687
Bug: 171305774
Test: make statsd_testdrive && ./out/host/linux-x86/bin/statsd_testdrive 8
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Test: atest ContentResolverTest (all)
Test: atest CtsJobSchedulerTestCases
Test: atest CtsSyncManagerTest
Test: atest SyncManagerTest
Test: atest SyncOperationTest
Test: atest SyncRequestTest
Change-Id: I8d51c4dfb57d52e9c507437107afbad48cc9cecd
2021-04-22 09:34:41 -07:00
Kweku Adams
6decc507bf Expand internal stop reasons.
Add explicit reasons for when a job is stopped because the real-time
clock was updated and for when a job called jobFinished() on its own
(...why did we not have this to begin with???).

Bug: 141645789
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Test: atest ContentResolverTest (all)
Test: atest CtsJobSchedulerTestCases
Test: atest CtsSyncManagerTest
Test: atest SyncManagerTest
Test: atest SyncOperationTest
Test: atest SyncRequestTest
Change-Id: I61392c55355d2526a32ea9597a0010b04f3875ac
2021-04-22 07:59:29 -07:00
Kweku Adams
805535cc55 Rename "legacy" stop reasons.
There are some uses for the "legacy" stop reasons that the public API
stop reasons can't cover well. Since we'll be keeping the "legacy"
reasons around, renaming them to "internal" to help explain the
differentiation.

Bug: 141645789
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Test: atest ContentResolverTest (all)
Test: atest CtsJobSchedulerTestCases
Test: atest CtsSyncManagerTest
Test: atest SyncManagerTest
Test: atest SyncOperationTest
Test: atest SyncRequestTest
Change-Id: I97e40d35b79dbd012216bc22e90d649639614854
2021-04-22 07:56:48 -07:00
Hui Yu
8c23d658c7 Temp allowlist bluetooth broadcast to start FGS for 10 seconds.
Add an overloaded version of Context.sendBroadcastMultiplePermissions() that can
specify BroadcastOptions, it is called by com.android.bluetooth package.

Bug: 182816627
Test: atest AdapterServiceTest
Test: atest AvrcpControllerStateMachineTest
Test: atest BondStateMachineTest
Test: atest MapClientStateMachineTest
Test: atest RemoteDevicesTest

Change-Id: I8bb2d2ed98ece70ebbe9d3a1b549b966d690de4f
2021-04-21 16:48:04 -07:00
Hui Yu
fae5e14059 Merge "Allow FGS started from MediaButtonReceiver to have while-in-use permissions." into sc-dev 2021-04-20 17:04:09 +00:00
Suprabh Shukla
03ade18672 A WorkSource version of AlarmManager#setExact
Inexact alarms will have a minimum length window enforced starting with
API S, so we need a clearer separate system API for apps that set alarms
on behalf of others.

Test: atest CtsAlarmManagerTestCases:BasicApiTests

Bug: 185530825
Change-Id: Ica8399b21421572e30a554f9897a352ce5fff557
2021-04-19 23:18:36 +00:00
Hui Yu
36429f87de Allow FGS started from MediaButtonReceiver to have while-in-use
permissions.

1. Create a generic FgsTempAllowList class, mFgsStartTempAllowList and
 mFgsWhileInUseTempAllowList are instantiated from FgsTempAllowList.
2. For mFgsWhileInUseTempAllowList, the uid on this list is allowed to
have while-in-use permission when the FGS is started from background for
a duration of time.
3. When media button is pressed, the targetUid is added to
mFgsWhileInUseTempAllowList, for the duration of 10 seconds, this way the
targetUid can start FGS from background and have while-in-use permission.
4. When checking for ProcessRecord.
mAllowBackgroundActivityStartsTokens, it is the caller app's
ProcessRecord should be checked instead of the service's ProcessRecord.

Bug: 182481312
Test: use b/167998084 reproduce steps, make a voip call, the
 receiver side screen is unlocked, the receiver side uses bluetooth
headset button to pick up the call, "dumpsys activity -a" shows the FGS
has "allowWhileInUsePermissionInFgs=true" and "isForeground=true".

Change-Id: Ic80aefe4202fe2210881bb8eea24b6e34cb1e7d0
2021-04-19 10:34:28 -07:00
Soonil Nagarkar
1bc2da8435 Make LocationProvider exemption SystemApi
LocationProviders can be defined outside the system server, and still
need access to this API.

Bug: 185505208
Test: presubmits
Change-Id: If50a200f8cb4c30fb3fff741b1751278aa4eb293
2021-04-15 13:01:19 -07:00
Suprabh Shukla
2d736276a9 Enforcing a minimum window on inexact alarms
Any non-exact alarms with window > 0, should have a specific minimum
window length. Otherwise, very small windows, say 1ms, are pratically
indistinguishable from exact alarms.

Test: atest FrameworksMockingServicesTests:com.android.server.alarm

Bug: 185199076
Bug: 185199018
Change-Id: Idf933b70a66f2a749cdb2689ab68a80204d212b1
2021-04-14 15:48:46 -07:00
Makoto Onuki
2ac94cb7a2 Remove the FGS exemption list
Fix: 176844961
Test: Build / Boot
Change-Id: I546ceebb64e05739577ed288e9603f0636c6aaff
2021-04-12 11:43:13 -07:00
Suprabh Shukla
38d5d66c80 More changes for the exact alarm permission
Adding a deny list option, which changes the default grant state of the
permission to denied. This means now alarm manager is the source of
truth of the permission state and exposes an API that clients like
Settings should call.
Also using the same API to cap the minimum standby-bucket
for apps with this permission to WORKING_SET.

Adding an app to the deny list may mean revocation of its permission, in
which case its exact alarms will be removed.
Meanwhile, performed some long needed refactoring on the remove methods,
so they re-use common code and are easier to maintain.

Also, changing strings for the Settings UI to be clearer.

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

Bug: 171306433
Bug: 130444055
Bug: 181894091
Bug: 181152252
Change-Id: I9410f988343800b7322963fecf3eafac9561b093
2021-04-08 14:15:28 -07:00
Suprabh Shukla
cebea4ced8 Merge "Adding a shell command to AlarmManager" into sc-dev 2021-04-08 02:24:38 +00:00
Suprabh Shukla
98b41398e7 Adding a shell command to AlarmManager
Adding a command to get the config version number which is incremented
everytime onPropertiesChanged is called. This is useful in waiting till
a change has been propagated to the service before proceeding with
tests.

Test: adb shell dumpsys alarm
adb shell cmd alarm get-config-version

Bug: 182835530
Change-Id: I171578255d4b69e75f535fd44ab0f5f462ea8d0b
2021-04-08 02:24:13 +00:00
Kweku Adams
36bd8292c3 Better handle uninstall cases.
1. Processes may not have been fully terminated by the time
   PackageManager broadcasts PACKAGE_FULLY_REMOVED (see b/165012101
   and b/162757029), so note that in the comments.
2. Use ACTION_PACKAGE_FULLY_REMOVED instead of ACTION_PACKAGE_REMOVED to
   avoid processing update broadcasts.
3. Make sure we don't attempt to reschedule or reprocess jobs of
   uninstalled apps.

Bug: 184098842
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/job
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/job
Test: atest CtsJobSchedulerTestCases
Change-Id: I355786885fcc8eccd31c5557b35de3e5243615d8
2021-04-06 10:36:05 -07:00
Hui Yu
8d599ec08e Merge "Exempt VPN apps from BG-FGS-launch restriction." into sc-dev 2021-04-01 16:41:40 +00:00
Hui Yu
0e0d89c2fa Exempt VPN apps from BG-FGS-launch restriction.
Exempt apps with OP_ACTIVATE_VPN or OP_ACTIVATE_PLATFORM_VPN.

Bug: 182502553.
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java#testFgsStartVpn

Change-Id: I0590a0b69a3081fdcd2c9aefe9c00e0e84d41740
2021-03-31 00:44:19 +00:00
Makoto Onuki
d0b0f4ce83 Merge "Add TEMPORARY_ALLOW_LIST_TYPE_NONE." into sc-dev 2021-03-29 21:32:40 +00:00
Varun Shah
d6494b1cce Add TEMPORARY_ALLOW_LIST_TYPE_NONE.
Also replace all usages of TempAllowListType defined in
PowerWhitelistManager with the newly added reference in
PowerExemptionManager.

Fixes: 183053095
Test: atest ActivityManagerFgsBgStartTest#testTempAllowListType
Test: atest PowerExemptionTest
Test: atest BroadcastOptionsTest
Change-Id: I2f47ca99d4dfa8f267bb029d2934f0f765b0c594
2021-03-25 11:15:56 -07:00
Varun Shah
8481c3ae9d Merge "Hide permanent allow list methods." into sc-dev 2021-03-25 17:20:27 +00:00
Remi NGUYEN VAN
40b4495f8e Merge "Use connectivity APIs from framework-connectivity" into sc-dev 2021-03-25 14:51:55 +00:00