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

Commit 5981a992 authored by Michael Groover's avatar Michael Groover Committed by Automerger Merge Worker
Browse files

Merge "Keep USB disconnected receiver active when ADB activity in bg" into...

Merge "Keep USB disconnected receiver active when ADB activity in bg" into rvc-d1-dev am: 9e5913cf

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12215433

Change-Id: Ifc4aab18a3be620ebed6badb66f3180013741564
parents b511e22c 9e5913cf
Loading
Loading
Loading
Loading
+14 −20
Original line number Original line Diff line number Diff line
@@ -70,6 +70,8 @@ public class UsbDebuggingActivity extends AlertActivity


        if (SystemProperties.getInt("service.adb.tcp.port", 0) == 0) {
        if (SystemProperties.getInt("service.adb.tcp.port", 0) == 0) {
            mDisconnectedReceiver = new UsbDisconnectedReceiver(this);
            mDisconnectedReceiver = new UsbDisconnectedReceiver(this);
            IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
            mBroadcastDispatcher.registerReceiver(mDisconnectedReceiver, filter);
        }
        }


        Intent intent = getIntent();
        Intent intent = getIntent();
@@ -119,6 +121,7 @@ public class UsbDebuggingActivity extends AlertActivity
            }
            }
            boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
            boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
            if (!connected) {
            if (!connected) {
                Log.d(TAG, "USB disconnected, notifying service");
                notifyService(false);
                notifyService(false);
                mActivity.finish();
                mActivity.finish();
            }
            }
@@ -126,30 +129,21 @@ public class UsbDebuggingActivity extends AlertActivity
    }
    }


    @Override
    @Override
    public void onStart() {
    protected void onDestroy() {
        super.onStart();
        if (mDisconnectedReceiver != null) {
            IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
            mBroadcastDispatcher.registerReceiver(mDisconnectedReceiver, filter);
        }
    }

    @Override
    protected void onStop() {
        if (mDisconnectedReceiver != null) {
        if (mDisconnectedReceiver != null) {
            mBroadcastDispatcher.unregisterReceiver(mDisconnectedReceiver);
            mBroadcastDispatcher.unregisterReceiver(mDisconnectedReceiver);
        }
        }
        super.onStop();
        // Only notify the service if the activity is finishing; if onDestroy has been called due to
    }
        // a configuration change then allow the user to still authorize the connection the next

        // time the activity is in the foreground.
    @Override
        if (isFinishing()) {
    protected void onDestroy() {
            // If the ADB service has not yet been notified due to this dialog being closed in some
            // If the ADB service has not yet been notified due to this dialog being closed in some
        // other way then notify the service to deny the connection to ensure system_server sends
            // other way then notify the service to deny the connection to ensure system_server
        // a response to adbd.
            // sends a response to adbd.
            if (!mServiceNotified) {
            if (!mServiceNotified) {
                notifyService(false);
                notifyService(false);
            }
            }
        }
        super.onDestroy();
        super.onDestroy();
    }
    }