Merge \"Move voice interaction callback list to VoiceInteractionManagerService\" into nyc-mr1-dev
am: b91a5e7431
Change-Id: I5fdf69335aaf3dd6ee77753b4f3cc554e1a0342c
This commit is contained in:
@@ -86,6 +86,9 @@ public class VoiceInteractionManagerService extends SystemService {
|
|||||||
final TreeSet<Integer> mLoadedKeyphraseIds;
|
final TreeSet<Integer> mLoadedKeyphraseIds;
|
||||||
SoundTriggerInternal mSoundTriggerInternal;
|
SoundTriggerInternal mSoundTriggerInternal;
|
||||||
|
|
||||||
|
private final RemoteCallbackList<IVoiceInteractionSessionListener>
|
||||||
|
mVoiceInteractionSessionListeners = new RemoteCallbackList<>();
|
||||||
|
|
||||||
public VoiceInteractionManagerService(Context context) {
|
public VoiceInteractionManagerService(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -1043,8 +1046,41 @@ public class VoiceInteractionManagerService extends SystemService {
|
|||||||
public void registerVoiceInteractionSessionListener(
|
public void registerVoiceInteractionSessionListener(
|
||||||
IVoiceInteractionSessionListener listener) {
|
IVoiceInteractionSessionListener listener) {
|
||||||
enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE);
|
enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE);
|
||||||
if (mImpl != null) {
|
synchronized (this) {
|
||||||
mImpl.registerVoiceInteractionSessionListener(listener);
|
mVoiceInteractionSessionListeners.register(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSessionShown() {
|
||||||
|
synchronized (this) {
|
||||||
|
final int size = mVoiceInteractionSessionListeners.beginBroadcast();
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
final IVoiceInteractionSessionListener listener =
|
||||||
|
mVoiceInteractionSessionListeners.getBroadcastItem(i);
|
||||||
|
try {
|
||||||
|
listener.onVoiceSessionShown();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Slog.e(TAG, "Error delivering voice interaction open event.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mVoiceInteractionSessionListeners.finishBroadcast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSessionHidden() {
|
||||||
|
synchronized (this) {
|
||||||
|
final int size = mVoiceInteractionSessionListeners.beginBroadcast();
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
final IVoiceInteractionSessionListener listener =
|
||||||
|
mVoiceInteractionSessionListeners.getBroadcastItem(i);
|
||||||
|
try {
|
||||||
|
listener.onVoiceSessionHidden();
|
||||||
|
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Slog.e(TAG, "Error delivering voice interaction closed event.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mVoiceInteractionSessionListeners.finishBroadcast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import android.content.pm.PackageManager;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteCallbackList;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -60,7 +59,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
|||||||
|
|
||||||
final Context mContext;
|
final Context mContext;
|
||||||
final Handler mHandler;
|
final Handler mHandler;
|
||||||
final Object mLock;
|
final VoiceInteractionManagerService.VoiceInteractionManagerServiceStub mServiceStub;
|
||||||
final int mUser;
|
final int mUser;
|
||||||
final ComponentName mComponent;
|
final ComponentName mComponent;
|
||||||
final IActivityManager mAm;
|
final IActivityManager mAm;
|
||||||
@@ -73,16 +72,13 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
|||||||
VoiceInteractionSessionConnection mActiveSession;
|
VoiceInteractionSessionConnection mActiveSession;
|
||||||
int mDisabledShowContext;
|
int mDisabledShowContext;
|
||||||
|
|
||||||
private final RemoteCallbackList<IVoiceInteractionSessionListener>
|
|
||||||
mVoiceInteractionSessionListeners = new RemoteCallbackList<>();
|
|
||||||
|
|
||||||
final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
|
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
|
||||||
String reason = intent.getStringExtra("reason");
|
String reason = intent.getStringExtra("reason");
|
||||||
if (!CLOSE_REASON_VOICE_INTERACTION.equals(reason) && !"dream".equals(reason)) {
|
if (!CLOSE_REASON_VOICE_INTERACTION.equals(reason) && !"dream".equals(reason)) {
|
||||||
synchronized (mLock) {
|
synchronized (mServiceStub) {
|
||||||
if (mActiveSession != null && mActiveSession.mSession != null) {
|
if (mActiveSession != null && mActiveSession.mSession != null) {
|
||||||
try {
|
try {
|
||||||
mActiveSession.mSession.closeSystemDialogs();
|
mActiveSession.mSession.closeSystemDialogs();
|
||||||
@@ -98,7 +94,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
|||||||
final ServiceConnection mConnection = new ServiceConnection() {
|
final ServiceConnection mConnection = new ServiceConnection() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
synchronized (mLock) {
|
synchronized (mServiceStub) {
|
||||||
mService = IVoiceInteractionService.Stub.asInterface(service);
|
mService = IVoiceInteractionService.Stub.asInterface(service);
|
||||||
try {
|
try {
|
||||||
mService.ready();
|
mService.ready();
|
||||||
@@ -113,11 +109,12 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VoiceInteractionManagerServiceImpl(Context context, Handler handler, Object lock,
|
VoiceInteractionManagerServiceImpl(Context context, Handler handler,
|
||||||
|
VoiceInteractionManagerService.VoiceInteractionManagerServiceStub stub,
|
||||||
int userHandle, ComponentName service) {
|
int userHandle, ComponentName service) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
mLock = lock;
|
mServiceStub = stub;
|
||||||
mUser = userHandle;
|
mUser = userHandle;
|
||||||
mComponent = service;
|
mComponent = service;
|
||||||
mAm = ActivityManagerNative.getDefault();
|
mAm = ActivityManagerNative.getDefault();
|
||||||
@@ -153,8 +150,9 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
|||||||
public boolean showSessionLocked(Bundle args, int flags,
|
public boolean showSessionLocked(Bundle args, int flags,
|
||||||
IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) {
|
IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) {
|
||||||
if (mActiveSession == null) {
|
if (mActiveSession == null) {
|
||||||
mActiveSession = new VoiceInteractionSessionConnection(mLock, mSessionComponentName,
|
mActiveSession = new VoiceInteractionSessionConnection(mServiceStub,
|
||||||
mUser, mContext, this, mInfo.getServiceInfo().applicationInfo.uid, mHandler);
|
mSessionComponentName, mUser, mContext, this,
|
||||||
|
mInfo.getServiceInfo().applicationInfo.uid, mHandler);
|
||||||
}
|
}
|
||||||
List<IBinder> activityTokens = null;
|
List<IBinder> activityTokens = null;
|
||||||
if (activityToken == null) {
|
if (activityToken == null) {
|
||||||
@@ -358,52 +356,20 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerVoiceInteractionSessionListener(
|
|
||||||
IVoiceInteractionSessionListener listener) {
|
|
||||||
synchronized (mLock) {
|
|
||||||
mVoiceInteractionSessionListeners.register(listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sessionConnectionGone(VoiceInteractionSessionConnection connection) {
|
public void sessionConnectionGone(VoiceInteractionSessionConnection connection) {
|
||||||
synchronized (mLock) {
|
synchronized (mServiceStub) {
|
||||||
finishLocked(connection.mToken, false);
|
finishLocked(connection.mToken, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSessionShown(VoiceInteractionSessionConnection connection) {
|
public void onSessionShown(VoiceInteractionSessionConnection connection) {
|
||||||
synchronized (mLock) {
|
mServiceStub.onSessionShown();
|
||||||
final int size = mVoiceInteractionSessionListeners.beginBroadcast();
|
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
final IVoiceInteractionSessionListener listener =
|
|
||||||
mVoiceInteractionSessionListeners.getBroadcastItem(i);
|
|
||||||
try {
|
|
||||||
listener.onVoiceSessionShown();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Slog.e(TAG, "Error delivering voice interaction open event.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mVoiceInteractionSessionListeners.finishBroadcast();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSessionHidden(VoiceInteractionSessionConnection connection) {
|
public void onSessionHidden(VoiceInteractionSessionConnection connection) {
|
||||||
synchronized (mLock) {
|
mServiceStub.onSessionHidden();
|
||||||
final int size = mVoiceInteractionSessionListeners.beginBroadcast();
|
|
||||||
for (int i = 0; i < size; ++i) {
|
|
||||||
final IVoiceInteractionSessionListener listener =
|
|
||||||
mVoiceInteractionSessionListeners.getBroadcastItem(i);
|
|
||||||
try {
|
|
||||||
listener.onVoiceSessionHidden();
|
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Slog.e(TAG, "Error delivering voice interaction closed event.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mVoiceInteractionSessionListeners.finishBroadcast();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user