Loading packages/SettingsLib/src/com/android/settingslib/Utils.java +0 −57 Original line number Diff line number Diff line Loading @@ -785,30 +785,6 @@ public class Utils { return false; } /** Whether to show the wireless charging notification. */ public static boolean shouldShowWirelessChargingNotification( @NonNull Context context, @NonNull String tag) { try { return shouldShowWirelessChargingNotificationInternal(context, tag); } catch (Exception e) { Log.e(tag, "shouldShowWirelessChargingNotification()", e); return false; } } /** Stores the timestamp of the wireless charging notification. */ public static void updateWirelessChargingNotificationTimestamp( @NonNull Context context, long timestamp, @NonNull String tag) { try { Secure.putLong( context.getContentResolver(), WIRELESS_CHARGING_NOTIFICATION_TIMESTAMP, timestamp); } catch (Exception e) { Log.e(tag, "setWirelessChargingNotificationTimestamp()", e); } } /** Whether to show the wireless charging warning in Settings. */ public static boolean shouldShowWirelessChargingWarningTip( @NonNull Context context, @NonNull String tag) { Loading @@ -833,37 +809,4 @@ public class Utils { Log.e(tag, "setWirelessChargingWarningEnabled()", e); } } private static boolean shouldShowWirelessChargingNotificationInternal( @NonNull Context context, @NonNull String tag) { final long lastNotificationTimeMillis = Secure.getLong( context.getContentResolver(), WIRELESS_CHARGING_NOTIFICATION_TIMESTAMP, WIRELESS_CHARGING_DEFAULT_TIMESTAMP); if (isWirelessChargingNotificationDisabled(lastNotificationTimeMillis)) { return false; } if (isInitialWirelessChargingNotification(lastNotificationTimeMillis)) { updateWirelessChargingNotificationTimestamp(context, System.currentTimeMillis(), tag); updateWirelessChargingWarningEnabled(context, /* enabled= */ true, tag); return true; } final long durationMillis = System.currentTimeMillis() - lastNotificationTimeMillis; final boolean show = durationMillis > WIRELESS_CHARGING_NOTIFICATION_THRESHOLD_MILLIS; Log.d(tag, "shouldShowWirelessChargingNotification = " + show); if (show) { updateWirelessChargingNotificationTimestamp(context, System.currentTimeMillis(), tag); updateWirelessChargingWarningEnabled(context, /* enabled= */ true, tag); } return show; } private static boolean isWirelessChargingNotificationDisabled(long lastNotificationTimeMillis) { return lastNotificationTimeMillis == Long.MIN_VALUE; } private static boolean isInitialWirelessChargingNotification(long lastNotificationTimeMillis) { return lastNotificationTimeMillis == WIRELESS_CHARGING_DEFAULT_TIMESTAMP; } } packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java +0 −81 Original line number Diff line number Diff line Loading @@ -16,9 +16,7 @@ package com.android.settingslib; import static com.android.settingslib.Utils.STORAGE_MANAGER_ENABLED_PROPERTY; import static com.android.settingslib.Utils.WIRELESS_CHARGING_DEFAULT_TIMESTAMP; import static com.android.settingslib.Utils.shouldShowWirelessChargingWarningTip; import static com.android.settingslib.Utils.updateWirelessChargingNotificationTimestamp; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -62,7 +60,6 @@ import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.shadows.ShadowSettings; import java.time.Duration; import java.util.ArrayList; import java.util.List; Loading Loading @@ -546,77 +543,6 @@ public class UtilsTest { assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse(); } @Test public void shouldShowWirelessChargingNotification_neverSendNotification_returnTrue() { updateWirelessChargingNotificationTimestamp( mContext, WIRELESS_CHARGING_DEFAULT_TIMESTAMP, TAG); assertThat(Utils.shouldShowWirelessChargingNotification(mContext, TAG)).isTrue(); } @Test public void shouldShowNotification_neverSendNotification_updateTimestampAndEnabledState() { updateWirelessChargingNotificationTimestamp( mContext, WIRELESS_CHARGING_DEFAULT_TIMESTAMP, TAG); Utils.shouldShowWirelessChargingNotification(mContext, TAG); assertThat(getWirelessChargingNotificationTimestamp()) .isNotEqualTo(WIRELESS_CHARGING_DEFAULT_TIMESTAMP); assertThat(shouldShowWirelessChargingWarningTip(mContext, TAG)).isTrue(); } @Test public void shouldShowWirelessChargingNotification_notificationDisabled_returnFalse() { updateWirelessChargingNotificationTimestamp(mContext, CURRENT_TIMESTAMP, TAG); assertThat(Utils.shouldShowWirelessChargingNotification(mContext, TAG)).isFalse(); } @Test public void shouldShowWirelessChargingNotification_withinTimeThreshold_returnFalse() { updateWirelessChargingNotificationTimestamp(mContext, CURRENT_TIMESTAMP, TAG); assertThat(Utils.shouldShowWirelessChargingNotification(mContext, TAG)).isFalse(); } @Test public void shouldShowWirelessChargingNotification_exceedTimeThreshold_returnTrue() { final long monthAgo = Duration.ofDays(31).toMillis(); final long timestamp = CURRENT_TIMESTAMP - monthAgo; updateWirelessChargingNotificationTimestamp(mContext, timestamp, TAG); assertThat(Utils.shouldShowWirelessChargingNotification(mContext, TAG)).isTrue(); } @Test public void shouldShowNotification_exceedTimeThreshold_updateTimestampAndEnabledState() { final long monthAgo = Duration.ofDays(31).toMillis(); final long timestamp = CURRENT_TIMESTAMP - monthAgo; updateWirelessChargingNotificationTimestamp(mContext, timestamp, TAG); Utils.shouldShowWirelessChargingNotification(mContext, TAG); assertThat(getWirelessChargingNotificationTimestamp()).isNotEqualTo(timestamp); assertThat(shouldShowWirelessChargingWarningTip(mContext, TAG)).isTrue(); } @Test public void updateWirelessChargingNotificationTimestamp_dismissForever_setMinValue() { updateWirelessChargingNotificationTimestamp(mContext, Long.MIN_VALUE, TAG); assertThat(getWirelessChargingNotificationTimestamp()).isEqualTo(Long.MIN_VALUE); } @Test public void updateWirelessChargingNotificationTimestamp_notDismissForever_setTimestamp() { updateWirelessChargingNotificationTimestamp(mContext, CURRENT_TIMESTAMP, TAG); assertThat(getWirelessChargingNotificationTimestamp()) .isNotEqualTo(WIRELESS_CHARGING_DEFAULT_TIMESTAMP); assertThat(getWirelessChargingNotificationTimestamp()).isNotEqualTo(Long.MIN_VALUE); } @Test public void shouldShowWirelessChargingWarningTip_enabled_returnTrue() { Utils.updateWirelessChargingWarningEnabled(mContext, true, TAG); Loading Loading @@ -644,11 +570,4 @@ public class UtilsTest { when(mUsbPortStatus.isConnected()).thenReturn(true); when(mUsbPortStatus.getComplianceWarnings()).thenReturn(new int[] {complianceWarningType}); } private long getWirelessChargingNotificationTimestamp() { return Settings.Secure.getLong( mContext.getContentResolver(), Utils.WIRELESS_CHARGING_NOTIFICATION_TIMESTAMP, WIRELESS_CHARGING_DEFAULT_TIMESTAMP); } } Loading
packages/SettingsLib/src/com/android/settingslib/Utils.java +0 −57 Original line number Diff line number Diff line Loading @@ -785,30 +785,6 @@ public class Utils { return false; } /** Whether to show the wireless charging notification. */ public static boolean shouldShowWirelessChargingNotification( @NonNull Context context, @NonNull String tag) { try { return shouldShowWirelessChargingNotificationInternal(context, tag); } catch (Exception e) { Log.e(tag, "shouldShowWirelessChargingNotification()", e); return false; } } /** Stores the timestamp of the wireless charging notification. */ public static void updateWirelessChargingNotificationTimestamp( @NonNull Context context, long timestamp, @NonNull String tag) { try { Secure.putLong( context.getContentResolver(), WIRELESS_CHARGING_NOTIFICATION_TIMESTAMP, timestamp); } catch (Exception e) { Log.e(tag, "setWirelessChargingNotificationTimestamp()", e); } } /** Whether to show the wireless charging warning in Settings. */ public static boolean shouldShowWirelessChargingWarningTip( @NonNull Context context, @NonNull String tag) { Loading @@ -833,37 +809,4 @@ public class Utils { Log.e(tag, "setWirelessChargingWarningEnabled()", e); } } private static boolean shouldShowWirelessChargingNotificationInternal( @NonNull Context context, @NonNull String tag) { final long lastNotificationTimeMillis = Secure.getLong( context.getContentResolver(), WIRELESS_CHARGING_NOTIFICATION_TIMESTAMP, WIRELESS_CHARGING_DEFAULT_TIMESTAMP); if (isWirelessChargingNotificationDisabled(lastNotificationTimeMillis)) { return false; } if (isInitialWirelessChargingNotification(lastNotificationTimeMillis)) { updateWirelessChargingNotificationTimestamp(context, System.currentTimeMillis(), tag); updateWirelessChargingWarningEnabled(context, /* enabled= */ true, tag); return true; } final long durationMillis = System.currentTimeMillis() - lastNotificationTimeMillis; final boolean show = durationMillis > WIRELESS_CHARGING_NOTIFICATION_THRESHOLD_MILLIS; Log.d(tag, "shouldShowWirelessChargingNotification = " + show); if (show) { updateWirelessChargingNotificationTimestamp(context, System.currentTimeMillis(), tag); updateWirelessChargingWarningEnabled(context, /* enabled= */ true, tag); } return show; } private static boolean isWirelessChargingNotificationDisabled(long lastNotificationTimeMillis) { return lastNotificationTimeMillis == Long.MIN_VALUE; } private static boolean isInitialWirelessChargingNotification(long lastNotificationTimeMillis) { return lastNotificationTimeMillis == WIRELESS_CHARGING_DEFAULT_TIMESTAMP; } }
packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java +0 −81 Original line number Diff line number Diff line Loading @@ -16,9 +16,7 @@ package com.android.settingslib; import static com.android.settingslib.Utils.STORAGE_MANAGER_ENABLED_PROPERTY; import static com.android.settingslib.Utils.WIRELESS_CHARGING_DEFAULT_TIMESTAMP; import static com.android.settingslib.Utils.shouldShowWirelessChargingWarningTip; import static com.android.settingslib.Utils.updateWirelessChargingNotificationTimestamp; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -62,7 +60,6 @@ import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.shadows.ShadowSettings; import java.time.Duration; import java.util.ArrayList; import java.util.List; Loading Loading @@ -546,77 +543,6 @@ public class UtilsTest { assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse(); } @Test public void shouldShowWirelessChargingNotification_neverSendNotification_returnTrue() { updateWirelessChargingNotificationTimestamp( mContext, WIRELESS_CHARGING_DEFAULT_TIMESTAMP, TAG); assertThat(Utils.shouldShowWirelessChargingNotification(mContext, TAG)).isTrue(); } @Test public void shouldShowNotification_neverSendNotification_updateTimestampAndEnabledState() { updateWirelessChargingNotificationTimestamp( mContext, WIRELESS_CHARGING_DEFAULT_TIMESTAMP, TAG); Utils.shouldShowWirelessChargingNotification(mContext, TAG); assertThat(getWirelessChargingNotificationTimestamp()) .isNotEqualTo(WIRELESS_CHARGING_DEFAULT_TIMESTAMP); assertThat(shouldShowWirelessChargingWarningTip(mContext, TAG)).isTrue(); } @Test public void shouldShowWirelessChargingNotification_notificationDisabled_returnFalse() { updateWirelessChargingNotificationTimestamp(mContext, CURRENT_TIMESTAMP, TAG); assertThat(Utils.shouldShowWirelessChargingNotification(mContext, TAG)).isFalse(); } @Test public void shouldShowWirelessChargingNotification_withinTimeThreshold_returnFalse() { updateWirelessChargingNotificationTimestamp(mContext, CURRENT_TIMESTAMP, TAG); assertThat(Utils.shouldShowWirelessChargingNotification(mContext, TAG)).isFalse(); } @Test public void shouldShowWirelessChargingNotification_exceedTimeThreshold_returnTrue() { final long monthAgo = Duration.ofDays(31).toMillis(); final long timestamp = CURRENT_TIMESTAMP - monthAgo; updateWirelessChargingNotificationTimestamp(mContext, timestamp, TAG); assertThat(Utils.shouldShowWirelessChargingNotification(mContext, TAG)).isTrue(); } @Test public void shouldShowNotification_exceedTimeThreshold_updateTimestampAndEnabledState() { final long monthAgo = Duration.ofDays(31).toMillis(); final long timestamp = CURRENT_TIMESTAMP - monthAgo; updateWirelessChargingNotificationTimestamp(mContext, timestamp, TAG); Utils.shouldShowWirelessChargingNotification(mContext, TAG); assertThat(getWirelessChargingNotificationTimestamp()).isNotEqualTo(timestamp); assertThat(shouldShowWirelessChargingWarningTip(mContext, TAG)).isTrue(); } @Test public void updateWirelessChargingNotificationTimestamp_dismissForever_setMinValue() { updateWirelessChargingNotificationTimestamp(mContext, Long.MIN_VALUE, TAG); assertThat(getWirelessChargingNotificationTimestamp()).isEqualTo(Long.MIN_VALUE); } @Test public void updateWirelessChargingNotificationTimestamp_notDismissForever_setTimestamp() { updateWirelessChargingNotificationTimestamp(mContext, CURRENT_TIMESTAMP, TAG); assertThat(getWirelessChargingNotificationTimestamp()) .isNotEqualTo(WIRELESS_CHARGING_DEFAULT_TIMESTAMP); assertThat(getWirelessChargingNotificationTimestamp()).isNotEqualTo(Long.MIN_VALUE); } @Test public void shouldShowWirelessChargingWarningTip_enabled_returnTrue() { Utils.updateWirelessChargingWarningEnabled(mContext, true, TAG); Loading Loading @@ -644,11 +570,4 @@ public class UtilsTest { when(mUsbPortStatus.isConnected()).thenReturn(true); when(mUsbPortStatus.getComplianceWarnings()).thenReturn(new int[] {complianceWarningType}); } private long getWirelessChargingNotificationTimestamp() { return Settings.Secure.getLong( mContext.getContentResolver(), Utils.WIRELESS_CHARGING_NOTIFICATION_TIMESTAMP, WIRELESS_CHARGING_DEFAULT_TIMESTAMP); } }