use of android.os.Handler in project platform_frameworks_base by android.
the class AudioTrack method postEventFromNative.
//---------------------------------------------------------
// Java methods called from the native side
//--------------------
@SuppressWarnings("unused")
private static void postEventFromNative(Object audiotrack_ref, int what, int arg1, int arg2, Object obj) {
//logd("Event posted from the native side: event="+ what + " args="+ arg1+" "+arg2);
AudioTrack track = (AudioTrack) ((WeakReference) audiotrack_ref).get();
if (track == null) {
return;
}
if (what == AudioSystem.NATIVE_EVENT_ROUTING_CHANGE) {
track.broadcastRoutingChange();
return;
}
NativePositionEventHandlerDelegate delegate = track.mEventHandlerDelegate;
if (delegate != null) {
Handler handler = delegate.getHandler();
if (handler != null) {
Message m = handler.obtainMessage(what, arg1, arg2, obj);
handler.sendMessage(m);
}
}
}
use of android.os.Handler in project platform_frameworks_base by android.
the class AudioTrack method addOnRoutingChangedListener.
/**
* Adds an {@link AudioRouting.OnRoutingChangedListener} to receive notifications of routing
* changes on this AudioTrack.
* @param listener The {@link AudioRouting.OnRoutingChangedListener} interface to receive
* notifications of rerouting events.
* @param handler Specifies the {@link Handler} object for the thread on which to execute
* the callback. If <code>null</code>, the {@link Handler} associated with the main
* {@link Looper} will be used.
*/
@Override
public void addOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener, Handler handler) {
synchronized (mRoutingChangeListeners) {
if (listener != null && !mRoutingChangeListeners.containsKey(listener)) {
testEnableNativeRoutingCallbacksLocked();
mRoutingChangeListeners.put(listener, new NativeRoutingEventHandlerDelegate(this, listener, handler != null ? handler : new Handler(mInitializationLooper)));
}
}
}
use of android.os.Handler in project platform_frameworks_base by android.
the class Camera2SurfaceViewTestCase method setUp.
@Override
protected void setUp() throws Exception {
/**
* Set up the camera preview required environments, including activity,
* CameraManager, HandlerThread, Camera IDs, and CameraStateCallback.
*/
super.setUp();
mContext = getActivity();
/**
* Workaround for mockito and JB-MR2 incompatibility
*
* Avoid java.lang.IllegalArgumentException: dexcache == null
* https://code.google.com/p/dexmaker/issues/detail?id=2
*/
System.setProperty("dexmaker.dexcache", mContext.getCacheDir().toString());
mCameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
assertNotNull("Unable to get CameraManager", mCameraManager);
mCameraIds = mCameraManager.getCameraIdList();
assertNotNull("Unable to get camera ids", mCameraIds);
mHandlerThread = new HandlerThread(TAG);
mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper());
mCameraListener = new BlockingStateCallback();
mCollector = new CameraErrorCollector();
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mIterations = getArgumentsAsNumber(ARG_KEY_ITERATIONS, 1).intValue();
mTestWaitIntervalMs = getArgumentsAsNumber(ARG_KEY_WAIT_INTERVAL_MS, 1000).longValue();
mWriteToFile = getArgumentsAsBoolean(ARG_KEY_RESULT_TO_FILE, true);
Log.i(TAG, "Argument: iteration count=" + mIterations);
Log.i(TAG, "Argument: interval (ms)=" + mTestWaitIntervalMs);
Log.i(TAG, "Argument: result to file=" + (mWriteToFile ? "true" : "false"));
mResultPrinter = new CameraTestResultPrinter(getInstrumentation(), mWriteToFile);
}
use of android.os.Handler in project platform_frameworks_base by android.
the class Camera2SurfaceViewTestCase method updatePreviewSurface.
/**
* Update the preview surface size.
*
* @param size The preview size to be updated.
*/
protected void updatePreviewSurface(Size size) {
if (size.equals(mPreviewSize) && mPreviewSurface != null) {
Log.w(TAG, "Skipping update preview surface size...");
return;
}
mPreviewSize = size;
Camera2SurfaceViewActivity ctsActivity = getActivity();
final SurfaceHolder holder = ctsActivity.getSurfaceView().getHolder();
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
holder.setFixedSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
}
});
boolean res = ctsActivity.waitForSurfaceSizeChanged(WAIT_FOR_SURFACE_CHANGE_TIMEOUT_MS, mPreviewSize.getWidth(), mPreviewSize.getHeight());
assertTrue("wait for surface change to " + mPreviewSize.toString() + " timed out", res);
mPreviewSurface = holder.getSurface();
assertNotNull("Preview surface is null", mPreviewSurface);
assertTrue("Preview surface is invalid", mPreviewSurface.isValid());
}
use of android.os.Handler in project platform_frameworks_base by android.
the class SettingsProviderTest method setSettingAndAssertSuccessfulChange.
private void setSettingAndAssertSuccessfulChange(Runnable setCommand, final int type, final String name, final String value, final int userId) throws Exception {
ContentResolver contentResolver = getContext().getContentResolver();
final Uri settingUri = getBaseUriForType(type);
final AtomicBoolean success = new AtomicBoolean();
ContentObserver contentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
public void onChange(boolean selfChange, Uri changeUri, int changeId) {
Log.i(LOG_TAG, "onChange(" + selfChange + ", " + changeUri + ", " + changeId + ")");
assertEquals("Wrong change Uri", changeUri, settingUri);
assertEquals("Wrong user id", userId, changeId);
String changeValue = getStringViaFrontEndApiSetting(type, name, userId);
assertEquals("Wrong setting value", value, changeValue);
success.set(true);
synchronized (mLock) {
mLock.notifyAll();
}
}
};
contentResolver.registerContentObserver(settingUri, false, contentObserver, userId);
try {
setCommand.run();
final long startTimeMillis = SystemClock.uptimeMillis();
synchronized (mLock) {
if (success.get()) {
return;
}
final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
if (elapsedTimeMillis > WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS) {
fail("Could not change setting for " + WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS + " ms");
}
final long remainingTimeMillis = WAIT_FOR_SETTING_URI_CHANGE_TIMEOUT_MILLIS - elapsedTimeMillis;
try {
mLock.wait(remainingTimeMillis);
} catch (InterruptedException ie) {
/* ignore */
}
}
} finally {
contentResolver.unregisterContentObserver(contentObserver);
}
}
Aggregations