Skip to content

Commit

Permalink
Start service for update checks in onPastCreate()
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiGr committed Oct 20, 2021
1 parent ac071b3 commit 768bb0b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
8 changes: 0 additions & 8 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -256,11 +255,4 @@ protected boolean isDisposedRxExceptionsReported() {
return false;
}

public static boolean wasAppInForeground() {
return wasAppInForeground;
}

public static void setWasAppInForeground(final boolean wasAppInForeground) {
App.wasAppInForeground = wasAppInForeground;
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,23 @@ private void handleResponse(@NonNull final Response response,
}
}

/**
* 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);
Expand Down
22 changes: 9 additions & 13 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ protected void onCreate(final Bundle savedInstanceState) {
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);
Expand Down Expand Up @@ -516,19 +525,6 @@ protected void onResume() {
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
Expand Down

0 comments on commit 768bb0b

Please sign in to comment.