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

Commit c3640cb2 authored by Alberto97's avatar Alberto97 Committed by Sam Mortimer
Browse files

Port ADB over network and ability to hide the notification

From: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Port "Option to hide Adb notification icon (2/2)"

From: Ricardo Cerqueira <cyanogenmod@cerqueira.org>
Framework: Forward port ADB over network (Part 2 of 2)

Includes:
- ADB Over Network, integration of the adb-host mode (already present)
  The feature can be used/tested without the Settings part:

    setprop service.adb.tcp.port 5555

  Note: This ADB setting is not persistent (for security purpose) and
  require init.rc implementation event like this : http://bit.ly/AdbTcpIP

  Author: Tanguy Pruvot
  Id: I5c61a53948349c785356cb5aae165110d75e3074

  Author: sssemil <suleymanovemil8@gmail.com>
  Show notification on adb over network too

  Screenshots - http://goo.gl/TgsRI6
  Id: I9ddc0aa9a4f330a06ab5d97a8645d1b31bb6f299

From: Ethan Chen <intervigil@gmail.com>
Use custom ADB over wifi property

* Use a custom system property to trigger the real one, so we avoid
  running afoul of any SELinux CTS requirements.

Change-Id: If23636cb5b51eb8fbdc76e9fa49ac474fbd6bf33
parent 2aff9a0e
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2017 The LineageOS Project
     Copyright (C) 2012-2014 The CyanogenMod Project
     Copyright (c) 2013, The Linux Foundation. All rights reserved.

     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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

    <!-- ADB over network notification -->
    <string name="adb_net_active_notification_title">ADB over network enabled</string>
    <!-- ADB over USB and network notification -->
    <string name="adb_both_active_notification_title">ADB over USB &amp; network enabled</string>
    <!-- ADB notification message-->
    <string name="adb_active_generic_notification_message">Touch to disable debugging.</string>

</resources>
+6 −0
Original line number Diff line number Diff line
@@ -3031,4 +3031,10 @@
  <java-symbol type="array" name="config_batteryPackageTypeService" />

  <java-symbol type="bool" name="config_useSystemClockforRotationSensor" />

  <!-- ADB notification -->
  <java-symbol type="string" name="adb_net_active_notification_title" />
  <java-symbol type="string" name="adb_both_active_notification_title" />
  <java-symbol type="string" name="adb_active_generic_notification_message" />

</resources>
+26 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources.Theme;
import android.database.ContentObserver;
import android.database.Cursor;
import android.os.BaseBundle;
import android.os.Binder;
import android.os.Build;
@@ -126,6 +128,8 @@ import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;

import lineageos.providers.LineageSettings;

import static android.view.Display.DEFAULT_DISPLAY;

public final class SystemServer {
@@ -270,6 +274,19 @@ public final class SystemServer {
        mRuntimeRestart = "1".equals(SystemProperties.get("sys.boot_completed"));
    }

    private class AdbPortObserver extends ContentObserver {
        public AdbPortObserver() {
            super(null);
        }
        @Override
        public void onChange(boolean selfChange) {
            int adbPort = LineageSettings.Secure.getInt(mContentResolver,
                LineageSettings.Secure.ADB_PORT, 0);
            // setting this will control whether ADB runs on TCP/IP or USB
            SystemProperties.set("adb.network.port", Integer.toString(adbPort));
        }
    }

