Commit Graph

183 Commits

Author SHA1 Message Date
TreeHugger Robot
a2fe748e7a Merge "Duration format for tunable settings" 2018-01-09 03:19:03 +00:00
Jeff Sharkey
9f2dc0527e Add DataUnit to clarify SI-vs-IEC units.
Mirrors the design of TimeUnit and ChronoUnit which many developers
are already familiar with, making it easy to pick up and use.

Yes, this is an enum.

Bug: 70915728
Test: bit FrameworksCoreTests:android.util.DataUnitTest
Change-Id: Id0cfdac5c81ed89c3c9ece23c964acba4a4f8471
2018-01-07 19:06:01 -07:00
Amith Yamasani
761d3ff06c Duration format for tunable settings
For JobScheduler, DeviceIdle and AppStandby constants, allow
using a more compact format than milliseconds,
which are a PITA to calculate.

So instead of 18640000000... whatever, you can
use PT2H (for 2 hours), or P2D (for 2 days), etc.
Uses Duration.parse() to do the parsing. See Duration
for format.

Test: adb shell settings put global app_standby_constants
      screen_thresholds=0/PT2H/PT12H/P2D
Fixes: 71554131
Change-Id: I5141854ec7df6de266725a67f1f3e2a6e0b4c1c1
2018-01-04 09:37:13 -08:00
Esteban Talavera
e51ffaa6ac Merge "Fix usagestats DUMP OF SERVICE" 2017-12-19 17:46:06 +00:00
Esteban Talavera
838ea24493 Fix usagestats DUMP OF SERVICE
DUMP OF SERVICE Usagestats was empty in bugreports
because an unexpected -a argument was being passed.
adb shell pm dump <package> had a similar issue with --packages

Change-Id: Ic67c723b8edc74ec7c9c48582b08896ca3430a4a
Fix: 70777338
Test: adb shell pm dump <package> and bugreports now contain usage stats
2017-12-19 15:23:43 +00:00
Amith Yamasani
172612c891 Global app standby flag
Disable app standby features if app_standby_enabled
is set to 0. This allows for UI and experiments to
control the feature.

Bug: 70655630
Test: adb shell settings put global app_standby_enabled 0
      adb shell dumpsys usagestats
      adb shell am get-standby-bucket <packagename>

Change-Id: Id6c62b078e52040767100f2997832cc586bb0806
2017-12-16 07:13:53 -08:00
Amith Yamasani
9388519d5e Don't allow certain bucket overrides
Don't allow EXEMPT to be overridden
Differentiate between shell and other callers who set
buckets.
Don't allow forced to be modified by bucketeer.
Don't allow bucketeer to modify NEVER bucket.

Fix a locking issue in listeners list. Don't use
the primary lock when calling out to listeners.

Fixes: 70622791
Fixes: 70622338

Test: atest FrameworksServicesTests:AppIdleHistoryTests
      atest FrameworksServicesTests:AppStandbyControllerTests
      atest CtsAppUsageHostTestCases
Change-Id: I22309478b947d6461235f5a77e08c7be86309e4b
2017-12-14 20:21:32 +00:00
Jeff Sharkey
6cff5c2840 Merge "API that reports first SDK level of the device." 2017-12-13 16:53:55 +00:00
Jeff Sharkey
28c660f11a API that reports first SDK level of the device.
This is different from SDK_INT, which can change due to OTA
software updates.

Test: cts-tradefed run commandAndExit cts-dev -m CtsOsTestCases -t android.os.cts.BuildTest
Bug: 69270887
Change-Id: Ic3f4b22b25dc08f3fbdbdf7622c953323447ea01
2017-12-12 14:11:14 -07:00
Amith Yamasani
e878931414 Allow multiple standby buckets to be set in one IPC
SystemApi to pass a map of packagename to bucket mapping.
Reduces the number of IPC calls to be made by bucketing
ML app.

