Skip to content

Commit

Permalink
Merge pull request #26 from omnt/feature/config_file
Browse files Browse the repository at this point in the history
Add Config Exporter/Importer
  • Loading branch information
derpeter authored Jul 23, 2024
2 parents a3ff335 + 48cf6af commit 805baec
Show file tree
Hide file tree
Showing 34 changed files with 1,180 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Bug Report
about: Use this template for creating bug report.
title: "[BUG] - BUG_DESCRIPTION"
title: "BUG_DESCRIPTION"
labels: bug
assignees: ""
---
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Feature Request
about: Use this template for creating feature request.
title: "[FEATURE] - FEATURE_DESCRIPTION"
title: "FEATURE_DESCRIPTION"
labels: feature
assignees: ""
---
Expand Down
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
}


}
buildFeatures {
viewBinding true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.SettingPreferences.ClearPreferencesListener;

public class ClearPreferencesFragment extends DialogFragment {
private ClearPreferencesListener listener;

public void setClearPreferencesListener(ClearPreferencesListener listener) {
this.listener = listener;
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction.
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.clear_preferences_message)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SharedPreferencesGrouper.getInstance(getContext()).clearConfig();
listener.onPreferenceChanged();
Toast.makeText(getContext(), "All Config Cleared!", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getContext(), "Canceled", Toast.LENGTH_SHORT).show();
}
});
// Create the AlertDialog object and return it.
return builder.create();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider;

import org.json.JSONObject;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.BuildConfig;

