Merge "Add getPackageName to VoiceInteractor"

This commit is contained in:
TreeHugger Robot
2022-02-12 02:29:50 +00:00
committed by Android (Google) Code Review
6 changed files with 52 additions and 1 deletions

View File

@@ -7048,6 +7048,7 @@ package android.app {
public final class VoiceInteractor {
method public android.app.VoiceInteractor.Request getActiveRequest(String);
method public android.app.VoiceInteractor.Request[] getActiveRequests();
method @NonNull public String getPackageName();
method public boolean isDestroyed();
method public void notifyDirectActionsChanged();
method public boolean registerOnDestroyedCallback(@NonNull java.util.concurrent.Executor, @NonNull Runnable);

View File

@@ -128,6 +128,7 @@ interface IActivityTaskManager {
int callingUid, in Intent intent, in String resolvedType,
in IVoiceInteractionSession session, in IVoiceInteractor interactor, int flags,
in ProfilerInfo profilerInfo, in Bundle options, int userId);
String getVoiceInteractorPackageName(in IBinder callingVoiceInteractor);
int startAssistantActivity(in String callingPackage, in String callingFeatureId, int callingPid,
int callingUid, in Intent intent, in String resolvedType, in Bundle options, int userId);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_GAME_ACTIVITY)")

View File

@@ -1168,6 +1168,23 @@ public final class VoiceInteractor {
}
}
/**
* @return the package name of the service providing the VoiceInteractionService.
*/
@NonNull
public String getPackageName() {
String packageName = null;
if (mActivity != null && mInteractor != null) {
try {
packageName = ActivityTaskManager.getService()
.getVoiceInteractorPackageName(mInteractor.asBinder());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
return packageName == null ? "" : packageName;
}
void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
String innerPrefix = prefix + " ";
if (mActiveRequests.size() > 0) {

View File

@@ -49,6 +49,13 @@ public abstract class VoiceInteractionManagerInternal {
*/
public abstract boolean hasActiveSession(String packageName);
/**
* Returns the package name of the active session.
*
* @param callingVoiceInteractor the voice interactor binder from the calling VoiceInteractor.
*/
public abstract String getVoiceInteractorPackageName(IBinder callingVoiceInteractor);
/**
* Gets the identity of the currently active HotwordDetectionService.
*
@@ -82,4 +89,4 @@ public abstract class VoiceInteractionManagerInternal {
return mOwnerUid;
}
}
}
}

View File

@@ -1694,6 +1694,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
.execute();
}
@Override
public String getVoiceInteractorPackageName(IBinder callingVoiceInteractor) {
return LocalServices.getService(VoiceInteractionManagerInternal.class)
.getVoiceInteractorPackageName(callingVoiceInteractor);
}
@Override
public int startAssistantActivity(String callingPackage, @NonNull String callingFeatureId,
int callingPid, int callingUid, Intent intent, String resolvedType, Bundle bOptions,

View File

@@ -262,6 +262,25 @@ public class VoiceInteractionManagerService extends SystemService {
return TextUtils.equals(packageName, session.mSessionComponentName.getPackageName());
}
@Override
public String getVoiceInteractorPackageName(IBinder callingVoiceInteractor) {
VoiceInteractionManagerServiceImpl impl =
VoiceInteractionManagerService.this.mServiceStub.mImpl;
if (impl == null) {
return null;
}
VoiceInteractionSessionConnection session =
impl.mActiveSession;
if (session == null) {
return null;
}
IVoiceInteractor voiceInteractor = session.mInteractor;
if (voiceInteractor == null || voiceInteractor.asBinder() != callingVoiceInteractor) {
return null;
}
return session.mSessionComponentName.getPackageName();
}
@Override
public HotwordDetectionServiceIdentity getHotwordDetectionServiceIdentity() {
// IMPORTANT: This is called when performing permission checks; do not lock!