Bug: 63527785
Test: atest CtsAppUsageHostTestCases
Change-Id: I4172fd30cc310092a1f182ae26267de9148009b7
2017-12-10 18:52:20 -08:00
TreeHugger Robot
e2fa77ab4d Merge "Timeout app predictions after 12 hours" 2017-12-08 23:27:11 +00:00
Amith Yamasani
bd7b302f91 Timeout app predictions after 12 hours
Ignore predicted bucket if it's been too long since the
last update, and use internal timeout logic to set
standby buckets.

Keep track of last predicted time and persist it.

Bug: 70219058
Test: atest FrameworksServicesTests:AppStandbyControllerTests

Change-Id: Ib2992201d204b92fdd4a0a00754d81e7bbfc292f
2017-12-08 13:46:17 -08:00
TreeHugger Robot
1b09d2ff8b Merge "Increase history of UsageEvents" 2017-12-08 13:16:43 +00:00
Amith Yamasani
5a8cc72386 Fix CTS tests failing due to job throttling
Instrumentation package should be immediately marked as active so
that the jobs aren't throttled.

Also, make sure special apps' buckets are correctly initialized.

Fixes: 68900608
Fixes: 69799327
Fixes: 69793822
Fixes: 69788489

Test: atest CtsNetSecPolicyUsesCleartextTrafficTrueTestCases
      atest FrameworksServicesTests:AppIdleHistoryTests
      atest FrameworksServicesTests:AppStandbyControllerTests
      atest CtsNetSecPolicyUsesCleartextTrafficUnspecifiedTestCases
      atest CtsNetSecConfigDownloadManagerTestCases
      atest CtsNetSecPolicyUsesCleartextTrafficFalseTestCases
      cts-tradefed run cts-dev -m CtsAppUsageHostTestCases
      cts-tradefed run cts-dev -m CtsHostsideNetworkTests
      gts-tradefed run gts-dev -m GtsUsageStatsTestCases

Change-Id: Ic880b6f5ed1fdb7912613e882ccf7b2d4e388159
2017-12-06 10:26:10 -08:00
Amith Yamasani
22af6c7e98 Allow privileged apps to query standby state
Only check for INTERACT_ACROSS_USERS in getAppStandbyBucket()

Bug: 70126098
Test: gts-tradefed run gts-dev -m GtsUsageStatsTestCases
Change-Id: I6c3f69ff56d8513f84c7d91162567d17c06980c3
2017-12-03 20:16:15 -08:00
Amith Yamasani
afbccb7d37 Expose App Standby APIs for apps and system
Allow apps to query their own standby bucket.
Allow privileged apps with PACKAGE_USAGE_STATS permission to
query apps.
Allow privileged apps with CHANGE_APP_IDLE_STATE to set the
standby state for apps, but not for themselves.
Removed AppStandby class and moved constants into UsageStatsManager.

Bug: 63527785
Test: cts-tradefed run cts-dev -m CtsAppUsageHostTestCases
Change-Id: I3c1c20f6ecb6d54e248233696039286b243d663c
2017-12-01 14:00:37 -08:00
Esteban Talavera
bb6b748ea3 Increase history of UsageEvents
We need over 8 days of UsageEvents in order to capture weekly
patterns in our app usage models

Change-Id: I8e1149b82cfbaedae4d19bbbfaeffa989bfd54e7
Fix: 69244223
Test: It builds
2017-12-01 13:11:34 +00:00
Christopher Tate
a732f014c5 The job scheduler now backs off jobs based on standby bucketing
The default parameters here translate to roughly this rate limiting:

  ACTIVE:   run jobs whenever
  WORKING:  ~ hourly
  FREQUENT: ~ every 6 hours
  RARE:     ~ daily

Bug: 63527785
Test: cts & manual (WIP)
      atest CtsJobSchedulerTestCases
Change-Id: I58f8e53e5bdf40601823e5a10a9f2383a6f67ae5
2017-11-22 22:07:06 +00:00
Amith Yamasani
a0ef1ca2b2 Cleanup old idle variables
Switch to using the new bucket thresholds and
remove the previous idle thresholds.

