108 Commits

Author SHA1 Message Date
Song Hu
bf9cb7e6e3 Promote frequently sharing apps as per monthly stats fetched from UsageStatsManager, in case PeopleService does not store enough sharing events when users just swicth to Sharesheet ranking in PeopleService.
Bug: 156320324
Test: atest com.android.server.people.prediction.ShareTargetPredictorTest
Test: atest com.android.server.people.prediction.SharesheetModelScorerTest
Test: atest com.android.server.people.data.UsageStatsQueryHelperTest

Change-Id: Iae7a3a8195ae4901cd1d9d673fe0cf8a27845488
2020-05-20 15:37:26 -07:00
Song Hu
c0128fa07d Merge "Changes in PeopleService to supprot ChooserTarget ranking. 1. Pass app share score from PeopleService to Aosp. 2. Skip storing ChooserTargets sharing event in PeopleService. 3. Adjust frequest used app promo decay." into rvc-dev 2020-05-05 07:08:26 +00:00
Jeff Sharkey
559130df3f Merge "Add custom Error Prone check for SDK comparisons." into rvc-dev 2020-05-04 23:10:06 +00:00
Jeff Sharkey
4d1d7b56cd Add custom Error Prone check for SDK comparisons.
Over the years we've had several obscure bugs related to how SDK level
comparisons are performed, specifically during the window of time
where we've started distributing the "frankenbuild" to developers.

Consider the case where a framework developer shipping release "R"
wants to only grant a specific behavior to modern apps; they could
write this in two different ways:

1. if (targetSdkVersion > Build.VERSION_CODES.Q) {
2. if (targetSdkVersion >= Build.VERSION_CODES.R) {

The safer of these two options is (2), which will ensure that
developers only get the behavior when *both* the app and the
platform concur on the specific SDK level having shipped.

Consider the breakage that would happen with option (1) if we
started shipping APKs that are based on the final R SDK, but are
then installed on earlier preview releases which still consider R
to be CUR_DEVELOPMENT; they'd risk crashing due to behaviors that
were never part of the official R SDK.

Bug: 64412239
Test: ./build/soong/soong_ui.bash --make-mode services RUN_ERROR_PRONE=true
Exempt-From-Owner-Approval: trivial blueprint changes
Change-Id: Ia20181f8602451ac9a719ea488d148e160708592
2020-05-04 23:09:48 +00:00
Song Hu
7e134c22eb Changes in PeopleService to supprot ChooserTarget ranking.
1. Pass app share score from PeopleService to Aosp.
2. Skip storing ChooserTargets sharing event in PeopleService.
3. Adjust frequest used app promo decay.

Bug: 151112858
Test: atest com.android.server.people.prediction.ShareTargetPredictorTest
Test: atest com.android.server.people.prediction.SharesheetModelScorerTest
Change-Id: If27d0c914b9f156403950e7ea601b4a7ad35b27f
2020-05-04 15:58:26 -07:00
Danning Chen
f4ba1c22a6 Uncache the shortcuts when Android system shuts down if the notification settings are not changed
Change-Id: Ib7e23f4b15ccca9c162cea187a26e7d89b8976a8
Test: Manual test
Test: atest DataManagerTest
Bug: 153357090
2020-04-30 23:37:56 -07:00
Danning Chen
28410f3def Cache the shortcut when the associated notifications are posted and uncache when they are gone
Change-Id: Ia569f9b31a0fe73242f2e6350805afe7c06d2cdf
Bug: 153357090
Test: Manual test
Test: atest DataManagerTest
Test: atest NotificationManagerServiceTest
2020-04-23 13:52:44 -07:00
Danning Chen
07cfaa6b08 Keep the conversation shortcut criteria in People Service consistent with the one in Notification Manager
Before this change, People Service uses the presence of the Person object
in ShortcutInfo as the criteria of conversation shortcut. This changes
the criteria that the shortcut needs to be a share shortcut instead of having Person object.

Change-Id: I1ea52a50c909ca96365c1d4e55af97931d048d8f
Test: atest ShortcutHelperTest
Test: atest DataManagerTest
Bug: 154254830
2020-04-21 10:51:20 -07:00
Susi Kharraz-Post
dde9c3afc8 Add sharesheet statsd logging
Add a Logger for sharesheet and add calls into ChooserActivity.java

Bug: 147508495
Test: manual testing and added unit tests into ChooserActivityTests.
Change-Id: I0024b5020f47475a28c4745af4d8ef268e5f85be
2020-04-03 11:07:19 +00:00
Song Hu
1d73eaf431 Factor freqeuncy and mimetype of past sharings, foreground app into
sharesheet model. Promote most frequent sharable apps to tackle cold
start issue when device doesn't hold enough sharing history.

Bug: 149822311
Test: manual test Sharesheet ranking on device
Test: atest com.android.server.people.prediction.ShareTargetPredictorTest
Test: atest com.android.server.people.prediction.SharesheetModelHelperTest
Test: atest com.android.server.people.data.UsageStatsQueryHelperTest
Change-Id: I6eb764448c0619cbc3b320b5f6432f559d1a15e1
2020-03-26 06:18:52 -07:00
Danning Chen
161f57512f Run PeopleService#onUserStopping on a background thread
Bug: 151481286
Test: atest com.android.server.people.data.DataManagerTest
Change-Id: If2b9215597ef280600c8834f414de780e3ef4f0b
2020-03-18 21:11:47 -07:00
Danning Chen
13b2112c8a Merge "Run PeopleService.onUserUnlocked() on worker thread instead of main thread" into rvc-dev 2020-03-11 05:51:26 +00:00
Dmitri Plotnikov
261d5d65fd Allow PeopleService to make blocking binder calls
Bug: 149788799
Test: presubmit

Change-Id: Ia23c96ce34942e95b029240e0d087b614e19b0f4
2020-03-10 22:59:05 +00:00
Danning Chen
a44febc6e2 Run PeopleService.onUserUnlocked() on worker thread instead of main thread
This change is targeting on reducing the latency to unlock a user. It
includes these changes:
(1) In DataManager.onUserUnlocked(), execute the listeners registration
code on a worker thread.
(2) Merge the usage stats service query and data persistence to one thread.
(3) Adjust the query events max age from 1 day to 5 mins because we
already persist those events in PeopleService. No need to re-query those
events.

With this change, PeopleService.onUserUnlocked() execution is reduced
from ~200 ms to <1ms. And listeners are set up after conversations being
loaded from the disk. This ensures at the events query time (such as
UsageStatsService query), all the conversations are already available in
People Service to avoid missing some events (events without an
associated conversation are dropped).

Change-Id: I5248afa2771588a2434c335867de4e2d1a2eb6f3
Test: atest com.android.server.people.data.DataManagerTest
Test: atest com.android.server.people.data.ConversationStoreTest
Test: atest com.android.server.people.data.PackageDataTest
Bug: 150733302
2020-03-09 17:50:19 -07:00
Danning Chen
18fecf78d3 Fix the bug that queries UsageStatsService for locked users
In addition to the bug fix, this also changes the user lifecycle callbacks People Service is using:

1) onUserUnlocking() -> onUserUnlocked()
2) onUserStopped() -> onUserStopping()

