mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-07-03 21:21:12 +08:00
parent
0d01d20485
commit
ae7a06cfa3
@ -234,7 +234,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
// NOTE: a null intent may be delivered due to START_STICKY
|
||||
// It can be simulated by starting the capture, putting PCAPdroid in the background and then running:
|
||||
// adb shell ps | grep remote_capture | awk '{print $2}' | xargs adb shell run-as com.emanuelef.remote_capture.debug kill
|
||||
CaptureSettings settings = (CaptureSettings) ((intent == null) ? null : intent.getSerializableExtra("settings"));
|
||||
CaptureSettings settings = ((intent == null) ? null : Utils.getSerializableExtra(intent, "settings", CaptureSettings.class));
|
||||
if(settings == null) {
|
||||
// Use the settings from mPrefs
|
||||
|
||||
@ -813,6 +813,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
|
||||
/* Stops the running Service. The SERVICE_STATUS_STOPPED notification is sent asynchronously
|
||||
* when mCaptureThread terminates. */
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void stopService() {
|
||||
CaptureService captureService = INSTANCE;
|
||||
Log.d(TAG, "stopService called (instance? " + (captureService != null) + ")");
|
||||
|
||||
@ -54,6 +54,7 @@ import android.net.Uri;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -75,6 +76,7 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
@ -99,6 +101,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
@ -1072,6 +1075,7 @@ public class Utils {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static BuildType getVerifiedBuild(Context ctx, String package_name) {
|
||||
try {
|
||||
Signature[] signatures;
|
||||
@ -1372,4 +1376,30 @@ public class Utils {
|
||||
public static String getUserAgent() {
|
||||
return "PCAPdroid v" + BuildConfig.VERSION_NAME;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "deprecation"})
|
||||
public static @Nullable <T extends Serializable> T getSerializableExtra(Intent intent, String key, Class<T> clazz) {
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
|
||||
return intent.getSerializableExtra(key, clazz);
|
||||
else {
|
||||
try {
|
||||
return (T)intent.getSerializableExtra(key);
|
||||
} catch (ClassCastException unused) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "deprecation"})
|
||||
public static @Nullable <T extends Serializable> T getSerializable(Bundle bundle, String key, Class<T> clazz) {
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
|
||||
return bundle.getSerializable(key, clazz);
|
||||
else {
|
||||
try {
|
||||
return (T)bundle.getSerializable(key);
|
||||
} catch (ClassCastException unused) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.ConnectionsRegister;
|
||||
import com.emanuelef.remote_capture.PCAPdroid;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.model.ConnectionDescriptor.Status;
|
||||
import com.emanuelef.remote_capture.model.ConnectionDescriptor.DecryptionStatus;
|
||||
import com.emanuelef.remote_capture.model.ConnectionDescriptor.FilteringStatus;
|
||||
@ -79,7 +80,7 @@ public class EditFilterActivity extends BaseActivity implements MenuProvider {
|
||||
|
||||
Intent intent = getIntent();
|
||||
if(intent != null) {
|
||||
FilterDescriptor desc = (FilterDescriptor)intent.getSerializableExtra(FILTER_DESCRIPTOR);
|
||||
FilterDescriptor desc = Utils.getSerializableExtra(intent, FILTER_DESCRIPTOR, FilterDescriptor.class);
|
||||
if(desc != null)
|
||||
mFilter = desc;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ package com.emanuelef.remote_capture.activities;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.fragments.EditListFragment;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.model.ListInfo;
|
||||
import com.emanuelef.remote_capture.model.MatchList;
|
||||
|
||||
@ -37,7 +37,7 @@ public class EditListActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
assert(getIntent() != null);
|
||||
ListInfo.Type ltype = (ListInfo.Type) getIntent().getSerializableExtra(LIST_TYPE_EXTRA);
|
||||
ListInfo.Type ltype = Utils.getSerializableExtra(getIntent(), LIST_TYPE_EXTRA, ListInfo.Type.class);
|
||||
assert(ltype != null);
|
||||
mListInfo = new ListInfo(ltype);
|
||||
|
||||
|
||||
@ -368,20 +368,26 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
private void peerInfoResult(final ActivityResult result) {
|
||||
if((result.getResultCode() == RESULT_OK) && (result.getData() != null)) {
|
||||
Intent data = result.getData();
|
||||
Serializable skus_extra = data.getSerializableExtra("skus");
|
||||
if(skus_extra instanceof HashSet) {
|
||||
HashSet<String> skus = (HashSet<String>) skus_extra;
|
||||
Log.d(TAG, "Found peer app info");
|
||||
|
||||
for(String sku: skus) {
|
||||
Log.d(TAG, "Peer sku: " + sku);
|
||||
mIab.addPeerSku(sku);
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
HashSet<String> skus = Utils.getSerializableExtra(data, "skus", HashSet.class);
|
||||
|
||||
if(skus != null) {
|
||||
Log.d(TAG, "Found peer app info");
|
||||
|
||||
for(String sku: skus) {
|
||||
Log.d(TAG, "Peer sku: " + sku);
|
||||
mIab.addPeerSku(sku);
|
||||
}
|
||||
|
||||
// success
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} catch (ClassCastException ignored) {}
|
||||
}
|
||||
|
||||
// fail
|
||||
Log.d(TAG, "Invalid peer app result");
|
||||
}
|
||||
|
||||
|
||||
@ -118,7 +118,8 @@ public class StatsActivity extends BaseActivity implements MenuProvider {
|
||||
}
|
||||
|
||||
private void updateStats(Intent intent) {
|
||||
CaptureStats stats = (CaptureStats) intent.getSerializableExtra("value");
|
||||
CaptureStats stats = Utils.getSerializableExtra(intent, "value", CaptureStats.class);
|
||||
assert(stats != null);
|
||||
|
||||
mBytesSent.setText(Utils.formatBytes(stats.bytes_sent));
|
||||
mBytesRcvd.setText(Utils.formatBytes(stats.bytes_rcvd));
|
||||
|
||||
@ -98,7 +98,8 @@ public class ConnectionPayload extends Fragment implements ConnectionDetailsActi
|
||||
PayloadChunk.ChunkType mode;
|
||||
assert args != null;
|
||||
ConnectionsRegister reg = CaptureService.requireConnsRegister();
|
||||
mode = (PayloadChunk.ChunkType) args.getSerializable("mode");
|
||||
mode = Utils.getSerializable(args, "mode", PayloadChunk.ChunkType.class);
|
||||
assert(mode != null);
|
||||
|
||||
mConn = reg.getConnById(args.getInt("conn_id"));
|
||||
if(mConn == null) {
|
||||
|
||||
@ -233,7 +233,7 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
|
||||
Intent intent = requireActivity().getIntent();
|
||||
|
||||
if(intent != null) {
|
||||
FilterDescriptor filter = (FilterDescriptor) intent.getSerializableExtra(FILTER_EXTRA);
|
||||
FilterDescriptor filter = Utils.getSerializableExtra(intent, FILTER_EXTRA, FilterDescriptor.class);
|
||||
if(filter != null) {
|
||||
mAdapter.mFilter = filter;
|
||||
fromIntent = true;
|
||||
@ -252,7 +252,7 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
|
||||
search = savedInstanceState.getString("search");
|
||||
|
||||
if(!fromIntent && savedInstanceState.containsKey("filter_desc"))
|
||||
mAdapter.mFilter = (FilterDescriptor) savedInstanceState.getSerializable("filter_desc");
|
||||
mAdapter.mFilter = Utils.getSerializable(savedInstanceState, "filter_desc", FilterDescriptor.class);
|
||||
}
|
||||
refreshActiveFilter();
|
||||
|
||||
@ -801,7 +801,7 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
|
||||
|
||||
private void filterResult(final ActivityResult result) {
|
||||
if(result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
|
||||
FilterDescriptor descriptor = (FilterDescriptor)result.getData().getSerializableExtra(EditFilterActivity.FILTER_DESCRIPTOR);
|
||||
FilterDescriptor descriptor = Utils.getSerializableExtra(result.getData(), EditFilterActivity.FILTER_DESCRIPTOR, FilterDescriptor.class);
|
||||
if(descriptor != null) {
|
||||
mAdapter.mFilter = descriptor;
|
||||
mAdapter.refreshFilteredConnections();
|
||||
|
||||
@ -100,7 +100,7 @@ public class EditListFragment extends Fragment implements MatchList.ListChangeLi
|
||||
mEmptyText = view.findViewById(R.id.list_empty);
|
||||
|
||||
assert getArguments() != null;
|
||||
mListInfo = new ListInfo((ListInfo.Type)getArguments().getSerializable(LIST_TYPE_ARG));
|
||||
mListInfo = new ListInfo(Utils.getSerializable(getArguments(), LIST_TYPE_ARG, ListInfo.Type.class));
|
||||
mList = mListInfo.getList();
|
||||
mList.addListChangeListener(this);
|
||||
|
||||
|
||||
@ -283,7 +283,8 @@ public class StatusFragment extends Fragment implements AppStateListener, MenuPr
|
||||
}
|
||||
|
||||
private void processStatsUpdateIntent(Intent intent) {
|
||||
CaptureStats stats = (CaptureStats) intent.getSerializableExtra("value");
|
||||
CaptureStats stats = Utils.getSerializableExtra(intent, "value", CaptureStats.class);
|
||||
assert(stats != null);
|
||||
|
||||
Log.d("MainReceiver", "Got StatsUpdate: bytes_sent=" + stats.pkts_sent + ", bytes_rcvd=" +
|
||||
stats.bytes_rcvd + ", pkts_sent=" + stats.pkts_sent + ", pkts_rcvd=" + stats.pkts_rcvd);
|
||||
|
||||
@ -79,20 +79,20 @@ public class CaptureSettings implements Serializable {
|
||||
// get a integer value from the bundle. The value may be represented as an int or as a string.
|
||||
private static int getInt(Intent intent, String key, int def_value) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
Object o = bundle.get(key);
|
||||
|
||||
if(o != null)
|
||||
return Integer.parseInt(o.toString());
|
||||
return def_value;
|
||||
String s = bundle.getString(key);
|
||||
if(s != null)
|
||||
return Integer.parseInt(s);
|
||||
return bundle.getInt(key, def_value);
|
||||
}
|
||||
|
||||
// get a boolean value from the bundle. The value may be represented as a bool or as a string.
|
||||
private static boolean getBool(Intent intent, String key, boolean def_value) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
Object o = bundle.get(key);
|
||||
|
||||
if(o != null)
|
||||
return Boolean.parseBoolean(o.toString());
|
||||
return def_value;
|
||||
String s = bundle.getString(key);
|
||||
if(s != null)
|
||||
return Boolean.parseBoolean(s);
|
||||
return bundle.getBoolean(key, def_value);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user