Java Code Examples for android.os.Process#myTid()

The following examples show how to use android.os.Process#myTid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IOPools.java    From Ezalor with Apache License 2.0 6 votes vote down vote up
private void open(int fd) {
    LogUtils.logi(IOHook.class.getSimpleName() + " openAfterCall fd:" + fd);

    final IOContext ioContext = getIOContext();
    ioContext.state = IOContext.OPEN;
    ioContext.ioRecord.fd = fd;
    ioContext.ioRecord.path = Utils.getPathByFD(fd);
    ioContext.ioRecord.openTime = System.currentTimeMillis();

    ioContext.ioRecord.process = Utils.getProcessName();
    ioContext.ioRecord.thread = Thread.currentThread().getName();
    ioContext.ioRecord.processId = Process.myPid();
    ioContext.ioRecord.threadId = Process.myTid();

    ioContext.ioRecord.stacktrace = getStackTrace();

    mPools.put(getKey(ioContext.ioRecord.fd), ioContext);
}
 
Example 2
Source File: LauncherModel.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
private void unbindItemInfosAndClearQueuedBindRunnables() {
    if (sWorkerThread.getThreadId() == Process.myTid()) {
        throw new RuntimeException("Expected unbindLauncherItemInfos() to be called from the " +
                "main thread");
    }

    // Clear any deferred bind runnables
    synchronized (mDeferredBindRunnables) {
        mDeferredBindRunnables.clear();
    }

    // Remove any queued UI runnables
    mHandler.cancelAll();
    // Unbind all the workspace items
    unbindWorkspaceItemsOnMainThread();
}
 
Example 3
Source File: AbsTaskHandlerRunner.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
@Override
public final void run() {
    if (isQuit) {
        return;
    }
    Thread.currentThread().setName(theTaskName);
    mTid = Process.myTid();
    Looper.prepare();
    if (isQuit) {
        return;
    }
    synchronized (this) {
        mLooper = Looper.myLooper();
        notifyAll();
    }
    Process.setThreadPriority(taskPriority);
    taskDispatchHandler = new WeakHandler<>(this, mLooper);
    onLooperPrepared();
    Looper.loop();
    mTid = -1;
}
 
Example 4
Source File: LauncherModel.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
private void onlyBindAllApps() {
    final Callbacks oldCallbacks = mCallbacks.get();
    if (oldCallbacks == null) {
        // This launcher has exited and nobody bothered to tell us.  Just bail.
        Log.w(TAG, "LoaderTask running with no launcher (onlyBindAllApps)");
        return;
    }

    // shallow copy
    @SuppressWarnings("unchecked")
    final ArrayList<AppInfo> list
            = (ArrayList<AppInfo>) mBgAllAppsList.data.clone();
    final WidgetsModel widgetList = mBgWidgetsModel.clone();
    Runnable r = new Runnable() {
        public void run() {
            final long t = SystemClock.uptimeMillis();
            final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
            if (callbacks != null) {
                callbacks.bindAllApplications(list);
                callbacks.bindAllPackages(widgetList);
            }
            if (DEBUG_LOADERS) {
                Log.d(TAG, "bound all " + list.size() + " apps from cache in "
                        + (SystemClock.uptimeMillis()-t) + "ms");
            }
        }
    };
    boolean isRunningOnMainThread = !(sWorkerThread.getThreadId() == Process.myTid());
    if (isRunningOnMainThread) {
        r.run();
    } else {
        mHandler.post(r);
    }
}
 
Example 5
Source File: LauncherModel.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
public void unbindItemInfosAndClearQueuedBindRunnables() {
    if (sWorkerThread.getThreadId() == Process.myTid()) {
        throw new RuntimeException("Expected unbindLauncherItemInfos() to be called from the " +
                "main thread");
    }

    // Clear any deferred bind runnables
    synchronized (mDeferredBindRunnables) {
        mDeferredBindRunnables.clear();
    }
    // Remove any queued bind runnables
    mHandler.cancelAllRunnablesOfType(MAIN_THREAD_BINDING_RUNNABLE);
    // Unbind all the workspace items
    unbindWorkspaceItemsOnMainThread();
}
 