    private void run() {
        try {
            traceBeginAndSlog("InitBeforeStartServices");
@@ -1513,6 +1530,15 @@ public final class SystemServer {
            }
        }

        // Make sure the ADB_ENABLED setting value matches the secure property value
        LineageSettings.Secure.putInt(mContentResolver, LineageSettings.Secure.ADB_PORT,
                Integer.parseInt(SystemProperties.get("service.adb.tcp.port", "-1")));

        // Register observer to listen for settings changes
        mContentResolver.registerContentObserver(
            LineageSettings.Secure.getUriFor(LineageSettings.Secure.ADB_PORT),
            false, new AdbPortObserver());

        // Before things start rolling, be sure we have decided whether
        // we are in safe mode.
        final boolean safeMode = wm.detectSafeMode();
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ LOCAL_SRC_FILES += \
LOCAL_JAVA_LIBRARIES := services.core \
android.hidl.manager-V1.0-java

LOCAL_JAVA_LIBRARIES += org.lineageos.platform.internal

LOCAL_STATIC_JAVA_LIBRARIES := android.hardware.usb-V1.0-java

include $(BUILD_STATIC_JAVA_LIBRARY)
+43 −9
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ import java.util.Map;
import java.util.Scanner;
import java.util.Set;

import lineageos.providers.LineageSettings;

/**
 * UsbDeviceManager manages USB state in device mode.
 */
@@ -375,7 +377,7 @@ public class UsbDeviceManager {
        private boolean mCurrentFunctionsApplied;
        private UsbAccessory mCurrentAccessory;
        private int mUsbNotificationId;
        private boolean mAdbNotificationShown;
        private int mAdbNotificationId;
        private int mCurrentUser = UserHandle.USER_NULL;
        private boolean mUsbCharging;
        private String mCurrentOemFunctions;
@@ -426,6 +428,20 @@ public class UsbDeviceManager {
                        Settings.Global.getUriFor(Settings.Global.ADB_ENABLED),
                        false, new AdbSettingsObserver());

                ContentObserver adbNotificationObserver = new ContentObserver(null) {
                    @Override
                    public void onChange(boolean selfChange) {
                        updateAdbNotification();
                    }
                };

                mContentResolver.registerContentObserver(
                        LineageSettings.Secure.getUriFor(LineageSettings.Secure.ADB_NOTIFY),
                                false, adbNotificationObserver);
                mContentResolver.registerContentObserver(
                        LineageSettings.Secure.getUriFor(LineageSettings.Secure.ADB_PORT),
                                false, adbNotificationObserver);

                // Watch for USB configuration changes
                mUEventObserver.startObserving(USB_STATE_MATCH);
                mUEventObserver.startObserving(ACCESSORY_START_MATCH);
@@ -1039,11 +1055,32 @@ public class UsbDeviceManager {
        private void updateAdbNotification() {
            if (mNotificationManager == null) return;
            final int id = SystemMessage.NOTE_ADB_ACTIVE;
            final int titleRes = com.android.internal.R.string.adb_active_notification_title;
            if (mAdbEnabled && mConnected) {
                if ("0".equals(SystemProperties.get("persist.adb.notify"))) return;
            boolean usbAdbActive = mAdbEnabled && mConnected;
            boolean netAdbActive = mAdbEnabled &&
                    LineageSettings.Secure.getInt(mContentResolver,
                            LineageSettings.Secure.ADB_PORT, -1) > 0;
            final int titleRes;
            boolean hideNotification = "0".equals(SystemProperties.get("persist.adb.notify"))
                    || LineageSettings.Secure.getInt(mContext.getContentResolver(),
                            LineageSettings.Secure.ADB_NOTIFY, 1) == 0;

            if (hideNotification) {
                titleRes = 0;
            } else if (usbAdbActive && netAdbActive) {
                titleRes = com.android.internal.R.string.adb_both_active_notification_title;
            } else if (usbAdbActive) {
                titleRes = com.android.internal.R.string.adb_active_notification_title;
            } else if (netAdbActive) {
                titleRes = com.android.internal.R.string.adb_net_active_notification_title;
            } else {
                titleRes = 0;
            }

                if (!mAdbNotificationShown) {
            if (titleRes != mAdbNotificationId) {
                if (mAdbNotificationId != 0) {
                    mNotificationManager.cancelAsUser(null, id, UserHandle.ALL);
                }
                if (titleRes != 0) {
                    Resources r = mContext.getResources();
                    CharSequence title = r.getText(titleRes);
                    CharSequence message = r.getText(
@@ -1072,13 +1109,10 @@ public class UsbDeviceManager {
                                    .extend(new Notification.TvExtender()
                                            .setChannelId(ADB_NOTIFICATION_CHANNEL_ID_TV))
                                    .build();
                    mAdbNotificationShown = true;
                    mNotificationManager.notifyAsUser(null, id, notification,
                            UserHandle.ALL);
                }
            } else if (mAdbNotificationShown) {
                mAdbNotificationShown = false;
                mNotificationManager.cancelAsUser(null, id, UserHandle.ALL);
                mAdbNotificationId = titleRes;
            }
        }