summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Wilson Wu <wilsonwu@google.com> 2019-11-26 02:39:29 -0800
committer android-build-merger <android-build-merger@google.com> 2019-11-26 02:39:29 -0800
commitfe7f309faead2bfc6c1535c9ba6b027c009bbf7e (patch)
tree153f877909ad8ba795a698725c61981fe0f28f4d
parent91d7defcfc97d629a9a578096b61bb51acbda30c (diff)
parentfc3f1408daf55561a6c8ed247b02d90092175b63 (diff)
Merge "Support showing alignment hint based on aligniment state of dock" into qt-qpr1-dev
am: fc3f1408da Change-Id: I4b9b1fd4c3209a6e3ae42c65d0a2b4c8484fc8ba
-rw-r--r--packages/SystemUI/res/values/strings.xml6
-rw-r--r--packages/SystemUI/src/com/android/systemui/dock/DockManager.java55
-rw-r--r--packages/SystemUI/src/com/android/systemui/dock/DockManagerImpl.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java34
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/dock/DockManagerFake.java11
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java78
6 files changed, 181 insertions, 11 deletions
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 1044ede009b1..236583896289 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -968,6 +968,12 @@
<!-- Message shown when face authentication fails and the pin pad is visible. [CHAR LIMIT=60] -->
<string name="keyguard_retry">Swipe up to try again</string>
+ <!-- Indication when device is slow charging due to misalignment on the dock. [CHAR LIMIT=60] -->
+ <string name="dock_alignment_slow_charging" product="default">Realign phone for faster charging</string>
+
+ <!-- Indication when device is not charging due to bad placement on the dock. [CHAR LIMIT=60] -->
+ <string name="dock_alignment_not_charging" product="default">Realign phone to charge wirelessly</string>
+
<!-- Text on keyguard screen and in Quick Settings footer indicating that the device is enterprise-managed by a Device Owner [CHAR LIMIT=60] -->
<string name="do_disclosure_generic">This device is managed by your organization</string>
diff --git a/packages/SystemUI/src/com/android/systemui/dock/DockManager.java b/packages/SystemUI/src/com/android/systemui/dock/DockManager.java
index d332f59a4500..42e065a113e6 100644
--- a/packages/SystemUI/src/com/android/systemui/dock/DockManager.java
+++ b/packages/SystemUI/src/com/android/systemui/dock/DockManager.java
@@ -17,12 +17,12 @@
package com.android.systemui.dock;
/**
- * Allows an app to handle dock events
+ * Allows an app to handle dock events.
*/
public interface DockManager {
/**
- * Uninitialized / undocking dock states
+ * Uninitialized / undocking dock states.
*/
int STATE_NONE = 0;
/**
@@ -30,34 +30,75 @@ public interface DockManager {
*/
int STATE_DOCKED = 1;
/**
- * The state for docking without showing UI
+ * The state for docking without showing UI.
*/
int STATE_DOCKED_HIDE = 2;
/**
- * Add a dock event listener into manager
+ * Indicates there's no alignment issue.
+ */
+ int ALIGN_STATE_GOOD = 0;
+
+ /**
+ * Indicates it's slightly not aligned with dock. Normally combines with slow charging issue.
+ */
+ int ALIGN_STATE_POOR = 1;
+
+ /**
+ * Indicates it's not aligned with dock. Normally combines with not charging issue.
+ */
+ int ALIGN_STATE_TERRIBLE = 2;
+
+ /**
+ * Adds a dock event listener into manager.
*
* @param callback A {@link DockEventListener} which want to add
*/
void addListener(DockEventListener callback);
/**
- * Remove the added listener from dock manager
+ * Removes the added listener from dock manager
*
* @param callback A {@link DockEventListener} which want to remove
*/
void removeListener(DockEventListener callback);
/**
+ * Adds a alignment listener into manager.
+ *
+ * @param listener A {@link AlignmentStateListener} which want to add
+ */
+ void addAlignmentStateListener(AlignmentStateListener listener);
+
+ /**
+ * Removes the added alignment listener from dock manager.
+ *
+ * @param listener A {@link AlignmentStateListener} which want to remove
+ */
+ void removeAlignmentStateListener(AlignmentStateListener listener);
+
+ /**
* Returns true if the device is in docking state.
*/
boolean isDocked();
- /** Callback for receiving dock events */
+ /**
+ * Listens to dock events.
+ */
interface DockEventListener {
/**
- * Override to handle dock events
+ * Override to handle dock events.
*/
void onEvent(int event);
}
+
+ /**
+ * Listens to dock alignment state changed.
+ */
+ interface AlignmentStateListener {
+ /**
+ * Override to handle alignment state changes.
+ */
+ void onAlignmentStateChanged(int alignState);
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/dock/DockManagerImpl.java b/packages/SystemUI/src/com/android/systemui/dock/DockManagerImpl.java
index fa7f5032ca16..f6d24e8a35c7 100644
--- a/packages/SystemUI/src/com/android/systemui/dock/DockManagerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/dock/DockManagerImpl.java
@@ -35,6 +35,14 @@ public class DockManagerImpl implements DockManager {
}
@Override
+ public void addAlignmentStateListener(AlignmentStateListener listener) {
+ }
+
+ @Override
+ public void removeAlignmentStateListener(AlignmentStateListener listener) {
+ }
+
+ @Override
public boolean isDocked() {
return false;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
index f3ae50b4ca23..dd5255afaf7f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
@@ -50,6 +50,7 @@ import com.android.settingslib.Utils;
import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
+import com.android.systemui.dock.DockManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
@@ -96,6 +97,7 @@ public class KeyguardIndicationController implements StateListener,
private final IBatteryStats mBatteryInfo;
private final SettableWakeLock mWakeLock;
private final LockPatternUtils mLockPatternUtils;
+ private final DockManager mDockManager;
private final int mSlowThreshold;
private final int mFastThreshold;
@@ -104,6 +106,7 @@ public class KeyguardIndicationController implements StateListener,
private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
private String mRestingIndication;
+ private String mAlignmentIndication = "";
private CharSequence mTransientIndication;
private ColorStateList mTransientTextColorState;
private ColorStateList mInitialTextColorState;
@@ -141,7 +144,8 @@ public class KeyguardIndicationController implements StateListener,
Dependency.get(AccessibilityController.class),
UnlockMethodCache.getInstance(context),
Dependency.get(StatusBarStateController.class),
- KeyguardUpdateMonitor.getInstance(context));
+ Dependency.get(KeyguardUpdateMonitor.class),
+ Dependency.get(DockManager.class));
}
/**
@@ -152,7 +156,8 @@ public class KeyguardIndicationController implements StateListener,
LockPatternUtils lockPatternUtils, WakeLock wakeLock, ShadeController shadeController,
AccessibilityController accessibilityController, UnlockMethodCache unlockMethodCache,
StatusBarStateController statusBarStateController,
- KeyguardUpdateMonitor keyguardUpdateMonitor) {
+ KeyguardUpdateMonitor keyguardUpdateMonitor,
+ DockManager dockManager) {
mContext = context;
mLockIcon = lockIcon;
mShadeController = shadeController;
@@ -160,6 +165,8 @@ public class KeyguardIndicationController implements StateListener,
mUnlockMethodCache = unlockMethodCache;
mStatusBarStateController = statusBarStateController;
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
+ mDockManager = dockManager;
+ mDockManager.addAlignmentStateListener(this::handleAlignStateChanged);
// lock icon is not used on all form factors.
if (mLockIcon != null) {
mLockIcon.setOnLongClickListener(this::handleLockLongClick);
@@ -213,6 +220,21 @@ public class KeyguardIndicationController implements StateListener,
mShadeController.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE, true /* force */);
}
+ private void handleAlignStateChanged(int alignState) {
+ String alignmentIndication = "";
+ if (alignState == DockManager.ALIGN_STATE_POOR) {
+ alignmentIndication =
+ mContext.getResources().getString(R.string.dock_alignment_slow_charging);
+ } else if (alignState == DockManager.ALIGN_STATE_TERRIBLE) {
+ alignmentIndication =
+ mContext.getResources().getString(R.string.dock_alignment_not_charging);
+ }
+ if (!alignmentIndication.equals(mAlignmentIndication)) {
+ mAlignmentIndication = alignmentIndication;
+ updateIndication(false);
+ }
+ }
+
/**
* Gets the {@link KeyguardUpdateMonitorCallback} instance associated with this
* {@link KeyguardIndicationController}.
@@ -256,7 +278,7 @@ public class KeyguardIndicationController implements StateListener,
if (visible) {
// If this is called after an error message was already shown, we should not clear it.
// Otherwise the error message won't be shown
- if (!mHandler.hasMessages(MSG_HIDE_TRANSIENT)) {
+ if (!mHandler.hasMessages(MSG_HIDE_TRANSIENT)) {
hideTransientIndication();
}
updateIndication(false);
@@ -367,6 +389,9 @@ public class KeyguardIndicationController implements StateListener,
mTextView.setTextColor(Color.WHITE);
if (!TextUtils.isEmpty(mTransientIndication)) {
mTextView.switchIndication(mTransientIndication);
+ } else if (!TextUtils.isEmpty(mAlignmentIndication)) {
+ mTextView.switchIndication(mAlignmentIndication);
+ mTextView.setTextColor(Utils.getColorError(mContext));
} else if (mPowerPluggedIn) {
String indication = computePowerIndication();
if (animate) {
@@ -395,6 +420,9 @@ public class KeyguardIndicationController implements StateListener,
&& mKeyguardUpdateMonitor.getUserHasTrust(userId)) {
mTextView.switchIndication(trustGrantedIndication);
mTextView.setTextColor(mInitialTextColorState);
+ } else if (!TextUtils.isEmpty(mAlignmentIndication)) {
+ mTextView.switchIndication(mAlignmentIndication);
+ mTextView.setTextColor(Utils.getColorError(mContext));
} else if (mPowerPluggedIn) {
String indication = computePowerIndication();
if (DEBUG_CHARGING_SPEED) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dock/DockManagerFake.java b/packages/SystemUI/tests/src/com/android/systemui/dock/DockManagerFake.java
index 839b5e4472c6..fd48d34ebea6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dock/DockManagerFake.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/dock/DockManagerFake.java
@@ -21,6 +21,7 @@ package com.android.systemui.dock;
*/
public class DockManagerFake implements DockManager {
DockEventListener mCallback;
+ AlignmentStateListener mAlignmentListener;
@Override
public void addListener(DockEventListener callback) {
@@ -33,6 +34,16 @@ public class DockManagerFake implements DockManager {
}
@Override
+ public void addAlignmentStateListener(AlignmentStateListener listener) {
+ mAlignmentListener = listener;
+ }
+
+ @Override
+ public void removeAlignmentStateListener(AlignmentStateListener listener) {
+ mAlignmentListener = listener;
+ }
+
+ @Override
public boolean isDocked() {
return false;
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
index c85e51545bc1..2fe51d35c490 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
@@ -50,8 +50,10 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
+import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
+import com.android.systemui.dock.DockManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
import com.android.systemui.statusbar.phone.LockIcon;
@@ -65,6 +67,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -100,6 +103,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
@Mock
private UserManager mUserManager;
+ @Mock
+ private DockManager mDockManager;
+ @Captor
+ private ArgumentCaptor<DockManager.AlignmentStateListener> mAlignmentListener;
private KeyguardIndicationTextView mTextView;
private KeyguardIndicationController mController;
@@ -135,7 +142,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
}
mController = new KeyguardIndicationController(mContext, mIndicationArea, mLockIcon,
mLockPatternUtils, mWakeLock, mShadeController, mAccessibilityController,
- mUnlockMethodCache, mStatusBarStateController, mKeyguardUpdateMonitor);
+ mUnlockMethodCache, mStatusBarStateController, mKeyguardUpdateMonitor,
+ mDockManager);
mController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
}
@@ -206,6 +214,74 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
}
@Test
+ public void createController_addsAlignmentListener() {
+ createController();
+
+ verify(mDockManager).addAlignmentStateListener(
+ any(DockManager.AlignmentStateListener.class));
+ }
+
+ @Test
+ public void onAlignmentStateChanged_showsSlowChargingIndication() {
+ createController();
+ verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
+ mController.setVisible(true);
+
+ mAlignmentListener.getValue().onAlignmentStateChanged(
+ DockManager.ALIGN_STATE_POOR);
+
+ assertThat(mTextView.getText()).isEqualTo(
+ mContext.getResources().getString(R.string.dock_alignment_slow_charging));
+ assertThat(mTextView.getCurrentTextColor()).isEqualTo(
+ Utils.getColorError(mContext).getDefaultColor());
+ }
+
+ @Test
+ public void onAlignmentStateChanged_showsNotChargingIndication() {
+ createController();
+ verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
+ mController.setVisible(true);
+
+ mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
+
+ assertThat(mTextView.getText()).isEqualTo(
+ mContext.getResources().getString(R.string.dock_alignment_not_charging));
+ assertThat(mTextView.getCurrentTextColor()).isEqualTo(
+ Utils.getColorError(mContext).getDefaultColor());
+ }
+
+ @Test
+ public void onAlignmentStateChanged_whileDozing_showsSlowChargingIndication() {
+ createController();
+ verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
+ mController.setVisible(true);
+ mController.setDozing(true);
+
+ mAlignmentListener.getValue().onAlignmentStateChanged(
+ DockManager.ALIGN_STATE_POOR);
+
+ assertThat(mTextView.getText()).isEqualTo(
+ mContext.getResources().getString(R.string.dock_alignment_slow_charging));
+ assertThat(mTextView.getCurrentTextColor()).isEqualTo(
+ Utils.getColorError(mContext).getDefaultColor());
+ }
+
+ @Test
+ public void onAlignmentStateChanged_whileDozing_showsNotChargingIndication() {
+ createController();
+ verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
+ mController.setVisible(true);
+ mController.setDozing(true);
+
+ mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
+
+ assertThat(mTextView.getText()).isEqualTo(
+ mContext.getResources().getString(R.string.dock_alignment_not_charging));
+ assertThat(mTextView.getCurrentTextColor()).isEqualTo(
+ Utils.getColorError(mContext).getDefaultColor());
+ }
+
+ @Test
public void transientIndication_holdsWakeLock_whenDozing() {
createController();