Skip to content

Commit

Permalink
Keep the version name the same between the two build flavors, and ins…
Browse files Browse the repository at this point in the history
…tead add the flavor in the app code when necessary
  • Loading branch information
christianrowlands committed Sep 26, 2024
1 parent 5328fa1 commit 7bc1734
Show file tree
Hide file tree
Showing 30 changed files with 112 additions and 144 deletions.
14 changes: 13 additions & 1 deletion networksurvey/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,19 @@ android {

// Has the extra CDR features and does not contain any tracking
cdr {
versionNameSuffix "-cdr"
versionNameSuffix ""
}
}

// Customize the APK file name for the CDR flavor
applicationVariants.all { variant ->
variant.outputs.all { output ->
def flavorName = variant.flavorName
def baseName = "$applicationName-$versionName"
if (flavorName == "cdr") {
baseName += "-cdr"
}
outputFileName = "$baseName-${variant.buildType.name}.apk"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions networksurvey/src/cdr/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
\n\nOne final note, SMS is currently supported for CDRs, but MMS is not. So messages associated with group
chats won\'t show up in the CDR CSV file.</string>

<string name="version_suffix">-cdr</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.location.LocationProvider;
Expand Down Expand Up @@ -41,6 +40,7 @@
import com.craxiom.networksurvey.listeners.IGnssFailureListener;
import com.craxiom.networksurvey.services.GrpcConnectionService;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.util.NsUtils;
import com.craxiom.networksurvey.util.PreferenceUtils;
import com.craxiom.networksurvey.util.ToggleLoggingTask;
import com.google.android.material.bottomnavigation.BottomNavigationView;
Expand Down Expand Up @@ -397,7 +397,7 @@ private void requestBackgroundLocationPermission()
*/
private boolean checkLocationProvider(boolean informUser)
{
final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
final LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (locationManager == null)
{
Timber.w("Could not get the location manager. Skipping checking the location provider");
Expand Down Expand Up @@ -538,7 +538,7 @@ private void startAndBindToNetworkSurveyService()
startService(startServiceIntent);

final Intent serviceIntent = new Intent(applicationContext, NetworkSurveyService.class);
final boolean bound = applicationContext.bindService(serviceIntent, surveyServiceConnection, Context.BIND_ABOVE_CLIENT);
final boolean bound = applicationContext.bindService(serviceIntent, surveyServiceConnection, BIND_ABOVE_CLIENT);
Timber.i("NetworkSurveyService bound in the NetworkSurveyActivity: %s", bound);
} catch (IllegalStateException e)
{
Expand Down Expand Up @@ -614,17 +614,15 @@ public void handleOnBackPressed()
}

/**
* Get the app version number and set it at the bottom of the navigation drawer.
*
* @since 0.1.2
* Get the app version name and set it at the bottom of the navigation drawer.
*/
private void setAppVersionNumber()
{
try
{
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
String appVersionName = NsUtils.getAppVersionName(this);
final TextView appVersionView = findViewById(R.id.app_version_name);
appVersionView.setText(getString(R.string.app_version, info.versionName));
appVersionView.setText(getString(R.string.app_version, appVersionName));
} catch (Exception e)
{
Timber.wtf(e, "Could not set the app version number");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.craxiom.networksurvey.listeners.IBluetoothSurveyRecordListener;
import com.craxiom.networksurvey.model.SortedSet;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.util.IOUtils;
import com.craxiom.networksurvey.util.NsUtils;
import com.craxiom.networksurvey.util.PreferenceUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -413,7 +413,7 @@ private void checkAndRemoveStaleRecords()
{
final BluetoothRecord bluetoothRecord = bluetoothRecordSortedSet.get(i);
// Adding 5_000 ms so that we have plenty of time for the next scan to return its results
if (IOUtils.getEpochFromRfc3339(bluetoothRecord.getData().getDeviceTime()) + bluetoothScanRateMs + 5_000 < currentTimeMillis)
if (NsUtils.getEpochFromRfc3339(bluetoothRecord.getData().getDeviceTime()) + bluetoothScanRateMs + 5_000 < currentTimeMillis)
{
itemsToRemove.add(bluetoothRecord);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import androidx.fragment.app.Fragment;

import com.craxiom.networksurvey.CalculationUtils;
import com.craxiom.networksurvey.util.CalculationUtils;
import com.craxiom.networksurvey.R;
import com.craxiom.networksurvey.util.CellularUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.craxiom.messaging.NrRecordData;
import com.craxiom.messaging.UmtsRecord;
import com.craxiom.messaging.UmtsRecordData;
import com.craxiom.networksurvey.CalculationUtils;
import com.craxiom.networksurvey.R;
import com.craxiom.networksurvey.constants.LteMessageConstants;
import com.craxiom.networksurvey.constants.NetworkSurveyConstants;
Expand All @@ -52,6 +51,7 @@
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.ui.cellular.CellularChartViewModel;
import com.craxiom.networksurvey.ui.cellular.ComposeFunctions;
import com.craxiom.networksurvey.util.CalculationUtils;
import com.craxiom.networksurvey.util.CellularUtils;
import com.craxiom.networksurvey.util.ColorUtils;
import com.craxiom.networksurvey.util.MathUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

package com.craxiom.networksurvey.lang;

import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.preference.PreferenceManager;

import com.craxiom.networksurvey.R;
import com.craxiom.networksurvey.util.LocaleUtils;

import java.util.Locale;

import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;

/**
* Dynamically changes the app locale
*/
Expand Down Expand Up @@ -54,7 +54,7 @@ private Context updateResources(Context context, String language)

Resources res = context.getResources();
Configuration config = new Configuration(res.getConfiguration());
if (LocaleUtils.isAtLeastVersion(JELLY_BEAN_MR1))
if (isAtLeastVersion(JELLY_BEAN_MR1))
{
config.setLocale(locale);
context = context.createConfigurationContext(config);
Expand All @@ -65,4 +65,9 @@ private Context updateResources(Context context, String language)
}
return context;
}

private static boolean isAtLeastVersion(int version)
{
return Build.VERSION.SDK_INT >= version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.craxiom.messaging.NrRecord;
import com.craxiom.messaging.UmtsRecord;
import com.craxiom.networksurvey.model.CellularRecordWrapper;
import com.craxiom.networksurvey.util.CalculationUtils;

import java.util.List;

Expand Down Expand Up @@ -86,7 +87,7 @@ default void onCellularBatch(List<CellularRecordWrapper> cellularGroup, int subs
* Notification of the current Data and Voice network types. This method is called even when the values have not
* changed.
* <p>
* See {@link com.craxiom.networksurvey.CalculationUtils#getNetworkType(int)} for the possible string values.
* See {@link CalculationUtils#getNetworkType(int)} for the possible string values.
*
* @param dataNetworkType The data network type (e.g. "LTE"), which might be different than the voice network type.
* @param voiceNetworkType The voice network type (e.g. "LTE").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.craxiom.networksurvey.constants.csv.BluetoothCsvConstants;
import com.craxiom.networksurvey.listeners.IBluetoothSurveyRecordListener;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.util.IOUtils;
import com.craxiom.networksurvey.util.MathUtils;
import com.craxiom.networksurvey.util.NsUtils;

import java.sql.SQLException;
import java.util.List;
Expand Down Expand Up @@ -111,7 +111,7 @@ private void writeBluetoothRecordToLogFile(final BluetoothRecord bluetoothRecord
row.setGeometry(geomData);

row.setValue(BluetoothCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(BluetoothMessageConstants.TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(BluetoothMessageConstants.TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(BluetoothMessageConstants.MISSION_ID_COLUMN, data.getMissionId());
row.setValue(BluetoothMessageConstants.RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(BluetoothCsvConstants.SPEED, data.getSpeed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import com.craxiom.networksurvey.constants.csv.UmtsCsvConstants;
import com.craxiom.networksurvey.listeners.ICellularSurveyRecordListener;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.util.IOUtils;
import com.craxiom.networksurvey.util.MathUtils;
import com.craxiom.networksurvey.util.NsUtils;
import com.google.common.base.Strings;

import java.sql.SQLException;
Expand Down Expand Up @@ -309,7 +309,7 @@ private void writeGsmRecordToLogFile(final GsmRecord gsmRecord)
row.setGeometry(geomData);

row.setValue(GsmCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(GsmMessageConstants.TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(GsmMessageConstants.TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(GsmMessageConstants.MISSION_ID_COLUMN, data.getMissionId());
row.setValue(GsmMessageConstants.RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(GsmMessageConstants.GROUP_NUMBER_COLUMN, data.getGroupNumber());
Expand Down Expand Up @@ -404,7 +404,7 @@ private void writeCdmaRecordToLogFile(final CdmaRecord cdmaRecord)
row.setGeometry(geomData);

row.setValue(CdmaCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(CdmaMessageConstants.TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(CdmaMessageConstants.TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(CdmaMessageConstants.MISSION_ID_COLUMN, data.getMissionId());
row.setValue(CdmaMessageConstants.RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(CdmaMessageConstants.GROUP_NUMBER_COLUMN, data.getGroupNumber());
Expand Down Expand Up @@ -490,7 +490,7 @@ private void writeUmtsRecordToLogFile(final UmtsRecord umtsRecord)
row.setGeometry(geomData);

row.setValue(UmtsCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(UmtsMessageConstants.TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(UmtsMessageConstants.TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(UmtsMessageConstants.MISSION_ID_COLUMN, data.getMissionId());
row.setValue(UmtsMessageConstants.RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(UmtsMessageConstants.GROUP_NUMBER_COLUMN, data.getGroupNumber());
Expand Down Expand Up @@ -585,7 +585,7 @@ private void writeLteRecordToLogFile(final LteRecord lteRecord)
row.setGeometry(geomData);

row.setValue(LteCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(LteMessageConstants.TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(LteMessageConstants.TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(LteMessageConstants.MISSION_ID_COLUMN, data.getMissionId());
row.setValue(LteMessageConstants.RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(LteMessageConstants.GROUP_NUMBER_COLUMN, data.getGroupNumber());
Expand Down Expand Up @@ -700,7 +700,7 @@ private void writeNrRecordToLogFile(final NrRecord nrRecord)
row.setGeometry(geomData);

row.setValue(NrCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(NrMessageConstants.DEVICE_TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(NrMessageConstants.DEVICE_TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(NrMessageConstants.MISSION_ID_COLUMN, data.getMissionId());
row.setValue(NrMessageConstants.RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(NrMessageConstants.GROUP_NUMBER_COLUMN, data.getGroupNumber());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.craxiom.networksurvey.logging;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
Expand All @@ -11,6 +9,7 @@
import com.craxiom.networksurvey.constants.NetworkSurveyConstants;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.services.SurveyRecordProcessor;
import com.craxiom.networksurvey.util.NsUtils;
import com.craxiom.networksurvey.util.PreferenceUtils;

import org.apache.commons.csv.CSVFormat;
Expand Down Expand Up @@ -186,7 +185,7 @@ private synchronized boolean prepareCsvForLogging()

Timber.i("Creating the log file: %s", loggingFileName);

final String versionName = getVersionName();
final String versionName = NsUtils.getAppVersionName(applicationContext);
final List<String> headerComments = new ArrayList<>();
headerComments.add("Created by Network Survey version=" + versionName);

Expand Down Expand Up @@ -426,19 +425,4 @@ public void reset()
recordCount.set(0);
}
}

/**
* @return The NS App version number, or an empty string if it could not be determined.
*/
private String getVersionName()
{
try
{
PackageInfo info = applicationContext.getPackageManager().getPackageInfo(applicationContext.getPackageName(), 0);
return info.versionName;
} catch (PackageManager.NameNotFoundException e)
{
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.craxiom.networksurvey.constants.csv.GnssCsvConstants;
import com.craxiom.networksurvey.listeners.IGnssSurveyRecordListener;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.util.IOUtils;
import com.craxiom.networksurvey.util.MathUtils;
import com.craxiom.networksurvey.util.NsUtils;

import java.sql.SQLException;

Expand Down Expand Up @@ -124,7 +124,7 @@ private void writeGnssRecordToLogFile(final GnssRecord gnssRecord)
row.setGeometry(geomData);

row.setValue(GnssCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(GnssMessageConstants.MISSION_ID_COLUMN, data.getMissionId());
row.setValue(RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(GROUP_NUMBER_COLUMN, data.getGroupNumber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.craxiom.networksurvey.constants.csv.PhoneStateCsvConstants;
import com.craxiom.networksurvey.listeners.IDeviceStatusListener;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.util.IOUtils;
import com.craxiom.networksurvey.util.NsUtils;
import com.craxiom.networksurvey.util.MathUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -109,7 +109,7 @@ public void onPhoneState(PhoneState phoneState)
row.setValue(ALTITUDE_COLUMN, data.getAltitude());

row.setValue(PhoneStateCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(MISSION_ID_COLUMN, data.getMissionId());
row.setValue(RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(PhoneStateCsvConstants.SPEED, data.getSpeed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.craxiom.networksurvey.listeners.IWifiSurveyRecordListener;
import com.craxiom.networksurvey.model.WifiRecordWrapper;
import com.craxiom.networksurvey.services.NetworkSurveyService;
import com.craxiom.networksurvey.util.IOUtils;
import com.craxiom.networksurvey.util.MathUtils;
import com.craxiom.networksurvey.util.NsUtils;

import java.sql.SQLException;
import java.util.List;
Expand Down Expand Up @@ -112,7 +112,7 @@ private void writeWifiBeaconRecordToLogFile(final WifiRecordWrapper wifiRecordWr
row.setGeometry(geomData);

row.setValue(WifiCsvConstants.DEVICE_SERIAL_NUMBER, data.getDeviceSerialNumber());
row.setValue(WifiBeaconMessageConstants.TIME_COLUMN, IOUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(WifiBeaconMessageConstants.TIME_COLUMN, NsUtils.getEpochFromRfc3339(data.getDeviceTime()));
row.setValue(WifiBeaconMessageConstants.MISSION_ID_COLUMN, data.getMissionId());
row.setValue(WifiBeaconMessageConstants.RECORD_NUMBER_COLUMN, data.getRecordNumber());
row.setValue(WifiCsvConstants.SPEED, data.getSpeed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.craxiom.messaging.phonestate.NetworkType;
import com.craxiom.networksurvey.services.controller.CellularController;
import com.craxiom.networksurvey.util.IOUtils;
import com.craxiom.networksurvey.util.NsUtils;

import java.time.ZonedDateTime;

Expand Down Expand Up @@ -87,7 +87,7 @@ public String[] getCsvRowArray()
// getHeaders method, and new columns should not be inserted in the middle since consuming
// applications need to trust that the order will not change.
return new String[]{
IOUtils.getRfc3339String(timestamp),
NsUtils.getRfc3339String(timestamp),
String.valueOf(location == null ? "" : location.getLatitude()),
String.valueOf(location == null ? "" : location.getLongitude()),
String.valueOf(location == null ? "" : location.getAltitude()),
Expand Down
Loading

0 comments on commit 7bc1734

Please sign in to comment.