diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index a495ae22..432a9d32 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -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: "" --- diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md index 753c5d57..f1758863 100644 --- a/.github/ISSUE_TEMPLATE/feature.md +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -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: "" --- diff --git a/app/build.gradle b/app/build.gradle index a734ee29..7cfa5b8e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/ClearPreferencesFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/ClearPreferencesFragment.java new file mode 100644 index 00000000..30f9d1c5 --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/ClearPreferencesFragment.java @@ -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(); + } + +} diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BuildInformation.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BuildInformation.java new file mode 100644 index 00000000..95a98fad --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/BuildInformation.java @@ -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; + } +} diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java index 9b572da2..f32ba465 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java @@ -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; @@ -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; @@ -76,6 +74,8 @@ 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 @@ -83,11 +83,11 @@ 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; @@ -99,6 +99,7 @@ public class DataProvider extends TelephonyCallback implements LocationListener, private ArrayList 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(); @@ -106,7 +107,7 @@ public class DataProvider extends TelephonyCallback implements LocationListener, 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. @@ -409,6 +410,15 @@ public void onCellInfoChanged(@NonNull List list) { ci = ciml; } + /** + * Get BuildInformation object + * + * @return BuildInformation + */ + public BuildInformation getBuildInformation() { + return buildInformation; + } + /** * Get CellInformation object * @@ -426,7 +436,7 @@ public List getCellInformation() { @SuppressLint("ObsoleteSdkInt") public List getCellInformationPoint() { List 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) { @@ -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); @@ -809,7 +819,7 @@ public Point getBatteryInformationPoint() { */ @SuppressLint("ObsoleteSdkInt") public Map getTagsMap() { - String tags = sp.getString("tags", "").strip().replace(" ", ""); + String tags = spg.getSharedPreference(SPType.logging_sp).getString("tags", "").strip().replace(" ", ""); Map tags_map = Collections.emptyMap(); if (!tags.isEmpty()) { try { @@ -821,7 +831,7 @@ public Map getTagsMap() { DeviceInformation di = getDeviceInformation(); Map 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())); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/HomeFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/HomeFragment.java index d96dfa46..8eaff9cd 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/HomeFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/HomeFragment.java @@ -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; @@ -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 { @@ -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); @@ -68,7 +70,7 @@ public HomeFragment() { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = requireContext(); - + spg = SharedPreferencesGrouper.getInstance(context); Thread.setDefaultUncaughtExceptionHandler(new GlobalExceptionHandler()); } @@ -403,7 +405,7 @@ private CardView get_cell_card_view() { List 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; } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java index 1b963900..09a833ec 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java @@ -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; @@ -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; @@ -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); } /** @@ -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)); } }); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnections.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnections.java index cbdf7d64..6e00ea2e 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnections.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnections.java @@ -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; @@ -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 diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3Fragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3Fragment.java index 139216ea..6ecb8f2d 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3Fragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3Fragment.java @@ -39,7 +39,6 @@ import androidx.lifecycle.Observer; import androidx.navigation.NavController; import androidx.navigation.fragment.NavHostFragment; -import androidx.preference.PreferenceManager; import androidx.work.Data; import androidx.work.OneTimeWorkRequest; import androidx.work.WorkInfo; @@ -61,6 +60,8 @@ import java.util.UUID; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; public class Iperf3Fragment extends Fragment { private static final String TAG = "iperf3InputFragment"; @@ -105,11 +106,12 @@ public class Iperf3Fragment extends Fragment { private String logFileDir; private String logFileName; private View v; - private SharedPreferences preferences; + private SharedPreferencesGrouper spg; private Iperf3Input input; private WorkManager iperf3WM; private Iperf3ResultsDataBase db; private ArrayList uids; + private Context ct; private final Runnable progressbarUpdate = new Runnable() { @Override public void run() { @@ -138,6 +140,8 @@ public void onCreate(@Nullable Bundle savedInstanceState) { if (!iperf3Path.exists()) { iperf3Path.mkdir(); } + this.ct = requireContext(); + this.spg = SharedPreferencesGrouper.getInstance(this.ct); } @Override @@ -186,7 +190,7 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - preferences.edit().putString(name, field.getText().toString()).apply(); + spg.getSharedPreference(SPType.iperf3_sp).edit().putString(name, field.getText().toString()).apply(); } @Override @@ -203,7 +207,7 @@ private void saveCheckboxInputToSharedPreferences(CheckBox box, String name) { box.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - preferences.edit().putBoolean(name, box.isChecked()).apply(); + spg.getSharedPreference(SPType.iperf3_sp).edit().putBoolean(name, box.isChecked()).apply(); } }); } @@ -211,7 +215,6 @@ public void onClick(View v) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { v = inflater.inflate(R.layout.fragment_iperf3_input, parent, false); - preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); iperf3EtIp = v.findViewById(R.id.iperf3_ip); iperf3EtPort = v.findViewById(R.id.iperf3_port); iperf3EtBandwidth = v.findViewById(R.id.iperf3_bandwidth); @@ -352,41 +355,22 @@ public void onFragmentResult(@NonNull String requestKey, writeToSP(); } }); + iperf3EtIp.setText(spg.getSharedPreference(SPType.iperf3_sp).getString(IPERF3IP, null)); + iperf3EtPort.setText(spg.getSharedPreference(SPType.iperf3_sp).getString(IPERF3PORT, null)); + iperf3EtBandwidth.setText(spg.getSharedPreference(SPType.iperf3_sp).getString(IPERF3BANDWIDTH, null)); + iperf3EtDuration.setText(spg.getSharedPreference(SPType.iperf3_sp).getString(IPERF3DURATION, null)); + iperf3EtInterval.setText(spg.getSharedPreference(SPType.iperf3_sp).getString(IPERF3INTERVAL, null)); + iperf3EtBytes.setText(spg.getSharedPreference(SPType.iperf3_sp).getString(IPERF3BYTES, null)); + iperf3EtStreams.setText(spg.getSharedPreference(SPType.iperf3_sp).getString(IPERF3STREAMS, null)); + iperf3Cport.setText(spg.getSharedPreference(SPType.iperf3_sp).getString(IPERF3CPORT, null)); + + iperf3BiDir.setChecked(spg.getSharedPreference(SPType.iperf3_sp).getBoolean(IPERF3BIDIR, false)); + iperf3Reverse.setChecked(spg.getSharedPreference(SPType.iperf3_sp).getBoolean(IPERF3REVERSE, false)); + iperf3OneOff.setChecked(spg.getSharedPreference(SPType.iperf3_sp).getBoolean(IPERF3ONEOFF, false)); + protocolSpinner.setSelection(spg.getSharedPreference(SPType.iperf3_sp).getInt(IPERF3IDXPROTOCOL, 0)); + iperf3ModeSpinner.setSelection(spg.getSharedPreference(SPType.iperf3_sp).getInt(IPERF3IDXMODE, 0)); - if (savedInstanceState != null) { - iperf3EtIp.setText(savedInstanceState.getString(IPERF3IP)); - iperf3EtPort.setText(savedInstanceState.getString(IPERF3PORT)); - iperf3EtBandwidth.setText(savedInstanceState.getString(IPERF3BANDWIDTH)); - iperf3EtDuration.setText(savedInstanceState.getString(IPERF3DURATION)); - iperf3EtInterval.setText(savedInstanceState.getString(IPERF3INTERVAL)); - iperf3EtBytes.setText(savedInstanceState.getString(IPERF3BYTES)); - iperf3EtStreams.setText(savedInstanceState.getString(IPERF3STREAMS)); - iperf3Cport.setText(savedInstanceState.getString(IPERF3CPORT)); - - iperf3BiDir.setChecked(savedInstanceState.getBoolean(IPERF3BIDIR)); - - iperf3Reverse.setChecked(savedInstanceState.getBoolean(IPERF3REVERSE)); - iperf3OneOff.setChecked(savedInstanceState.getBoolean(IPERF3ONEOFF)); - protocolSpinner.setSelection(savedInstanceState.getInt(IPERF3IDXPROTOCOL)); - iperf3ModeSpinner.setSelection(savedInstanceState.getInt(IPERF3IDXMODE)); - } else { - iperf3EtIp.setText(preferences.getString(IPERF3IP, null)); - iperf3EtPort.setText(preferences.getString(IPERF3PORT, null)); - iperf3EtBandwidth.setText(preferences.getString(IPERF3BANDWIDTH, null)); - iperf3EtDuration.setText(preferences.getString(IPERF3DURATION, null)); - iperf3EtInterval.setText(preferences.getString(IPERF3INTERVAL, null)); - iperf3EtBytes.setText(preferences.getString(IPERF3BYTES, null)); - iperf3EtStreams.setText(preferences.getString(IPERF3STREAMS, null)); - iperf3Cport.setText(preferences.getString(IPERF3CPORT, null)); - - iperf3BiDir.setChecked(preferences.getBoolean(IPERF3BIDIR, false)); - iperf3Reverse.setChecked(preferences.getBoolean(IPERF3REVERSE, false)); - iperf3OneOff.setChecked(preferences.getBoolean(IPERF3ONEOFF, false)); - protocolSpinner.setSelection(preferences.getInt(IPERF3IDXPROTOCOL, 0)); - iperf3ModeSpinner.setSelection(preferences.getInt(IPERF3IDXMODE, 0)); - - } try { Os.setenv("TMPDIR", String.valueOf(getActivity().getCacheDir()), true); } catch (ErrnoException e) { @@ -495,7 +479,7 @@ public void executeIperfCommand(View view) { - if (preferences.getBoolean("enable_influx", false) && input.iperf3Json) { + if (spg.getSharedPreference(SPType.iperf3_sp).getBoolean("enable_influx", false) && input.iperf3Json) { iperf3WM.beginWith(iperf3WR).then(iperf3LP).then(iperf3UP).enqueue(); } else if(input.iperf3Json) { iperf3WM.beginWith(iperf3WR).then(iperf3LP).enqueue(); @@ -659,7 +643,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) { } private void writeToSP() { - SharedPreferences.Editor editor = preferences.edit(); + SharedPreferences.Editor editor = spg.getSharedPreference(SPType.iperf3_sp).edit(); editor.putInt(IPERF3IDXPROTOCOL, protocolSpinner.getSelectedItemPosition()); editor.putInt(IPERF3IDXMODE, iperf3ModeSpinner.getSelectedItemPosition()); editor.putString(IPERF3IP, iperf3EtIp.getText().toString()); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3ToLineProtocolWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3ToLineProtocolWorker.java index cecf1d49..d0d7ba5c 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3ToLineProtocolWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3ToLineProtocolWorker.java @@ -9,13 +9,11 @@ package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3; import android.content.Context; -import android.content.SharedPreferences; import android.os.Build; import android.util.Log; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.preference.PreferenceManager; import androidx.work.Data; import androidx.work.Worker; import androidx.work.WorkerParameters; @@ -40,14 +38,16 @@ import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; public class Iperf3ToLineProtocolWorker extends Worker { private static final String TAG = "Iperf3UploadWorker"; InfluxdbConnection influx; - private final SharedPreferences sp; - private final String rawIperf3file; - private final String measurementName; - private final String ip; + private String rawIperf3file; + private String measurementName; + private String ip; + private SharedPreferencesGrouper spg; private String port; private String bandwidth; @@ -106,7 +106,7 @@ public Iperf3ToLineProtocolWorker(@NonNull Context context, @NonNull WorkerParam oneOff = getInputData().getBoolean("oneOff",false); client = getInputData().getBoolean("client",false); runID = getInputData().getString("iperf3WorkerID"); - sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + spg = SharedPreferencesGrouper.getInstance(getApplicationContext()); } private void setup(){ @@ -115,7 +115,7 @@ private void setup(){ public Map getTagsMap() { - String tags = sp.getString("tags", "").strip().replace(" ", ""); + String tags = spg.getSharedPreference(SPType.iperf3_sp).getString("tags", "").strip().replace(" ", ""); Map tags_map = Collections.emptyMap(); if (!tags.isEmpty()) { try { @@ -125,7 +125,7 @@ public Map getTagsMap() { } } Map 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())); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3UploadWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3UploadWorker.java index 35b89ab8..7f800c9c 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3UploadWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3UploadWorker.java @@ -31,14 +31,12 @@ public class Iperf3UploadWorker extends Worker { private static final String TAG = "Iperf3UploadWorker"; InfluxdbConnection influx; - private final SharedPreferences sp; private final String iperf3LineProtocolFile; public Iperf3UploadWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); iperf3LineProtocolFile = getInputData().getString("iperf3LineProtocolFile"); - sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); } private void setup(){ influx = InfluxdbConnections.getRicInstance(getApplicationContext()); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java index e0ee1ecf..5def1720 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java @@ -30,7 +30,6 @@ import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; -import androidx.preference.PreferenceManager; import com.influxdb.client.domain.WritePrecision; import com.influxdb.client.write.Point; @@ -52,6 +51,8 @@ import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.DataProvider; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; public class LoggingService extends Service { private static final String TAG = "Logging_Service"; @@ -64,8 +65,7 @@ public class LoggingService extends Service { InfluxdbConnection ic; // remote influxDB InfluxdbConnection lic; // local influxDB DataProvider dp; - SharedPreferences sp; - SharedPreferences.OnSharedPreferenceChangeListener listener; + SharedPreferencesGrouper spg; //private MainActivity ma; private Handler notificationHandler; private Handler remoteInfluxHandler; @@ -160,15 +160,15 @@ public void run() { gv.getLog_status().setColorFilter(Color.argb(255, 255, 0, 0)); long ts = System.currentTimeMillis(); // write network information - if (sp.getBoolean("influx_network_data", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("influx_network_data", false)) { } // write signal strength information - if (sp.getBoolean("influx_signal_data", false)) { // user settings here + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("influx_signal_data", false)) { // user settings here } // write cell information - if (sp.getBoolean("influx_cell_data", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("influx_cell_data", false)) { } // always add location information @@ -213,9 +213,9 @@ public int onStartCommand(Intent intent, int flags, int startId) { dp = gv.get_dp(); pm = getPackageManager(); nm = getSystemService(NotificationManager.class); - sp = PreferenceManager.getDefaultSharedPreferences(this); context = this; - interval = Integer.parseInt(sp.getString("logging_interval", "1000")); + spg = SharedPreferencesGrouper.getInstance(context); + interval = Integer.parseInt(spg.getSharedPreference(SPType.logging_sp).getString("logging_interval", "1000")); feature_telephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); if (feature_telephony) { tm = GlobalVars.getInstance().getTm(); @@ -240,7 +240,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { } // create preferences listener - listener = new SharedPreferences.OnSharedPreferenceChangeListener() { + spg.setListener( new SharedPreferences.OnSharedPreferenceChangeListener() { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (Objects.equals(key, "enable_influx")) { if (prefs.getBoolean(key, false)) { @@ -273,28 +273,27 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { stopLocalInfluxDB(); } } else if (Objects.equals(key, "logging_interval")) { - interval = Integer.parseInt(sp.getString("logging_interval", "1000")); + interval = Integer.parseInt(spg.getSharedPreference(SPType.logging_sp).getString("logging_interval", "1000")); } } - }; - sp.registerOnSharedPreferenceChangeListener(listener); + }, SPType.logging_sp); // Start foreground service and setup logging targets startForeground(1, builder.build()); - if (sp.getBoolean("enable_notification_update", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_notification_update", false)) { setupNotificationUpdate(); } - if (sp.getBoolean("enable_influx", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) { setupRemoteInfluxDB(); } - if (sp.getBoolean("enable_local_file_log", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_local_file_log", false)) { setupLocalFile(); } - if (sp.getBoolean("enable_local_influx_log", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_local_influx_log", false)) { setupLocalFile(); } return START_STICKY; @@ -303,13 +302,13 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy: Stop logging service"); - if (sp.getBoolean("enable_influx", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) { stopRemoteInfluxDB(); } - if (sp.getBoolean("enable_local_file_log", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_local_file_log", false)) { stopLocalFile(); } - if (sp.getBoolean("enable_local_influx_log", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_local_influx_log", false)) { stopLocalInfluxDB(); } @@ -323,7 +322,7 @@ private ArrayList getPoints() { long time = System.currentTimeMillis(); Map tags_map = dp.getTagsMap(); ArrayList logPoints = new ArrayList(); - if (sp.getBoolean("influx_network_data", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("influx_network_data", false)) { Point p = dp.getNetworkInformationPoint(); if (p.hasFields()) { p.time(time, WritePrecision.MS); @@ -334,7 +333,7 @@ private ArrayList getPoints() { } } - if (sp.getBoolean("influx_throughput_data", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("influx_throughput_data", false)) { Point p = dp.getNetworkCapabilitiesPoint(); if (p.hasFields()) { p.time(time, WritePrecision.MS); @@ -345,7 +344,7 @@ private ArrayList getPoints() { } } - if (sp.getBoolean("log_signal_data", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("log_signal_data", false)) { Point p = dp.getSignalStrengthPoint(); if (p.hasFields()) { p.time(time, WritePrecision.MS); @@ -356,7 +355,8 @@ private ArrayList getPoints() { } } - if (sp.getBoolean("log_wifi_data", false)) { + if + (spg.getSharedPreference(SPType.logging_sp).getBoolean("log_wifi_data", false)) { Point p = dp.getWifiInformationPoint(); if (p.hasFields()) { p.time(time, WritePrecision.MS); @@ -367,7 +367,7 @@ private ArrayList getPoints() { } } - if (sp.getBoolean("influx_cell_data", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("influx_cell_data", false)) { List ps = dp.getCellInformationPoint(); for (Point p : ps) { if (p.hasFields()) { @@ -379,7 +379,7 @@ private ArrayList getPoints() { } logPoints.addAll(ps); } - if (sp.getBoolean("influx_ip_address_data", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("influx_ip_address_data", false)) { List ps = dp.getNetworkInterfaceInformationPoints(); for (Point p : ps) { if (p.hasFields()) { @@ -392,7 +392,7 @@ private ArrayList getPoints() { logPoints.addAll(ps); } - if (sp.getBoolean("influx_battery_data", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("influx_battery_data", false)) { Point bp = dp.getBatteryInformationPoint(); bp.time(time, WritePrecision.MS); bp.addTags(tags_map); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingServiceOnBootReceiver.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingServiceOnBootReceiver.java index c7e22f50..3ab38cf8 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingServiceOnBootReceiver.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingServiceOnBootReceiver.java @@ -11,20 +11,19 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; -import androidx.preference.PreferenceManager; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; public class LoggingServiceOnBootReceiver extends BroadcastReceiver { - SharedPreferences sp; - + SharedPreferencesGrouper spg; @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { - sp = PreferenceManager.getDefaultSharedPreferences(context); - if (sp.getBoolean("start_logging_on_boot", false) && - sp.getBoolean("enable_logging", false)) { + spg = SharedPreferencesGrouper.getInstance(context); + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("start_logging_on_boot", false) && + spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_logging", false)) { Intent serviceIntent = new Intent(context, LoggingService.class); context.startService(serviceIntent); } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java index c07f9d54..83ac2cc5 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java @@ -17,7 +17,6 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.Signature; @@ -48,7 +47,6 @@ import androidx.navigation.fragment.NavHostFragment; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.PreferenceManager; import java.security.MessageDigest; import java.util.ArrayList; @@ -58,6 +56,8 @@ import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.DataProvider; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.NetworkCallback; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.WorkProfile.WorkProfileActivity; public class MainActivity extends AppCompatActivity implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback { @@ -65,10 +65,9 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen public TelephonyManager tm; public PackageManager pm; public DataProvider dp; + public SharedPreferencesGrouper spg; public boolean cp = false; public boolean feature_telephony = false; - SharedPreferences sp; - SharedPreferences.OnSharedPreferenceChangeListener listener; Intent loggingServiceIntent; NavController navController; private Handler requestCellInfoUpdateHandler; @@ -88,7 +87,7 @@ public void onCellInfo(@NonNull List list) { } }); } - requestCellInfoUpdateHandler.postDelayed(this, Integer.parseInt(sp.getString("logging_interval", "1000"))); + requestCellInfoUpdateHandler.postDelayed(this, Integer.parseInt(spg.getSharedPreference(SPType.logging_sp).getString("logging_interval", "1000"))); } }; private Context context; @@ -103,8 +102,7 @@ protected void onCreate(Bundle savedInstanceState) { // initialize variables we need later on context = getApplicationContext(); gv = GlobalVars.getInstance(); - sp = PreferenceManager.getDefaultSharedPreferences(this); - sp.registerOnSharedPreferenceChangeListener(listener); + spg = SharedPreferencesGrouper.getInstance(getApplicationContext()); pm = getPackageManager(); feature_telephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); @@ -149,18 +147,17 @@ protected void onCreate(Bundle savedInstanceState) { // make sure the subscription in the app settings exists in the current subscription list. // if it is not in the subscription list change it to the first one of the current list boolean valid_subscription = false; - String pref_subscription_str = sp.getString("select_subscription", "99999"); - //int pref_subscription = sp.getInt("select_subscription",9999999); + String pref_subscription_str = spg.getSharedPreference(SPType.mobile_network_sp).getString("select_subscription","99999"); for (SubscriptionInfo info : dp.getSubscriptions()) { if (Integer.parseInt(pref_subscription_str) == info.getSubscriptionId()) { valid_subscription = true; } } if (!valid_subscription) { - sp.edit().putString("select_subscription", String.valueOf(dp.getSubscriptions().iterator().next().getSubscriptionId())).apply(); + spg.getSharedPreference(SPType.mobile_network_sp).edit().putString("select_subscription", String.valueOf(dp.getSubscriptions().iterator().next().getSubscriptionId())).apply(); } // switch the telephony manager to a new one according to the app settings - tm = tm.createForSubscriptionId(Integer.parseInt(sp.getString("select_subscription", "0"))); + tm = tm.createForSubscriptionId(Integer.parseInt(spg.getSharedPreference(SPType.mobile_network_sp).getString("select_subscription", "0"))); } gv.setSm((SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)); @@ -176,7 +173,7 @@ protected void onCreate(Bundle savedInstanceState) { if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // if the location API on android is disabled and we don't want a fake location make a popup - if (!lm.isLocationEnabled() && !sp.getBoolean("fake_location", false)) { + if (!lm.isLocationEnabled() && !spg.getSharedPreference(SPType.logging_sp).getBoolean("fake_location", false)) { new AlertDialog.Builder(MainActivity.this) .setTitle(R.string.dialog_no_location_title) .setMessage(R.string.dialog_no_location) @@ -185,7 +182,7 @@ protected void onCreate(Bundle savedInstanceState) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(intent); }) - .setNegativeButton(R.string.dialog_no_location_fake, (dialog, which) -> sp.edit().putBoolean("fake_location", true).apply()) + .setNegativeButton(R.string.dialog_no_location_fake, (dialog, which) -> spg.getSharedPreference(SPType.logging_sp).edit().putBoolean("fake_location", true).apply()) .setIcon(android.R.drawable.ic_dialog_map) .show(); } @@ -195,12 +192,12 @@ protected void onCreate(Bundle savedInstanceState) { requestCellInfoUpdateHandler.post(requestCellInfoUpdate); loggingServiceIntent = new Intent(this, LoggingService.class); - if (sp.getBoolean("enable_logging", false)) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_logging", false)) { Log.d(TAG, "Start logging service"); context.startForegroundService(loggingServiceIntent); } - listener = (prefs, key) -> { + spg.setListener((prefs, key) -> { if (Objects.equals(key, "enable_logging")) { if (prefs.getBoolean(key, false)) { Log.i(TAG, "Start logging service"); @@ -210,7 +207,7 @@ protected void onCreate(Bundle savedInstanceState) { context.stopService(loggingServiceIntent); } } - }; + }, SPType.logging_sp); getAppSignature(); } @@ -461,6 +458,9 @@ public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat calle case "mobile_network_settings": navController.navigate(R.id.flagSettingFragment); break; + case "shared_preferences_io": + navController.navigate(R.id.fragment_shared_preferences_io); + break; } return true; } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MultiSelectDialogFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MultiSelectDialogFragment.java new file mode 100644 index 00000000..da6355f1 --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MultiSelectDialogFragment.java @@ -0,0 +1,89 @@ +package de.fraunhofer.fokus.OpenMobileNetworkToolkit; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.widget.Button; + +import androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MultiSelectDialogFragment extends DialogFragment { + + private Map itemsMap; + private OnMultiSelectListener listener; + private String title; + private Button selectAllButton; + private boolean allSelected = false; + + public MultiSelectDialogFragment(List keys, OnMultiSelectListener listener, String title) { + this.itemsMap = new HashMap<>(); + for (String key : keys) { + itemsMap.put(key, false); + } + this.listener = listener; + this.title = title; + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + selectAllButton = new Button(requireContext()); + selectAllButton.setText("Select All"); + selectAllButton.setOnClickListener(v -> toggleSelection()); + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setView(selectAllButton); + builder.setTitle(title) + .setMultiChoiceItems(itemsMap.keySet().toArray(new CharSequence[0]), + getCheckedItems(), this::onMultiChoiceClick) + .setPositiveButton("OK", this::onPositiveClick) + .setNegativeButton("Cancel", null); + return builder.create(); + } + + private void toggleSelection() { + allSelected = !allSelected; + selectAllButton.setText(allSelected ? "Deselect All" : "Select All"); + AlertDialog dialog = (AlertDialog) getDialog(); + int i = 0; + for (Map.Entry entry : itemsMap.entrySet()) { + entry.setValue(allSelected); + dialog.getListView().setItemChecked(i++, allSelected); + } + } + + private void onMultiChoiceClick(DialogInterface dialog, int which, boolean isChecked) { + String item = (String) ((AlertDialog) dialog).getListView().getItemAtPosition(which); + itemsMap.put(item, isChecked); + } + + private void onPositiveClick(DialogInterface dialog, int id) { + List selectedItems = new ArrayList<>(); + for (Map.Entry entry : itemsMap.entrySet()) { + if (entry.getValue()) { + selectedItems.add(entry.getKey()); + } + } + listener.onItemsSelected(selectedItems); + } + + private boolean[] getCheckedItems() { + boolean[] checkedItems = new boolean[itemsMap.size()]; + int i = 0; + for (Boolean isChecked : itemsMap.values()) { + checkedItems[i++] = isChecked; + } + return checkedItems; + } + + public interface OnMultiSelectListener { + void onItemsSelected(List selectedItems); + } +} \ No newline at end of file diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/OpenMobileNetworkToolkit.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/OpenMobileNetworkToolkit.java index 4c0b80ef..56b0a556 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/OpenMobileNetworkToolkit.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/OpenMobileNetworkToolkit.java @@ -9,7 +9,6 @@ package de.fraunhofer.fokus.OpenMobileNetworkToolkit; -import android.content.SharedPreferences; import android.os.Build; import android.os.PersistableBundle; import android.service.carrier.CarrierIdentifier; @@ -17,11 +16,12 @@ import android.telephony.CarrierConfigManager; import android.util.Log; -import androidx.preference.PreferenceManager; - import java.util.Arrays; import java.util.HashSet; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; + public class OpenMobileNetworkToolkit extends CarrierService { private static final String TAG = "OpenMobileNetworkToolkit"; public OpenMobileNetworkToolkit() { @@ -45,80 +45,80 @@ public PersistableBundle onLoadConfig(int subscription, CarrierIdentifier id) { public PersistableBundle applyCarrierSettings() { int sdk_version = Build.VERSION.SDK_INT; - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + SharedPreferencesGrouper spg = SharedPreferencesGrouper.getInstance(this); PersistableBundle configForSubId = new PersistableBundle(); Log.d(TAG, "applying carrier config"); // API 27 if (sdk_version >= Build.VERSION_CODES.O_MR1) { - configForSubId.putBoolean(CarrierConfigManager.KEY_DISPLAY_HD_AUDIO_PROPERTY_BOOL, sp.getBoolean("switch_KEY_DISPLAY_HD_AUDIO_PROPERTY_BOOL",false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_DISPLAY_HD_AUDIO_PROPERTY_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_DISPLAY_HD_AUDIO_PROPERTY_BOOL",false)); } // API 30 if (sdk_version >= Build.VERSION_CODES.R) { - configForSubId.putBoolean(CarrierConfigManager.KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL, sp.getBoolean("switch_KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL, sp.getBoolean("switch_KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_LTE_PLUS_DATA_ICON_BOOL, sp.getBoolean("switch_KEY_HIDE_LTE_PLUS_DATA_ICON_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, sp.getBoolean("switch_KEY_WORLD_MODE_ENABLED_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, sp.getBoolean("switch_KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL, sp.getBoolean("switch_KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, sp.getBoolean("switch_KEY_EDITABLE_WFC_MODE_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, sp.getBoolean("switch_KEY_EDITABLE_WFC_ROAMING_MODE_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL, sp.getBoolean("switch_KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_OVERRIDE_WFC_PROVISIONING_BOOL, sp.getBoolean("switch_KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL", false)); - configForSubId.putStringArray(CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY, new String[] {sp.getString("edit_text_KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY", "")}); - configForSubId.putStringArray(CarrierConfigManager.KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY, new String[] {sp.getString("edit_text_KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY", "")}); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_ALLOW_DEFLECT_IMS_CALL_BOOL, sp.getBoolean("switch_KEY_CARRIER_ALLOW_DEFLECT_IMS_CALL_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_LTE_PLUS_DATA_ICON_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_LTE_PLUS_DATA_ICON_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_WORLD_MODE_ENABLED_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_EDITABLE_WFC_MODE_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_EDITABLE_WFC_ROAMING_MODE_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_OVERRIDE_WFC_PROVISIONING_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL", false)); + configForSubId.putStringArray(CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY, new String[] {spg.getSharedPreference(SPType.carrier_sp).getString("edit_text_KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY", "")}); + configForSubId.putStringArray(CarrierConfigManager.KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY, new String[] {spg.getSharedPreference(SPType.carrier_sp).getString("edit_text_KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY", "")}); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_ALLOW_DEFLECT_IMS_CALL_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_ALLOW_DEFLECT_IMS_CALL_BOOL", true)); } // API 31 if (sdk_version >= Build.VERSION_CODES.S) { int[] nr_av = new int[2]; int i = 0; - for (String value: sp.getStringSet("multi_select_KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY", new HashSet<>(Arrays.asList("1", "2")))){ + for (String value: spg.getSharedPreference(SPType.carrier_sp).getStringSet("multi_select_KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY", new HashSet<>(Arrays.asList("1", "2")))){ nr_av[i] = Integer.parseInt(value); } configForSubId.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY, nr_av); - configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_TTY_HCO_VCO_WITH_RTT_BOOL, sp.getBoolean("switch_KEY_HIDE_TTY_HCO_VCO_WITH_RTT_BOOL", false)); - //configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G, sp.getBoolean("switch_KEY_HIDE_ENABLE_2G", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_RTT_UPGRADE_SUPPORTED_FOR_DOWNGRADED_VT_CALL_BOOL, sp.getBoolean("switch_KEY_RTT_UPGRADE_SUPPORTED_FOR_DOWNGRADED_VT_CALL_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_TTY_HCO_VCO_WITH_RTT_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_TTY_HCO_VCO_WITH_RTT_BOOL", false)); + //configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_ENABLE_2G", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_RTT_UPGRADE_SUPPORTED_FOR_DOWNGRADED_VT_CALL_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_RTT_UPGRADE_SUPPORTED_FOR_DOWNGRADED_VT_CALL_BOOL", true)); } // API <= 29 - configForSubId.putBoolean(CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL, sp.getBoolean("switch_KEY_FORCE_HOME_NETWORK_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL, sp.getBoolean("switch_KEY_PREFER_2G_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, sp.getBoolean("switch_KEY_CARRIER_SETTINGS_ENABLE_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_ALLOW_TURNOFF_IMS_BOOL, sp.getBoolean("switch_KEY_CARRIER_ALLOW_TURNOFF_IMS_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_WFC_IMS_AVAILABLE_BOOL, sp.getBoolean("switch_KEY_CARRIER_WFC_IMS_AVAILABLE_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, sp.getBoolean("switch_KEY_EDITABLE_ENHANCED_4G_LTE_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_AVAILABLE_BOOL, sp.getBoolean("switch_KEY_CARRIER_VOLTE_AVAILABLE_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, sp.getBoolean("switch_KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONED_BOOL, sp.getBoolean("switch_KEY_CARRIER_VOLTE_PROVISIONED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VT_AVAILABLE_BOOL, sp.getBoolean("switch_KEY_CARRIER_VT_AVAILABLE_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL, sp.getBoolean("switch_KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL, sp.getBoolean("switch_KEY_HIDE_ENHANCED_4G_LTE_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL, sp.getBoolean("switch_KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_IMS_APN_BOOL, sp.getBoolean("switch_KEY_HIDE_IMS_APN_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL, sp.getBoolean("switch_KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_PRESET_APN_DETAILS_BOOL, sp.getBoolean("switch_KEY_HIDE_PRESET_APN_DETAILS_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL, sp.getBoolean("switch_KEY_HIDE_SIM_LOCK_SETTINGS_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL, sp.getBoolean("switch_KEY_ALLOW_ADDING_APNS_BOOL", true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL, sp.getBoolean("switch_KEY_APN_EXPAND_BOOL",true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, sp.getBoolean("switch_KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_IMS_GBA_REQUIRED_BOOL, sp.getBoolean("switch_KEY_CARRIER_IMS_GBA_REQUIRED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL, sp.getBoolean("switch_KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL", false)); - configForSubId.putInt(CarrierConfigManager.KEY_VOLTE_REPLACEMENT_RAT_INT, Integer.parseInt(sp.getString("list_KEY_VOLTE_REPLACEMENT_RAT_INT9","18"))); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_USE_IMS_FIRST_FOR_EMERGENCY_BOOL, sp.getBoolean("switch_KEY_CARRIER_USE_IMS_FIRST_FOR_EMERGENCY_BOOL",false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL, sp.getBoolean("switch_KEY_AUTO_RETRY_ENABLED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL, sp.getBoolean("switch_KEY_WORLD_PHONE_BOOL",true)); - configForSubId.putBoolean(CarrierConfigManager.KEY_IS_IMS_CONFERENCE_SIZE_ENFORCED_BOOL, sp.getBoolean("switch_KEY_SUPPORT_PAUSE_IMS_VIDEO_CALLS_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_SUPPORT_PAUSE_IMS_VIDEO_CALLS_BOOL, sp.getBoolean("switch_KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, sp.getBoolean("switch_KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, sp.getBoolean("switch_KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL, sp.getBoolean("switch_KEY_SUPPORT_EMERGENCY_SMS_OVER_IMS_BOOL", false)); - configForSubId.putBoolean(CarrierConfigManager.KEY_SUPPORT_EMERGENCY_SMS_OVER_IMS_BOOL, sp.getBoolean("switch_KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT", false)); - configForSubId.putInt(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT, Integer.parseInt(sp.getString("list_KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT", "1"))); - configForSubId.putInt(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_MODE_INT, Integer.parseInt(sp.getString("list_KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_MODE_INT","1"))); - configForSubId.putBoolean(CarrierConfigManager.KEY_ALLOW_EMERGENCY_VIDEO_CALLS_BOOL, sp.getBoolean("switch_KEY_ALLOW_EMERGENCY_VIDEO_CALLS_BOOL",false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_FORCE_HOME_NETWORK_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_PREFER_2G_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_SETTINGS_ENABLE_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_ALLOW_TURNOFF_IMS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_ALLOW_TURNOFF_IMS_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_WFC_IMS_AVAILABLE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_WFC_IMS_AVAILABLE_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_EDITABLE_ENHANCED_4G_LTE_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_AVAILABLE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_VOLTE_AVAILABLE_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_VOLTE_PROVISIONED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VT_AVAILABLE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_VT_AVAILABLE_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_ENHANCED_4G_LTE_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_IMS_APN_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_IMS_APN_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_PRESET_APN_DETAILS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_PRESET_APN_DETAILS_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_HIDE_SIM_LOCK_SETTINGS_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_ALLOW_ADDING_APNS_BOOL", true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_APN_EXPAND_BOOL",true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_IMS_GBA_REQUIRED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_IMS_GBA_REQUIRED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL", false)); + configForSubId.putInt(CarrierConfigManager.KEY_VOLTE_REPLACEMENT_RAT_INT, Integer.parseInt(spg.getSharedPreference(SPType.carrier_sp).getString("list_KEY_VOLTE_REPLACEMENT_RAT_INT9","18"))); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_USE_IMS_FIRST_FOR_EMERGENCY_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_USE_IMS_FIRST_FOR_EMERGENCY_BOOL",false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_AUTO_RETRY_ENABLED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_AUTO_RETRY_ENABLED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_WORLD_PHONE_BOOL",true)); + configForSubId.putBoolean(CarrierConfigManager.KEY_IS_IMS_CONFERENCE_SIZE_ENFORCED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_SUPPORT_PAUSE_IMS_VIDEO_CALLS_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_SUPPORT_PAUSE_IMS_VIDEO_CALLS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_SUPPORT_EMERGENCY_SMS_OVER_IMS_BOOL", false)); + configForSubId.putBoolean(CarrierConfigManager.KEY_SUPPORT_EMERGENCY_SMS_OVER_IMS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT", false)); + configForSubId.putInt(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT, Integer.parseInt(spg.getSharedPreference(SPType.carrier_sp).getString("list_KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT", "1"))); + configForSubId.putInt(CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_MODE_INT, Integer.parseInt(spg.getSharedPreference(SPType.carrier_sp).getString("list_KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_MODE_INT","1"))); + configForSubId.putBoolean(CarrierConfigManager.KEY_ALLOW_EMERGENCY_VIDEO_CALLS_BOOL, spg.getSharedPreference(SPType.carrier_sp).getBoolean("switch_KEY_ALLOW_EMERGENCY_VIDEO_CALLS_BOOL",false)); Log.d(TAG, "Carrier settings applied"); return configForSubId; } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingFragment.java index 76805f60..99744b8f 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingFragment.java @@ -11,7 +11,6 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.text.Editable; @@ -37,6 +36,8 @@ import java.io.FileOutputStream; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; public class PingFragment extends Fragment { private final String TAG = "PingFragment"; @@ -47,7 +48,7 @@ public class PingFragment extends Fragment { private FileOutputStream stream; private EditText input; private Context ct; - private SharedPreferences sp; + private SharedPreferencesGrouper spg; private Metric rttMetric; private Metric packetLossMetric; @@ -82,7 +83,7 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - sp.edit().putString(name, field.getText().toString()).apply(); + spg.getSharedPreference(SPType.ping_sp).edit().putString(name, field.getText().toString()).apply(); } @Override @@ -100,17 +101,16 @@ private void handleInput(boolean ping_running){ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_ping, container, false); + ct = requireContext(); + spg = SharedPreferencesGrouper.getInstance(ct); - sp = getContext().getSharedPreferences("Ping", Context.MODE_PRIVATE); verticalLL = v.findViewById(R.id.ping_vertical_ll); horizontalLL1 = verticalLL.findViewById(R.id.ping_horizontal1_ll); aSwitch = verticalLL.findViewById(R.id.ping_switch); input = verticalLL.findViewById(R.id.ping_input); - input.setText(sp.getString("ping_input", "-w 5 8.8.8.8")); + input.setText(spg.getSharedPreference(SPType.ping_sp).getString("ping_input", "-w 5 8.8.8.8")); input.setEnabled(!PingService.isRunning()); - ct = requireContext(); - saveTextInputToSharedPreferences(input, "ping_input"); aSwitch.setChecked(PingService.isRunning()); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingService.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingService.java index 9928baaa..a3a26a3a 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingService.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingService.java @@ -3,7 +3,6 @@ import android.app.Service; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.icu.text.SimpleDateFormat; import android.os.Environment; import android.os.Handler; @@ -13,14 +12,21 @@ import android.widget.Toast; import androidx.annotation.Nullable; +import androidx.core.app.NotificationCompat; import androidx.lifecycle.Observer; -import androidx.preference.PreferenceManager; import androidx.work.Data; import androidx.work.OneTimeWorkRequest; import androidx.work.WorkInfo; import androidx.work.WorkManager; import com.influxdb.client.write.Point; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.DataProvider; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingInformations.PingInformation; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -50,8 +56,8 @@ public class PingService extends Service { private WorkManager wm; private Context context; private ArrayList pingWRs; - private SharedPreferences pingSP; - private SharedPreferences defaultSP; + private SharedPreferencesGrouper spg; + NotificationCompat.Builder builder; DataProvider dp; InfluxdbConnection influx; private static boolean isRunning = false; @@ -76,9 +82,8 @@ public int onStartCommand(Intent intent, int flags, int startId) { // setup class variables dp = gv.get_dp(); context = getApplicationContext(); - pingSP = context.getSharedPreferences("Ping", Context.MODE_PRIVATE); - defaultSP = PreferenceManager.getDefaultSharedPreferences(context); - if(defaultSP.getBoolean("enable_influx", false)) influx = InfluxdbConnections.getRicInstance(context); + spg = SharedPreferencesGrouper.getInstance(context); + if(spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) influx = InfluxdbConnections.getRicInstance(context); wm = WorkManager.getInstance(context); wm.cancelAllWorkByTag("Ping"); if(intent == null) return START_NOT_STICKY; @@ -98,7 +103,7 @@ private void setupPing(){ Files.createDirectories(Paths.get(path)); } catch (IOException e) { Toast.makeText(context, "could not create /omnt/ping Dir!", Toast.LENGTH_SHORT).show(); - pingSP.edit().putBoolean("ping", false).apply(); + spg.getSharedPreference(SPType.ping_sp).edit().putBoolean("ping", false).apply(); Log.d(TAG, "setupPing: could not create /omnt/ping Dir!"); return; } @@ -114,7 +119,7 @@ private void setupPing(){ } catch (IOException e) { Toast.makeText(context, "could not create logfile "+filename, Toast.LENGTH_SHORT).show(); Log.d(TAG, "setupPing: could not create logfile"); - pingSP.edit().putBoolean("ping", false).apply(); + spg.getSharedPreference(SPType.ping_sp).edit().putBoolean("ping", false).apply(); return; } @@ -124,10 +129,10 @@ private void setupPing(){ } catch (FileNotFoundException e) { Toast.makeText(context, "could not create output stream", Toast.LENGTH_SHORT).show(); Log.d(TAG, "setupPing: could not create output stream"); - pingSP.edit().putBoolean("ping", false).apply(); + spg.getSharedPreference(SPType.ping_sp).edit().putBoolean("ping", false).apply(); return; } - pingSP.edit().putBoolean("ping", true).apply(); + spg.getSharedPreference(SPType.ping_sp).edit().putBoolean("ping", true).apply(); pingLogging = new Handler(Objects.requireNonNull(Looper.myLooper())); PingParser pingParser = PingParser.getInstance(null); propertyChangeListener = pingParser.getListener(); @@ -148,7 +153,7 @@ public void propertyChange(PropertyChangeEvent evt) { e.printStackTrace(); } - if (defaultSP.getBoolean("enable_influx", false) && influx.getWriteApi() != null) { + if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false) && influx.getWriteApi() != null) { try { influx.writePoints(List.of(point)); } catch (IOException e) { @@ -190,7 +195,7 @@ public void parsePingCommand() { @Override public void run() { Data data = new Data.Builder() - .putString("input", pingSP.getString("ping_input", "8.8.8.8")) + .putString("input", spg.getSharedPreference(SPType.ping_sp).getString("ping_input", "8.8.8.8")) .build(); OneTimeWorkRequest pingWR = new OneTimeWorkRequest.Builder(PingWorker.class) @@ -241,7 +246,7 @@ private void stopPing(){ } - pingSP.edit().putBoolean("ping", false).apply(); + spg.getSharedPreference(SPType.ping_sp).edit().putBoolean("ping", false).apply(); pingWRs = new ArrayList<>(); } public static boolean isRunning() { diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SPType.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SPType.java new file mode 100644 index 00000000..911e2f12 --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SPType.java @@ -0,0 +1,38 @@ +package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences; + +public enum SPType { + logging_sp, + iperf3_sp, + ping_sp, + carrier_sp, + mobile_network_sp, + default_sp; + + + + public static SPType fromString(String text) { + for (SPType b : SPType.values()) { + if (b.toString().equalsIgnoreCase(text)) { + return b; + } + } + return null; + } + + public String toReadable(){ + String name = this.name().split("_")[0]; + switch(this){ + case logging_sp: + case ping_sp: + case carrier_sp: + case default_sp: + return name.substring(0,1).toUpperCase() + name.substring(1); + case mobile_network_sp: + return "Mobile Network"; + case iperf3_sp: + return "iPerf3"; + default: + return null; + } + } +} diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesGrouper.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesGrouper.java new file mode 100644 index 00000000..d981cd93 --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesGrouper.java @@ -0,0 +1,111 @@ +package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences; + + +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Log; + +import androidx.preference.PreferenceManager; + +import java.util.HashMap; + +public class SharedPreferencesGrouper { + private static final String TAG = "SharedPreferencesGrouper"; + private static SharedPreferencesGrouper instance; + + private final SharedPreferences loggingSP; + private final SharedPreferences carrierSP; + private final SharedPreferences iperf3SP; + private final SharedPreferences mobileNetworkSP; + private final SharedPreferences defaultSP; + private final SharedPreferences pingSP; + private final Context ct; + private HashMap spMap = new HashMap<>(); + public String getSharedPreferenceIdentifier(SPType key) { + return this.ct.getPackageName()+"."+key.toString(); + } + + public void clearConfig(){ + for(SharedPreferences sp: this.getAllSharedPreferences().values()){ + sp.edit().clear().apply(); + } + } + + + private SharedPreferencesGrouper(Context ct) { + this.ct = ct; + loggingSP = ct.getSharedPreferences(getSharedPreferenceIdentifier(SPType.logging_sp), Context.MODE_PRIVATE); + carrierSP = ct.getSharedPreferences(getSharedPreferenceIdentifier(SPType.carrier_sp), Context.MODE_PRIVATE); + iperf3SP = ct.getSharedPreferences(getSharedPreferenceIdentifier(SPType.iperf3_sp), Context.MODE_PRIVATE); + pingSP = ct.getSharedPreferences(getSharedPreferenceIdentifier(SPType.ping_sp), Context.MODE_PRIVATE); + mobileNetworkSP = ct.getSharedPreferences(getSharedPreferenceIdentifier(SPType.mobile_network_sp), Context.MODE_PRIVATE); + defaultSP = PreferenceManager.getDefaultSharedPreferences(ct); + } + + public static SharedPreferencesGrouper getInstance(Context ct) { + if(instance == null) { + instance = new SharedPreferencesGrouper(ct.getApplicationContext()); + } + return instance; + } + + public SharedPreferences getSharedPreference(SPType key){ + SharedPreferences sp; + switch (key) { + case logging_sp: + sp = loggingSP; + break; + case carrier_sp: + sp = carrierSP; + break; + case iperf3_sp: + sp = iperf3SP; + break; + case ping_sp: + sp = pingSP; + break; + case mobile_network_sp: + sp = mobileNetworkSP; + break; + default: + sp = defaultSP; + break; + } + return sp; + } + + public void removeListener(SPType key){ + SharedPreferences sp = this.getSharedPreference(key); + if(sp == null) { + Log.e(TAG, "SharedPreferences not found for "+key); + return; + } + SharedPreferences.OnSharedPreferenceChangeListener listener = this.spMap.get(key); + if(listener == null) { + Log.e(TAG, "Listener not found for "+key); + return; + } + sp.unregisterOnSharedPreferenceChangeListener(listener); + this.spMap.remove(key); + Log.i(TAG, "Listener removed for "+key); + } + public HashMap getAllSharedPreferences() { + + HashMap spList = new HashMap<>(); + for(SPType key: SPType.values()) { + spList.put(key, this.getSharedPreference(key)); + } + return spList; + } + public void setListener(SharedPreferences.OnSharedPreferenceChangeListener listener, SPType key) { + SharedPreferences sp = this.getSharedPreference(key); + if(sp == null) { + Log.e(TAG, "SharedPreferences not found for "+key); + return; + } + sp.registerOnSharedPreferenceChangeListener(listener); + this.spMap.put(key, listener); + Log.i(TAG, "Listener registered for "+key); + } + +} diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesIO.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesIO.java new file mode 100644 index 00000000..280eeb21 --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesIO.java @@ -0,0 +1,92 @@ +package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences; + +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Log; +import android.widget.Toast; + +import androidx.annotation.NonNull; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; + +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.BuildInformation; + +public class SharedPreferencesIO { + + private static final String TAG = "SharedPreferencesIO"; + + public static String exportPreferences(Context context) { + HashMap sharedPreferences = SharedPreferencesGrouper.getInstance(context).getAllSharedPreferences(); + JSONObject preferencesJson = new JSONObject(); + for(SPType key : sharedPreferences.keySet()) { + SharedPreferences prefs = sharedPreferences.get(key); + JSONObject spJSON = new JSONObject(prefs.getAll()); + try { + preferencesJson.put(key.toString(), spJSON); + } catch (JSONException e) { + Log.e(TAG, "Failed to export preference "+key, e); + } + } + try { + preferencesJson.put("BuildInformation", new BuildInformation().toJSON()); + return preferencesJson.toString(4); + } catch (JSONException e) { + Log.e(TAG, "Failed to Preference JSON to String", e); + return "{}"; + } + } + + public static void importPreferences(Context context, String jsonString) { + try { + JSONObject spJSON = new JSONObject(jsonString); + + spJSON.keys().forEachRemaining(key -> { + SPType spType = SPType.fromString(key); + if (spType == null) { + Log.e(TAG, "Unknown preference type: " + key); + return; + } + SharedPreferences prefs = SharedPreferencesGrouper.getInstance(context).getSharedPreference(spType); + SharedPreferences.Editor editor = prefs.edit(); + @NonNull JSONObject preferences; + try { + preferences = spJSON.getJSONObject(key); + } catch (JSONException e) { + Log.e(TAG, "Failed to get preferences for: " + key, e); + return; + } + preferences.keys().forEachRemaining(preferenceKey -> { + @NonNull Object value; + try { + value = preferences.get(preferenceKey); + } catch (JSONException e) { + Log.e(TAG, "Failed to get value for: " + preferenceKey, e); + return; + } + if (value instanceof Boolean) { + editor.putBoolean(preferenceKey, (Boolean) value); + } else if (value instanceof Float) { + editor.putFloat(preferenceKey, (Float) value); + } else if (value instanceof Integer) { + editor.putInt(preferenceKey, (Integer) value); + } else if (value instanceof Long) { + editor.putLong(preferenceKey, (Long) value); + } else if (value instanceof String) { + editor.putString(preferenceKey, (String) value); + } + }); + editor.apply(); + Log.d(TAG, "Imported: " + key); + }); + + } catch (Exception e) { + Log.e(TAG, "Failed to import preferences", e); + Toast.makeText(context, "Failed to import preferences", Toast.LENGTH_SHORT).show(); + } + } + + +} diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesIOFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesIOFragment.java new file mode 100644 index 00000000..0c4998a2 --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Preferences/SharedPreferencesIOFragment.java @@ -0,0 +1,372 @@ +package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.Typeface; +import android.graphics.text.LineBreakConfig; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.provider.DocumentsContract; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ScrollView; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.ClearPreferencesFragment; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.MultiSelectDialogFragment; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.SettingPreferences.ClearPreferencesListener; + +import org.json.JSONObject; + +public class SharedPreferencesIOFragment extends Fragment implements ClearPreferencesListener { + + private static final String TAG = "SharedPreferencesIOFragment"; + private Context context; + private Uri uri; + private LinearLayout mainLayout; + private ScrollView scrollView; + + private final ActivityResultLauncher exportPreferencesLauncher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), result -> { + if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { + Uri uri = result.getData().getData(); + exportPreferencesToFile(uri); + } else { + showToast("Failed to export preferences"); + } + }); + + private final ActivityResultLauncher importPreferencesLauncher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), result -> { + if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { + Uri uri = result.getData().getData(); + importPreferencesFromFile(uri); + } else { + showToast("Failed to import preferences"); + } + }); + + public SharedPreferencesIOFragment() { + super(R.layout.fragment_shared_preferences_io); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_shared_preferences_io, container, false); + context = requireContext(); + + setupUI(view); + + String configDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + .getAbsolutePath() + "/omnt/configs/"; + File configFolder = new File(configDir); + + if (!configFolder.exists()) { + boolean success = configFolder.mkdir(); + if(!success) { + Log.e(TAG, "Failed to create config folder"); + } + } + uri = Uri.parse(configDir); + + addSharedPreferencesViews(); + + return view; + } + + private void clearConfig() { + ClearPreferencesFragment fragment = new ClearPreferencesFragment(); + fragment.setClearPreferencesListener(this); + fragment.show(getParentFragmentManager(), "clear_preferences"); + } + + + private void setupUI(View view) { + mainLayout = view.findViewById(R.id.fragment_shared_preferences_io); + + Button exportButton = createButton("Export Config", v -> createFile()); + Button importButton = createButton("Import Config", v -> pickFile()); + Button clearConfigButton = createButton("Clear Config", v -> clearConfig()); + + LinearLayout buttonLayout = new LinearLayout(context); + buttonLayout.setOrientation(LinearLayout.HORIZONTAL); + buttonLayout.addView(exportButton); + buttonLayout.addView(importButton); + + LinearLayout buttonContainer = new LinearLayout(context); + buttonContainer.setOrientation(LinearLayout.VERTICAL); + buttonContainer.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); + buttonContainer.addView(buttonLayout); + buttonContainer.addView(clearConfigButton); + buttonContainer.setBackgroundColor(context.getColor(R.color.debug_darkDebugBg)); + + mainLayout.addView(buttonContainer); + } + + private Button createButton(String text, View.OnClickListener onClickListener) { + Button button = new Button(context); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + params.weight = 0.5f; + button.setLayoutParams(params); + button.setText(text); + button.setOnClickListener(onClickListener); + return button; + } + + private void addSharedPreferencesViews() { + LinearLayout preferencesLayout = new LinearLayout(context); + preferencesLayout.setOrientation(LinearLayout.VERTICAL); + for (Map.Entry spEntry : SharedPreferencesGrouper.getInstance(context).getAllSharedPreferences().entrySet()) { + preferencesLayout.addView(generateSharedPreferencesView(spEntry.getKey(), spEntry.getValue())); + } + + scrollView = new ScrollView(context); + scrollView.addView(preferencesLayout); + mainLayout.addView(scrollView); + } + + private void createFile() { + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("application/json"); + intent.putExtra(Intent.EXTRA_TITLE, "omnt_config.json"); + intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri); + exportPreferencesLauncher.launch(intent); + } + + private void pickFile() { + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.setType("application/json"); + intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri); + importPreferencesLauncher.launch(intent); + } + + private void exportPreferencesToFile(Uri uri) { + try (OutputStreamWriter writer = new OutputStreamWriter(context.getContentResolver().openOutputStream(uri))) { + String jsonString = SharedPreferencesIO.exportPreferences(context); + writer.write(jsonString); + showToast("Preferences exported"); + } catch (Exception e) { + Log.e(TAG, "Failed to export preferences", e); + showToast("Failed to export preferences"); + } + } + + + + private List getKeysFromJson(String jsonString) { + List keys = new ArrayList<>(); + try { + JSONObject jsonObject = new JSONObject(jsonString); + Iterator iter = jsonObject.keys(); + while (iter.hasNext()) { + String current = iter.next(); + if (SPType.fromString(current) != null) { + keys.add(current); + } + } + + } catch (Exception e) { + Log.e(TAG, "Failed to parse JSON", e); + } + return keys; + } + + + private void importPreferencesFromFile(Uri uri) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(context.getContentResolver().openInputStream(uri)))) { + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + stringBuilder.append(line); + } + String jsonString = stringBuilder.toString(); + List keys = getKeysFromJson(jsonString); + + MultiSelectDialogFragment dialogFragment = getMultiSelectDialogFragment(jsonString, keys); + dialogFragment.show(getParentFragmentManager(), "multiSelectDialog"); + } catch (Exception e) { + Log.e(TAG, "Failed to import Config", e); + showToast("Failed to import Config"); + } + } + + private @NonNull MultiSelectDialogFragment getMultiSelectDialogFragment(String jsonString, List keys) { + MultiSelectDialogFragment.OnMultiSelectListener listener = selectedItems -> { + try { + JSONObject jsonObject = new JSONObject(jsonString); + JSONObject filteredJsonObject = new JSONObject(); + for (String key : selectedItems) { + filteredJsonObject.put(key, jsonObject.get(key)); + } + SharedPreferencesIO.importPreferences(context, filteredJsonObject.toString()); + onPreferenceChanged(); + showToast("Config imported"); + } catch (Exception e) { + Log.e(TAG, "Failed to import Config", e); + showToast("Failed to import Config"); + } + }; + + return new MultiSelectDialogFragment(keys, listener, "Select Config to import"); + } + + private LinearLayout generateSharedPreferencesView(SPType type, SharedPreferences sharedPreferences) { + LinearLayout layout = new LinearLayout(context); + layout.setOrientation(LinearLayout.VERTICAL); + layout.setLayoutParams(new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT)); + + // Container layout for the TextView and ImageView + LinearLayout headerLayout = new LinearLayout(context); + headerLayout.setOrientation(LinearLayout.HORIZONTAL); + headerLayout.setLayoutParams(new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT)); + headerLayout.setPadding(16, 16, 16, 16); // Add padding + + TextView typeTextView = new TextView(context); + typeTextView.setText(type.toReadable()); + typeTextView.setTextSize(18); + typeTextView.setTypeface(typeTextView.getTypeface(), Typeface.BOLD); + typeTextView.setTextColor(context.getColor(R.color.design_default_color_primary)); + typeTextView.setLayoutParams(new LinearLayout.LayoutParams( + 0, + LinearLayout.LayoutParams.WRAP_CONTENT, + 1.0f)); // Weight 1 to take remaining space + + ImageView expandIcon = new ImageView(context); + expandIcon.setImageResource(R.drawable.baseline_expand_more_24); // Set your expand/collapse icon + expandIcon.setLayoutParams(new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT)); + expandIcon.setPadding(16, 0, 16, 0); // Padding for the icon + + // Add TextView and ImageView to the header layout + headerLayout.addView(typeTextView); + headerLayout.addView(expandIcon); + + layout.addView(headerLayout); + + // Add a divider below the header layout + View divider = new View(context); + LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + 2); + dividerParams.setMargins(0, 0, 0, 16); + divider.setLayoutParams(dividerParams); + divider.setBackgroundColor(context.getColor(R.color.design_default_color_on_primary)); + layout.addView(divider); + + // Container for shared preferences entries + LinearLayout entriesLayout = new LinearLayout(context); + entriesLayout.setOrientation(LinearLayout.VERTICAL); + entriesLayout.setLayoutParams(new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT)); + layout.addView(entriesLayout); + + // Initially hide the entries layout + entriesLayout.setVisibility(View.GONE); + + // Add shared preferences entries to the entriesLayout + for (Map.Entry entry : sharedPreferences.getAll().entrySet()) { + LinearLayout entryLayout = new LinearLayout(context); + entryLayout.setOrientation(LinearLayout.HORIZONTAL); + entryLayout.setLayoutParams(new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT)); + + // Create and style the keyTextView + TextView keyTextView = new TextView(context); + keyTextView.setLayoutParams(new LinearLayout.LayoutParams( + 0, + LinearLayout.LayoutParams.WRAP_CONTENT, + 0.6f)); // Adjusted weight for better appearance + keyTextView.setText(entry.getKey()); + keyTextView.setTextSize(10); + keyTextView.setPadding(8, 8, 8, 8); // Add padding + + // Create and style the valueEditText + TextView valueEditText = new TextView(context); + valueEditText.setLayoutParams(new LinearLayout.LayoutParams( + 0, + LinearLayout.LayoutParams.WRAP_CONTENT, + 0.4f)); // Adjusted weight for better appearance + valueEditText.setText(entry.getValue().toString()); + valueEditText.setTextSize(10); + valueEditText.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + valueEditText.setLineBreakStyle(LineBreakConfig.LINE_BREAK_STYLE_STRICT); + } + valueEditText.setPadding(8, 8, 8, 8); // Add padding + + entryLayout.addView(keyTextView); + entryLayout.addView(valueEditText); + entriesLayout.addView(entryLayout); + } + + // Toggle the visibility of the entries layout on icon click + expandIcon.setOnClickListener(new View.OnClickListener() { + private boolean isExpanded = false; + + @Override + public void onClick(View v) { + if (isExpanded) { + entriesLayout.setVisibility(View.GONE); + expandIcon.setImageResource(R.drawable.baseline_expand_more_24); + } else { + entriesLayout.setVisibility(View.VISIBLE); + expandIcon.setImageResource(R.drawable.baseline_expand_less_24); + } + isExpanded = !isExpanded; + } + }); + + return layout; + } + + + + private void showToast(String message) { + if (context != null) { + Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onPreferenceChanged() { + mainLayout.removeView(scrollView); + addSharedPreferencesViews(); + } +} diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/ClearPreferencesListener.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/ClearPreferencesListener.java new file mode 100644 index 00000000..d2fd222c --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/ClearPreferencesListener.java @@ -0,0 +1,5 @@ +package de.fraunhofer.fokus.OpenMobileNetworkToolkit.SettingPreferences; + +public interface ClearPreferencesListener { + void onPreferenceChanged(); +} diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/LoggingSettingsFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/LoggingSettingsFragment.java index 17847778..4f85f723 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/LoggingSettingsFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/LoggingSettingsFragment.java @@ -17,6 +17,8 @@ import androidx.preference.SwitchPreferenceCompat; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; public class LoggingSettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -25,12 +27,15 @@ public class LoggingSettingsFragment extends PreferenceFragmentCompat @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + SharedPreferencesGrouper spg = SharedPreferencesGrouper.getInstance(requireContext()); + getPreferenceManager().setSharedPreferencesName(spg.getSharedPreferenceIdentifier(SPType.logging_sp)); setPreferencesFromResource(R.xml.preference_logging, rootKey); getPreferenceScreen().getSharedPreferences() .registerOnSharedPreferenceChangeListener(this); enable_influx_switch = findPreference("enable_influx"); + androidx.preference.EditTextPreference editTextPreference = getPreferenceManager().findPreference("logging_interval"); editTextPreference.setOnBindEditTextListener( @@ -39,6 +44,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { + if(s == null) return; if (s.equals("enable_logging")) { boolean logger = sharedPreferences.getBoolean("enable_logging", false); Log.d(TAG, "Logger update: " + logger); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/MobileNetworkSettingsFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/MobileNetworkSettingsFragment.java index a5623889..2ad46be4 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/MobileNetworkSettingsFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/MobileNetworkSettingsFragment.java @@ -26,7 +26,6 @@ import androidx.preference.EditTextPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.PreferenceManager; import androidx.preference.SwitchPreference; import java.util.Arrays; @@ -36,6 +35,8 @@ import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.NetworkInformation; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; public class MobileNetworkSettingsFragment extends PreferenceFragmentCompat implements OnSharedPreferenceChangeListener { @@ -102,7 +103,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { ct = requireContext(); plmnId = ct.getString(R.string.select_plmn); accessNetworkType = ct.getString(R.string.access_networktype); - preferences = PreferenceManager.getDefaultSharedPreferences(ct); + preferences = SharedPreferencesGrouper.getInstance(ct).getSharedPreference(SPType.mobile_network_sp); int sdk_version = Build.VERSION.SDK_INT; @@ -182,6 +183,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { gv = GlobalVars.getInstance(); + getPreferenceManager().setSharedPreferencesName(SharedPreferencesGrouper.getInstance(requireContext()).getSharedPreferenceIdentifier(SPType.carrier_sp)); setPreferencesFromResource(R.xml.preference_mobile_network, rootKey); Preference button = getPreferenceManager().findPreference("apply_cs_settings"); if (button != null) { diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/SettingsFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/SettingsFragment.java index bc7409ac..73994b84 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/SettingsFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/SettingsFragment.java @@ -22,12 +22,16 @@ import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; public class SettingsFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.preference, rootKey); + SharedPreferencesGrouper spg = SharedPreferencesGrouper.getInstance(requireContext()); + getPreferenceManager().setSharedPreferencesName(spg.getSharedPreferenceIdentifier(SPType.default_sp)); ListPreference sub_select = findPreference("select_subscription"); ArrayList entries = new ArrayList<>(); ArrayList entryValues = new ArrayList<>(); diff --git a/app/src/main/res/drawable/ic_action_share_white.xml b/app/src/main/res/drawable/ic_action_share_blue.xml similarity index 94% rename from app/src/main/res/drawable/ic_action_share_white.xml rename to app/src/main/res/drawable/ic_action_share_blue.xml index 727cff76..d06e4a40 100644 --- a/app/src/main/res/drawable/ic_action_share_white.xml +++ b/app/src/main/res/drawable/ic_action_share_blue.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_shared_preferences_io.xml b/app/src/main/res/layout/fragment_shared_preferences_io.xml new file mode 100644 index 00000000..81881757 --- /dev/null +++ b/app/src/main/res/layout/fragment_shared_preferences_io.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index cf28a0d2..64ecf6ab 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -188,4 +188,15 @@ app:destination="@id/HomeFragment" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c1c4e94..6f0c339e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -145,9 +145,20 @@ Show neighbour cells\n Home screen settings App settings - Android IMS + Android IMS> Log WiFi information> + + logging_sp + iperf3_sp + carrier_sp + mobile_network_sp + Do you want to clear all Configuartions? + Yes + No + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 02af0e97..9f26876a 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -42,7 +42,6 @@ android:layout_height="wrap_content" android:defaultValue="1" android:title="Set subscription (SIM)" - app:dialogIcon="@drawable/sim_card" app:dialogTitle="Subscription to be used by OMNT" app:icon="@drawable/sim_card" app:key="select_subscription" /> @@ -50,4 +49,9 @@ android:icon="@drawable/baseline_restart_alt_24" app:key="reset_modem" app:title="Reboot Modem" /> + \ No newline at end of file diff --git a/docs/OpenMobileNetworkToolkit.md b/docs/OpenMobileNetworkToolkit.md index b264a192..929ba881 100644 --- a/docs/OpenMobileNetworkToolkit.md +++ b/docs/OpenMobileNetworkToolkit.md @@ -6,6 +6,7 @@ * [Android Tweaks](android_tweaks.md) * OMNT Usage * [Home](./home.md) + * [Config](./config.md) * [iPerf3](./iperf3.md) * [Ping](./ping.md) * [Special Codes](./special_codes.md) diff --git a/docs/config.md b/docs/config.md new file mode 100644 index 00000000..118717fe --- /dev/null +++ b/docs/config.md @@ -0,0 +1,127 @@ +## Configuration via Config File + +You can export the current settings of the App via the Config Menu. +Navigate to `Settings` and click on `Config`. +Here, you'll find options to export, import, and reset the Config (note: resetting cannot be undone!). + +The current configuration of the App will also be displayed. + +Please note that there is currently no sanity check for the settings after importing them. +If the app crashes after importing an invalid Config, reinstall the app. + +## Config File Example + +The config file should ideally be placed under `/sdcard0/Documents/omnt/configs`, but it can be stored anywhere on the device. +When importing the config file, you can also select specific parts of the file to import. +An example of a config file is shown below: +```json +{ + "default_sp": { + "select_subscription": "1", + "show_neighbour_cells": true + }, + "mobile_network_sp": { + "select_network_type": "CDMA2000", + "select_subscription": "3" + }, + "logging_sp": { + "influx_ip_address_data": false, + "influx_token": "", + "enable_notification_update": false, + "enable_local_file_log": false, + "start_logging_on_boot": false, + "log_neighbour_cells": false, + "tags": "device=", + "influx_URL": "", + "influx_bucket": "", + "log_signal_data": false, + "influx_throughput_data": false, + "measurement_name": "", + "logging_interval": "1000", + "log_wifi_data": false, + "enable_influx": false, + "fake_location": false, + "influx_battery_data": false, + "enable_logging": false, + "influx_network_data": false, + "influx_org": "", + "influx_cell_data": false + }, + "iperf3_sp": { + "iperf3Streams": "", + "iperf3Interval": "", + "iperf3Port": "", + "iperf3OneOff": false, + "iperf3Bytes": "", + "iperf3Duration": "", + "iperf3Bandwidth": "", + "iperf3IP": "", + "iperf3cport": "", + "iperf3Reverse": false, + "iperf3BiDir": false + }, + "carrier_sp": { + "switch_KEY_WORLD_MODE_ENABLED_BOOL": true, + "list_KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT": "1", + "switch_KEY_CARRIER_SETTINGS_ENABLE_BOOL": true, + "switch_KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL": false, + "switch_KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL": false, + "switch_KEY_DISPLAY_HD_AUDIO_PROPERTY_BOOL": false, + "switch_KEY_AUTO_RETRY_ENABLED_BOOL": false, + "select_network_type": "CDMA2000", + "switch_KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL": false, + "switch_KEY_SUPPORT_PAUSE_IMS_VIDEO_CALLS_BOOL": false, + "list_KEY_VOLTE_REPLACEMENT_RAT_INT9": "18", + "switch_KEY_HIDE_LTE_PLUS_DATA_ICON_BOOL": false, + "switch_KEY_ALLOW_EMERGENCY_VIDEO_CALLS_BOOL": false, + "switch_KEY_CARRIER_VOLTE_PROVISIONED_BOOL": false, + "switch_KEY_FORCE_HOME_NETWORK_BOOL": false, + "switch_KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL": false, + "switch_KEY_HIDE_TTY_HCO_VCO_WITH_RTT_BOOL": false, + "switch_KEY_HIDE_ENHANCED_4G_LTE_BOOL": false, + "switch_KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL": false, + "switch_KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL": false, + "edit_text_KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY": "", + "switch_KEY_ALLOW_ADDING_APNS_BOOL": true, + "switch_KEY_SUPPORT_EMERGENCY_SMS_OVER_IMS_BOOL": false, + "switch_KEY_CARRIER_ALLOW_DEFLECT_IMS_CALL_BOOL": true, + "switch_KEY_CARRIER_ALLOW_TURNOFF_IMS_BOOL": true, + "switch_KEY_EDITABLE_WFC_MODE_BOOL": true, + "switch_KEY_PREFER_2G_BOOL": false, + "switch_KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL": false, + "switch_KEY_EDITABLE_WFC_ROAMING_MODE_BOOL": true, + "switch_KEY_RTT_UPGRADE_SUPPORTED_FOR_DOWNGRADED_VT_CALL_BOOL": true, + "switch_KEY_HIDE_PRESET_APN_DETAILS_BOOL": false, + "switch_KEY_CARRIER_VOLTE_AVAILABLE_BOOL": true, + "switch_KEY_CARRIER_USE_IMS_FIRST_FOR_EMERGENCY_BOOL": false, + "switch_KEY_HIDE_ENABLE_2G": false, + "switch_KEY_WORLD_PHONE_BOOL": true, + "switch_KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL": true, + "switch_KEY_CARRIER_VT_AVAILABLE_BOOL": false, + "switch_KEY_HIDE_IMS_APN_BOOL": false, + "switch_KEY_CARRIER_IMS_GBA_REQUIRED_BOOL": false, + "switch_KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL": false, + "switch_KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL": false, + "switch_KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL": true, + "switch_KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL": false, + "switch_KEY_EDITABLE_ENHANCED_4G_LTE_BOOL": true, + "edit_text_KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY": "", + "switch_KEY_CARRIER_WFC_IMS_AVAILABLE_BOOL": true, + "switch_KEY_APN_EXPAND_BOOL": true, + "list_KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_MODE_INT": "1", + "switch_KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL": false, + "switch_KEY_HIDE_SIM_LOCK_SETTINGS_BOOL": false + }, + "ping_sp": { + "ping_input": "-w 5 8.8.8.8", + "ping": false + }, + "BuildInformation": { + "BuildType": "debug", + "VersionCode": 3, + "VersionName": "0.3", + "ApplicationId": "de.fraunhofer.fokus.OpenMobileNetworkToolkit", + "Debug": true + } +} +``` \ No newline at end of file