@@ -41,7 +41,7 @@ public class AppUpdateManager {
4141 private String latestPreRelease ;
4242 private long lastChecked ;
4343 private boolean preReleaseNewer ;
44- private boolean lastCheckSuccess ;
44+
4545 private AppUpdateManager () {
4646 this .compatFile = new File (MainApplication .getINSTANCE ().getFilesDir (), "compat.txt" );
4747 this .latestRelease = MainApplication .getBootSharedPreferences ().getString ("updater_latest_release" , BuildConfig .VERSION_NAME );
@@ -51,7 +51,8 @@ private AppUpdateManager() {
5151 if (this .compatFile .isFile ()) {
5252 try {
5353 this .parseCompatibilityFlags (new FileInputStream (this .compatFile ));
54- } catch (IOException e ) {
54+ } catch (
55+ IOException e ) {
5556 e .printStackTrace ();
5657 }
5758 }
@@ -73,118 +74,134 @@ public static boolean shouldForceHide(String repoId) {
7374
7475 // Return true if should show a notification
7576 public boolean checkUpdate (boolean force ) {
76- if (!BuildConfig .ENABLE_AUTO_UPDATER ) return false ;
77- if (!force && this .peekShouldUpdate ()) return true ;
77+ if (!BuildConfig .ENABLE_AUTO_UPDATER )
78+ return false ;
79+ if (!force && this .peekShouldUpdate ())
80+ return true ;
7881 long lastChecked = this .lastChecked ;
7982 if (lastChecked != 0 &&
8083 // Avoid spam calls by putting a 60 seconds timer
8184 lastChecked < System .currentTimeMillis () - 60000L )
8285 return force && this .peekShouldUpdate ();
8386 synchronized (this .updateLock ) {
84- if (lastChecked != this .lastChecked ) return this .peekShouldUpdate ();
87+ if (lastChecked != this .lastChecked )
88+ return this .peekShouldUpdate ();
8589 boolean preReleaseNewer = true ;
8690 try {
8791 JSONArray releases = new JSONArray (new String (Http .doHttpGet (RELEASES_API_URL , false ), StandardCharsets .UTF_8 ));
8892 String latestRelease = null , latestPreRelease = null ;
8993 for (int i = 0 ; i < releases .length (); i ++) {
9094 JSONObject release = releases .getJSONObject (i );
9195 // Skip invalid entries
92- if (release .getBoolean ("draft" )) continue ;
96+ if (release .getBoolean ("draft" ))
97+ continue ;
9398 boolean preRelease = release .getBoolean ("prerelease" );
9499 String version = release .getString ("tag_name" );
95- if (version .startsWith ("v" )) version = version .substring (1 );
100+ if (version .startsWith ("v" ))
101+ version = version .substring (1 );
96102 if (preRelease ) {
97- if (latestPreRelease == null ) latestPreRelease = version ;
103+ if (latestPreRelease == null )
104+ latestPreRelease = version ;
98105 } else if (latestRelease == null ) {
99106 latestRelease = version ;
100- if (latestPreRelease == null ) preReleaseNewer = false ;
107+ if (latestPreRelease == null )
108+ preReleaseNewer = false ;
101109 }
102110 if (latestRelease != null && latestPreRelease != null ) {
103111 break ; // We read everything we needed to read.
104112 }
105113 }
106- if (latestRelease != null ) this .latestRelease = latestRelease ;
114+ if (latestRelease != null )
115+ this .latestRelease = latestRelease ;
107116 if (latestPreRelease != null ) {
108117 this .latestPreRelease = latestPreRelease ;
109118 this .preReleaseNewer = preReleaseNewer ;
110119 } else if (!preReleaseNewer ) {
111120 this .latestPreRelease = "" ;
112121 this .preReleaseNewer = false ;
113122 }
114- if (BuildConfig .DEBUG ) Log .i (TAG , "Latest release: " + latestRelease );
115- if (BuildConfig .DEBUG ) Log .i (TAG , "Latest pre-release: " + latestPreRelease );
116- if (BuildConfig .DEBUG ) Log .i (TAG , "Latest pre-release newer: " + preReleaseNewer );
123+ if (BuildConfig .DEBUG )
124+ Log .d (TAG , "Latest release: " + latestRelease );
125+ if (BuildConfig .DEBUG )
126+ Log .d (TAG , "Latest pre-release: " + latestPreRelease );
127+ if (BuildConfig .DEBUG )
128+ Log .d (TAG , "Latest pre-release newer: " + preReleaseNewer );
117129 this .lastChecked = System .currentTimeMillis ();
118- this .lastCheckSuccess = true ;
119- } catch (Exception ioe ) {
120- this .lastCheckSuccess = false ;
130+ } catch (
131+ Exception ioe ) {
121132 Log .e ("AppUpdateManager" , "Failed to check releases" , ioe );
122133 }
123134 }
124135 return this .peekShouldUpdate ();
125136 }
126137
127138 public void checkUpdateCompat () {
128- if (BuildConfig .DEBUG ) Log .i (TAG , "Checking compatibility flags" );
139+ if (BuildConfig .DEBUG )
140+ Log .d (TAG , "Checking compatibility flags" );
129141 if (this .compatFile .exists ()) {
130142 long lastUpdate = this .compatFile .lastModified ();
131143 if (lastUpdate <= System .currentTimeMillis () && lastUpdate + 600_000L > System .currentTimeMillis ()) {
132144 return ; // Skip update
133145 }
134146 }
135147 try {
136- if (BuildConfig .DEBUG ) Log .i (TAG , "Downloading compatibility flags" );
148+ if (BuildConfig .DEBUG )
149+ Log .d (TAG , "Downloading compatibility flags" );
137150 JSONObject object = new JSONObject (new String (Http .doHttpGet (COMPAT_API_URL , false ), StandardCharsets .UTF_8 ));
138151 if (object .isNull ("body" )) {
139- if (BuildConfig .DEBUG ) Log .i (TAG , "Compatibility flags not found" );
152+ if (BuildConfig .DEBUG )
153+ Log .d (TAG , "Compatibility flags not found" );
140154 compatDataId .clear ();
141155 Files .write (compatFile , new byte [0 ]);
142156 return ;
143157 }
144- if (BuildConfig .DEBUG ) Log .i (TAG , "Parsing compatibility flags" );
158+ if (BuildConfig .DEBUG )
159+ Log .d (TAG , "Parsing compatibility flags" );
145160 byte [] rawData = object .getString ("body" ).getBytes (StandardCharsets .UTF_8 );
146161 this .parseCompatibilityFlags (new ByteArrayInputStream (rawData ));
147162 Files .write (compatFile , rawData );
148- if (! BuildConfig .ENABLE_AUTO_UPDATER ) this . lastCheckSuccess = true ;
149- if ( BuildConfig . DEBUG ) Log .i (TAG , "Compatibility flags update finishing" );
163+ if (BuildConfig .DEBUG )
164+ Log .d (TAG , "Compatibility flags update finishing" );
150165 return ;
151- } catch (Exception e ) {
152- if (! BuildConfig . ENABLE_AUTO_UPDATER ) this . lastCheckSuccess = false ;
166+ } catch (
167+ Exception e ) {
153168 Log .e ("AppUpdateManager" , "Failed to update compat list" , e );
154169 }
155- if (BuildConfig .DEBUG ) Log .i (TAG , "Compatibility flags updated" );
170+ if (BuildConfig .DEBUG )
171+ Log .d (TAG , "Compatibility flags updated" );
156172 }
157173
158174 public boolean peekShouldUpdate () {
159- if (!BuildConfig .ENABLE_AUTO_UPDATER ) return false ;
175+ if (!BuildConfig .ENABLE_AUTO_UPDATER )
176+ return false ;
160177 // Convert both BuildConfig.VERSION_NAME and latestRelease to int
161178 int currentVersion = 0 , latestVersion = 0 ;
162179 try {
163180 currentVersion = Integer .parseInt (BuildConfig .VERSION_NAME .replace ("." , "" ));
164181 latestVersion = Integer .parseInt (this .latestRelease .replace ("." , "" ));
165- } catch (NumberFormatException ignored ) {
182+ } catch (
183+ NumberFormatException ignored ) {
166184 }
167185 return currentVersion < latestVersion || (this .preReleaseNewer && currentVersion < Integer .parseInt (this .latestPreRelease .replace ("." , "" )));
168186 }
169187
170188 public boolean peekHasUpdate () {
171- if (!BuildConfig .ENABLE_AUTO_UPDATER ) return false ;
189+ if (!BuildConfig .ENABLE_AUTO_UPDATER )
190+ return false ;
172191 return !BuildConfig .VERSION_NAME .equals (this .preReleaseNewer ? this .latestPreRelease : this .latestRelease );
173192 }
174193
175- public boolean isLastCheckSuccess () {
176- return lastCheckSuccess ;
177- }
178-
179194 private void parseCompatibilityFlags (InputStream inputStream ) throws IOException {
180195 compatDataId .clear ();
181196 BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (inputStream , StandardCharsets .UTF_8 ));
182197 String line ;
183198 while ((line = bufferedReader .readLine ()) != null ) {
184199 line = line .trim ();
185- if (line .isEmpty () || line .startsWith ("#" )) continue ;
200+ if (line .isEmpty () || line .startsWith ("#" ))
201+ continue ;
186202 int i = line .indexOf ('/' );
187- if (i == -1 ) continue ;
203+ if (i == -1 )
204+ continue ;
188205 int value = 0 ;
189206 for (String arg : line .substring (i + 1 ).split ("," )) {
190207 switch (arg ) {
0 commit comments