The user lifecycle callback changes are based on a recent callback API
change in ag/10396717. This change will make the service run safer: it
avoids performing queries on locked users.

Change-Id: I4d0ebdb80f2181b5eb5a636d345c53a01c7df210
Test: Manual test
Test: atest com.android.server.people.data.DataManagerTest
Bug: 150882079
2020-03-05 16:38:25 -08:00
Trung Lam
d28d403f8f Merge "Fix events/<key> folders not being deleted during onDestory." into rvc-dev 2020-03-02 19:31:56 +00:00
Trung Lam
a23db05da5 Merge "Fix unit tests for people service." into rvc-dev 2020-03-02 19:31:43 +00:00
Trung Lam
070b71cfa4 Fix events/<key> folders not being deleted during onDestory.
Change-Id: Ib9eb9d493d7e6b216d1182b15807e028b9f42bed
Test: Built and tested on device.
Bug: 150395599
2020-02-27 15:04:58 -08:00
Trung Lam
2dcfcc1dee Fix unit tests for people service.
Change-Id: I27f46b65055880f53fccc0e8a609c520fa0ef053
Test: Built and tested on device.
Bug: 150242664
2020-02-27 15:04:06 -08:00
Trung Lam
8839aaee6d Merge "Implement backup and restoration of conversation infos." into rvc-dev 2020-02-27 19:56:29 +00:00
Trung Lam
b213fca0ed Implement backup and restoration of conversation infos.
Change-Id: I2cc08c54b714b4ab65762ae261cf8a50d7f258fd
Test: Built and tested on device.
Bug: 147512341
2020-02-25 14:32:25 -08:00
Trung Lam
9d298d4d7c Merge "Delete package directory when app is uninstalled." into rvc-dev 2020-02-25 21:43:03 +00:00
Felipe Leme
339b7149af Improved user callbacks on SystemService:
* Renamed:

  onStartUser() -> onUserStarting()
  onStopUser() -> onUserStopping()
  onSwitchUser() -> onUserSwitching()
  onUnlockUser() -> onUserUnlocking()
  onCleanupUser() -> onUserStopped()
  isSupportedUser() -> isUserSupported()