public class BuildInformation {

public String getBuildType() {
return BuildConfig.BUILD_TYPE;
}

public int getVersionCode() {
return BuildConfig.VERSION_CODE;
}

public String getVersionName() {
return BuildConfig.VERSION_NAME;
}

public String getApplicationId() {
return BuildConfig.APPLICATION_ID;
}

public boolean isDebug() {
return BuildConfig.DEBUG;
}

public JSONObject toJSON(){

JSONObject json = new JSONObject();
try {
json.put("BuildType", getBuildType());
json.put("VersionCode", getVersionCode());
json.put("VersionName", getVersionName());
json.put("ApplicationId", getApplicationId());
json.put("Debug", isDebug());
} catch (Exception e) {
e.printStackTrace();
}

return json;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
Expand Down Expand Up @@ -52,7 +51,6 @@
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
Expand All @@ -76,18 +74,20 @@
import java.util.Objects;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;

/**
* OMNT Data Provider class. Collects and provides all information the app can access
*/
public class DataProvider extends TelephonyCallback implements LocationListener, TelephonyCallback.CellInfoListener, TelephonyCallback.PhysicalChannelConfigListener, TelephonyCallback.SignalStrengthsListener {
private static final String TAG = "DataProvider";
private final Context ct;
private final SharedPreferences sp;
private final boolean permission_phone_state;
private final DeviceInformation di = new DeviceInformation();
private final BatteryInformation bi = new BatteryInformation();
private final LocationCallback locationCallback;
private final SharedPreferencesGrouper spg;
private ConnectivityManager cm;
private TelephonyManager tm;
private SubscriptionManager sm;
Expand All @@ -99,14 +99,15 @@ public class DataProvider extends TelephonyCallback implements LocationListener,
private ArrayList<SignalStrengthInformation> ssi = new ArrayList<>();
private WifiInfo wi = null;
private LocationManager lm;
private BuildInformation buildInformation = new BuildInformation();
// Time stamp, should be updated on each update of internal data caches
private long ts = System.currentTimeMillis();

@SuppressLint("ObsoleteSdkInt")
public DataProvider(Context context) {
GlobalVars gv = GlobalVars.getInstance();
ct = context;
sp = PreferenceManager.getDefaultSharedPreferences(ct);
spg = SharedPreferencesGrouper.getInstance(ct);
permission_phone_state = gv.isPermission_phone_state();

// we can only relay on some APIs if this is a phone.
Expand Down Expand Up @@ -409,6 +410,15 @@ public void onCellInfoChanged(@NonNull List<CellInfo> list) {
ci = ciml;
}

/**
* Get BuildInformation object
*
* @return BuildInformation
*/
public BuildInformation getBuildInformation() {
return buildInformation;
}

/**
* Get CellInformation object
*
Expand All @@ -426,7 +436,7 @@ public List<CellInformation> getCellInformation() {
@SuppressLint("ObsoleteSdkInt")
public List<Point> getCellInformationPoint() {
List<Point> points = new ArrayList<>();
boolean nc = sp.getBoolean("log_neighbour_cells", false);
boolean nc = spg.getSharedPreference(SPType.logging_sp).getBoolean("log_neighbour_cells", false);
for (CellInformation ci_ : ci) {
// check if want to log neighbour cells and skip non registered cells
if (!nc) {
Expand Down Expand Up @@ -702,7 +712,7 @@ public Point getLocationPoint() {
point.time(System.currentTimeMillis(), WritePrecision.MS);
// falling back to fake if no location is available is not the best solution.
// We should ask the user / add configuration what to do
if (sp.getBoolean("fake_location", false) || li == null) {
if (spg.getSharedPreference(SPType.logging_sp).getBoolean("fake_location", false) || li == null) {
point.addField("longitude", 13.3143266);
point.addField("latitude", 52.5259678);
point.addField("altitude", 34.0);
Expand Down Expand Up @@ -809,7 +819,7 @@ public Point getBatteryInformationPoint() {
*/
@SuppressLint("ObsoleteSdkInt")
public Map<String, String> getTagsMap() {
String tags = sp.getString("tags", "").strip().replace(" ", "");
String tags = spg.getSharedPreference(SPType.logging_sp).getString("tags", "").strip().replace(" ", "");
Map<String, String> tags_map = Collections.emptyMap();
if (!tags.isEmpty()) {
try {
Expand All @@ -821,7 +831,7 @@ public Map<String, String> getTagsMap() {
DeviceInformation di = getDeviceInformation();

Map<String, String> tags_map_modifiable = new HashMap<>(tags_map);
tags_map_modifiable.put("measurement_name", sp.getString("measurement_name", "OMNT"));
tags_map_modifiable.put("measurement_name", spg.getSharedPreference(SPType.logging_sp).getString("measurement_name", "OMNT"));
tags_map_modifiable.put("manufacturer", di.getManufacturer());
tags_map_modifiable.put("model", di.getModel());
tags_map_modifiable.put("sdk_version", String.valueOf(di.getAndroidSDK()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import androidx.cardview.widget.CardView;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import java.util.ArrayList;
Expand All @@ -49,6 +48,8 @@
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.NetworkInformation;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.NetworkInterfaceInformation;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.SignalStrengthInformation;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;


public class HomeFragment extends Fragment {
Expand All @@ -59,6 +60,7 @@ public class HomeFragment extends Fragment {
private boolean cp;
private GlobalVars gv;
private SwipeRefreshLayout swipeRefreshLayout;
private SharedPreferencesGrouper spg;

public HomeFragment() {
super(R.layout.fragment_home);
Expand All @@ -68,7 +70,7 @@ public HomeFragment() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = requireContext();

spg = SharedPreferencesGrouper.getInstance(context);
Thread.setDefaultUncaughtExceptionHandler(new GlobalExceptionHandler());
}

Expand Down Expand Up @@ -403,7 +405,7 @@ private CardView get_cell_card_view() {
List<CellInformation> cil = dp.getCellInformation();
int cell = 1;
for (CellInformation ci : cil) {
if (!PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_neighbour_cells", false) && !ci.isRegistered()) {
if (!spg.getSharedPreference(SPType.logging_sp).getBoolean("show_neighbour_cells", false) && ! ci.isRegistered()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.Log;

import androidx.preference.PreferenceManager;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
Expand All @@ -30,12 +28,14 @@
import java.util.List;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;
import io.reactivex.rxjava3.core.BackpressureOverflowStrategy;


public class InfluxdbConnection {
private final static String TAG = "InfluxDBConnection";
SharedPreferences sp;
SharedPreferencesGrouper spg;
private final String url;
private InfluxDBClient influxDBClient;
private WriteApi writeApi;
Expand All @@ -46,9 +46,9 @@ public InfluxdbConnection(String URL, String token, String org, String bucket,
char[] token1 = token.toCharArray();
this.url = URL;
this.gv = GlobalVars.getInstance();
sp = PreferenceManager.getDefaultSharedPreferences(context);
influxDBClient = InfluxDBClientFactory.create(this.url, token1, org, bucket);
influxDBClient.enableGzip();
spg = SharedPreferencesGrouper.getInstance(context);
}

/**
Expand All @@ -72,13 +72,13 @@ public void open_write_api() {
value.logEvent();
});
writeApi.listenEvents(WriteSuccessEvent.class, value -> {
if ( sp.getBoolean("enable_influx", false)) {
if ( spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) {
gv.getLog_status().setColorFilter(Color.argb(255, 0, 255, 0));
}
});
writeApi.listenEvents(WriteRetriableErrorEvent.class, value -> {
value.logEvent();
if ( sp.getBoolean("enable_influx", false)) {
if ( spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) {
gv.getLog_status().setColorFilter(Color.argb(255, 255, 0, 0));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import androidx.preference.PreferenceManager;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;

public class InfluxdbConnections {
private static final String TAG = "InfluxdbConnections";
private static InfluxdbConnection ric;
Expand All @@ -27,11 +30,11 @@ private InfluxdbConnections() {

public static InfluxdbConnection getRicInstance(Context context) {
if (ric == null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String url = sp.getString("influx_URL", "");
String org = sp.getString("influx_org", "");
String bucket = sp.getString("influx_bucket", "");
String token = sp.getString("influx_token", "");
SharedPreferencesGrouper spg = SharedPreferencesGrouper.getInstance(context);
String url = spg.getSharedPreference(SPType.logging_sp).getString("influx_URL", "");
String org = spg.getSharedPreference(SPType.logging_sp).getString("influx_org", "");
String bucket = spg.getSharedPreference(SPType.logging_sp).getString("influx_bucket", "");
String token = spg.getSharedPreference(SPType.logging_sp).getString("influx_token", "");
if (url.isEmpty() || org.isEmpty() || bucket.isEmpty() || token.isEmpty()) {
Log.e(TAG, "Influx parameters incomplete, can't setup logging");
// if we are an UI thread we make a toast, if not logging have to be enough
Expand Down
Loading

0 comments on commit 805baec

Please sign in to comment.