Limit all network access to Wi-Fi only.
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3bf93e8..8235055 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.fairphone.updater"
- android:versionCode="27"
- android:versionName="27 (FP 1.8.4)" >
+ android:versionCode="28"
+ android:versionName="28 (FP 1.8.4)" >
<uses-sdk
android:minSdkVersion="17"
diff --git a/src/com/fairphone/updater/FairphoneUpdater.java b/src/com/fairphone/updater/FairphoneUpdater.java
index fbf88d5..bf1476d 100644
--- a/src/com/fairphone/updater/FairphoneUpdater.java
+++ b/src/com/fairphone/updater/FairphoneUpdater.java
@@ -108,7 +108,7 @@
private Store mSelectedStore;
private TextView headerMainAppStoreText;
- public static enum HeaderType
+ public enum HeaderType
{
MAIN_FAIRPHONE, MAIN_ANDROID, MAIN_APP_STORE, FAIRPHONE, ANDROID, OTHER_OS, APP_STORE
}
@@ -160,8 +160,6 @@
mSharedPreferences.edit().remove(UpdaterService.LAST_CONFIG_DOWNLOAD_IN_MS).apply();
}
- startService();
-
if (mDeviceVersion != null)
{
mLatestVersion = isConfigLoaded ? UpdaterData.getInstance().getLatestVersion(mDeviceVersion.getImageType()) : null;
@@ -171,9 +169,6 @@
mLatestVersion = null;
}
- getSelectedVersionFromSharedPreferences();
- getSelectedStoreFromSharedPreferences();
-
initHeaderViews();
setupFragments(savedInstanceState);
@@ -246,7 +241,7 @@
}
public void forceConfigDownload(){
- Utils.downloadConfigFile(this, true);
+ Utils.startUpdaterService(getApplicationContext(), true);
}
private void initHeaderViews()
diff --git a/src/com/fairphone/updater/UpdaterService.java b/src/com/fairphone/updater/UpdaterService.java
index 89158e3..a0527ce 100644
--- a/src/com/fairphone/updater/UpdaterService.java
+++ b/src/com/fairphone/updater/UpdaterService.java
@@ -67,7 +67,6 @@
public static final String LAST_CONFIG_DOWNLOAD_IN_MS = "LAST_CONFIG_DOWNLOAD_IN_MS";
private static final int CONFIG_FILE_DOWNLOAD_TIMEOUT_MILLIS = 23500;
- public static final String ACTION_FAIRPHONE_UPDATER_CONFIG_FILE_DOWNLOAD = "FAIRPHONE_UPDATER_CONFIG_FILE_DOWNLOAD";
public static final String EXTRA_FORCE_CONFIG_FILE_DOWNLOAD = "FORCE_DOWNLOAD";
private static final String TAG = UpdaterService.class.getSimpleName();
@@ -85,8 +84,9 @@
private SharedPreferences mSharedPreferences;
private final static long DOWNLOAD_GRACE_PERIOD_IN_MS = 24 /* hour */ * Utils.MINUTES_IN_HOUR /* minute */ * Utils.SECONDS_IN_MINUTE /* second */ * 1000 /* millisecond */;
+ private BroadcastReceiver networkStateReceiver;
- @Override
+ @Override
public int onStartCommand(Intent intent, int flags, int startId)
{
// remove the logs
@@ -105,27 +105,14 @@
setupConnectivityMonitoring();
- if (hasInternetConnection())
+ if (Utils.isWiFiEnabled(getApplicationContext()))
{
- downloadConfigFile(false);
+ downloadConfigFile(intent != null && intent.getBooleanExtra(EXTRA_FORCE_CONFIG_FILE_DOWNLOAD, false));
}
// setup the gapps installer
GappsInstallerHelper.checkGappsAreInstalled(getApplicationContext());
- BroadcastReceiver mBCastConfigFileDownload = new BroadcastReceiver() {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (hasInternetConnection()) {
- boolean forceDownload = intent.getBooleanExtra(EXTRA_FORCE_CONFIG_FILE_DOWNLOAD, false);
- downloadConfigFile(forceDownload);
- }
- }
- };
-
- getApplicationContext().registerReceiver(mBCastConfigFileDownload, new IntentFilter(ACTION_FAIRPHONE_UPDATER_CONFIG_FILE_DOWNLOAD));
-
runInstallationDisclaimer(getApplicationContext());
return Service.START_STICKY;
@@ -178,7 +165,7 @@
long now = System.currentTimeMillis();
long last_download = mSharedPreferences.getLong(LAST_CONFIG_DOWNLOAD_IN_MS, 0L);
if( forceDownload || now > (last_download + DOWNLOAD_GRACE_PERIOD_IN_MS) ) {
- Log.d(TAG, "Downloading updater configuration file.");
+ Log.i(TAG, "Downloading updater configuration file.");
// remove the old file if its still there for some reason
removeLatestFileDownload(getApplicationContext());
@@ -414,53 +401,49 @@
private void setupConnectivityMonitoring()
{
- // Check current connectivity status
- ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
- boolean is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
- boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
- mInternetConnectionAvailable = isWifi || is3g;
+ if (networkStateReceiver == null) {
+ // Check current connectivity status
+ mInternetConnectionAvailable = Utils.isWiFiEnabled(getApplicationContext());
- // Setup monitoring for future connectivity status changes
- BroadcastReceiver networkStateReceiver = new BroadcastReceiver()
- {
- @Override
- public void onReceive(Context context, Intent intent)
+ // Setup monitoring for future connectivity status changes
+ networkStateReceiver = new BroadcastReceiver()
{
- if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false))
+ @Override
+ public void onReceive(Context context, Intent intent)
{
- Log.i(TAG, "Lost network connectivity.");
- mInternetConnectionAvailable = false;
- if (mLatestFileDownloadId != 0 && mDownloadManager != null)
+ if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) {
+ Log.i(TAG, "Lost network connectivity.");
+ mInternetConnectionAvailable = false;
+ if (mLatestFileDownloadId != 0 && mDownloadManager != null)
+ {
+ onDownloadStatus(mLatestFileDownloadId, new Runnable() {
+ @Override
+ public void run() {
+ Log.d(TAG, "Removing pending download.");
+ mDownloadManager.remove(mLatestFileDownloadId);
+ saveLatestDownloadId(0);
+ }
+ });
+ }
+ }
+ else
{
- onDownloadStatus(mLatestFileDownloadId, new Runnable() {
- @Override
- public void run() {
- Log.d(TAG, "Removing pending download.");
- mDownloadManager.remove(mLatestFileDownloadId);
- saveLatestDownloadId(0);
+ int conn_type = intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_DUMMY);
+ if( conn_type == ConnectivityManager.TYPE_WIFI ) {
+ Log.i(TAG, "Network connectivity potentially available.");
+ if (!mInternetConnectionAvailable) {
+ downloadConfigFile(false);
}
- });
+ mInternetConnectionAvailable = true;
+ }
}
}
- else
- {
- Log.i(TAG, "Network connectivity potentially available.");
- if (!mInternetConnectionAvailable)
- {
- downloadConfigFile(false);
- }
- mInternetConnectionAvailable = true;
- }
- }
- };
+ };
- IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
- registerReceiver(networkStateReceiver, filter);
- }
+ IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
+ registerReceiver(networkStateReceiver, filter);
- private boolean hasInternetConnection()
- {
- return mInternetConnectionAvailable;
+ }
}
private void setupDownloadManager()
diff --git a/src/com/fairphone/updater/tools/Utils.java b/src/com/fairphone/updater/tools/Utils.java
index 55e51a8..a407c13 100644
--- a/src/com/fairphone/updater/tools/Utils.java
+++ b/src/com/fairphone/updater/tools/Utils.java
@@ -16,11 +16,7 @@
package com.fairphone.updater.tools;
-import android.annotation.SuppressLint;
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningServiceInfo;
import android.app.DownloadManager;
-import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@@ -30,8 +26,6 @@
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
-import android.provider.DocumentsContract;
-import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
@@ -138,40 +132,9 @@
public static void startUpdaterService(Context context, boolean forceDownload)
{
- boolean isNotRunning = !isServiceRunning(context);
-
- if (isNotRunning)
- {
- Log.e(TAG, "Starting Updater Service...");
- Intent i = new Intent(context, UpdaterService.class);
- context.startService(i);
- try
- {
- Thread.sleep(DELAY_100_MILLIS);
- } catch (InterruptedException e)
- {
- Log.w(TAG, "Start Updater service delay error: " + e.getLocalizedMessage());
- }
- }
- else if (forceDownload)
- {
- downloadConfigFile(context, true);
- }
- }
-
- private static boolean isServiceRunning(Context context)
- {
- boolean isRunning = false;
- ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
- {
- if (UpdaterService.class.getName().equals(service.service.getClassName()))
- {
- isRunning = true;
- break;
- }
- }
- return isRunning;
+ Intent i = new Intent(context, UpdaterService.class);
+ i.putExtra(UpdaterService.EXTRA_FORCE_CONFIG_FILE_DOWNLOAD, forceDownload);
+ context.startService(i);
}
// --Commented out by Inspection START (06/02/2015 12:26):
@@ -195,13 +158,6 @@
// }
// --Commented out by Inspection STOP (06/02/2015 12:26)
- public static void downloadConfigFile(Context context, boolean forceDownload)
- {
- Intent i = new Intent(UpdaterService.ACTION_FAIRPHONE_UPDATER_CONFIG_FILE_DOWNLOAD);
- i.putExtra(UpdaterService.EXTRA_FORCE_CONFIG_FILE_DOWNLOAD, forceDownload);
- context.sendBroadcast(i);
- }
-
// **************************************************************************************************************
// HELPERS
// **************************************************************************************************************
@@ -462,7 +418,7 @@
return prop;
} catch (NoSuchElementException e)
{
- Log.w(TAG, "Error reading prop "+name+". Defaulting to " + defaultValue + ": " + e.getLocalizedMessage());
+ Log.d(TAG, "Error reading prop "+name+". Defaulting to " + defaultValue + ": " + e.getLocalizedMessage());
return defaultValue;
} catch (Exception e)
{