Skip to content

Instantly share code, notes, and snippets.

View user-mw's full-sized avatar

Vladislav user-mw

  • Russian Federation
View GitHub Profile
@user-mw
user-mw / CoroutineContext.kt
Created April 28, 2022 10:26
CoroutineContext. Whole interface.
package kotlin.coroutines
/**
* Persistent context for the coroutine. It is an indexed set of [Element] instances.
* An indexed set is a mix between a set and a map.
* Every element in this set has a unique [Key].
*/
@SinceKotlin("1.3")
public interface CoroutineContext {
/**
@user-mw
user-mw / CoroutineScope.kt
Created April 19, 2022 05:30
Code of entire file CoroutineScope.kt
@file:OptIn(ExperimentalContracts::class)
package kotlinx.coroutines
import kotlinx.coroutines.internal.*
import kotlinx.coroutines.intrinsics.*
import kotlin.contracts.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
@user-mw
user-mw / CoroutineScope.kt
Created April 18, 2022 05:59
Coroutines. CoroutineScope code
// Code
public interface CoroutineScope {
/**
* The context of this scope.
* Context is encapsulated by the scope and used for implementation of coroutine builders that are extensions on the scope.
* Accessing this property in general code is not recommended for any purposes except accessing the [Job] instance for advanced usages.
*
* By convention, should contain an instance of a [job][Job] to enforce structured concurrency.
*/
@user-mw
user-mw / Builders.common.kt
Created April 15, 2022 06:18
Coroutines. async() inside
// Code
public fun <T> CoroutineScope.async(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> T
): Deferred<T> {
val newContext = newCoroutineContext(context)
val coroutine = if (start.isLazy)
LazyDeferredCoroutine(newContext, block) else
@user-mw
user-mw / Builders.common.kt
Created April 13, 2022 06:08
Coroutines. launch() inside
// Code
public fun CoroutineScope.launch(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> Unit
): Job {
val newContext = newCoroutineContext(context)
val coroutine = if (start.isLazy)
LazyStandaloneCoroutine(newContext, block) else
@user-mw
user-mw / ClipboardService.java
Last active July 25, 2021 15:06
Method setPrimaryClip() inside ClipboardImpl
public class ClipboardService extends SystemService {
// Code
private class ClipboardImpl extends IClipboard.Stub {
// Code
@Override
public void setPrimaryClip(ClipData clip, String callingPackage, @UserIdInt int userId) {
synchronized (this) {
if (clip == null || clip.getItemCount() <= 0) {
@user-mw
user-mw / ClipboardManager.java
Created June 6, 2021 16:37
Code of setPrimaryClip() in ClipboardManager.java
@SystemService(Context.CLIPBOARD_SERVICE)
public class ClipboardManager extends android.text.ClipboardManager {
// Code
public void setPrimaryClip(@NonNull ClipData clip) {
try {
// Code
mService.setPrimaryClip(clip, mContext.getOpPackageName(), mContext.getUserId());
} catch (RemoteException e) {
@user-mw
user-mw / ClipboardManager.java
Created June 1, 2021 18:21
Method reportPrimaryClipChanged()
@SystemService(Context.CLIPBOARD_SERVICE)
public class ClipboardManager extends android.text.ClipboardManager {
// Code
@UnsupportedAppUsage
void reportPrimaryClipChanged() {
// Code
synchronized (mPrimaryClipChangedListeners) {
@user-mw
user-mw / ClipboardManager.java
Created June 1, 2021 18:14
Initialization of mPrimaryClipChangedServiceListener
@SystemService(Context.CLIPBOARD_SERVICE)
public class ClipboardManager extends android.text.ClipboardManager {
// Code
private final IOnPrimaryClipChangedListener.Stub mPrimaryClipChangedServiceListener
= new IOnPrimaryClipChangedListener.Stub() {
@Override
public void dispatchPrimaryClipChanged() {
mHandler.post(() -> {
@user-mw
user-mw / ClipboardManager.java
Created June 1, 2021 16:49
Method addPrimaryClipChangedListener() in ClipboardManager.java
@SystemService(Context.CLIPBOARD_SERVICE)
public class ClipboardManager extends android.text.ClipboardManager {
// Code
public void addPrimaryClipChangedListener(OnPrimaryClipChangedListener what) {
// Code
mService.addPrimaryClipChangedListener(
mPrimaryClipChangedServiceListener, mContext.getOpPackageName(),
mContext.getUserId());