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

Commit 1aae20f4 authored by George Chan's avatar George Chan Committed by Android (Google) Code Review
Browse files

Merge "Updated Strings to finalized version and refactored string names to be...

Merge "Updated Strings to finalized version and refactored string names to be more consistent with the feature and fixed disablement of USB during bootup." into main
parents c9518448 559fe30c
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -6910,26 +6910,34 @@ ul.</string>
    <string name="fingerprint_loe_notification_msg">Your fingerprints can no longer be recognized. Set up Fingerprint Unlock again.</string>
    <!--  AdvancedProtectionService USB notifications -->
    <!-- Notification app title for all notifications. -->
    <string name="usb_apm_usb_plugged_in_when_locked_notification_app_title">Security &amp; privacy</string>
    <string name="usb_apm_usb_plugged_in_when_locked_notification_title">Unlock your screen first</string>
    <string name="usb_apm_usb_plugged_in_when_locked_replug_notification_title">Unlock screen &amp; reconnect</string>
    <string name="usb_apm_usb_plugged_in_when_locked_notification_text">Advanced Protection requires your usual screen unlock for USB data transfers</string>
    <string name="usb_apm_usb_plugged_in_when_locked_replug_notification_text">Advanced Protection requires your usual screen unlock for USB data transfers</string>
    <!-- Notification title for when USB is plugged in when USB is disabled with replug notification. -->
    <string name="usb_apm_usb_plugged_in_when_locked_replug_notification_title">Unlock screen and reconnect USB</string>
    <!-- Notification title for when USB is plugged in when USB is disabled notification. -->
    <string name="usb_apm_usb_plugged_in_when_locked_notification_title">Unlock screen to connect USB</string>
    <string name="usb_apm_usb_plugged_in_when_locked_low_power_charge_notification_text">Advanced Protection requires your screen unlock for USB transfer or fast charging</string>
    <string name="usb_apm_usb_plugged_in_when_locked_low_power_charge_replug_notification_text">Advanced Protection requires your screen unlock for USB transfer or fast charging</string>
    <string name="usb_apm_usb_plugged_in_for_power_brick_notification_text">Advanced Protection requires your usual screen unlock for USB fast charging</string>
    <string name="usb_apm_usb_plugged_in_for_power_brick_replug_notification_text">Advanced Protection requires your usual screen unlock for USB fast charging</string>
    <!-- Notification text for when USB is plugged in when USB is disabled with replug notification. -->
    <string name="usb_apm_usb_plugged_in_when_locked_replug_notification_text">Advanced Protection requires your screen to be unlocked to initiate USB connectivity</string>
    <!-- Notification text for when a USB data device is plugged in when USB is disabled notification. -->
    <string name="usb_apm_usb_plugged_in_when_locked_data_notification_text">Advanced Protection requires your screen to be unlocked to initiate USB connectivity
</string>
    <!-- Notification text for when a USB charger that needs data lines is plugged and USB is disabled notification. -->
    <string name="usb_apm_usb_plugged_in_when_locked_charge_notification_text">Advanced Protection requires your screen to be unlocked for faster charging</string>
    <!-- Notification text for when a USB data device that also charges is plugged and USB is disabled notification. -->
    <string name="usb_apm_usb_plugged_in_when_locked_charge_data_notification_text">For faster charging or to initiate USB connectivity, Advanced Protection requires your screen to be unlocked</string>
    <!-- Notification button label to silence the notification. -->
    <string name="usb_apm_usb_plugged_in_when_locked_notification_silence_action_text">Silence</string>
    <!-- Notification title when notifications are silenced. -->
    <string name="usb_apm_usb_notification_silenced_title">Notifications silenced</string>
    <string name="usb_apm_usb_notification_silenced_text">Advanced Protection USB notifications silenced until you restart device</string>
    <!-- Notification text when notifications are silenced. -->
    <string name="usb_apm_usb_notification_silenced_text">You won’t receive Advanced Protection USB notifications until you restart your device</string>
    <string name="usb_apm_usb_suspicious_activity_notification_title">Suspicious USB activity</string>
    <string name="usb_apm_usb_suspicious_activity_notification_text">USB data signal has been disabled.</string>
    <string name="usb_apm_usb_suspicious_activity_notification_text">USB data signal has been disabled</string>
    <!-- Fingerprint failed rate too high notification title -->
    <string name="fingerprint_frr_notification_title">Having trouble with Fingerprint Unlock?</string>
