Start service for update checks in onPastCreate()

pull/7291/head
TobiGr 2021-10-20 23:55:14 +02:00
rodzic ac071b383f
commit 768bb0bbcd
3 zmienionych plików z 26 dodań i 21 usunięć

Wyświetl plik

@ -65,7 +65,6 @@ public class App extends MultiDexApplication {
public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID;
private static final String TAG = App.class.toString();
private static App app;
private static boolean wasAppInForeground = false;
@NonNull
public static App getApp() {
@ -256,11 +255,4 @@ public class App extends MultiDexApplication {
return false;
}
public static boolean wasAppInForeground() {
return wasAppInForeground;
}
public static void setWasAppInForeground(final boolean wasAppInForeground) {
App.wasAppInForeground = wasAppInForeground;
}
}

Wyświetl plik

@ -235,6 +235,23 @@ public final class CheckForNewAppVersion extends IntentService {
}
}
/**
* Start a new service which
* checks if all conditions for performing a version check are met,
* fetches the API endpoint {@link #NEWPIPE_API_URL} containing info
* about the latest NewPipe version
* and displays a notification about ana available update.
* <br>
* Following conditions need to be met, before data is request from the server:
* <ul>
* <li> The app is signed with the correct signing key (by TeamNewPipe / schabi).
* If the signing key differs from the one used upstream, the update cannot be installed.</li>
* <li>The user enabled searching for and notifying about updates in the settings.</li>
* <li>The app did not recently check for updates.
* We do not want to make unnecessary connections and DOS our servers.</li>
* </ul>
* <b>Must not be executed</b> when the app is in background.
*/
public static void startNewVersionCheckService() {
final Intent intent = new Intent(App.getApp().getApplicationContext(),
CheckForNewAppVersion.class);

Wyświetl plik

@ -166,6 +166,15 @@ public class MainActivity extends AppCompatActivity {
openMiniPlayerUponPlayerStarted();
}
@Override
protected void onPostCreate(final Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Start the service which is checking all conditions
// and eventually searching for a new version.
// The service searching for a new NewPipe version must not be started in background.
startNewVersionCheckService();
}
private void setupDrawer() throws Exception {
//Tabs
final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
@ -516,19 +525,6 @@ public class MainActivity extends AppCompatActivity {
getString(R.string.enable_watch_history_key), true);
drawerLayoutBinding.navigation.getMenu().findItem(ITEM_ID_HISTORY)
.setVisible(isHistoryEnabled);
if (!App.wasAppInForeground()) {
// Check for new app version
// The service searching for a new NewPipe version must not be started in background
// and therefore needs to be placed in onResume().
// Only start the service once when app is started
// and not everytime onResume() is called.
if (DEBUG) {
Log.d(TAG, "App is in foreground for the first time");
}
App.setWasAppInForeground(true);
startNewVersionCheckService();
}
}
@Override