use of android.os.Looper in project android_frameworks_base by ParanoidAndroid.
the class SystemSensorManager method registerListenerImpl.
/** @hide */
@Override
protected boolean registerListenerImpl(SensorEventListener listener, Sensor sensor, int delay, Handler handler) {
// We map SensorEventListener to a SensorEventQueue, which holds the looper
if (sensor == null)
throw new IllegalArgumentException("sensor cannot be null");
// Trigger Sensors should use the requestTriggerSensor call.
if (Sensor.getReportingMode(sensor) == Sensor.REPORTING_MODE_ONE_SHOT)
return false;
synchronized (mSensorListeners) {
SensorEventQueue queue = mSensorListeners.get(listener);
if (queue == null) {
Looper looper = (handler != null) ? handler.getLooper() : mMainLooper;
queue = new SensorEventQueue(listener, looper, this);
if (!queue.addSensor(sensor, delay)) {
queue.dispose();
return false;
}
mSensorListeners.put(listener, queue);
return true;
} else {
return queue.addSensor(sensor, delay);
}
}
}
use of android.os.Looper in project android_frameworks_base by ResurrectionRemix.
the class SurfaceTexture method setOnFrameAvailableListener.
/**
* Register a callback to be invoked when a new image frame becomes available to the
* SurfaceTexture.
* <p>
* If a handler is specified, the callback will be invoked on that handler's thread.
* If no handler is specified, then the callback may be called on an arbitrary thread,
* so it is not safe to call {@link #updateTexImage} without first binding the OpenGL ES
* context to the thread invoking the callback.
* </p>
*
* @param listener The listener to use, or null to remove the listener.
* @param handler The handler on which the listener should be invoked, or null
* to use an arbitrary thread.
*/
public void setOnFrameAvailableListener(@Nullable final OnFrameAvailableListener listener, @Nullable Handler handler) {
if (listener != null) {
// Although we claim the thread is arbitrary, earlier implementation would
// prefer to send the callback on the creating looper or the main looper
// so we preserve this behavior here.
Looper looper = handler != null ? handler.getLooper() : mCreatorLooper != null ? mCreatorLooper : Looper.getMainLooper();
mOnFrameAvailableHandler = new Handler(looper, null, true) {
/*async*/
@Override
public void handleMessage(Message msg) {
listener.onFrameAvailable(SurfaceTexture.this);
}
};
} else {
mOnFrameAvailableHandler = null;
}
}
use of android.os.Looper in project android_frameworks_base by ResurrectionRemix.
the class AccessibilityManager method sendAccessibilityEvent.
/**
* Sends an {@link AccessibilityEvent}.
*
* @param event The event to send.
*
* @throws IllegalStateException if accessibility is not enabled.
*
* <strong>Note:</strong> The preferred mechanism for sending custom accessibility
* events is through calling
* {@link android.view.ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)}
* instead of this method to allow predecessors to augment/filter events sent by
* their descendants.
*/
public void sendAccessibilityEvent(AccessibilityEvent event) {
final IAccessibilityManager service;
final int userId;
synchronized (mLock) {
service = getServiceLocked();
if (service == null) {
return;
}
if (!mIsEnabled) {
Looper myLooper = Looper.myLooper();
if (myLooper == Looper.getMainLooper()) {
throw new IllegalStateException("Accessibility off. Did you forget to check that?");
} else {
// If we're not running on the thread with the main looper, it's possible for
// the state of accessibility to change between checking isEnabled and
// calling this method. So just log the error rather than throwing the
// exception.
Log.e(LOG_TAG, "AccessibilityEvent sent with accessibility disabled");
return;
}
}
userId = mUserId;
}
boolean doRecycle = false;
try {
event.setEventTime(SystemClock.uptimeMillis());
// it is possible that this manager is in the same process as the service but
// client using it is called through Binder from another process. Example: MMS
// app adds a SMS notification and the NotificationManagerService calls this method
long identityToken = Binder.clearCallingIdentity();
doRecycle = service.sendAccessibilityEvent(event, userId);
Binder.restoreCallingIdentity(identityToken);
if (DEBUG) {
Log.i(LOG_TAG, event + " sent");
}
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error during sending " + event + " ", re);
} finally {
if (doRecycle) {
event.recycle();
}
}
}
use of android.os.Looper in project android_frameworks_base by ResurrectionRemix.
the class AccessibilityManager method interrupt.
/**
* Requests feedback interruption from all accessibility services.
*/
public void interrupt() {
final IAccessibilityManager service;
final int userId;
synchronized (mLock) {
service = getServiceLocked();
if (service == null) {
return;
}
if (!mIsEnabled) {
Looper myLooper = Looper.myLooper();
if (myLooper == Looper.getMainLooper()) {
throw new IllegalStateException("Accessibility off. Did you forget to check that?");
} else {
// If we're not running on the thread with the main looper, it's possible for
// the state of accessibility to change between checking isEnabled and
// calling this method. So just log the error rather than throwing the
// exception.
Log.e(LOG_TAG, "Interrupt called with accessibility disabled");
return;
}
}
userId = mUserId;
}
try {
service.interrupt(userId);
if (DEBUG) {
Log.i(LOG_TAG, "Requested interrupt from all services");
}
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error while requesting interrupt from all services. ", re);
}
}
use of android.os.Looper in project android_frameworks_base by ResurrectionRemix.
the class Visualizer method setDataCaptureListener.
/**
* Registers an OnDataCaptureListener interface and specifies the rate at which the capture
* should be updated as well as the type of capture requested.
* <p>Call this method with a null listener to stop receiving the capture updates.
* @param listener OnDataCaptureListener registered
* @param rate rate in milliHertz at which the capture should be updated
* @param waveform true if a waveform capture is requested: the onWaveFormDataCapture()
* method will be called on the OnDataCaptureListener interface.
* @param fft true if a frequency capture is requested: the onFftDataCapture() method will be
* called on the OnDataCaptureListener interface.
* @return {@link #SUCCESS} in case of success,
* {@link #ERROR_NO_INIT} or {@link #ERROR_BAD_VALUE} in case of failure.
*/
public int setDataCaptureListener(OnDataCaptureListener listener, int rate, boolean waveform, boolean fft) {
synchronized (mListenerLock) {
mCaptureListener = listener;
}
if (listener == null) {
// make sure capture callback is stopped in native code
waveform = false;
fft = false;
}
int status = native_setPeriodicCapture(rate, waveform, fft);
if (status == SUCCESS) {
if ((listener != null) && (mNativeEventHandler == null)) {
Looper looper;
if ((looper = Looper.myLooper()) != null) {
mNativeEventHandler = new NativeEventHandler(this, looper);
} else if ((looper = Looper.getMainLooper()) != null) {
mNativeEventHandler = new NativeEventHandler(this, looper);
} else {
mNativeEventHandler = null;
status = ERROR_NO_INIT;
}
}
}
return status;
}
Aggregations