* Added:

  onUserUnlocked()

Tested on automotive, which uses the callbacks to dump user metrics:

$ adb shell dumpsys car_service --user-metrics
adb shell dumpsys car_service --user-metrics
* User Metrics *
  no users starting
  no users stopping
Last 10 started users
  2020-02-21T19:44:47.101 - user=0 start=2020-02-21 19:44:45.357 unlocking=+885ms unlocked=+1s122ms
  2020-02-21T19:44:56.376 - user=10 start=2020-02-21 19:44:47.380 switch=+209ms unlocking=+8s262ms unlocked=+8s994ms
  2020-02-21T20:00:08.792 - user=11 start=2020-02-21 20:00:04.634 switch(from 10)=+351ms unlocking=+4s44ms unlocked=+4s156ms
Last 10 stopped users
  2020-02-21T20:00:48.323 - user=10 stop=2020-02-21 20:00:16.741 shutdown=+31s581ms

Test: m update-api
Test: atest BackupManagerServiceTest
Test: manual verification (see above)
Fixes: 150001654

Exempt-From-Owner-Approval: approved on master right before rvc split

Merged-In: I8774c57620030b9aa8e7ec039a6a758ad56db368
Change-Id: I8774c57620030b9aa8e7ec039a6a758ad56db368
(cherry picked from commit 58e7458ac7204992c5408eb2d6420d767afc4eb8)
2020-02-24 16:44:52 +00:00
Trung Lam
3ef69f7e7f Delete package directory when app is uninstalled.
Test: Built and test on device.
Bug: 149946247
Change-Id: I57cbd3d853dad7a4d291427c53e0ef1b61274893
2020-02-23 19:12:51 -08:00
Danning Chen
bbf1b376c1 Merge "Listen to the shortcut add/update/delete changes from PeopleService" 2020-02-21 00:55:54 +00:00
Trung Lam
c554fff4ee Merge "Add direct reading/writing of contact phone number after PDD apporoval." 2020-02-20 23:36:38 +00:00
Danning Chen
3fc66d03ef Listen to the shortcut add/update/delete changes from PeopleService
Bug: 146522621
Bug: 149556516
Test: atest com.android.server.people.data.DataManagerTest
Change-Id: I8752b50179c0fb67880324da79e51276c67d0ee9
2020-02-20 22:36:52 +00:00
Song Hu
78b3cd5775 Merge "Implement sharesheet ranking in PeopleService. Ranking is only based on recency of past sharing for the moment." 2020-02-20 12:41:41 +00:00
Trung Lam
92b8a72db8 Add direct reading/writing of contact phone number after PDD apporoval.
Test: Built and tested on device.
Bug: 147782721
Change-Id: I496e39c447a02ebfb7bb1d3668656eada6a2a59f
2020-02-19 22:10:19 -08:00
Song Hu
ba132e4f26 Implement sharesheet ranking in PeopleService. Ranking is only based on
recency of past sharing for the moment.

Bug: 149822311
Test: atest com.android.server.people.data.DataManagerTest
Test: atest com.android.server.people.data.ShareTargetPredictorTest
Change-Id: I90d1b3f488b34fede7d577dc04832b976f4a1bbb
2020-02-19 18:39:06 -08:00
Trung Lam
e66d38a61c Implement onDestroy for ConversationStore for when an app gets
uninstalled.

