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;
|
||||||
@@ -70,65 +75,93 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (path)
|
rows = (MatrixCursor) BuildersKt.runBlocking
|
||||||
{
|
(
|
||||||
case "ping":
|
EmptyCoroutineContext.INSTANCE,
|
||||||
// out: ping=pong
|
(_, continuation) -> MutexKt.withLock
|
||||||
rows = handlePing(args);
|
(
|
||||||
break;
|
mutex,
|
||||||
case "cards":
|
null,
|
||||||
// out (many, can be empty): slotId, portId
|
new Function0<MatrixCursor>()
|
||||||
rows = handleGetCards(args);
|
{
|
||||||
break;
|
@Override
|
||||||
case "profiles":
|
public MatrixCursor invoke()
|
||||||
// in: slotId, portId
|
{
|
||||||
// out (many, can be empty): iccid, isEnabled, name, nickname
|
MatrixCursor rows;
|
||||||
rows = handleGetProfiles(args);
|
|
||||||
break;
|
try
|
||||||
case "downloadProfile":
|
{
|
||||||
// in: (slotId, portId) AND (activationCode OR address, matchingId?, confirmationCode?) AND imei?
|
switch (path)
|
||||||
// out (single, can be empty): iccid, isEnabled, name, nickname
|
{
|
||||||
rows = handleDownloadProfile(args);
|
case "ping":
|
||||||
break;
|
// out: ping=pong
|
||||||
case "deleteProfile":
|
rows = handlePing(args);
|
||||||
// in: slotId, portId, iccid
|
break;
|
||||||
// out: success
|
case "cards":
|
||||||
rows = handleDeleteProfile(args);
|
// out (many, can be empty): slotId, portId
|
||||||
break;
|
rows = handleGetCards(args);
|
||||||
case "enableProfile":
|
break;
|
||||||
// in: slotId, portId, iccid, refresh(true)
|
case "profiles":
|
||||||
// out: success
|
// in: slotId, portId
|
||||||
rows = handleEnableProfile(args);
|
// out (many, can be empty): iccid, isEnabled, name, nickname
|
||||||
break;
|
rows = handleGetProfiles(args);
|
||||||
case "disableProfile":
|
break;
|
||||||
// in: slotId, portId, iccid, refresh(true)
|
case "downloadProfile":
|
||||||
// out: success
|
// in: (slotId, portId) AND (activationCode OR address, matchingId?, confirmationCode?) AND imei?
|
||||||
rows = handleDisableProfile(args);
|
// out (single, can be empty): iccid, isEnabled, name, nickname
|
||||||
break;
|
rows = handleDownloadProfile(args);
|
||||||
case "activeProfile":
|
break;
|
||||||
// in: slotId, portId
|
case "deleteProfile":
|
||||||
// out (single, can be empty): iccid, isEnabled, name, nickname
|
// in: slotId, portId, iccid
|
||||||
rows = handleGetActiveProfile(args);
|
// out: success
|
||||||
break;
|
rows = handleDeleteProfile(args);
|
||||||
case "disableActiveProfile":
|
break;
|
||||||
// in: slotId, portId, refresh(true)
|
case "enableProfile":
|
||||||
// out (single, can be empty): iccid, isEnabled, name, nickname
|
// in: slotId, portId, iccid, refresh(true)
|
||||||
rows = handleDisableActiveProfile(args);
|
// out: success
|
||||||
break;
|
rows = handleEnableProfile(args);
|
||||||
case "switchProfile":
|
break;
|
||||||
// in: slotId, portId, iccid, enable(true), refresh(true)
|
case "disableProfile":
|
||||||
// out: success
|
// in: slotId, portId, iccid, refresh(true)
|
||||||
rows = handleSwitchProfile(args);
|
// out: success
|
||||||
break;
|
rows = handleDisableProfile(args);
|
||||||
case "setNickname":
|
break;
|
||||||
// in: slotId, portId, iccid, nickname
|
case "activeProfile":
|
||||||
// out: success
|
// in: slotId, portId
|
||||||
rows = handleSetNickname(args);
|
// out (single, can be empty): iccid, isEnabled, name, nickname
|
||||||
break;
|
rows = handleGetActiveProfile(args);
|
||||||
default:
|
break;
|
||||||
rows = error("unknown_path");
|
case "disableActiveProfile":
|
||||||
break;
|
// in: slotId, portId, refresh(true)
|
||||||
}
|
// out (single, can be empty): iccid, isEnabled, name, nickname
|
||||||
|
rows = handleDisableActiveProfile(args);
|
||||||
|
break;
|
||||||
|
case "switchProfile":
|
||||||
|
// in: slotId, portId, iccid, enable(true), refresh(true)
|
||||||
|
// out: success
|
||||||
|
rows = handleSwitchProfile(args);
|
||||||
|
break;
|
||||||
|
case "setNickname":
|
||||||
|
// in: slotId, portId, iccid, nickname
|
||||||
|
// out: success
|
||||||
|
rows = handleSetNickname(args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
rows = error("unknown_path");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
rows = error(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
continuation
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user