Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
*/
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 boolean permission_phone_state;
private final DeviceInformation di = new DeviceInformation();
private final BatteryInformation bi = new BatteryInformation();
Expand All @@ -107,7 +106,9 @@ public class DataProvider extends TelephonyCallback implements LocationListener,
// Time stamp, should be updated on each update of internal data caches
private long ts = System.currentTimeMillis();

@SuppressLint("ObsoleteSdkInt")
private final Context ct;

@SuppressLint("MissingPermission")
public DataProvider(Context context) {
GlobalVars gv = GlobalVars.getInstance();
ct = context;
Expand All @@ -120,31 +121,23 @@ public DataProvider(Context context) {
sm = (SubscriptionManager) ct.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
}

// We need location permission otherwise logging is useless
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
lm = (LocationManager) ct.getSystemService(Context.LOCATION_SERVICE);
if (lm.isLocationEnabled()) {
Log.d(TAG, "Location Provider " + lm.getProviders(true));
li = new LocationInformation(); // empty LocationInformation to be filled by callback
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
lm.requestLocationUpdates(LocationManager.FUSED_PROVIDER, 0, 0, this);
Location loc = lm.getLastKnownLocation(LocationManager.FUSED_PROVIDER);
if (loc != null) {
onLocationChanged(Objects.requireNonNull(lm.getLastKnownLocation(LocationManager.FUSED_PROVIDER)));
}
} else {
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
onLocationChanged(Objects.requireNonNull(lm.getLastKnownLocation(LocationManager.GPS_PROVIDER)));
}
} else {
Log.d(TAG, "GPS is disabled");
// todo use same popup as in main activity
lm = (LocationManager) ct.getSystemService(Context.LOCATION_SERVICE);
if (lm.isLocationEnabled()) {
Log.d(TAG, "Location Provider " + lm.getProviders(true));
li = new LocationInformation(); // empty LocationInformation to be filled by callback

lm.requestLocationUpdates(LocationManager.FUSED_PROVIDER, 0, 0, this);
Location loc = lm.getLastKnownLocation(LocationManager.FUSED_PROVIDER);
if (loc != null) {
onLocationChanged(Objects.requireNonNull(lm.getLastKnownLocation(LocationManager.FUSED_PROVIDER)));
}

} else {
Log.d(TAG, "No Location Permissions");
// todo we need to handle this in more details as we can't do logging without it
Log.d(TAG, "GPS is disabled");
// todo use same popup as in main activity
}


locationCallback = new LocationCallback() {
@Override
public void onLocationResult(@NonNull LocationResult locationResult) {
Expand All @@ -154,17 +147,14 @@ public void onLocationResult(@NonNull LocationResult locationResult) {

startLocationUpdates();
registerWiFiCallback();

// initialize internal state
refreshAll();
}

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

/**
Expand Down Expand Up @@ -329,8 +319,6 @@ public List<Point> getNetworkInterfaceInformationPoints() {
*
* @param list is the list of currently visible cells.
*/
@SuppressLint("ObsoleteSdkInt")
@Override
public void onCellInfoChanged(@NonNull List<CellInfo> list) {
updateTimestamp();
long ts_ = ts;
Expand Down Expand Up @@ -448,7 +436,7 @@ public List<Point> getCellInformationPoint() {
public List<CellInfo> getAllCellInfo() {
List<CellInfo> cellInfo;
if (ActivityCompat.checkSelfPermission(ct, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Access Fine Location permission missing");
Log.e(TAG, "Access Fine Location permission missing");
cellInfo = new ArrayList<>();
} else {
cellInfo = tm.getAllCellInfo();
Expand Down Expand Up @@ -781,21 +769,12 @@ public String getIMSI() {
*
* @return List of SubscriptionIno
*/
@SuppressLint("ObsoleteSdkInt")
public List<SubscriptionInfo> getSubscriptions() {
List<SubscriptionInfo> subscriptions = new ArrayList<>();
ArrayList<SubscriptionInfo> activeSubscriptions = new ArrayList<>();

if (Build.VERSION.SDK_INT >= 30) {
subscriptions.addAll(sm.getCompleteActiveSubscriptionInfoList());
} else {
if (ActivityCompat.checkSelfPermission(ct, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
List<SubscriptionInfo> subscriptions_ = sm.getActiveSubscriptionInfoList();
if (subscriptions_ != null) {
subscriptions.addAll(subscriptions_);
}
}
if (ActivityCompat.checkSelfPermission(ct, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
return activeSubscriptions;
}
List<SubscriptionInfo> subscriptions = new ArrayList<>(sm.getCompleteActiveSubscriptionInfoList());
for (SubscriptionInfo info : Objects.requireNonNull(subscriptions)) {
if (tm.getSimState(info.getSimSlotIndex()) == TelephonyManager.SIM_STATE_READY) {
activeSubscriptions.add(info);
Expand All @@ -814,7 +793,6 @@ public void refreshAll() {
refreshNetworkInformation();
refreshBatteryInfo();
refreshNetworkInterfaceInformation();
onCellInfoChanged(getAllCellInfo());

SignalStrength ss = tm.getSignalStrength();
// if the phone is not connected and we missed the update on tis we clear our internal cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class GlobalVars {
public final int[] WCDMA_ECNO_Threasholds = {-24,-14,-6,1};
public final int[] WCDMA_RSCP_Threasholds = {-115,-105,-95,-85};

// Predefined values for "select_subscription" preference
public static int MULTIPLE_SUBSCRIPTIONS_SELECTED_ID = 99999;
public static int INVALID_SUBSCRIPTION_ID = -1;

public static final String INFLUX_WRITE_STATUS = "influxdb_write_status";
private static GlobalVars instance;
ImageView log_status;
Expand Down
Loading