diff --git a/F-Droid/src/org/fdroid/fdroid/FDroid.java b/F-Droid/src/org/fdroid/fdroid/FDroid.java index 80346c758..b78c537c0 100644 --- a/F-Droid/src/org/fdroid/fdroid/FDroid.java +++ b/F-Droid/src/org/fdroid/fdroid/FDroid.java @@ -34,7 +34,6 @@ import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.AlertDialog; import android.text.TextUtils; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -100,6 +99,10 @@ public class FDroid extends ActionBarActivity { getContentResolver().registerContentObserver(uri, true, new AppObserver()); InstallIntoSystemDialogActivity.firstTime(this); + + if (UpdateService.isNetworkAvailableForUpdate(this)) { + UpdateService.updateNow(this); + } } @Override diff --git a/F-Droid/src/org/fdroid/fdroid/UpdateService.java b/F-Droid/src/org/fdroid/fdroid/UpdateService.java index b07573151..f40571198 100644 --- a/F-Droid/src/org/fdroid/fdroid/UpdateService.java +++ b/F-Droid/src/org/fdroid/fdroid/UpdateService.java @@ -305,18 +305,28 @@ public class UpdateService extends IntentService implements ProgressListener { return false; } - // If we are to update the repos only on wifi, make sure that - // connection is active - if (prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) { - ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo.State wifi = conMan.getNetworkInfo(1).getState(); - if (wifi != NetworkInfo.State.CONNECTED && - wifi != NetworkInfo.State.CONNECTING) { - Log.i(TAG, "Skipping update - wifi not available"); - return false; - } + return isNetworkAvailableForUpdate(this); + } + + /** + * If we are to update the repos only on wifi, make sure that connection is active + */ + public static boolean isNetworkAvailableForUpdate(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + + // this could be cellular or wifi + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + if (activeNetwork == null) + return false; + + if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI + && prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) { + Log.i(TAG, "Skipping update - wifi not available"); + return false; + } else { + return activeNetwork.isConnectedOrConnecting(); } - return true; } @Override