Merge "ATV a11y shortcut (CL 1 of 3): Update key chord" into oc-mr1-dev
This commit is contained in:
@@ -24,6 +24,7 @@ import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.ContentObserver;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.Ringtone;
|
||||
@@ -138,13 +139,18 @@ public class AccessibilityShortcutController {
|
||||
final int userId = ActivityManager.getCurrentUser();
|
||||
final int dialogAlreadyShown = Settings.Secure.getIntForUser(
|
||||
cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, 0, userId);
|
||||
// Use USAGE_ASSISTANCE_ACCESSIBILITY for TVs to ensure that TVs play the ringtone as they
|
||||
// have less ways of providing feedback like vibration.
|
||||
final int audioAttributesUsage = hasFeatureLeanback()
|
||||
? AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY
|
||||
: AudioAttributes.USAGE_NOTIFICATION_EVENT;
|
||||
|
||||
// Play a notification tone
|
||||
final Ringtone tone =
|
||||
RingtoneManager.getRingtone(mContext, Settings.System.DEFAULT_NOTIFICATION_URI);
|
||||
if (tone != null) {
|
||||
tone.setAudioAttributes(new AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
|
||||
.setUsage(audioAttributesUsage)
|
||||
.build());
|
||||
tone.play();
|
||||
}
|
||||
@@ -254,6 +260,10 @@ public class AccessibilityShortcutController {
|
||||
AccessibilityServiceInfo.FEEDBACK_ALL_MASK).contains(serviceInfo);
|
||||
}
|
||||
|
||||
private boolean hasFeatureLeanback() {
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
|
||||
}
|
||||
|
||||
// Class to allow mocking of static framework calls
|
||||
public static class FrameworkObjectProvider {
|
||||
public AccessibilityManager getAccessibilityManagerInstance(Context context) {
|
||||
|
||||
@@ -3398,11 +3398,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
if (!down) {
|
||||
cancelPreloadRecentApps();
|
||||
|
||||
if (mHasFeatureLeanback) {
|
||||
// Clear flags
|
||||
mAccessibilityTvKey2Pressed = down;
|
||||
}
|
||||
|
||||
mHomePressed = false;
|
||||
if (mHomeConsumed) {
|
||||
mHomeConsumed = false;
|
||||
@@ -3457,13 +3452,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
preloadRecentApps();
|
||||
}
|
||||
} else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
|
||||
if (mHasFeatureLeanback) {
|
||||
mAccessibilityTvKey2Pressed = down;
|
||||
if (interceptAccessibilityGestureTv()) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!keyguardOn) {
|
||||
handleLongPressOnHome(event.getDeviceId());
|
||||
}
|
||||
@@ -3630,11 +3618,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
return 0;
|
||||
} else if (mHasFeatureLeanback && interceptBugreportGestureTv(keyCode, down)) {
|
||||
return -1;
|
||||
} else if (mHasFeatureLeanback && keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
|
||||
mAccessibilityTvKey1Pressed = down;
|
||||
if (interceptAccessibilityGestureTv()) {
|
||||
return -1;
|
||||
}
|
||||
} else if (mHasFeatureLeanback && interceptAccessibilityGestureTv(keyCode, down)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Toggle Caps Lock on META-ALT.
|
||||
@@ -3855,20 +3840,28 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
|
||||
/**
|
||||
* TV only: recognizes a remote control gesture as Accessibility shortcut.
|
||||
* Shortcut: Long press (HOME + DPAD_CENTER)
|
||||
* Shortcut: Long press (BACK + DPAD_DOWN)
|
||||
*/
|
||||
private boolean interceptAccessibilityGestureTv() {
|
||||
private boolean interceptAccessibilityGestureTv(int keyCode, boolean down) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
mAccessibilityTvKey1Pressed = down;
|
||||
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
|
||||
mAccessibilityTvKey2Pressed = down;
|
||||
}
|
||||
|
||||
if (mAccessibilityTvKey1Pressed && mAccessibilityTvKey2Pressed) {
|
||||
if (!mAccessibilityTvScheduled) {
|
||||
mAccessibilityTvScheduled = true;
|
||||
Message msg = Message.obtain(mHandler, MSG_ACCESSIBILITY_TV);
|
||||
msg.setAsynchronous(true);
|
||||
mHandler.sendMessage(msg);
|
||||
mHandler.sendMessageDelayed(msg,
|
||||
ViewConfiguration.get(mContext).getAccessibilityShortcutKeyTimeout());
|
||||
}
|
||||
} else if (mAccessibilityTvScheduled) {
|
||||
mHandler.removeMessages(MSG_ACCESSIBILITY_TV);
|
||||
mAccessibilityTvScheduled = false;
|
||||
}
|
||||
|
||||
return mAccessibilityTvScheduled;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user