Bug: 63527785
Test: atest AppStandbyControllerTests
      atest AppIdleHistoryTests

Change-Id: Ica3fd10fe172faa5b4e712b08273b77357fdae14
2017-11-20 09:43:56 -08:00
Amith Yamasani
301e94a9ef Shorter thresholds for app standby
Start off with slightly more aggressive timeouts to
switch between buckets. 12Hrs, 24Hrs and 48Hrs.

Bug: 63527785
Test: atest AppStandbyControllerTests
Change-Id: I4aa0cc38ef91538192eda0f48dd3840217aa49c4
2017-11-17 16:35:44 -08:00
Amith Yamasani
803eab6906 Add a new usage event type for seen notification
On a notification becoming visible, NOTIFICATION_SEEN event is
dispatched. This will only bump up the app's bucket to WORKING_SET and
no higher. Same goes for sync adapters associated with a content
provider. Only move them to WORKING_SET.

Updated NotificationManagerService to report event to usagestats on
visibility changes.

Bug: 63527785
Test: runtest -x
frameworks/base/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
atest NotificationManagerServiceTest
Change-Id: I5b132e1fc1f70e2126473b43b9b1979fbc523b85
2017-11-16 09:15:03 -08:00
Amith Yamasani
84cd7b7a9e Allow standby timeouts to occur after usage
And inform listeners when the bucket changes, not just when
going in and out of RARE bucket.
Avoid redundant callbacks when informing listeners.

Bug: 63527785
Test: runtest -x
frameworks/base/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
Change-Id: Icd98d59f597147fbf8ea4bf44edf4b3b3d5c8e14
2017-11-08 15:06:10 -08:00
Dianne Hackborn
c81983a0c3 Start removing remaining pm code to package manager
Everything is now moved out of the pm command except for
the various install commands.  I am going to hold of on
those since they require doing some resolution with the
current implementations in the package manager to make
sure they match and behave identically to the implementations
currently in the pm command.  But other than that, everything
in pm is now just redirecting over to "cmd package".

Also fix up some of the dumpsys output of a few other sevices
when asking to print the data for a particular package, so
the "pm dump" command gives a little more sane result.

Test: manual

Change-Id: I139e06e560203b72243d7eea9543c2240db0f8f8
2017-10-25 12:19:26 -07:00
Amith Yamasani
17fffee490 App Bucketing for Standby
Manage the standby bucket in AppStandbyController

Default implementation of bucketing based on simple timeout:
 ACTIVE, if recently used
 12 hrs to move to WORKING_SET
 2 days to move to FREQUENT
 7 days to move to RARE
 (subject to change)

RARE bucket equates to the old "idle" or "inactive" state for
an app.

Bug: 63527785
Test: AppStandbyControllerTests.java
Change-Id: I970d7afcdf47c31a9413da8fd4852066a13676a2
2017-10-24 19:24:15 -07:00
Amith Yamasani
7e528f3fda Refactor App Standby code
Move the App Standby code out of UsageStatsService into
an AppStandbyController class. This doesn't change any
behavior. Also, it doesn't change the entry points, which
are still in UsageStatsManager. The binder APIs are still
in UsageStatsService and are forwarded to
AppStandbyController.

This change is in preparation for switching to app standby
buckets instead of a boolean state.

Bug: 63527785
Test: adb shell dumpsys usagestats
      adb shell am set-inactive <packagename> true
      // Ensure state changes are persisted

Change-Id: Ic94357bdc891d1defae37bb29d533b6153a09967
2017-10-05 17:30:37 -07:00
Dianne Hackborn
3e99f654fb Fix issue #34471029: Don't allow audio use from background apps.
This is becoming a common pattern (keeping track of which processes
are cached and not allowing them to do stuff in that state), so I
am turning this in to a general mechanism for monitoring this state
through the activity manager's IUidObserver.  Now we can just have
AudoService implement its own IUidObserver to get this state and
update which uids it is blocking.