+7 −8
Original line number Diff line number Diff line
@@ -6251,21 +6251,20 @@
  <!-- Advanced Protection Service USB feature -->

  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_notification_app_title" />
  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_notification_title" />

  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_replug_notification_title" />
  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_notification_title" />

  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_notification_text" />
  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_replug_notification_text" />

  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_low_power_charge_notification_text" />
  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_low_power_charge_replug_notification_text" />

  <java-symbol type="string" name="usb_apm_usb_plugged_in_for_power_brick_notification_text" />
  <java-symbol type="string" name="usb_apm_usb_plugged_in_for_power_brick_replug_notification_text" />
  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_data_notification_text" />
  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_charge_notification_text" />
  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_charge_data_notification_text" />

  <java-symbol type="string" name="usb_apm_usb_plugged_in_when_locked_notification_silence_action_text" />

  <java-symbol type="string" name="usb_apm_usb_notification_silenced_title" />
  <java-symbol type="string" name="usb_apm_usb_notification_silenced_text" />

  <java-symbol type="string" name="usb_apm_usb_suspicious_activity_notification_title" />
  <java-symbol type="string" name="usb_apm_usb_suspicious_activity_notification_text" />

+20 −13
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.security.advancedprotection.features;
import static android.app.Notification.EXTRA_SUBSTITUTE_APP_NAME;
import static android.content.Intent.ACTION_SCREEN_OFF;
import static android.content.Intent.ACTION_USER_PRESENT;
import static android.content.Intent.ACTION_LOCKED_BOOT_COMPLETED;
import static android.hardware.usb.UsbManager.ACTION_USB_PORT_CHANGED;
import static android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_USB;
import static android.hardware.usb.UsbPortStatus.DATA_STATUS_DISABLED_FORCE;
@@ -151,25 +152,24 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
    private static final Map<Integer, Integer> NOTIFICATION_TYPE_TO_TEXT =
            Map.of(
                    NOTIFICATION_CHARGE,
                    R.string.usb_apm_usb_plugged_in_for_power_brick_notification_text,
                    R.string.usb_apm_usb_plugged_in_when_locked_charge_notification_text,
                    NOTIFICATION_CHARGE_DATA,
                    R.string.usb_apm_usb_plugged_in_when_locked_low_power_charge_notification_text,
                    R.string.usb_apm_usb_plugged_in_when_locked_charge_data_notification_text,
                    NOTIFICATION_DATA,
                    R.string.usb_apm_usb_plugged_in_when_locked_notification_text);
                    R.string.usb_apm_usb_plugged_in_when_locked_data_notification_text);
    private static final Map<Integer, Integer> NOTIFICATION_TYPE_TO_TEXT_WITH_REPLUG =
            Map.of(
                    NOTIFICATION_CHARGE,
                    R.string.usb_apm_usb_plugged_in_for_power_brick_replug_notification_text,
                    R.string.usb_apm_usb_plugged_in_when_locked_replug_notification_text,
                    NOTIFICATION_CHARGE_DATA,
                    R.string
                            .usb_apm_usb_plugged_in_when_locked_low_power_charge_replug_notification_text,
                    R.string.usb_apm_usb_plugged_in_when_locked_charge_data_notification_text,
                    NOTIFICATION_DATA,
                    R.string.usb_apm_usb_plugged_in_when_locked_replug_notification_text);
                    R.string.usb_apm_usb_plugged_in_when_locked_data_notification_text);

    private final ReentrantLock mDisableLock = new ReentrantLock();
    private final Context mContext;

    private AtomicBoolean mApmRequestedUsbDisable = new AtomicBoolean(false);
    private AtomicBoolean mApmRequestedUsbDataStatus = new AtomicBoolean(false);

    // We use handlers for tasks that may need to be updated by broadcasts events.
    private Handler mDelayedDisableHandler = new Handler(Looper.getMainLooper());
