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

Commit 48264400 authored by George Chan's avatar George Chan
Browse files

Updated USB data hook changed the exception fallback to based on full opt-in...

Updated USB data hook changed the exception fallback to based on full opt-in mechanism. Also added feature capability check on device and increase USB recovery timeout to 60 seconds.

Bug: 418846176, 419921206
Test: manual testing
Flag: android.security.aapm_feature_usb_data_protection
Change-Id: Iac40b6ed714df1420f365317b11e626d4d336de5
parent cbd4919a
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import android.os.UserHandle;
import android.os.SystemClock;
import android.security.Flags;
import android.util.Slog;
import android.content.pm.PackageManager;

import com.android.server.LocalServices;
import java.lang.Runnable;
@@ -108,7 +109,7 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
    private static final int NOTIFICATION_CHARGE_DATA = 1;
    private static final int NOTIFICATION_DATA = 2;

    private static final int DELAY_DISABLE_MILLIS = 5000;
    private static final int DELAY_DISABLE_MILLIS = 15000;
    private static final int USB_DATA_CHANGE_MAX_RETRY_ATTEMPTS = 3;
    private static final long USB_PORT_POWER_BRICK_CONNECTION_CHECK_TIMEOUT_DEFAULT_MILLIS = 3000;
    private static final long USB_PD_COMPLIANCE_CHECK_TIMEOUT_DEFAULT_MILLIS = 1000;
@@ -186,6 +187,11 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
            Context context, boolean enabled, AdvancedProtectionService advancedProtectionService) {
        super(context, enabled);
        mContext = context;
        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST)
                && !mContext.getPackageManager()
                        .hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)) {
            return;
        }
        mUsbManager = Objects.requireNonNull(mContext.getSystemService(UsbManager.class));
        mNotificationManager =
                Objects.requireNonNull(mContext.getSystemService(NotificationManager.class));
@@ -205,12 +211,13 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
    @Override
    public boolean isAvailable() {
        boolean usbDataProtectionEnabled =
                // TODO(b/418846176): Set fallback default to false once product flag is set
                SystemProperties.getBoolean(USB_DATA_PROTECTION_ENABLE_SYSTEM_PROPERTY, true);
                SystemProperties.getBoolean(USB_DATA_PROTECTION_ENABLE_SYSTEM_PROPERTY, false);
        if (!usbDataProtectionEnabled) {
            Slog.d(TAG, "USB data protection is disabled through system property");
        }
        return Flags.aapmFeatureUsbDataProtection()
                && (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST) || mContext.getPackageManager()
                        .hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY))
                && mAdvancedProtectionService.isUsbDataProtectionEnabled()
                && mCanSetUsbDataSignal
                && usbDataProtectionEnabled;