Example 6
Source File: LauncherModel.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
static Pair<Long, int[]> findNextAvailableIconSpace(Context context, String name,
                                                    Intent launchIntent,
                                                    int firstScreenIndex,
                                                    ArrayList<Long> workspaceScreens) {
    // Lock on the app so that we don't try and get the items while apps are being added
    LauncherAppState app = LauncherAppState.getInstance();
    LauncherModel model = app.getModel();
    boolean found = false;
    synchronized (app) {
        if (sWorkerThread.getThreadId() != Process.myTid()) {
            // Flush the LauncherModel worker thread, so that if we just did another
            // processInstallShortcut, we give it time for its shortcut to get added to the
            // database (getItemsInLocalCoordinates reads the database)
            model.flushWorkerThread();
        }
        final ArrayList<ItemInfo> items = LauncherModel.getItemsInLocalCoordinates(context);

        // Try adding to the workspace screens incrementally, starting at the default or center
        // screen and alternating between +1, -1, +2, -2, etc. (using ~ ceil(i/2f)*(-1)^(i-1))
        firstScreenIndex = Math.min(firstScreenIndex, workspaceScreens.size());
        int count = workspaceScreens.size();
        for (int screen = firstScreenIndex; screen < count && !found; screen++) {
            int[] tmpCoordinates = new int[2];
            if (findNextAvailableIconSpaceInScreen(items, tmpCoordinates,
                    workspaceScreens.get(screen))) {
                // Update the Launcher db
                return new Pair<Long, int[]>(workspaceScreens.get(screen), tmpCoordinates);
            }
        }
    }
    return null;
}
 
Example 7
Source File: LauncherModel.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
public void unbindItemInfosAndClearQueuedBindRunnables() {
	if (sWorkerThread.getThreadId() == Process.myTid()) {
		throw new RuntimeException(
				"Expected unbindLauncherItemInfos() to be called from the "
						+ "main thread");
	}

	// Clear any deferred bind runnables
	mDeferredBindRunnables.clear();
	// Remove any queued bind runnables
	mHandler.cancelAllRunnablesOfType(MAIN_THREAD_BINDING_RUNNABLE);
	// Unbind all the workspace items
	unbindWorkspaceItemsOnMainThread();
}
 
Example 8
Source File: LauncherModel.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
static Pair<Long, int[]> findNextAvailableIconSpace(Context context,
		String name, Intent launchIntent, int firstScreenIndex,
		ArrayList<Long> workspaceScreens) {
	// Lock on the app so that we don't try and get the items while apps are
	// being added
	LauncherAppState app = LauncherAppState.getInstance();
	LauncherModel model = app.getModel();
	boolean found = false;
	synchronized (app) {
		if (sWorkerThread.getThreadId() != Process.myTid()) {
			// Flush the LauncherModel worker thread, so that if we just did
			// another
			// processInstallShortcut, we give it time for its shortcut to
			// get added to the
			// database (getItemsInLocalCoordinates reads the database)
			model.flushWorkerThread();
		}
		final ArrayList<ItemInfo> items = LauncherModel
				.getItemsInLocalCoordinates(context);

		// Try adding to the workspace screens incrementally, starting at
		// the default or center
		// screen and alternating between +1, -1, +2, -2, etc. (using ~
		// ceil(i/2f)*(-1)^(i-1))
		firstScreenIndex = Math.min(firstScreenIndex,
				workspaceScreens.size());
		int count = workspaceScreens.size();
		for (int screen = firstScreenIndex; screen < count && !found; screen++) {
			int[] tmpCoordinates = new int[2];
			if (findNextAvailableIconSpaceInScreen(items, tmpCoordinates,
					workspaceScreens.get(screen))) {
				// Update the Launcher db
				return new Pair<Long, int[]>(workspaceScreens.get(screen),
						tmpCoordinates);
			}
		}
	}
	return null;
}
 
Example 9
Source File: LauncherModel.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the specified runnable immediately if called from the worker thread,
 * otherwise it is posted on the worker thread handler.
 */
private static void runOnWorkerThread(Runnable r) {
	if (sWorkerThread.getThreadId() == Process.myTid()) {
		r.run();
	} else {
		// If we are not on the worker thread, then post to the worker
		// handler
		sWorker.post(r);
	}
}
 
Example 10
Source File: LauncherModel.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private void runOnMainThread(Runnable r, int type) {
	if (sWorkerThread.getThreadId() == Process.myTid()) {
		// If we are on the worker thread, post onto the main handler
		mHandler.post(r);
	} else {
		r.run();
	}
}
 
