Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f322840 authored by Dave Carey's avatar Dave Carey Committed by Michael Bestas
Browse files

Settings: Implement ADB notification and ADB over network

Original commit title in CM 13.0:
Settings: Forward port ADB over network (Part 1 of 2)

Squashed commit of the ADB-related changes in:

 - Adb over network (Settings part for Jellybean)
   + Display WiFi IP Address & Port as preference summary.
   Note: adb_over_network were already pushed in 5555aae3
   Author: Tanguy Pruvot
   Id: Ia05aa8f6281c9bdcb3d5e62566b103c38bc70b82

 - Settings : Fix mismatched dialog listener
   Set listener on correct dialog
   Author: Danesh Mondegarian
   Id: I0c05af859ad0e93ba6a1d3d395dc6c31e9949426

 - ADB: missing dialog dismiss, and use updateCheckBox()
   this function check if debug features are enabled.
   Author: Tanguy Pruvot
   Id: I675a3a9ce5c28b16f9e13e78499e5f6f897b9dd3

 - DevelopmentSettings: Refactor ADB over Network
   The checkbox would never enable adbd in tcpip mode.
   Author: Alexander Hofbauer
   Id: Iab8307bb91f69d85ed3a46d5ef09274fa8b03da

 - Settings: Fix compilation
   Author: Ethan Chen
   Id: I25e3350408a7e70400b0ed74ec30882b3f310dec

 - Settings: Move Secure settings to CMSettings
   Author: Clark Scheff
   Id: If2e4f1e44b448c953f6fb1f3a0689b73cc3958c0

 - Development Settings: fix setting reset on disable
   Author: Thiago Vinícius Freire de Araújo Ribeiro
   Id: Ifa1ee25cfab32b7a236e02055006f0d2a4b07f37

 - Settings: Cleanup ALL the strings
   Author: Michael Bestas
   Id: I7928655125f360de62c25313d01a228e7cd886b5

 - settings: Add missing strings
   Author: Steve Kondik
   Id: I99318ea1f391983cc85583c2777b578beeeef011

 - Settings: Set ADB notification on by default
   Fixes the wrong initial state shown in settings.
   From: Arne Coucheron
   Id: Icd08c21a3327c05103c7738c19cbf1c20306fa3a

[rashed] Adapt to 8.1

Change-Id: I3d61408946912fa0e5f796531413c78255257efe
parent df2a317f
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -25,4 +25,18 @@
    <!-- Whether the keyguard will directly show the PIN entry -->
    <string name="lock_directly_show_pin">Directly show PIN entry</string>
    <string name="lock_directly_show_pin_summary">Skip the swipe to unlock screen and immediately begin PIN entry</string>

    <!-- Android debugging -->
    <string name="adb_enable">Android debugging</string>
    <string name="adb_enable_summary">Enable the Android Debug Bridge (ADB) interface</string>

    <!-- Android debugging notification -->
    <string name="adb_notify">Debugging notify</string>
    <string name="adb_notify_summary">Display a notification when USB or network debugging is enabled</string>

    <!-- Android debugging over network -->
    <string name="adb_over_network">ADB over network</string>
    <string name="adb_over_network_summary">Enable TCP/IP debugging over network interfaces (Wi\u2011Fi, USB networks). This setting is reset on reboot</string>
    <string name="adb_over_network_warning">WARNING: When ADB over network is enabled, your phone is open for intrusions on all connected networks!\n\nOnly use this feature when you are connected on trusted networks.\n\nDo you really want to enable this function?</string>

</resources>
+15 −2
Original line number Diff line number Diff line
@@ -108,8 +108,21 @@

        <SwitchPreference
            android:key="enable_adb"
            android:title="@string/enable_adb"
            android:summary="@string/enable_adb_summary"/>
            android:title="@string/adb_enable"
            android:summary="@string/adb_enable_summary" />

        <lineageos.preference.LineageSecureSettingSwitchPreference
            android:key="adb_notify"
            android:title="@string/adb_notify"
            android:summary="@string/adb_notify_summary"
            android:dependency="enable_adb"
            android:defaultValue="true" />

        <SwitchPreference
            android:key="adb_over_network"
            android:title="@string/adb_over_network"
            android:summary="@string/adb_over_network_summary"
            android:dependency="enable_adb" />

        <Preference android:key="clear_adb_keys"
                android:title="@string/clear_adb_keys" />
+74 −1
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.hardware.usb.IUsbManager;
import android.hardware.usb.UsbManager;
import android.net.NetworkUtils;
import android.net.wifi.IWifiManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.BatteryManager;
@@ -101,6 +104,8 @@ import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
import com.android.settingslib.drawer.CategoryKey;

import lineageos.providers.LineageSettings;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -124,6 +129,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
     */
    public static final String PREF_SHOW = "show";

    private static final String ADB_TCPIP = "adb_over_network";
    private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
    private static final String ENABLE_TERMINAL = "enable_terminal";
    private static final String KEEP_SCREEN_ON = "keep_screen_on";
