Merge "Improve SystemUIBootTiming performance in OneHandedController" into sc-dev
This commit is contained in:
@@ -43,7 +43,6 @@ import android.util.Slog;
|
|||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -79,6 +78,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
|
|
||||||
private volatile boolean mIsOneHandedEnabled;
|
private volatile boolean mIsOneHandedEnabled;
|
||||||
private volatile boolean mIsSwipeToNotificationEnabled;
|
private volatile boolean mIsSwipeToNotificationEnabled;
|
||||||
|
private boolean mIsShortcutEnabled;
|
||||||
private boolean mTaskChangeToExit;
|
private boolean mTaskChangeToExit;
|
||||||
private boolean mLockedDisabled;
|
private boolean mLockedDisabled;
|
||||||
private boolean mKeyguardShowing;
|
private boolean mKeyguardShowing;
|
||||||
@@ -143,6 +143,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
private final ContentObserver mTimeoutObserver;
|
private final ContentObserver mTimeoutObserver;
|
||||||
private final ContentObserver mTaskChangeExitObserver;
|
private final ContentObserver mTaskChangeExitObserver;
|
||||||
private final ContentObserver mSwipeToNotificationEnabledObserver;
|
private final ContentObserver mSwipeToNotificationEnabledObserver;
|
||||||
|
private final ContentObserver mShortcutEnabledObserver;
|
||||||
|
|
||||||
private AccessibilityManager.AccessibilityStateChangeListener
|
private AccessibilityManager.AccessibilityStateChangeListener
|
||||||
mAccessibilityStateChangeListener =
|
mAccessibilityStateChangeListener =
|
||||||
@@ -174,13 +175,13 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
@Override
|
@Override
|
||||||
public void onStartFinished(Rect bounds) {
|
public void onStartFinished(Rect bounds) {
|
||||||
mState.setState(STATE_ACTIVE);
|
mState.setState(STATE_ACTIVE);
|
||||||
notifyShortcutState(STATE_ACTIVE);
|
notifyShortcutStateChanged(STATE_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopFinished(Rect bounds) {
|
public void onStopFinished(Rect bounds) {
|
||||||
mState.setState(STATE_NONE);
|
mState.setState(STATE_NONE);
|
||||||
notifyShortcutState(STATE_NONE);
|
notifyShortcutStateChanged(STATE_NONE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -295,6 +296,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
mTaskChangeExitObserver = getObserver(this::onTaskChangeExitSettingChanged);
|
mTaskChangeExitObserver = getObserver(this::onTaskChangeExitSettingChanged);
|
||||||
mSwipeToNotificationEnabledObserver =
|
mSwipeToNotificationEnabledObserver =
|
||||||
getObserver(this::onSwipeToNotificationEnabledChanged);
|
getObserver(this::onSwipeToNotificationEnabledChanged);
|
||||||
|
mShortcutEnabledObserver = getObserver(this::onShortcutEnabledChanged);
|
||||||
|
|
||||||
mDisplayController.addDisplayChangingController(mRotationController);
|
mDisplayController.addDisplayChangingController(mRotationController);
|
||||||
setupCallback();
|
setupCallback();
|
||||||
@@ -349,11 +351,13 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
*/
|
*/
|
||||||
void setSwipeToNotificationEnabled(boolean enabled) {
|
void setSwipeToNotificationEnabled(boolean enabled) {
|
||||||
mIsSwipeToNotificationEnabled = enabled;
|
mIsSwipeToNotificationEnabled = enabled;
|
||||||
updateOneHandedEnabled();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void notifyShortcutState(@OneHandedState.State int state) {
|
void notifyShortcutStateChanged(@OneHandedState.State int state) {
|
||||||
|
if (!isShortcutEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mOneHandedSettingsUtil.setOneHandedModeActivated(
|
mOneHandedSettingsUtil.setOneHandedModeActivated(
|
||||||
mContext.getContentResolver(), state == STATE_ACTIVE ? 1 : 0, mUserId);
|
mContext.getContentResolver(), state == STATE_ACTIVE ? 1 : 0, mUserId);
|
||||||
}
|
}
|
||||||
@@ -443,6 +447,9 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
mOneHandedSettingsUtil.registerSettingsKeyObserver(
|
mOneHandedSettingsUtil.registerSettingsKeyObserver(
|
||||||
Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED,
|
Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED,
|
||||||
mContext.getContentResolver(), mSwipeToNotificationEnabledObserver, newUserId);
|
mContext.getContentResolver(), mSwipeToNotificationEnabledObserver, newUserId);
|
||||||
|
mOneHandedSettingsUtil.registerSettingsKeyObserver(
|
||||||
|
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
|
||||||
|
mContext.getContentResolver(), mShortcutEnabledObserver, newUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unregisterSettingObservers() {
|
private void unregisterSettingObservers() {
|
||||||
@@ -454,6 +461,8 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
mTaskChangeExitObserver);
|
mTaskChangeExitObserver);
|
||||||
mOneHandedSettingsUtil.unregisterSettingsKeyObserver(mContext.getContentResolver(),
|
mOneHandedSettingsUtil.unregisterSettingsKeyObserver(mContext.getContentResolver(),
|
||||||
mSwipeToNotificationEnabledObserver);
|
mSwipeToNotificationEnabledObserver);
|
||||||
|
mOneHandedSettingsUtil.unregisterSettingsKeyObserver(mContext.getContentResolver(),
|
||||||
|
mShortcutEnabledObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSettings() {
|
private void updateSettings() {
|
||||||
@@ -489,15 +498,6 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void notifyUserConfigChanged(boolean success) {
|
|
||||||
if (!success) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// TODO Check UX if popup Toast to notify user when auto-enabled one-handed is good option.
|
|
||||||
Toast.makeText(mContext, R.string.one_handed_tutorial_title, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void onActivatedActionChanged() {
|
void onActivatedActionChanged() {
|
||||||
if (!isShortcutEnabled()) {
|
if (!isShortcutEnabled()) {
|
||||||
@@ -508,7 +508,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
if (!isOneHandedEnabled()) {
|
if (!isOneHandedEnabled()) {
|
||||||
final boolean success = mOneHandedSettingsUtil.setOneHandedModeEnabled(
|
final boolean success = mOneHandedSettingsUtil.setOneHandedModeEnabled(
|
||||||
mContext.getContentResolver(), 1 /* Enabled for shortcut */, mUserId);
|
mContext.getContentResolver(), 1 /* Enabled for shortcut */, mUserId);
|
||||||
notifyUserConfigChanged(success);
|
Slog.d(TAG, "Auto enabled One-handed mode by shortcut trigger, success=" + success);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSwipeToNotificationEnabled()) {
|
if (isSwipeToNotificationEnabled()) {
|
||||||
@@ -596,11 +596,11 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
mOneHandedUiEventLogger.writeEvent(enabled
|
mOneHandedUiEventLogger.writeEvent(enabled
|
||||||
? OneHandedUiEventLogger.EVENT_ONE_HANDED_SETTINGS_SHOW_NOTIFICATION_ENABLED_ON
|
? OneHandedUiEventLogger.EVENT_ONE_HANDED_SETTINGS_SHOW_NOTIFICATION_ENABLED_ON
|
||||||
: OneHandedUiEventLogger.EVENT_ONE_HANDED_SETTINGS_SHOW_NOTIFICATION_ENABLED_OFF);
|
: OneHandedUiEventLogger.EVENT_ONE_HANDED_SETTINGS_SHOW_NOTIFICATION_ENABLED_OFF);
|
||||||
|
}
|
||||||
|
|
||||||
// Also checks one handed mode settings since they all need gesture overlay.
|
void onShortcutEnabledChanged() {
|
||||||
setEnabledGesturalOverlay(
|
mIsShortcutEnabled = mOneHandedSettingsUtil.getShortcutEnabled(
|
||||||
enabled || mOneHandedSettingsUtil.getSettingsOneHandedModeEnabled(
|
mContext.getContentResolver(), mUserId);
|
||||||
mContext.getContentResolver(), mUserId), true /* DelayExecute */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupTimeoutListener() {
|
private void setupTimeoutListener() {
|
||||||
@@ -620,7 +620,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean isShortcutEnabled() {
|
boolean isShortcutEnabled() {
|
||||||
return mOneHandedSettingsUtil.getShortcutEnabled(mContext.getContentResolver(), mUserId);
|
return mIsShortcutEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -634,9 +634,9 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If setting is pull screen, notify shortcut one_handed_mode_activated to reset
|
// If setting is pull screen, notify shortcut one_handed_mode_activated to reset
|
||||||
// and align status with current mState when function enabled.
|
// and align status with current mState when one-handed gesture enabled.
|
||||||
if (isOneHandedEnabled() && !isSwipeToNotificationEnabled()) {
|
if (isOneHandedEnabled() && !isSwipeToNotificationEnabled()) {
|
||||||
notifyShortcutState(mState.getState());
|
notifyShortcutStateChanged(mState.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
mTouchHandler.onOneHandedEnabled(mIsOneHandedEnabled);
|
mTouchHandler.onOneHandedEnabled(mIsOneHandedEnabled);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.content.ContentResolver;
|
|||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
@@ -170,7 +171,7 @@ public final class OneHandedSettingsUtil {
|
|||||||
public boolean getShortcutEnabled(ContentResolver resolver, int userId) {
|
public boolean getShortcutEnabled(ContentResolver resolver, int userId) {
|
||||||
final String targets = Settings.Secure.getStringForUser(resolver,
|
final String targets = Settings.Secure.getStringForUser(resolver,
|
||||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, userId);
|
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, userId);
|
||||||
return targets != null ? targets.contains(ONE_HANDED_MODE_TARGET_NAME) : false;
|
return TextUtils.isEmpty(targets) ? false : targets.contains(ONE_HANDED_MODE_TARGET_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -406,7 +407,7 @@ public class OneHandedControllerTest extends OneHandedTestCase {
|
|||||||
false);
|
false);
|
||||||
mSpiedOneHandedController.onActivatedActionChanged();
|
mSpiedOneHandedController.onActivatedActionChanged();
|
||||||
|
|
||||||
verify(mSpiedOneHandedController).notifyUserConfigChanged(anyBoolean());
|
verify(mMockSettingsUitl).setOneHandedModeEnabled(any(), eq(1), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -441,7 +442,7 @@ public class OneHandedControllerTest extends OneHandedTestCase {
|
|||||||
mSpiedOneHandedController.registerEventCallback(mMockEventCallback);
|
mSpiedOneHandedController.registerEventCallback(mMockEventCallback);
|
||||||
mSpiedOneHandedController.setOneHandedEnabled(true);
|
mSpiedOneHandedController.setOneHandedEnabled(true);
|
||||||
|
|
||||||
verify(mSpiedOneHandedController).notifyShortcutState(anyInt());
|
verify(mSpiedOneHandedController).notifyShortcutStateChanged(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -468,7 +469,7 @@ public class OneHandedControllerTest extends OneHandedTestCase {
|
|||||||
false /* To avoid test runner create Toast */);
|
false /* To avoid test runner create Toast */);
|
||||||
mSpiedOneHandedController.onActivatedActionChanged();
|
mSpiedOneHandedController.onActivatedActionChanged();
|
||||||
|
|
||||||
verify(mSpiedOneHandedController).notifyUserConfigChanged(anyBoolean());
|
verify(mMockSettingsUitl).setOneHandedModeEnabled(any(), eq(1), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -481,6 +482,5 @@ public class OneHandedControllerTest extends OneHandedTestCase {
|
|||||||
mSpiedOneHandedController.onActivatedActionChanged();
|
mSpiedOneHandedController.onActivatedActionChanged();
|
||||||
|
|
||||||
verify(mMockSettingsUitl, never()).setOneHandedModeEnabled(any(), anyInt(), anyInt());
|
verify(mMockSettingsUitl, never()).setOneHandedModeEnabled(any(), anyInt(), anyInt());
|
||||||
verify(mSpiedOneHandedController, never()).notifyUserConfigChanged(anyBoolean());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user