Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Refactor iPerf3 Vol. 2 #29

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ android {
signingConfig signingConfigs.debug
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
Expand All @@ -99,6 +100,8 @@ android {
lint {
abortOnError false
}


}

spdxSbom {
Expand All @@ -122,17 +125,17 @@ spdxSbom {
dependencies {
implementation 'androidx.preference:preference:1.2.1'
implementation 'androidx.work:work-runtime:2.9.0'
implementation 'com.google.android.material:material:1.12.0'
def room_version = "2.6.1"

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.guava:guava:33.2.1-jre'
implementation 'androidx.concurrent:concurrent-futures:1.2.0'
implementation 'androidx.activity:activity:1.9.0'
implementation 'androidx.fragment:fragment:1.8.1'
implementation 'androidx.activity:activity:1.9.1'
implementation 'androidx.fragment:fragment:1.8.2'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment:2.7.7'
implementation 'androidx.navigation:navigation-ui:2.7.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "3d98e37212367d9d5ef195be31a59c58",
"identityHash": "12fc36c505cf323268351cd8ce794593",
"entities": [
{
"tableName": "iperf3_result_database",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` TEXT NOT NULL, `result` INTEGER NOT NULL, `uploaded` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `input` TEXT, PRIMARY KEY(`uid`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` TEXT NOT NULL, `result` INTEGER NOT NULL, `uploaded` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `input` TEXT, `intervals` TEXT, PRIMARY KEY(`uid`))",
"fields": [
{
"fieldPath": "uid",
Expand Down Expand Up @@ -37,13 +37,19 @@
"columnName": "input",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "intervals",
"columnName": "intervals",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"uid"
],
"autoGenerate": false
]
},
"indices": [],
"foreignKeys": []
Expand All @@ -52,7 +58,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3d98e37212367d9d5ef195be31a59c58')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '12fc36c505cf323268351cd8ce794593')"
]
}
}
13 changes: 10 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,21 @@
<service
android:name="de.fraunhofer.fokus.OpenMobileNetworkToolkit.LoggingService"
android:foregroundServiceType="location" />
<service
android:name="de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingService" />

<service android:name="de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingService">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="to run Ping"/>
</service>

<service android:name="androidx.work.impl.foreground.SystemForegroundService" android:foregroundServiceType="specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="explanation_for_special_use"/>
</service>
<service android:name="de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Iperf3Service"
android:foregroundServiceType="specialUse"
android:label="iPerf3 Service">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="to run iPerf3 executions"/>
</service>


<receiver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void refreshDeviceInformation() {
if (tm.hasCarrierPrivileges()) {
try {
di.setIMEI(tm.getImei());
di.setMEID(tm.getMeid());
//di.setMEID(tm.getMeid());
di.setSimSerial(tm.getSimSerialNumber());
di.setSubscriberId(tm.getSubscriberId());
di.setNetworkAccessIdentifier(tm.getNai());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ private CardView get_network_card_view() {
NetworkCallback nc = new NetworkCallback(context);
TableLayout tl = new TableLayout(context);

if(ni == null) {
tl.addView(rowBuilder("No Network Information available", ""));
return cardView_from_table_builder("Network Information", tl);
}

addRows(tl, new String[][]{
{getString(R.string.networkOperatorName), ni.getNetworkOperatorName()},
{getString(R.string.simOperatorName), ni.getSimOperatorName()},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.WorkManager;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database.Converter;

import androidx.room.ProvidedTypeConverter;
import androidx.room.TypeConverter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Interval;

@ProvidedTypeConverter
public class IntervalsConverter {
@TypeConverter
public static ArrayList<Interval> fromString(String value) {
Type listType = new TypeToken<ArrayList<Interval>>() {}.getType();
return new Gson().fromJson(value, listType);
}

@TypeConverter
public static String fromArrayList(ArrayList<Interval> list) {
Gson gson = new Gson();
return gson.toJson(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/

package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3;
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database.Converter;

import androidx.room.ProvidedTypeConverter;
import androidx.room.TypeConverter;

import com.google.gson.Gson;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Iperf3Input;

@ProvidedTypeConverter
public class Iperf3InputConverter {
@TypeConverter
public Iperf3Fragment.Iperf3Input StringToIperf3Input(String string) {
return new Gson().fromJson(string, Iperf3Fragment.Iperf3Input.class);
public Iperf3Input StringToIperf3Input(String string) {
return new Gson().fromJson(string, Iperf3Input.class);
}

@TypeConverter
public String Iperf3InputToString(Iperf3Fragment.Iperf3Input example) {
public String Iperf3InputToString(Iperf3Input example) {
return new Gson().toJson(example);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database;

import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database.Converter.IntervalsConverter;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database.Converter.Iperf3InputConverter;

@Database(entities = {Iperf3RunResult.class}, version = 1, exportSchema = false)
@TypeConverters({IntervalsConverter.class})
public abstract class Iperf3ResultsDataBase extends RoomDatabase {
private static volatile Iperf3ResultsDataBase INSTANCE;

public abstract Iperf3RunResultDao iperf3RunResultDao();

public static Iperf3ResultsDataBase getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (Iperf3ResultsDataBase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
Iperf3ResultsDataBase.class, "iperf3_database")
.addTypeConverter(new Iperf3InputConverter())
.allowMainThreadQueries()
.build();
}
}
}
return INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/

package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3;
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database;

import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
Expand All @@ -15,6 +15,12 @@
import androidx.room.TypeConverters;

import java.sql.Timestamp;
import java.util.ArrayList;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database.Converter.IntervalsConverter;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database.Converter.Iperf3InputConverter;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Iperf3Input;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Interval;

@Entity(tableName = "iperf3_result_database")
public class Iperf3RunResult {
Expand All @@ -33,9 +39,13 @@ public class Iperf3RunResult {

@ColumnInfo(name = "input")
@TypeConverters({Iperf3InputConverter.class})
public Iperf3Fragment.Iperf3Input input;
public Iperf3Input input;

@ColumnInfo(name = "intervals")
@TypeConverters({IntervalsConverter.class})
public ArrayList<Interval> intervals;

public Iperf3RunResult(String uid, int result, boolean upload, Iperf3Fragment.Iperf3Input input,
public Iperf3RunResult(String uid, int result, boolean upload, Iperf3Input input,
Timestamp timestamp) {
this.uid = uid;
this.result = result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/

package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3;
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.TypeConverters;
import androidx.room.Update;

import java.util.ArrayList;
import java.util.List;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Database.Converter.IntervalsConverter;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Intervals;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Interval;

@Dao
public interface Iperf3RunResultDao {
@Query("SELECT * FROM iperf3_result_database")
Expand All @@ -44,6 +50,15 @@ public interface Iperf3RunResultDao {
@Query("UPDATE iperf3_result_database SET uploaded=:uploaded WHERE uid=:uid")
void updateUpload(String uid, boolean uploaded);

@Query("SELECT intervals FROM iperf3_result_database WHERE uid=:uid")
LiveData<Intervals> getIntervals(String uid);

@Query("UPDATE iperf3_result_database SET intervals=:intervals WHERE uid=:uid")
void updateIntervals(String uid, ArrayList<Interval> intervals);

@Query("SELECT * FROM iperf3_result_database WHERE uid=:uid")
LiveData<Iperf3RunResult> getLiveRunResult(String uid);

@Update
void update(Iperf3RunResult iperf3RunResult);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Fragments.Input;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Fragments.Iperf3Fragment;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.Fragments.Output.Iperf3ListFragment;

public class Iperf3CardAdapter extends FragmentStateAdapter {


private ArrayList<Fragment> fragmentList = new ArrayList<>();

public Iperf3CardAdapter(@NonNull FragmentActivity fragmentActivity) {
super(fragmentActivity);

this.addFragment(Iperf3CardFragment.newInstance(0));
this.fragmentList.add(Iperf3ListFragment.newInstance());
}

public void addFragment(Iperf3CardFragment fragment) {
int fragmentPosition = Math.max(fragmentList.size() - 1, 0);
fragmentList.add(fragmentPosition, fragment);
notifyItemInserted(fragmentList.size() - 2);
}

public ArrayList<Iperf3CardFragment> getFragments() {
ArrayList<Iperf3CardFragment> fragments = new ArrayList<>();
for (Fragment fragment : fragmentList) {
if(fragment instanceof Iperf3CardFragment) fragments.add((Iperf3CardFragment) fragment);
}
return fragments;
}
@NonNull
@Override
public Fragment createFragment(int position) {
return fragmentList.get(position);
}

@Override
public int getItemCount() {
return fragmentList.size();
}
}
Loading