@@ -233,7 +233,7 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
            UserManager userManager,
            Handler delayDisableHandler,
            Handler delayedNotificationHandler,
            AtomicBoolean apmRequestedUsbDisable,
            AtomicBoolean apmRequestedUsbDataStatus,
            boolean canSetUsbDataSignal,
            boolean afterFirstUnlock) {
        super(context, false);
@@ -248,7 +248,7 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
        mCanSetUsbDataSignal = canSetUsbDataSignal;
        mIsAfterFirstUnlock = afterFirstUnlock;
        mUserManager = userManager;
        mApmRequestedUsbDisable = apmRequestedUsbDisable;
        mApmRequestedUsbDataStatus = apmRequestedUsbDataStatus;
    }

    @Override
@@ -365,7 +365,7 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
                                    /*
                                     * Due to limitations of current APIs, we cannot cannot fully
                                     * rely on power brick and pd compliance check to be accurate
                                     * until it's passed the check timeouts unless the value is
                                     * until it's passed the check timeouts or the value is
                                     * POWER_BRICK_STATUS_CONNECTED or isCompliant=true
                                     * respectively.
                                     */
@@ -391,6 +391,10 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
                                    createAndSendNotificationIfDeviceIsLocked(
                                            portStatus, NOTIFICATION_DATA);
                                }
                            // Any earlier call to USBService during bootup have a risk of having
                            // request dropped due to USB stack not being ready.
                            } else if (ACTION_LOCKED_BOOT_COMPLETED.equals(intent.getAction())) {
                                setUsbDataSignalIfPossible(false);
                            }
                        } catch (Exception e) {
                            Slog.e(TAG, "USB Data protection failed with: " + e.getMessage());
@@ -669,7 +673,7 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
            // to framework. So we can only assume that disable request is honored.
            // The atomic boolean check is to make sure it requested by us and not by other reasons
            // ie. Enterprise policy.
            boolean isDataEnabled = isRequestedDisabled && mApmRequestedUsbDisable.get();
            boolean isDataEnabled = isRequestedDisabled && mApmRequestedUsbDataStatus.get();
            int usbHalVersion = mUsbManager.getUsbHalVersion();
            // For AIDL implementation, DATA_STATUS_ENABLED is fed back to framework from the HAL
            if (usbHalVersion > UsbManager.USB_HAL_V1_3) {
@@ -703,9 +707,11 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
            int usbChangeStateReattempts = 0;
            while (usbChangeStateReattempts < USB_DATA_CHANGE_MAX_RETRY_ATTEMPTS) {
                try {
                    Slog.d(TAG, "Setting USB data: " + status);
                    if (mUsbManagerInternal.enableUsbDataSignal(status, USB_DISABLE_REASON_APM)) {
                        mApmRequestedUsbDisable.set(status);
                        mApmRequestedUsbDataStatus.set(status);
                        successfullySetUsbDataSignal = true;
                        Slog.d(TAG, "Successfully set USB data");
                        break;
                    } else {
                        Slog.e(TAG, "USB Data protection toggle to " + status + " attempt failed");
@@ -757,6 +763,7 @@ public class UsbDataAdvancedProtectionHook extends AdvancedProtectionHook {
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(ACTION_USER_PRESENT);
        filter.addAction(ACTION_SCREEN_OFF);
        filter.addAction(ACTION_LOCKED_BOOT_COMPLETED);
        filter.addAction(UsbManager.ACTION_USB_PORT_CHANGED);

        mContext.registerReceiverAsUser(
+74 −40

File changed.

Preview size limit exceeded, changes collapsed.