Wrap query handlers in MutexKt.withLock
This commit is contained in:
@@ -19,10 +19,13 @@ import java.net.URL;
|
|||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
|
||||||
|
import kotlin.jvm.functions.Function0;
|
||||||
import kotlin.jvm.functions.Function2;
|
import kotlin.jvm.functions.Function2;
|
||||||
import kotlin.coroutines.Continuation;
|
import kotlin.coroutines.Continuation;
|
||||||
import kotlin.coroutines.EmptyCoroutineContext;
|
import kotlin.coroutines.EmptyCoroutineContext;
|
||||||
import kotlinx.coroutines.BuildersKt;
|
import kotlinx.coroutines.BuildersKt;
|
||||||
|
import kotlinx.coroutines.sync.Mutex;
|
||||||
|
import kotlinx.coroutines.sync.MutexKt;
|
||||||
|
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@@ -46,6 +49,7 @@ import net.typeblog.lpac_jni.ProfileDownloadCallback;
|
|||||||
public class LpaBridgeProvider extends ContentProvider
|
public class LpaBridgeProvider extends ContentProvider
|
||||||
{
|
{
|
||||||
private AppContainer appContainer;
|
private AppContainer appContainer;
|
||||||
|
private final Mutex mutex = MutexKt.Mutex(false);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate()
|
public boolean onCreate()
|
||||||
@@ -55,6 +59,7 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
|
||||||
{
|
{
|
||||||
MatrixCursor rows;
|
MatrixCursor rows;
|
||||||
@@ -68,6 +73,22 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rows = (MatrixCursor) BuildersKt.runBlocking
|
||||||
|
(
|
||||||
|
EmptyCoroutineContext.INSTANCE,
|
||||||
|
(_, continuation) -> MutexKt.withLock
|
||||||
|
(
|
||||||
|
mutex,
|
||||||
|
null,
|
||||||
|
new Function0<MatrixCursor>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public MatrixCursor invoke()
|
||||||
|
{
|
||||||
|
MatrixCursor rows;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (path)
|
switch (path)
|
||||||
@@ -134,6 +155,18 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
{
|
{
|
||||||
rows = error(ex.getMessage());
|
rows = error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
continuation
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
rows = error(ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectColumns(rows, projection, new String[] { "error" });
|
return projectColumns(rows, projection, new String[] { "error" });
|
||||||
|
|||||||
Reference in New Issue
Block a user