@@ -265,6 +271,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
    private boolean mHaveDebugSettings;
    private boolean mDontPokeProperties;
    private EnableAdbPreferenceController mEnableAdbController;
    private SwitchPreference mAdbOverNetwork;
    private Preference mClearAdbKeys;
    private SwitchPreference mEnableTerminal;
    private RestrictedSwitchPreference mKeepScreenOn;
@@ -353,6 +360,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
    private boolean mDialogClicked;
    private Dialog mEnableDialog;

    private Dialog mAdbTcpDialog;
    private Dialog mAdbKeysDialog;
    private boolean mUnavailable;

@@ -421,6 +429,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
        final PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
                findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
        mEnableAdbController = new EnableAdbPreferenceController(getActivity());
        mAdbOverNetwork = findAndInitSwitchPref(ADB_TCPIP);
        mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
        if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
            if (debugDebuggingCategory != null) {
@@ -851,6 +860,35 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
        updateBluetoothDisableAbsVolumeOptions();
        updateBluetoothEnableInbandRingingOptions();
        updateBluetoothA2dpConfigurationValues();
        updateAdbOverNetwork();
    }

    private void updateAdbOverNetwork() {
        int port = LineageSettings.Secure.getInt(getActivity().getContentResolver(),
                LineageSettings.Secure.ADB_PORT, 0);
        boolean enabled = port > 0;

        updateSwitchPreference(mAdbOverNetwork, enabled);

        WifiInfo wifiInfo = null;

        if (enabled) {
            IWifiManager wifiManager = IWifiManager.Stub.asInterface(
                    ServiceManager.getService(Context.WIFI_SERVICE));
            try {
                wifiInfo = wifiManager.getConnectionInfo(getActivity().getOpPackageName());
            } catch (RemoteException e) {
                Log.e(TAG, "wifiManager, getConnectionInfo()", e);
            }
        }

        if (wifiInfo != null) {
            String hostAddress = NetworkUtils.intToInetAddress(
                    wifiInfo.getIpAddress()).getHostAddress();
            mAdbOverNetwork.setSummary(hostAddress + ":" + String.valueOf(port));
        } else {
            mAdbOverNetwork.setSummary(R.string.adb_over_network_summary);
        }
    }

    private void resetDangerousOptions() {
@@ -869,6 +907,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
        mBugReportInPowerController.resetPreference();
        mEnableAdbController.resetPreference();
        resetDebuggerOptions();
        resetAdbNotifyOptions();
        writeLogpersistOption(null, true);
        writeLogdSizeOption(null);
        writeAnimationScaleOption(0, mWindowAnimationScale, null);
@@ -886,6 +925,11 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
        pokeSystemProperties();
    }

    private void resetAdbNotifyOptions() {
        LineageSettings.Secure.putInt(getActivity().getContentResolver(),
                LineageSettings.Secure.ADB_NOTIFY, 1);
    }

    private void updateHdcpValues() {
        ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
        if (hdcpChecking != null) {
@@ -2472,7 +2516,24 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
            return true;
        }

        if (preference == mClearAdbKeys) {
        if (preference == mAdbOverNetwork) {
            if (mAdbOverNetwork.isChecked()) {
                if (mAdbTcpDialog != null) {
                    dismissDialogs();
                }
                mAdbTcpDialog = new AlertDialog.Builder(getActivity()).setMessage(
                        getResources().getString(R.string.adb_over_network_warning))
                        .setTitle(R.string.adb_over_network)
                        .setPositiveButton(android.R.string.yes, this)
                        .setNegativeButton(android.R.string.no, this)
                        .show();
                mAdbTcpDialog.setOnDismissListener(this);
            } else {
                LineageSettings.Secure.putInt(getActivity().getContentResolver(),
                        LineageSettings.Secure.ADB_PORT, -1);
                updateAdbOverNetwork();
            }
        } else if (preference == mClearAdbKeys) {
            if (mAdbKeysDialog != null) dismissDialogs();
            mAdbKeysDialog = new AlertDialog.Builder(getActivity())
                    .setMessage(R.string.adb_keys_warning_message)
@@ -2661,6 +2722,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
            mLogpersistClearDialog.dismiss();
            mLogpersistClearDialog = null;
        }
        if (mAdbTcpDialog != null) {
            mAdbTcpDialog.dismiss();
            mAdbTcpDialog = null;
        }
    }

    public void onClick(DialogInterface dialog, int which) {
@@ -2689,6 +2754,11 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
            } else {
                updateLogpersistValues();
            }
        } else if (dialog == mAdbTcpDialog) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                LineageSettings.Secure.putInt(getActivity().getContentResolver(),
                        LineageSettings.Secure.ADB_PORT, 5555);
            }
        }
    }

@@ -2701,6 +2771,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
            mEnableDialog = null;
        } else if (dialog == mLogpersistClearDialog) {
            mLogpersistClearDialog = null;
        } else if (dialog == mAdbTcpDialog) {
            updateAdbOverNetwork();
            mAdbTcpDialog = null;
        }
    }