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

Commit bfd93618 authored by Dave Carey's avatar Dave Carey Committed by Bruno Martins
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

Change-Id: I3d61408946912fa0e5f796531413c78255257efe
parent f899da6e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,19 @@
     limitations under the License.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- 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>

    <!-- [CHAR LIMIT=NONE] Device Info screen. Countdown for user taps to enable development settings -->
    <plurals name="show_dev_countdown_cm">
        <item quantity="one">You are now <xliff:g id="step_count">%1$d</xliff:g> step away from enabling development settings.</item>
+15 −2
Original line number Diff line number Diff line
@@ -128,8 +128,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" />
+16 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ import java.util.List;

public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFragment
        implements SwitchBar.OnSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost,
        AdbClearKeysDialogHost, LogPersistDialogHost,
        WirelessAdbDialogHost, AdbClearKeysDialogHost, LogPersistDialogHost,
        BluetoothA2dpHwOffloadRebootDialog.OnA2dpHwDialogConfirmedListener {

    private static final String TAG = "DevSettingsDashboard";
@@ -249,6 +249,20 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controller.onAdbDialogDismissed();
    }

    @Override
    public void onWirelessAdbDialogConfirmed() {
        final WirelessAdbPreferenceController controller = getDevelopmentOptionsController(
                WirelessAdbPreferenceController.class);
        controller.onWirelessAdbDialogConfirmed();
    }

    @Override
    public void onWirelessAdbDialogDismissed() {
        final WirelessAdbPreferenceController controller = getDevelopmentOptionsController(
                WirelessAdbPreferenceController.class);
        controller.onWirelessAdbDialogDismissed();
    }

    @Override
    public void onAdbClearKeysDialogConfirmed() {
        final ClearAdbKeysPreferenceController controller = getDevelopmentOptionsController(
@@ -392,6 +406,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new CoolColorTemperaturePreferenceController(context));
        controllers.add(new DisableAutomaticUpdatesPreferenceController(context));
        controllers.add(new AdbPreferenceController(context, fragment));
        controllers.add(new WirelessAdbPreferenceController(context, fragment));
        controllers.add(new ClearAdbKeysPreferenceController(context, fragment));
        controllers.add(new LocalTerminalPreferenceController(context));
        controllers.add(new BugReportInPowerPreferenceController(context));
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.development;

/**
 * Interface for WirelessAdbWarningDialogFragment callbacks.
 */
public interface WirelessAdbDialogHost {

    /**
     * Called when the user presses ok on the warning dialog.
     */
    void onWirelessAdbDialogConfirmed();

    /**
     * Called when the user dismisses or cancels the warning dialog.
     */
    void onWirelessAdbDialogDismissed();
}
+130 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.development;

import android.content.Context;
import android.net.NetworkUtils;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v14.preference.SwitchPreference;
import android.text.TextUtils;

import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

import lineageos.providers.LineageSettings;

public class WirelessAdbPreferenceController extends DeveloperOptionsPreferenceController
        implements PreferenceControllerMixin {

    private static final String TAG = "WirelessAdbPreferenceController";
    private static final String PREF_KEY = "adb_over_network";

    private final DevelopmentSettingsDashboardFragment mFragment;
    private final WifiManager mWifiManager;

    public WirelessAdbPreferenceController(Context context,
            DevelopmentSettingsDashboardFragment fragment) {
        super(context);

        mFragment = fragment;
        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    }

    @Override
    public String getPreferenceKey() {
        return PREF_KEY;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);

        updatePreference();

        if (!isAdminUser()) {
            mPreference.setEnabled(false);
        }
    }

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (Utils.isMonkeyRunning()) {
            return false;
        }

        if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
            if (((SwitchPreference) mPreference).isChecked()) {
                WirelessAdbWarningDialog.show(mFragment);
            } else {
                LineageSettings.Secure.putInt(mContext.getContentResolver(),
                       LineageSettings.Secure.ADB_PORT, -1);
                updatePreference();
            }
            return true;
        }
        return false;
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        if (isAdminUser()) {
            mPreference.setEnabled(true);
        }
    }

    public void onWirelessAdbDialogConfirmed() {
        LineageSettings.Secure.putInt(mContext.getContentResolver(),
                LineageSettings.Secure.ADB_PORT, 5555);
        updatePreference();
    }

    public void onWirelessAdbDialogDismissed() {
        updatePreference();
    }

    private void updatePreference() {
        int port = LineageSettings.Secure.getInt(mContext.getContentResolver(),
                LineageSettings.Secure.ADB_PORT, -1);
        boolean enabled = port > 0;
        WifiInfo wifiInfo = mWifiManager.getConnectionInfo();

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

        ((SwitchPreference) mPreference).setChecked(enabled);
    }

    @VisibleForTesting
    boolean isAdminUser() {
        return ((UserManager) mContext.getSystemService(Context.USER_SERVICE)).isAdminUser();
    }
}
Loading