Refactor
This commit is contained in:
@@ -236,22 +236,14 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
|
|
||||||
private MatrixCursor handleGetProfiles(Map<String, String> args) throws Exception
|
private MatrixCursor handleGetProfiles(Map<String, String> args) throws Exception
|
||||||
{
|
{
|
||||||
List<LocalProfileInfo> profiles = withEuiccChannel
|
var profiles = getProfiles(args);
|
||||||
(
|
|
||||||
args,
|
|
||||||
(channel, _) -> channel.getLpa().getProfiles()
|
|
||||||
);
|
|
||||||
|
|
||||||
return profiles(profiles);
|
return profiles(profiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MatrixCursor handleGetActiveProfile(Map<String, String> args) throws Exception
|
private MatrixCursor handleGetActiveProfile(Map<String, String> args) throws Exception
|
||||||
{
|
{
|
||||||
List<LocalProfileInfo> profiles = withEuiccChannel
|
var profiles = getProfiles(args);
|
||||||
(
|
|
||||||
args,
|
|
||||||
(channel, _) -> channel.getLpa().getProfiles()
|
|
||||||
);
|
|
||||||
|
|
||||||
var enabledProfile = LPAUtilsKt.getEnabled(profiles);
|
var enabledProfile = LPAUtilsKt.getEnabled(profiles);
|
||||||
|
|
||||||
@@ -284,11 +276,7 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
else if (!tryGetArgAsString(args, "address", address))
|
else if (!tryGetArgAsString(args, "address", address))
|
||||||
return missingArgError("activationCode_or_address");
|
return missingArgError("activationCode_or_address");
|
||||||
|
|
||||||
List<LocalProfileInfo> profilesBefore = withEuiccChannel
|
var profilesBefore = getProfiles(args);
|
||||||
(
|
|
||||||
args,
|
|
||||||
(channel, _) -> channel.getLpa().getProfiles()
|
|
||||||
);
|
|
||||||
|
|
||||||
var iccidsBefore = profilesBefore.stream()
|
var iccidsBefore = profilesBefore.stream()
|
||||||
.map(LocalProfileInfo::getIccid)
|
.map(LocalProfileInfo::getIccid)
|
||||||
@@ -316,7 +304,6 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
{
|
{
|
||||||
String[] callbackUrl = new String[1];
|
String[] callbackUrl = new String[1];
|
||||||
|
|
||||||
// TODO: test if it works
|
|
||||||
if (tryGetArgAsString(args, "callbackUrl", callbackUrl))
|
if (tryGetArgAsString(args, "callbackUrl", callbackUrl))
|
||||||
{
|
{
|
||||||
var url = new URI(callbackUrl[0]).toURL();
|
var url = new URI(callbackUrl[0]).toURL();
|
||||||
@@ -348,11 +335,7 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
List<LocalProfileInfo> profilesAfter = withEuiccChannel
|
var profilesAfter = getProfiles(args);
|
||||||
(
|
|
||||||
args,
|
|
||||||
(channel, _) -> channel.getLpa().getProfiles()
|
|
||||||
);
|
|
||||||
|
|
||||||
var downloadedProfile = profilesAfter.stream()
|
var downloadedProfile = profilesAfter.stream()
|
||||||
.filter(p -> !iccidsBefore.contains(p.getIccid()))
|
.filter(p -> !iccidsBefore.contains(p.getIccid()))
|
||||||
@@ -362,6 +345,37 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
if (downloadedProfile == null)
|
if (downloadedProfile == null)
|
||||||
return empty();
|
return empty();
|
||||||
|
|
||||||
|
// boolean[] enable = new boolean[1];
|
||||||
|
// boolean[] refresh = new boolean[1];
|
||||||
|
|
||||||
|
// if (tryGetArgAsBoolean(args, "enable", enable) && enable[0])
|
||||||
|
// {
|
||||||
|
// if (!tryGetArgAsBoolean(args, "refresh", refresh))
|
||||||
|
// refresh[0] = true;
|
||||||
|
|
||||||
|
// String iccid = downloadedProfile.getIccid();
|
||||||
|
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// withEuiccChannel
|
||||||
|
// (
|
||||||
|
// args,
|
||||||
|
// (channel, _) -> channel.getLpa().enableProfile(iccid, refresh[0])
|
||||||
|
// );
|
||||||
|
|
||||||
|
// profilesAfter = getProfiles(args);
|
||||||
|
|
||||||
|
// downloadedProfile = profilesAfter.stream()
|
||||||
|
// .filter(p -> p.getIccid().equals(iccid))
|
||||||
|
// .findFirst()
|
||||||
|
// .orElseThrow(); // should never happen
|
||||||
|
// }
|
||||||
|
// catch (Exception ex)
|
||||||
|
// {
|
||||||
|
// // ignored
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
return profile(downloadedProfile);
|
return profile(downloadedProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,11 +453,7 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
// if (iccid == null)
|
// if (iccid == null)
|
||||||
// return empty();
|
// return empty();
|
||||||
|
|
||||||
// List<LocalProfileInfo> profiles = withEuiccChannel
|
// var profiles = getProfiles(args);
|
||||||
// (
|
|
||||||
// args,
|
|
||||||
// (channel, _) -> channel.getLpa().getProfiles()
|
|
||||||
// );
|
|
||||||
|
|
||||||
// var profile = profiles.stream()
|
// var profile = profiles.stream()
|
||||||
// .filter(p -> iccid.equals(p.getIccid()))
|
// .filter(p -> iccid.equals(p.getIccid()))
|
||||||
@@ -532,24 +542,28 @@ public class LpaBridgeProvider extends ContentProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> T withEuiccChannel(int slotId, int portId, Function2<EuiccChannel, Continuation<? super T>, ?> operation) throws Exception
|
|
||||||
{
|
|
||||||
var euiccChannelManager = appContainer.getEuiccChannelManager();
|
|
||||||
|
|
||||||
return (T) BuildersKt.runBlocking
|
|
||||||
(
|
|
||||||
EmptyCoroutineContext.INSTANCE,
|
|
||||||
(_, continuation) -> euiccChannelManager.withEuiccChannel(slotId, portId, operation, continuation)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> T withEuiccChannel(Map<String, String> args, Function2<EuiccChannel, Continuation<? super T>, ?> operation) throws Exception
|
private <T> T withEuiccChannel(Map<String, String> args, Function2<EuiccChannel, Continuation<? super T>, ?> operation) throws Exception
|
||||||
{
|
{
|
||||||
var slotId = new int[1];
|
var slotId = new int[1];
|
||||||
var portId = new int[1];
|
var portId = new int[1];
|
||||||
requireSlotAndPort(args, slotId, portId);
|
requireSlotAndPort(args, slotId, portId);
|
||||||
|
|
||||||
return withEuiccChannel(slotId[0], portId[0], operation);
|
var euiccChannelManager = appContainer.getEuiccChannelManager();
|
||||||
|
|
||||||
|
return (T) BuildersKt.runBlocking
|
||||||
|
(
|
||||||
|
EmptyCoroutineContext.INSTANCE,
|
||||||
|
(_, continuation) -> euiccChannelManager.withEuiccChannel(slotId[0], portId[0], operation, continuation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LocalProfileInfo> getProfiles(Map<String, String> args) throws Exception
|
||||||
|
{
|
||||||
|
return withEuiccChannel
|
||||||
|
(
|
||||||
|
args,
|
||||||
|
(channel, _) -> channel.getLpa().getProfiles()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user