Skip to content

Commit

Permalink
Update TM reference in Dataprovider instat of creating a new instance…
Browse files Browse the repository at this point in the history
…, add and use parameter less constructors for initialization before data is avaialble
  • Loading branch information
PeterHasse committed Dec 19, 2024
1 parent 4c3ccb8 commit cddbde4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class DataProvider extends TelephonyCallback implements LocationListener,
// internal data caches
private List<CellInformation> ci = new ArrayList<>();
private LocationInformation li = new LocationInformation();
private NetworkInformation ni;// = new NetworkInformation();
private NetworkInformation ni = new NetworkInformation();
private List<NetworkInterfaceInformation> nii = new ArrayList<>();
private ArrayList<CellInformation> ssi = new ArrayList<>();
private WifiInformation wi = null;
Expand Down Expand Up @@ -160,6 +160,14 @@ public void onLocationResult(@NonNull LocationResult locationResult) {
refreshAll();
}

/**
* Update the current Telephony Manager reference e.g. after subscription change
* @param tm new Telephony Manager reference
*/
public void setTm(TelephonyManager tm) {
this.tm = tm;
}

/**
* Refresh Network Information
*/
Expand Down Expand Up @@ -888,11 +896,12 @@ public void onUnavailable() {
wi = null;
}
};
cm.registerNetworkCallback(request, networkCallback);
cm.requestNetwork(request, networkCallback);
cm.registerNetworkCallback(request, networkCallback); //todo this call back is already registered
//cm.requestNetwork(request, networkCallback);
}
} catch (Exception e) {
Log.d("Network Callback: Exception in registerNetworkCallback", "Catch exception");
Log.d(TAG, "Network Callback: Exception in registerNetworkCallback");
Log.d(TAG,e.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

package de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider;

import android.content.Context;
import android.widget.TableLayout;

import java.util.List;

public class LocationInformation extends Information {
Expand All @@ -33,6 +30,12 @@ public LocationInformation(double longitude, double latitude, double altitude, S
}

public LocationInformation() {
this.longitude = -1;
this.latitude = -1;
this.altitude = -1;
this.provider = "N/A";
this.accuracy = -1;
this.speed = -1;
}

public List<String> getProviderList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.telephony.AccessNetworkConstants;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.widget.TableLayout;

import java.util.Arrays;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars;

public class NetworkInformation extends Information {
private final String networkOperatorName;
Expand All @@ -39,6 +34,16 @@ public NetworkInformation(String networkOperatorName, String simOperatorName, St
this.preferredOpportunisticDataSubscriptionId = preferredOpportunisitcDataSubscitptionId;
}

public NetworkInformation() {
this.networkOperatorName = "N/A";
this.simOperatorName = "N/A";
this.networkSpecifier = "N/A";
this.dataState = TelephonyManager.DATA_UNKNOWN;
this.dataNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
this.phoneType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
this.preferredOpportunisticDataSubscriptionId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
}

/**
* Get the Network Operator Name
* @return Operator Name string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ protected void onCreate(Bundle savedInstanceState) {
}
// switch the telephony manager to a new one according to the app settings
tm = tm.createForSubscriptionId(Integer.parseInt(spg.getSharedPreference(SPType.default_sp).getString("select_subscription", "0")));

// update reference to tm
gv.setTm(tm);
dp = new DataProvider(this);
dp.setTm(tm);
}

gv.setSm((SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
Expand Down

0 comments on commit cddbde4

Please sign in to comment.