Convert cols from string to boolean in rowsToJson
This commit is contained in:
@@ -36,6 +36,7 @@ import android.database.Cursor;
|
|||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
import im.angry.openeuicc.OpenEuiccApplication;
|
import im.angry.openeuicc.OpenEuiccApplication;
|
||||||
@@ -56,12 +57,21 @@ import net.typeblog.lpac_jni.ProfileDownloadCallback;
|
|||||||
public class LpaProvider extends ContentProvider
|
public class LpaProvider extends ContentProvider
|
||||||
{
|
{
|
||||||
private AppContainer appContainer;
|
private AppContainer appContainer;
|
||||||
private final Mutex mutex = MutexKt.Mutex(false);
|
private Mutex mutex;
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate()
|
public boolean onCreate()
|
||||||
{
|
{
|
||||||
appContainer = ((OpenEuiccApplication) getContext().getApplicationContext()).getAppContainer();
|
appContainer = ((OpenEuiccApplication) getContext().getApplicationContext()).getAppContainer();
|
||||||
|
|
||||||
|
mutex = MutexKt.Mutex(false);
|
||||||
|
|
||||||
|
gson = new GsonBuilder()
|
||||||
|
.serializeNulls()
|
||||||
|
.disableHtmlEscaping()
|
||||||
|
.create();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +119,13 @@ public class LpaProvider extends ContentProvider
|
|||||||
// out (many, can be empty): int slotId, int portId
|
// out (many, can be empty): int slotId, int portId
|
||||||
case "cards" -> handleGetCards(args);
|
case "cards" -> handleGetCards(args);
|
||||||
// in: int slotId, int portId
|
// in: int slotId, int portId
|
||||||
// out (many, can be empty): string iccid, bool isEnabled, string name, string nickname
|
// out (many, can be empty): string iccid, bool enabled, string name, string nickname
|
||||||
case "profiles" -> handleGetProfiles(args);
|
case "profiles" -> handleGetProfiles(args);
|
||||||
// in: int slotId, int portId
|
// in: int slotId, int portId
|
||||||
// out (single, can be empty): string iccid, bool isEnabled, string name, string nickname
|
// out (single, can be empty): string iccid, bool enabled, string name, string nickname
|
||||||
case "activeProfile" -> handleGetActiveProfile(args);
|
case "activeProfile" -> handleGetActiveProfile(args);
|
||||||
// in: int slotId, int portId, (either {string activationCode} or {string address, string? matchingId}), string? confirmationCode, string? imei
|
// in: int slotId, int portId, (either {string activationCode} or {string address, string? matchingId}), string? confirmationCode, string? imei
|
||||||
// out (single, can be empty): string iccid, bool isEnabled, string name, string nickname
|
// out (single, can be empty): string iccid, bool enabled, string name, string nickname
|
||||||
case "downloadProfile" -> handleDownloadProfile(args);
|
case "downloadProfile" -> handleDownloadProfile(args);
|
||||||
// in: int slotId, int portId, string iccid
|
// in: int slotId, int portId, string iccid
|
||||||
// out: bool success
|
// out: bool success
|
||||||
@@ -561,7 +571,7 @@ public class LpaProvider extends ContentProvider
|
|||||||
|
|
||||||
// region LPA Helpers
|
// region LPA Helpers
|
||||||
|
|
||||||
private EuiccChannel findEuiccChannel(DefaultEuiccChannelManager euiccChannelManager, int slotId, int portId) throws Exception
|
private static EuiccChannel findEuiccChannel(DefaultEuiccChannelManager euiccChannelManager, int slotId, int portId) throws Exception
|
||||||
{
|
{
|
||||||
var findEuiccChannelByPortMethod = DefaultEuiccChannelManager.class.getDeclaredMethod("findEuiccChannelByPort", int.class, int.class, Continuation.class);
|
var findEuiccChannelByPortMethod = DefaultEuiccChannelManager.class.getDeclaredMethod("findEuiccChannelByPort", int.class, int.class, Continuation.class);
|
||||||
findEuiccChannelByPortMethod.setAccessible(true);
|
findEuiccChannelByPortMethod.setAccessible(true);
|
||||||
@@ -767,7 +777,7 @@ public class LpaProvider extends ContentProvider
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requireSlotAndPort(Map<String, String> args, int[] slotIdOut, int[] portIdOut) throws Exception
|
private static void requireSlotAndPort(Map<String, String> args, int[] slotIdOut, int[] portIdOut) throws Exception
|
||||||
{
|
{
|
||||||
final String slotIdArg = "slotId";
|
final String slotIdArg = "slotId";
|
||||||
final String portIdArg = "portId";
|
final String portIdArg = "portId";
|
||||||
@@ -835,7 +845,7 @@ public class LpaProvider extends ContentProvider
|
|||||||
String[] columns =
|
String[] columns =
|
||||||
{
|
{
|
||||||
"iccid",
|
"iccid",
|
||||||
"isEnabled",
|
"enabled",
|
||||||
"name",
|
"name",
|
||||||
"nickname"
|
"nickname"
|
||||||
};
|
};
|
||||||
@@ -925,7 +935,7 @@ public class LpaProvider extends ContentProvider
|
|||||||
return outRows;
|
return outRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String rowsToJson(MatrixCursor rows)
|
private String rowsToJson(MatrixCursor rows)
|
||||||
{
|
{
|
||||||
String[] rowCols = rows.getColumnNames();
|
String[] rowCols = rows.getColumnNames();
|
||||||
var outRows = new ArrayList<Map<String, Object>>();
|
var outRows = new ArrayList<Map<String, Object>>();
|
||||||
@@ -963,15 +973,31 @@ public class LpaProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var booleanCols = List.of
|
||||||
|
(
|
||||||
|
"success",
|
||||||
|
"enabled"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (String colName : booleanCols)
|
||||||
|
{
|
||||||
|
Object colValue = row.get(colName);
|
||||||
|
|
||||||
|
if (colValue instanceof String)
|
||||||
|
{
|
||||||
|
String colValueString = (String) colValue;
|
||||||
|
|
||||||
|
if (colValueString.equalsIgnoreCase("false") || colValueString.equalsIgnoreCase("true"))
|
||||||
|
{
|
||||||
|
row.put(colName, Boolean.parseBoolean(colValueString));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
outRows.add(row);
|
outRows.add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
String json = new GsonBuilder()
|
return gson.toJson(outRows);
|
||||||
.serializeNulls()
|
|
||||||
.create()
|
|
||||||
.toJson(outRows);
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
@@ -980,10 +1006,7 @@ public class LpaProvider extends ContentProvider
|
|||||||
|
|
||||||
private void httpPostAsJson(URL url, Map<String, Object> data) throws Exception
|
private void httpPostAsJson(URL url, Map<String, Object> data) throws Exception
|
||||||
{
|
{
|
||||||
String json = new GsonBuilder()
|
String json = gson.toJson(data);
|
||||||
.serializeNulls()
|
|
||||||
.create()
|
|
||||||
.toJson(data);
|
|
||||||
|
|
||||||
var httpConnection = (HttpURLConnection) url.openConnection();
|
var httpConnection = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user