38
38
import java .util .Objects ;
39
39
import java .util .regex .Matcher ;
40
40
import java .util .regex .Pattern ;
41
+ import java .util .stream .Stream ;
41
42
42
43
import static airsquared .blobsaver .app .Utils .containsIgnoreCase ;
43
44
import static airsquared .blobsaver .app .Utils .executeProgram ;
44
45
import static airsquared .blobsaver .app .Utils .extractBuildManifest ;
45
46
import static airsquared .blobsaver .app .Utils .getFirmwareList ;
47
+ import static airsquared .blobsaver .app .Utils .getSignedBetas ;
46
48
import static airsquared .blobsaver .app .Utils .getSignedFirmwares ;
47
49
48
50
public class TSS extends Task <String > {
@@ -57,6 +59,7 @@ public class TSS extends Task<String> {
57
59
58
60
private final String boardConfig ;
59
61
62
+ private final boolean includeBetas ;
60
63
private final String manualVersion ;
61
64
private final String manualIpswURL ;
62
65
@@ -67,11 +70,12 @@ public class TSS extends Task<String> {
67
70
/**
68
71
* Private constructor; use {@link TSS.Builder} instead
69
72
*/
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 ) {
71
74
this .deviceIdentifier = deviceIdentifier ;
72
75
this .ecid = ecid ;
73
76
this .savePath = savePath ;
74
77
this .boardConfig = boardConfig ;
78
+ this .includeBetas = includeBetas ;
75
79
this .manualVersion = manualVersion ;
76
80
this .manualIpswURL = manualIpswURL ;
77
81
this .apnonce = apnonce ;
@@ -91,7 +95,6 @@ protected String call() throws TSSException {
91
95
List <Utils .IOSVersion > iosVersions = getIOSVersions ();
92
96
System .out .println ("iosVersions = " + iosVersions );
93
97
ArrayList <String > args = constructArgs ();
94
- final int urlIndex = args .size () - 1 ;
95
98
96
99
StringBuilder responseBuilder = new StringBuilder ("Successfully saved blobs in\n " ).append (savePath );
97
100
if (manualIpswURL == null ) {
@@ -100,18 +103,7 @@ protected String call() throws TSSException {
100
103
101
104
// can't use forEach() because exception won't be caught
102
105
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 );
115
107
116
108
if (iosVersion .versionString () != null ) {
117
109
responseBuilder .append (iosVersion .versionString ());
@@ -134,6 +126,29 @@ protected String call() throws TSSException {
134
126
return responseBuilder .toString ();
135
127
}
136
128
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
+
137
152
private void checkInputs () throws TSSException {
138
153
boolean hasCorrectIdentifierPrefix = deviceIdentifier .startsWith ("iPad" ) || deviceIdentifier .startsWith ("iPod" )
139
154
|| deviceIdentifier .startsWith ("iPhone" ) || deviceIdentifier .startsWith ("AppleTV" );
@@ -177,6 +192,8 @@ private List<Utils.IOSVersion> getIOSVersions() throws TSSException {
177
192
.orElseThrow (() -> new TSSException ("No versions found." , false )));
178
193
} else if (manualIpswURL != null ) {
179
194
return Collections .singletonList (new Utils .IOSVersion (null , manualIpswURL , null ));
195
+ } else if (includeBetas ) {
196
+ return Stream .concat (getSignedFirmwares (deviceIdentifier ), getSignedBetas (deviceIdentifier )).toList ();
180
197
} else { // all signed firmwares
181
198
return getSignedFirmwares (deviceIdentifier ).toList ();
182
199
}
@@ -252,7 +269,7 @@ && containsIgnoreCase(tsscheckerLog, "checking tss status failed")) {
252
269
@ SuppressWarnings ("UnusedReturnValue" )
253
270
public static class Builder {
254
271
private String device , ecid , savePath , boardConfig , manualVersion , manualIpswURL , apnonce , generator ;
255
- private boolean saveToTSSSaver , saveToSHSHHost ;
272
+ private boolean includeBetas , saveToTSSSaver , saveToSHSHHost ;
256
273
257
274
public Builder setDevice (String device ) {
258
275
this .device = device ;
@@ -296,6 +313,11 @@ public Builder setGenerator(String generator) {
296
313
return this ;
297
314
}
298
315
316
+ public Builder setIncludeBetas (boolean includeBetas ) {
317
+ this .includeBetas = includeBetas ;
318
+ return this ;
319
+ }
320
+
299
321
public Builder saveToTSSSaver (boolean saveToTSSSaver ) {
300
322
this .saveToTSSSaver = saveToTSSSaver ;
301
323
return this ;
@@ -310,7 +332,7 @@ public TSS build() {
310
332
return new TSS (Objects .requireNonNull (device , "Device" ),
311
333
Objects .requireNonNull (ecid , "ECID" ),
312
334
Objects .requireNonNull (savePath , "Save Path" ),
313
- boardConfig , manualVersion , manualIpswURL , apnonce , generator , saveToTSSSaver , saveToSHSHHost );
335
+ boardConfig , includeBetas , manualVersion , manualIpswURL , apnonce , generator , saveToTSSSaver , saveToSHSHHost );
314
336
}
315
337
}
316
338
0 commit comments