Skip to content
Merged
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 @@ -27,6 +27,7 @@
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
Expand Down Expand Up @@ -532,16 +533,19 @@ private CardView get_network_card_view() {
NetworkCallback nc = new NetworkCallback(context);
TableLayout tl = new TableLayout(context);

addRows(tl, new String[][]{
{getString(R.string.networkOperatorName), ni.getNetworkOperatorName()},
{getString(R.string.simOperatorName), ni.getSimOperatorName()},
{getString(R.string.networkSpecifier), ni.getNetworkSpecifier()},
{getString(R.string.dataState), ni.getDataStateString()},
{getString(R.string.dataNetworkType), ni.getDataNetworkTypeString()},
{getString(R.string.phoneType), ni.getPhoneTypeString()},
{getString(R.string.preferredOpportunisticDataSubscriptionId), String.valueOf(ni.getPreferredOpportunisticDataSubscriptionId())},
}, true);

if (ni != null) {
addRows(tl, new String[][]{
{getString(R.string.networkOperatorName), ni.getNetworkOperatorName()},
{getString(R.string.simOperatorName), ni.getSimOperatorName()},
{getString(R.string.networkSpecifier), ni.getNetworkSpecifier()},
{getString(R.string.dataState), ni.getDataStateString()},
{getString(R.string.dataNetworkType), ni.getDataNetworkTypeString()},
{getString(R.string.phoneType), ni.getPhoneTypeString()},
{getString(R.string.preferredOpportunisticDataSubscriptionId), String.valueOf(ni.getPreferredOpportunisticDataSubscriptionId())},
}, true);
} else {
Toast.makeText(getContext(), "NetworkInformation was not ready!", Toast.LENGTH_SHORT).show();
}

if (GlobalVars.getInstance().isPermission_phone_state() && tm.getSimState() == TelephonyManager.SIM_STATE_READY) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Expand Down Expand Up @@ -644,4 +648,4 @@ private CardView get_wifi_card_view() {
public void onDestroyView() {
super.onDestroyView();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;
Expand Down Expand Up @@ -60,9 +60,13 @@ public class LoggingService extends Service {
DataProvider dp;
SharedPreferencesGrouper spg;
private Handler notificationHandler;
private HandlerThread notificationHandlerThread;
private Handler remoteInfluxHandler;
private HandlerThread remoteInfluxHandlerThread;
private Handler localInfluxHandler;
private HandlerThread localInfluxHandlerThread;
private Handler localFileHandler;
private HandlerThread localFileHandlerThread;
private List<Point> logFilePoints;
private FileOutputStream stream;
private int interval;
Expand Down Expand Up @@ -250,6 +254,7 @@ public void onDestroy() {
if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) {
stopRemoteInfluxDB();
}

if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_local_file_log", false)) {
stopLocalFile();
}
Expand Down Expand Up @@ -403,8 +408,7 @@ private void setupLocalFile() {
Log.d(TAG,e.toString());
}

localFileHandler = new Handler(Objects.requireNonNull(Looper.myLooper()));
localFileHandler.post(localFileUpdate);
initLocalFileHandlerAndItsThread();
}

private void stopLocalFile() {
Expand All @@ -419,11 +423,22 @@ private void stopLocalFile() {
Log.d(TAG,e.toString());
}
}

if (localFileHandlerThread != null) {
localFileHandlerThread.quitSafely();
try {
localFileHandlerThread.join();
} catch (InterruptedException e) {
Log.e(TAG, "Exception happened!! "+e, e);
}
}
}

private void setupNotificationUpdate() {
Log.d(TAG, "setupNotificationUpdate");
notificationHandler = new Handler(Objects.requireNonNull(Looper.myLooper()));
notificationHandlerThread = new HandlerThread("NotificationHandlerThread");
notificationHandlerThread.start();
notificationHandler = new Handler(Objects.requireNonNull(notificationHandlerThread.getLooper()));
notificationHandler.post(notification_updater);
}

Expand All @@ -432,13 +447,25 @@ private void stopNotificationUpdate() {
notificationHandler.removeCallbacks(notification_updater);
builder.setContentText(null);
nm.notify(1, builder.build());

if (notificationHandlerThread != null) {
notificationHandlerThread.quitSafely();
try {
notificationHandlerThread.join();
} catch (InterruptedException e) {
Log.e(TAG, "Exception happened!! "+e, e);
}
notificationHandlerThread = null;
}
}

private void setupLocalInfluxDB() {
Log.d(TAG, "setupLocalInfluxDB");
lic = InfluxdbConnections.getLicInstance(getApplicationContext());
Objects.requireNonNull(lic).open_write_api();
localInfluxHandler = new Handler(Objects.requireNonNull(Looper.myLooper()));
localInfluxHandlerThread = new HandlerThread("LocalInfluxHandlerThread");
localInfluxHandlerThread.start();
localInfluxHandler = new Handler(Objects.requireNonNull(localFileHandlerThread.getLooper()));
localInfluxHandler.post(localInfluxUpdate);
}

Expand All @@ -454,6 +481,15 @@ private void stopLocalInfluxDB() {
if (lic != null) {
lic.disconnect();
}
if (localInfluxHandlerThread != null) {
localInfluxHandlerThread.quitSafely();
try {
localInfluxHandlerThread.join();
} catch (InterruptedException e) {
Log.e(TAG, "Exception happened!! "+e, e);
}
localInfluxHandlerThread = null;
}
}

/**
Expand All @@ -463,7 +499,9 @@ private void setupRemoteInfluxDB() {
Log.d(TAG, "setupRemoteInfluxDB");
ic = InfluxdbConnections.getRicInstance(getApplicationContext());
Objects.requireNonNull(ic).open_write_api();
remoteInfluxHandler = new Handler(Objects.requireNonNull(Looper.myLooper()));
remoteInfluxHandlerThread = new HandlerThread("RemoteInfluxHandlerThread");
remoteInfluxHandlerThread.start();
remoteInfluxHandler = new Handler(Objects.requireNonNull(remoteInfluxHandlerThread.getLooper()));
remoteInfluxHandler.post(RemoteInfluxUpdate);
ImageView log_status = gv.getLog_status();
if (log_status != null) {
Expand All @@ -485,6 +523,16 @@ private void stopRemoteInfluxDB() {
}
}

if (remoteInfluxHandlerThread != null) {
remoteInfluxHandlerThread.quitSafely();
try {
remoteInfluxHandlerThread.join();
} catch (InterruptedException e) {
Log.e(TAG, "Exception happened!! "+e, e);
}
remoteInfluxHandlerThread = null;
}

// close disconnect influx connection if existing
if (ic != null) {
ic.disconnect();
Expand All @@ -501,4 +549,11 @@ private void stopRemoteInfluxDB() {
public IBinder onBind(Intent intent) {
return null;
}
}

private void initLocalFileHandlerAndItsThread() {
localFileHandlerThread = new HandlerThread("LocalFileHandlerThread");
localFileHandlerThread.start();
localFileHandler = new Handler(Objects.requireNonNull(localFileHandlerThread.getLooper()));
localFileHandler.post(localFileUpdate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.HandlerThread;
import android.os.StrictMode;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
Expand Down Expand Up @@ -71,6 +71,7 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen
Intent loggingServiceIntent;
NavController navController;
private Handler requestCellInfoUpdateHandler;
private HandlerThread requestCellInfoUpdateHandlerThread;
private GlobalVars gv;
/**
* Runnable to handle Cell Info Updates
Expand Down Expand Up @@ -191,8 +192,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

requestCellInfoUpdateHandler = new Handler(Objects.requireNonNull(Looper.myLooper()));
requestCellInfoUpdateHandler.post(requestCellInfoUpdate);
initHandlerAndHandlerThread();

loggingServiceIntent = new Intent(this, LoggingService.class);
if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_logging", false)) {
Expand Down Expand Up @@ -475,4 +475,11 @@ public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat calle
}
return true;
}
}

private void initHandlerAndHandlerThread() {
requestCellInfoUpdateHandlerThread = new HandlerThread("RequestCellInfoUpdateHandlerThread");
requestCellInfoUpdateHandlerThread.start();
requestCellInfoUpdateHandler = new Handler(Objects.requireNonNull(requestCellInfoUpdateHandlerThread.getLooper()));
requestCellInfoUpdateHandler.post(requestCellInfoUpdate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.icu.text.SimpleDateFormat;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class PingService extends Service {
private static final String TAG = "PingService";
private FileOutputStream ping_stream;
private Handler pingLogging;
private HandlerThread pingLoggingHandleThread;
private WorkManager wm;
private Context context;
private ArrayList<OneTimeWorkRequest> pingWRs;
Expand Down Expand Up @@ -128,7 +130,9 @@ private void setupPing(){
return;
}
spg.getSharedPreference(SPType.ping_sp).edit().putBoolean("ping", true).apply();
pingLogging = new Handler(Objects.requireNonNull(Looper.myLooper()));
pingLoggingHandleThread = new HandlerThread("PingLoggingHandlerThread");
pingLoggingHandleThread.start();
pingLogging = new Handler(Objects.requireNonNull(pingLoggingHandleThread.getLooper()));
PingParser pingParser = PingParser.getInstance(null);
propertyChangeListener = pingParser.getListener();
if(propertyChangeListener != null){
Expand Down Expand Up @@ -230,6 +234,15 @@ public void onChanged(Object o) {
private void stopPing(){

if (pingLogging != null )pingLogging.removeCallbacks(pingUpdate);
if (pingLoggingHandleThread != null) {
pingLoggingHandleThread.quitSafely();
try {
pingLoggingHandleThread.join();
} catch (InterruptedException e) {
Log.e(TAG, "Exception happened!! "+e, e);
}
pingLoggingHandleThread = null;
}
try {
if (ping_stream != null) ping_stream.close();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.StringRes;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;

Expand Down Expand Up @@ -320,7 +321,7 @@ public void run() {
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
));
errorText.setText(getString(R.string.cell_na));
errorText.setText(getSafeString(R.string.cell_na));
error.addView(errorText);
mainLL.addView(error);
} else {
Expand All @@ -343,4 +344,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
updateUIHandler.postDelayed(updateUI, 500);
return view;
}

public String getSafeString(@StringRes int resId) {
if (context == null) {
return "N/A";
} else {
return context.getResources().getString(resId);
}
}
}