This required making some changes to uid change reports so that
the integer is now a bit mask instead of an enumerations, but that
is what it was already turning in to anyway.  (This gets rid of
the crazy GONE_IDLE constant that we'd needed to add before because
it wasn't a bit mask).

Eventually the power manager should be changed to be told about
these changes to cached state instead of listening to every proc
state change, but we'll do that later, it is more disruption than
I want to take for now.  However, while working on this, I noticed
that the power manager had regressed in the cached uids it would
actually block, because the activity manager was no longer telling
it about all uids that are idle.  (I think this happened when I had
to change the default idle state of UidRecord to true.)  So I am
adding a bit of new code to keep track of what idle state we last
reported to observers, to make sure we tell it about newly created
uids that are idle but have never actually become active.

Test: runtest -c com.android.server.am.ActivityManagerServiceTest frameworks-services

Change-Id: I7bfd46bacadd4cab2a69f40e6e52afb4e67b456a
2017-07-10 17:24:20 +01:00
Jeff Sharkey
c8b29ac6f0 Change storage migration to use quota APIs.
New quota APIs are much faster than trying to measure manually, and
removing this last user of calculateDirectorySize() means we can
remove it once and for all.

Bug: 36056324
Test: builds, boots
Change-Id: Ibdf1ee4e8885680e106df6a9269b6309ddc61af8
2017-07-06 11:29:10 -06:00
Jeff Sharkey
35e46d2972 Active camera apps can defy reserved cache space.
We normally prevent apps from allocating into the "reserved" cache
space, but this change makes an exception for an active camera app,
since the user is probably trying to capture an important memory.

This change only lets the active camera app clear up to half of the
reserved space, since we don't want to completely destroy the
experience of all other apps.

Test: manual app before/during/after active camera session
Bug: 38267830
Change-Id: Ie9e63884fb2638ca881e10b894629eea84601648
2017-06-12 14:27:23 -06:00
Jeff Sharkey
ddff807b76 Consistent "low storage" behavior.
When answering the question "how much space is free", use the same
logic for Settings UI and StorageManager.getAllocatableBytes().  That
is, the reported free space is usable bytes plus any cached data the
system is willing to delete automatically.

This does *not* include any reserved cache space, since we don't want
abusive apps to penalize other well-behaved apps that are storing
their data in cache locations.  Callers freeing cached data need to
now explicitly request defiance of the reserved cache space.  (Most
callers are already doing this by using FLAG_ALLOCATE_AGGRESSIVE.)

Rewrite the core logic of DeviceStorageMonitorService to understand
this new "reserved" cache space, and to be easier to understand.  It
also now handles cached data on adopted storage volumes, which had
been ignored until now.  Also fix bug where we had skipped "low"
broadcasts when the device skipped directly from/to "full" state.

Bug: 38008706
Test: cts-tradefed run commandAndExit cts-dev -m CtsJobSchedulerTestCases -t android.jobscheduler.cts.StorageConstraintTest
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Change-Id: Icbdcf3b52775f7ada1ceaeff2f96094c8d8052f9
2017-05-30 22:17:23 -06:00
TreeHugger Robot
1de10d6602 Merge "System installed launcher can see instant apps" into oc-dev 2017-05-24 20:38:56 +00:00
Todd Kennedy
3051caac52 System installed launcher can see instant apps
Change-Id: I97f791b61f9b4f7ed33305345bf3d92394b40ae4
Fixes: 38202759
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.EphemeralTest
Test: Manual. Create sample app that replaces the launcher to test ability to see ephemeral apps.
2017-05-24 07:34:55 -07:00
Makoto Onuki
303e4157eb Fix NPE in usage stats manager (recent regression)
Change-Id: I305bb64b11c9240dc0df5d7b08a9a970660157c8
Fix: 38430177
Test: build and boot
2017-05-19 10:31:52 -07:00
Makoto Onuki
ad623015a1 Restrict access to instant app data in usage stats
- Events are obfuscated based on whether the app was instant or not at
the time each event was logged.

- UsageStats are obfuscated based on whether each app is instant or
not at the moment.

Bug 38202133
Test: Manual test using UsageStatsTest and instant apps

Change-Id: I3c74309196b88d010d317cb0dd6749bf4624e876
2017-05-16 12:33:43 -07:00
Jeff Sharkey
06823d4c2e Use "real" free space; refresh on large changes.
For volumes where the OS manages cached data, use the "free space" as
reported by StorageStatsManager, which is the same value shown in
the Settings app and other UI elements.

Also, when the storage space changes significantly, invalidate anyone
who was holding a cached "free space" value.

Test: builds, boots
Bug: 38146029
Change-Id: I4b3a484a8bf32cd137a83f1ea441beca6dc6719a
2017-05-09 16:55:31 -06:00
Jeff Sharkey
5a421ad0ef Merge "Defeat @Nullable String[] with empty list." into oc-dev 2017-05-07 17:40:32 +00:00
Jeff Sharkey
2abd66c4ff Defeat @Nullable String[] with empty list.
Test: builds, boots
Bug: 37577123
Change-Id: I6bf1af565398c30aecc0939a23846c0f85c13ffe
2017-05-05 15:26:25 -06:00
Jeff Sharkey
fd65813157 Offer to wait until broadcasts have drained.
We've seen evidence of lab devices racing with other apps that are
using cache space immediately after tests wipe it clean, which can
cause test failures.  To mitigate this, try our best to wait for the
device to go "idle" by watching for broadcast queues to fully drain.

Also improve javadocs along the way.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 37486230, 37566983, 37913442, 37914374
Change-Id: I4d430db443b6fa6d33a625fe07b90279b5d51c12
2017-05-05 14:58:47 -06:00
Jeff Sharkey
a4d34d971c Respond to API council feedback.
Move aggressive allocation to @SystemApi, which means we can hide
the "flags" API variants.

Remove UUID APIs, since we should use existing Serializable APIs.

Relax permission checks to allow apps to ask for their own stats.

Improve docs.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 37534687, 37534941, 37718184, 37738770
Change-Id: I6a763fb3ab3169c8d3329765bb31e1ee08d9ced7
2017-04-27 11:33:39 -06:00
Jeff Sharkey
0034788844 Fix code accounting bugs, track external app data.
When counting code size, don't include APKs baked into the system.

Settings already accounts external storage used by apps, so they
need a way to exclude that from the total space used by external
storage; give them new getAppSize() API.

Refine docs to explain that emulated storage might be included in
measured statistics.

Resolve symlinks as part of matching getUuidForPath().

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 35812899, 35844919, 37193650
Change-Id: Iec3ce8b336b71dc98a7d25fdd30fa78e9ee826dc
2017-04-18 21:00:13 -06:00
Jeff Sharkey
789a8fc792 Storage API polishing.
Based on API council feedback, switch to using real UUID objects
instead of Strings.  Since UUID is a general-purpose utility class
that will be passed around quite a bit, add it to Parcel and Bundle.

Define well-known namespaced UUID values for "default" and "primary
physical" storage devices, which will let us annotate a bunch of
things with @NonNull.

Define new extras for MANAGE_STORAGE intent that apps can use to
signal where and how much space they'd like the user to free up.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 37325923, 35812899, 35806020
Change-Id: I8421b126d680f69141a361c1e77223fe2bf4a325
2017-04-17 12:19:50 -06:00
Daniel Nishi
b28c9d6b2d Fix crash when measuring storage.
If we are measuring storage and a volume is removed at the same time,
we can enter a state where we previously verified the volume existed,
but it no longer does. This causes an NPE.

By adding in a null check, we can avoid this crash.

Change-Id: Ib8dbf05102a122bdf4bb6063374e993a1de68425
Fixes: 36689190
Test: None
2017-04-06 14:32:13 -07:00
TreeHugger Robot
fd463121c6 Merge "We really want f_frsize and f_bavail." into oc-dev 2017-04-03 07:37:49 +00:00
Jeff Sharkey
dafb17e7eb We really want f_frsize and f_bavail.
It's confusing, but f_bsize is not the value you're looking for; the
real block size is f_frsize.  Fix all those bugs.

Also, the vast majority of clients are interested in the usable
disk space, not including reserved space.

Test: builds, boots
Bug: 36840579
Change-Id: Ib1470389afd49c14cab62282ec1e978ebb2c4791
2017-04-02 23:33:38 -06:00
Jeff Sharkey
6df866a851 Enforce PACKAGE_USAGE_STATS for usage data.
Some system services are offering package usage data through both
public/system APIs and through dump() calls.  In principle, usage
data hould always be protected with PACKAGE_USAGE_STATS, so start
enforcing that.  (Otherwise if a user blocked PACKAGE_USAGE_STATS
access to an app, that app could still obtain the data via dump()
if they held the DUMP permission.)

Bottom line, let's respect the user's wishes.

Protecting the entire output like this is pretty blunt, but future
CLs can add more nuance to the output if desired.

Test: cts-tradefed run commandAndExit cts-dev -m CtsSecurityTestCases -t android.security.cts.ServicePermissionsTest
Bug: 32806790
Change-Id: I46173562713bea7d89e12a4313c78eb52ea8d77d
2017-04-02 22:29:07 -06:00
Jeff Sharkey
fe9a53bc45 Consistent dump() permission checking.
This change introduces new methods on DumpUtils that can check if the
caller has DUMP and/or PACKAGE_USAGE_STATS access.  It then moves all
existing dump() methods to use these checks so that we emit
consistent error messages.

Test: cts-tradefed run commandAndExit cts-dev -m CtsSecurityTestCases -t android.security.cts.ServicePermissionsTest
Bug: 32806790
Change-Id: Iaff6b9506818ee082b1e169c89ebe1001b3bfeca
2017-04-02 22:29:07 -06:00
Kang Li
2bdf134eff Move retention length of users' chooser selections to SystemProperties,
to meet CDD requirement.

bug: 33423136
Test: manual - shared images in Camera. More CTS and GTS tests to be
added.

Change-Id: I0e0c759bec11137e2290f4a43a92be8e97eef022
2017-03-27 08:19:41 -07:00
Jeff Sharkey
b5a35b8181 Refactor cache behavior from "atmoic" to "group".
Using the word "atomic" has too much baggage relating to locking
guarantees, so move to something softer.

Add isQuotaSupported() for CTS tests.

Move CacheQuotaStrategy over to using SparseLongArray, which has a
more efficient memory footprint inside the system server.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 35812899, 35684969, 36482620
Change-Id: I894f53e6f3bc76c77d1bb18c51db14833df14a49
2017-03-22 21:33:53 -06:00
TreeHugger Robot
d3b1def2eb Merge "Enable cache clearing v2 logic, fix bugs." 2017-03-15 07:16:43 +00:00
Jeff Sharkey
e730ae877a Enable cache clearing v2 logic, fix bugs.
Now that we have CTS tests to verify the cache clearing v2 logic,
we're ready to enable it!

Switch storage APIs over to "usable space" to match implementation
down in installd.  Add a missing clearCallingIdentity(), and offer
better logging for missing appop permission.

Load quotas from disk right away at device boot instead of waiting.

Bug: 35685848, 35684969
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Change-Id: I8167e0322b4662ca6c975da5c50715e2d71332a7
2017-03-14 23:39:03 -06:00
Jeff Sharkey
6bb5d0fabb Allow querying for apps on adopted storage.
Apps that live on adopted storage devices appear to be uninstalled
while ejected.  They're technically still valid apps, with allocated
UIDs, so use MATCH_UNINSTALLED_PACKAGES when querying for their
details.

Test: builds, boots
Bug: 36177795
Change-Id: Ia7ed5f0462b1f47609ea8e1ace6fa145e0b5602c
2017-03-14 11:03:09 -06:00