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

Commit c227aec2 authored by Badhri Jagan Sridharan's avatar Badhri Jagan Sridharan
Browse files

Add option to "Enable USB"

Under the updated flow, the user is given an option to re-enable
USB port and disable contaminant detection until the next unplug
of the USB accessory.

Also, display a Toast message conveying that the USB port has
been re-enabled.

Bug: 128534822
Test: Tested with the mock circuit.
Change-Id: Ifd0a6658a443ae8966ae9128a20e827ed5b03380
parent f7b41fc2
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -165,6 +165,12 @@
    <!-- Message of USB contaminant presence dialog [CHAR LIMIT=NONE] -->
    <!-- Message of USB contaminant presence dialog [CHAR LIMIT=NONE] -->
    <string name="usb_contaminant_message">To protect your device from liquid or debris, the USB port is disabled and won\u2019t detect any accessories.\n\nYou\u2019ll be notified when it\u2019s safe to use the USB port again.</string>
    <string name="usb_contaminant_message">To protect your device from liquid or debris, the USB port is disabled and won\u2019t detect any accessories.\n\nYou\u2019ll be notified when it\u2019s safe to use the USB port again.</string>


    <!-- Toast for enabling ports from USB contaminant dialog [CHAR LIMIT=NONE] -->
    <string name="usb_port_enabled">USB port enabled to detect chargers and accessories</string>

    <!-- Button text to disable contaminant detection [CHAR LIMIT=NONE] -->
    <string name="usb_disable_contaminant_detection">Enable USB</string>

    <!-- Checkbox label for application compatibility mode ON (zooming app to look like it's running
    <!-- Checkbox label for application compatibility mode ON (zooming app to look like it's running
         on a phone).  [CHAR LIMIT=25] -->
         on a phone).  [CHAR LIMIT=25] -->
    <string name="compat_mode_on">Zoom to fill screen</string>
    <string name="compat_mode_on">Zoom to fill screen</string>
+16 −3
Original line number Original line Diff line number Diff line
@@ -16,14 +16,17 @@


package com.android.systemui.usb;
package com.android.systemui.usb;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Intent;
import android.hardware.usb.ParcelableUsbPort;
import android.hardware.usb.ParcelableUsbPort;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPort;
import android.os.Bundle;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager;
import android.widget.Toast;


import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import com.android.internal.app.AlertController;
@@ -36,7 +39,6 @@ public class UsbContaminantActivity extends AlertActivity
                                  implements DialogInterface.OnClickListener {
                                  implements DialogInterface.OnClickListener {
    private static final String TAG = "UsbContaminantActivity";
    private static final String TAG = "UsbContaminantActivity";


    private UsbDisconnectedReceiver mDisconnectedReceiver;
    private UsbPort mUsbPort;
    private UsbPort mUsbPort;


    @Override
    @Override
@@ -55,8 +57,10 @@ public class UsbContaminantActivity extends AlertActivity
        final AlertController.AlertParams ap = mAlertParams;
        final AlertController.AlertParams ap = mAlertParams;
        ap.mTitle = getString(R.string.usb_contaminant_title);
        ap.mTitle = getString(R.string.usb_contaminant_title);
        ap.mMessage = getString(R.string.usb_contaminant_message);
        ap.mMessage = getString(R.string.usb_contaminant_message);
        ap.mPositiveButtonText = getString(android.R.string.ok);
        ap.mNegativeButtonText = getString(android.R.string.ok);
        ap.mPositiveButtonListener = this;
        ap.mNeutralButtonText = getString(R.string.usb_disable_contaminant_detection);
        ap.mNegativeButtonListener = this;
        ap.mNeutralButtonListener = this;


        setupAlert();
        setupAlert();
    }
    }
@@ -68,6 +72,15 @@ public class UsbContaminantActivity extends AlertActivity


    @Override
    @Override
    public void onClick(DialogInterface dialog, int which) {
    public void onClick(DialogInterface dialog, int which) {
        if (which == AlertDialog.BUTTON_NEUTRAL) {
            try {
                mUsbPort.enableContaminantDetection(false);
                Toast.makeText(this, R.string.usb_port_enabled,
                    Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                Log.e(TAG, "Unable to notify Usb service", e);
            }
        }
        finish();
        finish();
    }
    }
}
}