Handle notifications

This commit is contained in:
Laiteux
2025-11-07 14:47:07 +04:00
parent 9d633b36f7
commit 75eab9f3d0

View File

@@ -51,6 +51,7 @@ import im.angry.openeuicc.util.ActivationCode;
import im.angry.openeuicc.util.PreferenceUtilsKt; import im.angry.openeuicc.util.PreferenceUtilsKt;
import im.angry.openeuicc.util.PreferenceFlowWrapper; import im.angry.openeuicc.util.PreferenceFlowWrapper;
import net.typeblog.lpac_jni.LocalProfileInfo; import net.typeblog.lpac_jni.LocalProfileInfo;
import net.typeblog.lpac_jni.LocalProfileNotification;
import net.typeblog.lpac_jni.ProfileDownloadCallback; import net.typeblog.lpac_jni.ProfileDownloadCallback;
public class LpaProvider extends ContentProvider public class LpaProvider extends ContentProvider
@@ -425,6 +426,8 @@ public class LpaProvider extends ContentProvider
// } // }
// } // }
handleNotification(args, downloadedProfile.getIccid(), LocalProfileNotification.Operation.Install);
return profile(downloadedProfile); return profile(downloadedProfile);
} }
@@ -443,6 +446,9 @@ public class LpaProvider extends ContentProvider
(channel, _) -> channel.getLpa().deleteProfile(iccid[0]) (channel, _) -> channel.getLpa().deleteProfile(iccid[0])
); );
if (success)
handleNotification(args, iccid[0], LocalProfileNotification.Operation.Delete);
return success(success); return success(success);
} }
@@ -457,12 +463,23 @@ public class LpaProvider extends ContentProvider
if (!tryGetArgAsBoolean(args, "refresh", refresh)) if (!tryGetArgAsBoolean(args, "refresh", refresh))
refresh[0] = true; refresh[0] = true;
var profiles = getProfiles(args);
var previousActiveProfile = LPAUtilsKt.getEnabled(profiles);
boolean success = withEuiccChannel boolean success = withEuiccChannel
( (
args, args,
(channel, _) -> channel.getLpa().enableProfile(iccid[0], refresh[0]) (channel, _) -> channel.getLpa().enableProfile(iccid[0], refresh[0])
); );
if (success)
{
if (previousActiveProfile != null)
handleNotification(args, previousActiveProfile.getIccid(), LocalProfileNotification.Operation.Disable);
handleNotification(args, iccid[0], LocalProfileNotification.Operation.Enable);
}
return success(success); return success(success);
} }
@@ -485,6 +502,9 @@ public class LpaProvider extends ContentProvider
(channel, _) -> channel.getLpa().disableProfile(iccid[0], refresh[0]) (channel, _) -> channel.getLpa().disableProfile(iccid[0], refresh[0])
); );
if (success)
handleNotification(args, iccid[0], LocalProfileNotification.Operation.Disable);
return success(success); return success(success);
} }
@@ -503,6 +523,9 @@ public class LpaProvider extends ContentProvider
(channel, _) -> LPAUtilsKt.disableActiveProfileKeepIccId(channel.getLpa(), refresh[0]) (channel, _) -> LPAUtilsKt.disableActiveProfileKeepIccId(channel.getLpa(), refresh[0])
); );
if (iccid != null)
handleNotification(args, iccid, LocalProfileNotification.Operation.Disable);
return success(); return success();
// if (iccid == null) // if (iccid == null)
@@ -604,6 +627,53 @@ public class LpaProvider extends ContentProvider
return profiles; return profiles;
} }
private void handleNotification(Map<String, String> args, String iccid, LocalProfileNotification.Operation operation)
{
try
{
var preferenceName = switch (operation)
{
case Install -> "notificationsDownload";
case Delete -> "notificationsDelete";
case Enable, Disable -> "notificationsSwitch";
};
if (!getPreference(preferenceName))
return;
@SuppressWarnings("unchecked")
var notifications = (List<LocalProfileNotification>) withEuiccChannel
(
args,
(channel, _) -> channel.getLpa().getNotifications()
);
var notification = notifications.stream()
.filter(n -> n.getIccid().equals(iccid) && n.getProfileManagementOperation() == operation)
.sorted((n1, n2) -> Long.compare(n2.getSeqNumber(), n1.getSeqNumber())) // descending
.findFirst()
.orElse(null);
if (notification == null)
return;
withEuiccChannel
(
args,
(channel, _) ->
{
channel.getLpa().handleNotification(notification);
channel.getLpa().deleteNotification(notification.getSeqNumber());
return null;
}
);
}
catch (Exception ex)
{
// ignored
}
}
// endregion // endregion
// region Preference Helpers // region Preference Helpers