Start service for update checks in onPastCreate()
This commit is contained in:
parent
ac071b383f
commit
768bb0bbcd
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue