import android.app.Service;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
switch (msg.what) {
case MSG_START_LISTENING:
StartListeningArgs args = (StartListeningArgs) msg.obj;
- dispatchStartListening(args.mIntent, args.mListener);
+ dispatchStartListening(args.mIntent, args.mListener, args.mCallingUid);
break;
case MSG_STOP_LISTENING:
dispatchStopListening((IRecognitionListener) msg.obj);
}
};
- private void dispatchStartListening(Intent intent, final IRecognitionListener listener) {
+ private void dispatchStartListening(Intent intent, final IRecognitionListener listener,
+ int callingUid) {
if (mCurrentCallback == null) {
if (DBG) Log.d(TAG, "created new mCurrentCallback, listener = " + listener.asBinder());
try {
Log.e(TAG, "dead listener on startListening");
return;
}
- mCurrentCallback = new Callback(listener);
+ mCurrentCallback = new Callback(listener, callingUid);
RecognitionService.this.onStartListening(intent, mCurrentCallback);
} else {
try {
public final Intent mIntent;
public final IRecognitionListener mListener;
+ public final int mCallingUid;
- public StartListeningArgs(Intent intent, IRecognitionListener listener) {
+ public StartListeningArgs(Intent intent, IRecognitionListener listener, int callingUid) {
this.mIntent = intent;
this.mListener = listener;
+ this.mCallingUid = callingUid;
}
}
*/
public class Callback {
private final IRecognitionListener mListener;
+ private final int mCallingUid;
- private Callback(IRecognitionListener listener) {
+ private Callback(IRecognitionListener listener, int callingUid) {
mListener = listener;
+ mCallingUid = callingUid;
}
/**
public void rmsChanged(float rmsdB) throws RemoteException {
mListener.onRmsChanged(rmsdB);
}
+
+ /**
+ * Return the Linux uid assigned to the process that sent you the current transaction that
+ * is being processed. This is obtained from {@link Binder#getCallingUid()}.
+ */
+ public int getCallingUid() {
+ return mCallingUid;
+ }
}
/** Binder of the recognition service */
if (service != null && service.checkPermissions(listener)) {
service.mHandler.sendMessage(Message.obtain(service.mHandler,
MSG_START_LISTENING, service.new StartListeningArgs(
- recognizerIntent, listener)));
+ recognizerIntent, listener, Binder.getCallingUid())));
}
}