From d243c60e634dbb22b974d11c113e1f98a9f51b47 Mon Sep 17 00:00:00 2001 From: Flavio Fiszman Date: Fri, 12 Feb 2021 20:16:30 +0000 Subject: [PATCH] Creates PeopleManager API isConversation Change-Id: I075cd72363ba0ea0e84bb57fe017fce20e051862 Test: atest DataManagerTest Bug: 180122164 --- core/api/system-current.txt | 9 ++++++ .../android/app/people/IPeopleManager.aidl | 3 ++ .../android/app/people/PeopleManager.java | 29 +++++++++++++++++++ core/res/AndroidManifest.xml | 6 ++++ data/etc/privapp-permissions-platform.xml | 2 ++ packages/Shell/AndroidManifest.xml | 3 ++ .../android/server/people/PeopleService.java | 16 ++++++++++ .../server/people/data/DataManager.java | 9 ++++++ .../server/people/data/DataManagerTest.java | 16 ++++++++++ 9 files changed, 93 insertions(+) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index cec2f98ec87b0..79c8035410e3b 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -197,6 +197,7 @@ package android { field public static final String READ_INSTALL_SESSIONS = "android.permission.READ_INSTALL_SESSIONS"; field public static final String READ_NETWORK_USAGE_HISTORY = "android.permission.READ_NETWORK_USAGE_HISTORY"; field public static final String READ_OEM_UNLOCK_STATE = "android.permission.READ_OEM_UNLOCK_STATE"; + field public static final String READ_PEOPLE_DATA = "android.permission.READ_PEOPLE_DATA"; field public static final String READ_PRINT_SERVICES = "android.permission.READ_PRINT_SERVICES"; field public static final String READ_PRINT_SERVICE_RECOMMENDATIONS = "android.permission.READ_PRINT_SERVICE_RECOMMENDATIONS"; field public static final String READ_PRIVILEGED_PHONE_STATE = "android.permission.READ_PRIVILEGED_PHONE_STATE"; @@ -1275,6 +1276,14 @@ package android.app.job { } +package android.app.people { + + public final class PeopleManager { + method @RequiresPermission(android.Manifest.permission.READ_PEOPLE_DATA) public boolean isConversation(@NonNull String, @NonNull String); + } + +} + package android.app.prediction { public final class AppPredictionContext implements android.os.Parcelable { diff --git a/core/java/android/app/people/IPeopleManager.aidl b/core/java/android/app/people/IPeopleManager.aidl index ebe9f60dc1507..d000f3b0b01da 100644 --- a/core/java/android/app/people/IPeopleManager.aidl +++ b/core/java/android/app/people/IPeopleManager.aidl @@ -49,6 +49,9 @@ interface IPeopleManager { /** Removes all the recent conversations and uncaches their cached shortcuts. */ void removeAllRecentConversations(); + /** Returns whether the shortcutId is backed by a Conversation in People Service. */ + boolean isConversation(in String packageName, int userId, in String shortcutId); + /** * Returns the last interaction with the specified conversation. If the * conversation can't be found or no interactions have been recorded, returns 0L. diff --git a/core/java/android/app/people/PeopleManager.java b/core/java/android/app/people/PeopleManager.java index de7ba622ae88b..d348edb6dfbf5 100644 --- a/core/java/android/app/people/PeopleManager.java +++ b/core/java/android/app/people/PeopleManager.java @@ -17,6 +17,8 @@ package android.app.people; import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.annotation.SystemApi; import android.annotation.SystemService; import android.content.Context; import android.content.pm.ParceledListSlice; @@ -53,6 +55,33 @@ public final class PeopleManager { Context.PEOPLE_SERVICE)); } + /** + * Returns whether a shortcut has a conversation associated. + * + *

Requires android.permission.READ_PEOPLE_DATA permission. + * + *

This method may return different results for the same shortcut over time, as an app adopts + * conversation features or if a user hasn't communicated with the conversation associated to + * the shortcut in a while, so the result should not be stored and relied on indefinitely by + * clients. + * + * @param packageName name of the package the conversation is part of + * @param shortcutId the shortcut id backing the conversation + * @return whether the {@shortcutId} is backed by a Conversation. + * + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.READ_PEOPLE_DATA) + public boolean isConversation(@NonNull String packageName, @NonNull String shortcutId) { + Preconditions.checkStringNotEmpty(packageName); + Preconditions.checkStringNotEmpty(shortcutId); + try { + return mService.isConversation(packageName, mContext.getUserId(), shortcutId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } /** * Sets or updates a {@link ConversationStatus} for a conversation. diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 6456e4e2a59ae..e268fde4b66d1 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -5496,6 +5496,12 @@ + + + diff --git a/data/etc/privapp-permissions-platform.xml b/data/etc/privapp-permissions-platform.xml index fe4d0cf80ee0d..8fd5d804adc05 100644 --- a/data/etc/privapp-permissions-platform.xml +++ b/data/etc/privapp-permissions-platform.xml @@ -478,6 +478,8 @@ applications that come with the platform + + diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml index 539a81bf43a03..dbd25ceecae41 100644 --- a/packages/Shell/AndroidManifest.xml +++ b/packages/Shell/AndroidManifest.xml @@ -406,6 +406,9 @@ + + +