diff --git a/app/src/main/java/com/emanuelef/remote_capture/MitmAddon.java b/app/src/main/java/com/emanuelef/remote_capture/MitmAddon.java index 8d77e9c3..cbab7793 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/MitmAddon.java +++ b/app/src/main/java/com/emanuelef/remote_capture/MitmAddon.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with PCAPdroid. If not, see . * - * Copyright 2022 - Emanuele Faranda + * Copyright 2022-24 - Emanuele Faranda */ package com.emanuelef.remote_capture; @@ -34,6 +34,7 @@ import android.os.Message; import android.os.Messenger; import android.os.ParcelFileDescriptor; +import android.os.PowerManager; import android.os.RemoteException; import androidx.annotation.NonNull; @@ -48,8 +49,8 @@ import java.lang.ref.WeakReference; public class MitmAddon { - public static final long PACKAGE_VERSION_CODE = 16; - public static final String PACKAGE_VERSION_NAME = "v0.16"; + public static final long PACKAGE_VERSION_CODE = 17; + public static final String PACKAGE_VERSION_NAME = "v1.0"; public static final String REPOSITORY = "https://github.com/emanuele-f/PCAPdroid-mitm"; private static final String TAG = "MitmAddon"; private final Context mContext; @@ -295,4 +296,28 @@ public boolean stopProxy() { return false; } } + + // NOTE: doze could be disabled by PCAPdroid itself, however this is moved to the addon to avoid + // any issues with the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Google Play policies + public boolean disableDoze() { + if(mService == null) + return false; + + Log.i(TAG, "Send disable doze"); + Message msg = Message.obtain(null, MitmAPI.MSG_DISABLE_DOZE); + try { + mService.send(msg); + return true; + } catch (RemoteException e) { + e.printStackTrace(); + return false; + } + } + + public static boolean isDozeEnabled(Context context) { + final PowerManager manager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + + return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) && (manager != null) + && !manager.isIgnoringBatteryOptimizations(MitmAPI.PACKAGE_NAME); + } } diff --git a/app/src/main/java/com/emanuelef/remote_capture/MitmReceiver.java b/app/src/main/java/com/emanuelef/remote_capture/MitmReceiver.java index 4650089c..e3cfb824 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/MitmReceiver.java +++ b/app/src/main/java/com/emanuelef/remote_capture/MitmReceiver.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with PCAPdroid. If not, see . * - * Copyright 2022 - Emanuele Faranda + * Copyright 2022-24 - Emanuele Faranda */ package com.emanuelef.remote_capture; @@ -483,6 +483,11 @@ public void onMitmGetCaCertificateResult(@Nullable String ca_pem) { return; } + if (MitmAddon.isDozeEnabled(mContext)) { + Utils.showToastLong(mContext, R.string.mitm_doze_notice); + mAddon.disableDoze(); + } + if(mThread != null) mThread.interrupt(); diff --git a/app/src/main/java/com/emanuelef/remote_capture/activities/AboutActivity.java b/app/src/main/java/com/emanuelef/remote_capture/activities/AboutActivity.java index f14a9607..ddd6614a 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/activities/AboutActivity.java +++ b/app/src/main/java/com/emanuelef/remote_capture/activities/AboutActivity.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with PCAPdroid. If not, see . * - * Copyright 2020-21 - Emanuele Faranda + * Copyright 2020-24 - Emanuele Faranda */ package com.emanuelef.remote_capture.activities; @@ -55,6 +55,7 @@ import com.emanuelef.remote_capture.Billing; import com.emanuelef.remote_capture.CaptureService; import com.emanuelef.remote_capture.Log; +import com.emanuelef.remote_capture.MitmAddon; import com.emanuelef.remote_capture.R; import com.emanuelef.remote_capture.Utils; import com.emanuelef.remote_capture.model.Prefs; @@ -147,6 +148,7 @@ public boolean onMenuItemSelected(MenuItem item) { String deviceInfo = Utils.getBuildInfo(this) + "\n\n" + Prefs.asString(this); + // Private DNS Utils.PrivateDnsMode dns_mode = CaptureService.getPrivateDnsMode(); if(dns_mode == null) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { @@ -164,6 +166,9 @@ public boolean onMenuItemSelected(MenuItem item) { if(dns_mode != null) deviceInfo += "\n" + "PrivateDnsMode: " + dns_mode; + // Mitm doze + deviceInfo += "\n" + "MitmBatteryOptimized: " + ((MitmAddon.isInstalled(this) && MitmAddon.isDozeEnabled(this)) ? "true" : "false"); + LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.scrollable_dialog, null); ((TextView)view.findViewById(R.id.text)).setText(deviceInfo); diff --git a/app/src/main/java/com/pcapdroid/mitm/MitmAPI.java b/app/src/main/java/com/pcapdroid/mitm/MitmAPI.java index d88fa128..923011c8 100644 --- a/app/src/main/java/com/pcapdroid/mitm/MitmAPI.java +++ b/app/src/main/java/com/pcapdroid/mitm/MitmAPI.java @@ -30,6 +30,7 @@ public class MitmAPI { public static final int MSG_START_MITM = 1; public static final int MSG_GET_CA_CERTIFICATE = 2; public static final int MSG_STOP_MITM = 3; + public static final int MSG_DISABLE_DOZE = 4; public static final String MITM_CONFIG = "mitm_config"; public static final String CERTIFICATE_RESULT = "certificate"; public static final String SSLKEYLOG_RESULT = "sslkeylog"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f44df8e9..34f1d7d0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -493,4 +493,5 @@ This connection will not be decrypted. Create a decryption rule to decrypt it TLS decryption is only applied to connections that match the configured rules. Do you want to create decryption rules now? Active VPN detected + Battery optimization may interfere with the mitm addon