Example 11
Source File: LauncherModel.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/** Runs the specified runnable immediately if called from the worker thread, otherwise it is
 * posted on the worker thread handler. */
private static void runOnWorkerThread(Runnable r) {
    if (sWorkerThread.getThreadId() == Process.myTid()) {
        r.run();
    } else {
        // If we are not on the worker thread, then post to the worker handler
        sWorker.post(r);
    }
}
 
Example 12
Source File: LauncherModel.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/** Runs the specified runnable immediately if called from the worker thread, otherwise it is
 * posted on the worker thread handler. */
@Thunk static void runOnWorkerThread(Runnable r) {
    if (sWorkerThread.getThreadId() == Process.myTid()) {
        r.run();
    } else {
        // If we are not on the worker thread, then post to the worker handler
        sWorker.post(r);
    }
}
 
Example 13
Source File: LauncherModel.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/** Runs the specified runnable immediately if called from the main thread, otherwise it is
 * posted on the main thread handler. */
@Thunk void runOnMainThread(Runnable r) {
    if (sWorkerThread.getThreadId() == Process.myTid()) {
        // If we are on the worker thread, post onto the main handler
        mHandler.post(r);
    } else {
        r.run();
    }
}
 
Example 14
Source File: LauncherModel.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/** Runs the specified runnable immediately if called from the main thread, otherwise it is
 * posted on the main thread handler. */
private void runOnMainThread(Runnable r) {
    if (sWorkerThread.getThreadId() == Process.myTid()) {
        // If we are on the worker thread, post onto the main handler
        mHandler.post(r);
    } else {
        r.run();
    }
}
 
Example 15
Source File: MoneroHandlerThread.java    From xmrwallet with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    mTid = Process.myTid();
    Looper.prepare();
    synchronized (this) {
        mLooper = Looper.myLooper();
        notifyAll();
    }
    Process.setThreadPriority(mPriority);
    onLooperPrepared();
    Looper.loop();
    mTid = -1;
}
 
Example 16
Source File: LauncherModel.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
private void onlyBindAllApps() {
    final Callbacks oldCallbacks = mCallbacks.get();
    if (oldCallbacks == null) {
        // This launcher has exited and nobody bothered to tell us.  Just bail.
        Log.w(TAG, "LoaderTask running with no launcher (onlyBindAllApps)");
        return;
    }

    // shallow copy
    @SuppressWarnings("unchecked")
    final ArrayList<AppInfo> list
            = (ArrayList<AppInfo>) mBgAllAppsList.data.clone();
    Runnable r = new Runnable() {
        public void run() {
            final long t = SystemClock.uptimeMillis();
            final Callbacks callbacks = tryGetCallbacks(oldCallbacks);
            if (callbacks != null) {
                callbacks.bindAllApplications(list);
            }
            if (DEBUG_LOADERS) {
                Log.d(TAG, "bound all " + list.size() + " apps from cache in "
                        + (SystemClock.uptimeMillis()-t) + "ms");
            }
        }
    };
    boolean isRunningOnMainThread = !(sWorkerThread.getThreadId() == Process.myTid());
    if (isRunningOnMainThread) {
        r.run();
    } else {
        mHandler.post(r);
    }
}
 
Example 17
Source File: PeerConnectionFactory.java    From webrtc_android with MIT License 4 votes vote down vote up
public static ThreadInfo getCurrent() {
  return new ThreadInfo(Thread.currentThread(), Process.myTid());
}
 
Example 18
Source File: Utilities.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public static void assertWorkerThread() {
    if (LauncherAppState.isDogfoodBuild() &&
            (LauncherModel.sWorkerThread.getThreadId() != Process.myTid())) {
        throw new IllegalStateException();
    }
}
 
Example 19
Source File: EarlyTraceEvent.java    From 365browser with Apache License 2.0 4 votes vote down vote up
Event(String name) {
    mName = name;
    mThreadId = Process.myTid();
    mBeginTimeMs = SystemClock.elapsedRealtime();
}
 
Example 20
Source File: EarlyTraceEvent.java    From cronet with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Returns a key which consists of |name| and the ID of the current thread.
 * The key is used with pending events making them thread-specific, thus avoiding
 * an exception when similarly named events are started from multiple threads.
 */
@VisibleForTesting
static String makeEventKeyForCurrentThread(String name) {
    return name + "@" + Process.myTid();
}