Change-Id: I8ad6ec2987c509d6713abdd4244c314cb05e79a1
Test: Built and tested on device.
Bug: 149789130
2020-02-19 15:54:36 -08:00
Trung Lam
88961798e6 Add persistence of Event and EventIndex during device reboot.
Change-Id: Ic6c403a000a776eca2a3e9678c25862693a04c2e
Test: Built on device and unit tests.
Bug: 149356114
2020-02-19 15:54:24 -08:00
Danning Chen
6fb9750619 Keep the event information in EventIndex for at most 63 days instead of 64 days
Bug: 149758587
Bug: 146522621
Test: atest com.android.server.people.data.EventIndexTest
Change-Id: I0cae2a5c958d88aab9f76a7ee198fc2e6d69971c
2020-02-19 21:40:06 +00:00
Danning Chen
91f90e0fd6 Add getShareTargets() to ShortcutServiceInternal and get caller's user ID from AppPredictionSessionId
Previously, the caller's user ID was got from Binder. But
AppPredictionManager clears caller's identity. The only way to get the
caller's user ID is to get it from session ID.

Bug: 146522621
Test: atest com.android.server.people.data.DataManagerTest
Test: atest com.android.server.people.data.ShareTargetPredictorTest
Change-Id: Ia0dc35879084110849e06e919ff3b3c7241c46fd
2020-02-18 13:23:04 -08:00
Danning Chen
1cc7197864 Cache the shortcut if the user has changed the conversation's notification settings
Change-Id: Ic4125e5fa510e82d13a578f7c7aa03c397b80354
Bug: 146522621
Test: atest com.android.server.people.data.DataManagerTest
Test: atest com.android.server.people.data.ConversationInfoTest
2020-02-14 12:20:46 -08:00
Danning Chen
7af601e8ed Listen to the notification posted events from NotificationListenerService instead
UsageStats NOTIFICATION_INTERRUPTION events are only created if a
conversation has its own conversation-specific notification channel
created. Switch to NotificationListenerService so that we could get the notification posted events from all conversations.

Bug: 146522621
Test: atest com.android.server.people.data.DataManagerTest
Test: atest com.android.server.people.data.UsageStatsQueryHelperTest
Change-Id: Iaa120567891144a952707deb5cea1321aa28341c
2020-02-14 10:59:52 -08:00
Danning Chen
94580df0a8 Move the initialization of Call/SMS/MMS content observers out of the DataManager constructor
This change is to speed up the system boot time. The people service
start time will be reduced from ~1.5 ms to ~0.5 ms.

Bug: 149245782
Test: Manual run with System.nanoTime() logged
Change-Id: I9114b3c9e3637b2498618220665cd98df1d1f994
2020-02-14 10:59:52 -08:00
Danning Chen
443b3e9993 Merge "Add a JobScheduler service to prune the People Service data on a daily basis" 2020-02-14 07:41:59 +00:00
Danning Chen
c4933eb5b7 Add a JobScheduler service to prune the People Service data on a daily basis
- Refactor the class EventStore to simplify the event history access methods
- Add the prune methods to delete the data for:
  - uninstalled packages
  - event data that exceeds the retention period
  - call events data for non-dialer packages
  - SMS events data for non-SMS-app packages
  - orphan events (the annotated locus ID or phone number have  changed in the associated shortcut)
- Change the package-level events to class-level for the app share events

Bug: 146522621
Test: Manually verify the behavior on device \
    atest com.android.server.people.data.DataManagerTest \
    atest com.android.server.people.data.PackageDataTest
Change-Id: I3f17ed269fe5cb05f1d3696e44dfb0bed951678f
2020-02-13 12:45:42 -08:00
Varun Shah
0cbb6b63ee Obfuscate visibility of notification-related events.
UsageStats will return obfuscated NOTIFICATION_SEEN or
NOTIFICATION_INTERRUPTION events to callers of #queryEvents
and #queryEventsForUser if they don't hold the MANAGE_NOTIFICATIONS
permission.

Additionaly, refactor the query API in UsageStats to take in flags as
defined in UsageEvents to make future obfuscation/visibility parameters
cleaner.

Also, add the MANAGE_NOTIFICATIONS permission to shell for CTS test.

Bug: 144724524
Test: atest android.app.usage.cts.UsageStatsTest
Test: atest com.android.server.people.data.UsageStatsQueryHelperTest
Test: atest android.content.pm.cts.shortcutmanager.ShortcutManagerUsageTest
Change-Id: I118de7e589ac8dd5924d3740c70903fa484b79b5
2020-02-13 12:01:13 -08:00
Tyler Gunn
8d95abab29 Merge "API Review cleanups." 2020-02-13 16:05:53 +00:00
Tyler Gunn
754493b82f API Review cleanups.
- New @SystemApis on Conference and PhoneAccount were missing the required
permissions annotations.
- Rename PROPERTY_ASSISTED_DIALING_USED to PROPERTY_ASSISTED_DIALING
- Standardize get/setConnectionStartElapsedRealtimeMillis method naming
across Connection and Conference classes.
- Clarify Conference#sendConferenceEvent API documentation to match the
docs present for similar method in Connection; include some examples of
valid event/extras combinations.
- Update TelecomManager#getDefaultdialerPackage to use UserHandle instead
of userId.
- Move Conference#getConnectionStartElapsedRealtimeMillis to public API
since the setter is already part of the public API.

