3838import java .util .Objects ;
3939import java .util .regex .Matcher ;
4040import java .util .regex .Pattern ;
41+ import java .util .stream .Stream ;
4142
4243import static airsquared .blobsaver .app .Utils .containsIgnoreCase ;
4344import static airsquared .blobsaver .app .Utils .executeProgram ;
4445import static airsquared .blobsaver .app .Utils .extractBuildManifest ;
4546import static airsquared .blobsaver .app .Utils .getFirmwareList ;
47+ import static airsquared .blobsaver .app .Utils .getSignedBetas ;
4648import static airsquared .blobsaver .app .Utils .getSignedFirmwares ;
4749
4850public class TSS extends Task <String > {
@@ -57,6 +59,7 @@ public class TSS extends Task<String> {
5759
5860 private final String boardConfig ;
5961
62+ private final boolean includeBetas ;
6063 private final String manualVersion ;
6164 private final String manualIpswURL ;
6265
@@ -67,11 +70,12 @@ public class TSS extends Task<String> {
6770 /**
6871 * Private constructor; use {@link TSS.Builder} instead
6972 */
70- private TSS (String deviceIdentifier , String ecid , String savePath , String boardConfig , String manualVersion , String manualIpswURL , String apnonce , String generator , boolean saveToTSSSaver , boolean saveToSHSHHost ) {
73+ private TSS (String deviceIdentifier , String ecid , String savePath , String boardConfig , boolean includeBetas , String manualVersion , String manualIpswURL , String apnonce , String generator , boolean saveToTSSSaver , boolean saveToSHSHHost ) {
7174 this .deviceIdentifier = deviceIdentifier ;
7275 this .ecid = ecid ;
7376 this .savePath = savePath ;
7477 this .boardConfig = boardConfig ;
78+ this .includeBetas = includeBetas ;
7579 this .manualVersion = manualVersion ;
7680 this .manualIpswURL = manualIpswURL ;
7781 this .apnonce = apnonce ;
@@ -91,7 +95,6 @@ protected String call() throws TSSException {
9195 List <Utils .IOSVersion > iosVersions = getIOSVersions ();
9296 System .out .println ("iosVersions = " + iosVersions );
9397 ArrayList <String > args = constructArgs ();
94- final int urlIndex = args .size () - 1 ;
9598
9699 StringBuilder responseBuilder = new StringBuilder ("Successfully saved blobs in\n " ).append (savePath );
97100 if (manualIpswURL == null ) {
@@ -100,18 +103,7 @@ protected String call() throws TSSException {
100103
101104 // can't use forEach() because exception won't be caught
102105 for (Utils .IOSVersion iosVersion : iosVersions ) {
103- try {
104- args .set (urlIndex , extractBuildManifest (iosVersion .ipswURL ()).toString ());
105- } catch (IOException e ) {
106- throw new TSSException ("Unable to extract BuildManifest." , true , e );
107- }
108- try {
109- System .out .println ("Running: " + args );
110- String tssLog = executeProgram (args );
111- parseTSSLog (tssLog );
112- } catch (IOException e ) {
113- throw new TSSException ("There was an error starting tsschecker." , true , e );
114- }
106+ saveFor (iosVersion , args );
115107
116108 if (iosVersion .versionString () != null ) {
117109 responseBuilder .append (iosVersion .versionString ());
@@ -134,6 +126,29 @@ protected String call() throws TSSException {
134126 return responseBuilder .toString ();
135127 }
136128
129+
130+ private void saveFor (Utils .IOSVersion iosVersion , ArrayList <String > args ) throws TSSException {
131+ final int urlIndex = args .size () - 1 ;
132+ try {
133+ args .set (urlIndex , extractBuildManifest (iosVersion .ipswURL ()).toString ());
134+ } catch (IOException e ) {
135+ throw new TSSException ("Unable to extract BuildManifest." , true , e );
136+ }
137+ try {
138+ System .out .println ("Running: " + args );
139+ String tssLog = executeProgram (args );
140+ parseTSSLog (tssLog );
141+ } catch (IOException e ) {
142+ throw new TSSException ("There was an error starting tsschecker." , true , e );
143+ } catch (TSSException e ) {
144+ if ((manualVersion == null && manualIpswURL == null ) && e .getMessage ().contains ("not being signed" )) {
145+ System .out .println ("Warning: ignoring unsigned version; API might be out of date" );
146+ return ; // ignore not being signed (API might not be updated)
147+ }
148+ throw e ;
149+ }
150+ }
151+
137152 private void checkInputs () throws TSSException {
138153 boolean hasCorrectIdentifierPrefix = deviceIdentifier .startsWith ("iPad" ) || deviceIdentifier .startsWith ("iPod" )
139154 || deviceIdentifier .startsWith ("iPhone" ) || deviceIdentifier .startsWith ("AppleTV" );
@@ -177,6 +192,8 @@ private List<Utils.IOSVersion> getIOSVersions() throws TSSException {
177192 .orElseThrow (() -> new TSSException ("No versions found." , false )));
178193 } else if (manualIpswURL != null ) {
179194 return Collections .singletonList (new Utils .IOSVersion (null , manualIpswURL , null ));
195+ } else if (includeBetas ) {
196+ return Stream .concat (getSignedFirmwares (deviceIdentifier ), getSignedBetas (deviceIdentifier )).toList ();
180197 } else { // all signed firmwares
181198 return getSignedFirmwares (deviceIdentifier ).toList ();
182199 }
@@ -252,7 +269,7 @@ && containsIgnoreCase(tsscheckerLog, "checking tss status failed")) {
252269 @ SuppressWarnings ("UnusedReturnValue" )
253270 public static class Builder {
254271 private String device , ecid , savePath , boardConfig , manualVersion , manualIpswURL , apnonce , generator ;
255- private boolean saveToTSSSaver , saveToSHSHHost ;
272+ private boolean includeBetas , saveToTSSSaver , saveToSHSHHost ;
256273
257274 public Builder setDevice (String device ) {
258275 this .device = device ;
@@ -296,6 +313,11 @@ public Builder setGenerator(String generator) {
296313 return this ;
297314 }
298315
316+ public Builder setIncludeBetas (boolean includeBetas ) {
317+ this .includeBetas = includeBetas ;
318+ return this ;
319+ }
320+
299321 public Builder saveToTSSSaver (boolean saveToTSSSaver ) {
300322 this .saveToTSSSaver = saveToTSSSaver ;
301323 return this ;
@@ -310,7 +332,7 @@ public TSS build() {
310332 return new TSS (Objects .requireNonNull (device , "Device" ),
311333 Objects .requireNonNull (ecid , "ECID" ),
312334 Objects .requireNonNull (savePath , "Save Path" ),
313- boardConfig , manualVersion , manualIpswURL , apnonce , generator , saveToTSSSaver , saveToSHSHHost );
335+ boardConfig , includeBetas , manualVersion , manualIpswURL , apnonce , generator , saveToTSSSaver , saveToSHSHHost );
314336 }
315337 }
316338
0 commit comments