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

Commit b126dea6 authored by Daichi Hirono's avatar Daichi Hirono Committed by android-build-merger
Browse files

Merge "Skip MTP launch notification for devices having FEATURE_AUTOMOTIVE."...

Merge "Skip MTP launch notification for devices having FEATURE_AUTOMOTIVE." into nyc-dev am: 05133ad0
am: e3c06e16

* commit 'e3c06e16':
  Skip MTP launch notification for devices having FEATURE_AUTOMOTIVE.
parents 8f8327f4 e3c06e16
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
@@ -101,8 +102,8 @@ class MtpNotificationManager {
                TAG, device.getDeviceId(), notification);
    }

    void hideNotification(UsbDevice device) {
        mContext.getSystemService(NotificationManager.class).cancel(TAG, device.getDeviceId());
    void hideNotification(int deviceId) {
        mContext.getSystemService(NotificationManager.class).cancel(TAG, deviceId);
    }

    private class Receiver extends BroadcastReceiver {
@@ -121,7 +122,13 @@ class MtpNotificationManager {
        }
    }

    static boolean isMtpDevice(UsbDevice device) {
    static boolean shouldShowNotification(PackageManager packageManager, UsbDevice device) {
        // We don't show MTP notification for devices that has FEATURE_AUTOMOTIVE.
        return !packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE) &&
                isMtpDevice(device);
    }

    private static boolean isMtpDevice(UsbDevice device) {
        for (int i = 0; i < device.getInterfaceCount(); i++) {
            final UsbInterface usbInterface = device.getInterface(i);
            if ((usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE &&
+2 −4
Original line number Diff line number Diff line
@@ -738,7 +738,7 @@ class UsbSettingsManager {
        // Send broadcast to running activity with registered intent
        mUserContext.sendBroadcast(intent);

        if (MtpNotificationManager.isMtpDevice(device)) {
        if (MtpNotificationManager.shouldShowNotification(mPackageManager, device)) {
            // Show notification if the device is MTP storage.
            mMtpNotificationManager.showNotification(device);
        } else {
@@ -769,9 +769,7 @@ class UsbSettingsManager {
        if (DEBUG) Slog.d(TAG, "usbDeviceRemoved, sending " + intent);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);

        if (MtpNotificationManager.isMtpDevice(device)) {
            mMtpNotificationManager.hideNotification(device);
        }
        mMtpNotificationManager.hideNotification(device.getDeviceId());
    }

    public void accessoryAttached(UsbAccessory accessory) {