Test: Run Telecom and Telephony CTS tests.
Test: Run Telephony unit tests.
Test: Perform manual single-party-conference regression test to confirm
that conference behavior does not regress.

Bug: 147301297
Bug: 148286830
Bug: 148284863
Bug: 148284843
Bug: 148287068
Bug: 148285484
Bug: 148285560
Change-Id: I1f446d81859fa109d74af3661a42a0bd224de5aa
2020-02-12 20:44:27 -08:00
Yuliya Kamatkova
fea62a512b Restrict visibility of LOCUS_ID_SET events.
UsageStats will not return LOCUS_ID_SET events to callers
of #queryEvents and #queryEventsForUser if they don't have visibility.

Bug: 148821246
Test: manual, atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest
Change-Id: Ic904a97e66775ef63bc8b84e67e8f430b2a4121b
2020-02-12 11:20:22 -08:00
Trung Lam
a127fceb73 Add persistence of ConversationInfo during device reboot.
Change-Id: I01ee08eb212a42b0c19d654241adb6afd718c14b
Test: Build and run on test device.
Bug: 147782721
2020-02-08 23:42:05 -08:00
Danning Chen
44725cd285 Listen to the notification channel creation/modification/deletion events
Bug: 146522621
Test: atest com.android.server.people.data.DataManagerTest
Change-Id: I2e465627c16bc3055f784d81800f2907c2728025
2020-02-06 17:21:59 -08:00
Danning Chen
e4294d62ef Merge "Add UsageStatsQueryHelper to People Service" 2020-02-07 00:33:46 +00:00
Danning Chen
b601629811 Add UsageStatsQueryHelper to People Service
It processes these UsageStats events:
- SHORTCUT_INVOCATION
- NOTIFICATION_INTERRUPTION
- LOCUS_ID_SET
- ACTIVITY_PAUSED/STOPPED/DESTROYED

The in-app conversation is counted from the LOCUS_ID_SET event to the
next LOCUS_ID_SET event, or the associated Activity is
paused/stopped/destroyed.

Change-Id: I5ecb78e61f9f69129e7fa9cc67e9e94b2148fcda
Test: Manual tests \
    atest com.android.server.people.data.UsageStatsQueryHelperTest \
    atest com.android.server.people.data.DataManagerTest \
    atest com.android.server.people.data.CallLogQueryHelperTest \
    atest com.android.server.people.data.ConversationInfoTest \
    atest com.android.server.people.data.ConversationStoreTest
Bug: 146522621
2020-02-06 14:41:35 -08:00
Mehdi Alizadeh
7a2b81b7d3 Merge "Adds locus Id to ShortcutQuery to find shortcuts based on LocusId" 2020-02-06 02:50:38 +00:00
Mehdi Alizadeh
ae808ff765 Adds locus Id to ShortcutQuery to find shortcuts based on LocusId
Bug: 148085173
Test: atest com.android.server.pm.ShortcutManagerTest1 \
            com.android.server.pm.ShortcutManagerTest2 \
            com.android.server.pm.ShortcutManagerTest3 \
            com.android.server.pm.ShortcutManagerTest4 \
            com.android.server.pm.ShortcutManagerTest5 \
            com.android.server.pm.ShortcutManagerTest6 \
            com.android.server.pm.ShortcutManagerTest7 \
            com.android.server.pm.ShortcutManagerTest8 \
            com.android.server.pm.ShortcutManagerTest9 \
            com.android.server.pm.ShortcutManagerTest10
Test: atest DataManagerTest

Change-Id: Ie789582a43db6d53130f4a0e5bff646a3c08c71e
2020-02-05 13:53:47 -08:00
Danning Chen
b3f852127e Fix the NPE when reading the call log or SMS if a device has multiple user profiles
Change-Id: Iec6485653367f2f005c2b7e17f23ab611e39e13b
Bug: 148918224
Test: atest com.android.server.people.data.DataManagerTest
2020-02-05 11:52:50 -08:00