am d6216305: Merge "Disable more hotkeys while in setup." into lmp-mr1-dev
* commit 'd62163055f983b95a954f1a6c2cbc8e0085a7ab5': Disable more hotkeys while in setup.
This commit is contained in:
@@ -28,9 +28,9 @@ import android.media.session.MediaSessionLegacyHelper;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Slog;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.HapticFeedbackConstants;
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.FallbackEventHandler;
|
import android.view.FallbackEventHandler;
|
||||||
@@ -117,15 +117,20 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
|
|||||||
dispatcher.startTracking(event, this);
|
dispatcher.startTracking(event, this);
|
||||||
} else if (event.isLongPress() && dispatcher.isTracking(event)) {
|
} else if (event.isLongPress() && dispatcher.isTracking(event)) {
|
||||||
dispatcher.performedLongPress(event);
|
dispatcher.performedLongPress(event);
|
||||||
mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
if (isUserSetupComplete()) {
|
||||||
// launch the VoiceDialer
|
mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||||
Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
|
// launch the VoiceDialer
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
|
||||||
try {
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
sendCloseSystemWindows();
|
try {
|
||||||
mContext.startActivity(intent);
|
sendCloseSystemWindows();
|
||||||
} catch (ActivityNotFoundException e) {
|
mContext.startActivity(intent);
|
||||||
startCallActivity();
|
} catch (ActivityNotFoundException e) {
|
||||||
|
startCallActivity();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Not starting call activity because user "
|
||||||
|
+ "setup is in progress.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -139,13 +144,18 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
|
|||||||
dispatcher.startTracking(event, this);
|
dispatcher.startTracking(event, this);
|
||||||
} else if (event.isLongPress() && dispatcher.isTracking(event)) {
|
} else if (event.isLongPress() && dispatcher.isTracking(event)) {
|
||||||
dispatcher.performedLongPress(event);
|
dispatcher.performedLongPress(event);
|
||||||
mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
if (isUserSetupComplete()) {
|
||||||
sendCloseSystemWindows();
|
mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||||
// Broadcast an intent that the Camera button was longpressed
|
sendCloseSystemWindows();
|
||||||
Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
|
// Broadcast an intent that the Camera button was longpressed
|
||||||
intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
|
Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
|
||||||
mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF,
|
intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
|
||||||
null, null, null, 0, null, null);
|
mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF,
|
||||||
|
null, null, null, 0, null, null);
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Not dispatching CAMERA long press because user "
|
||||||
|
+ "setup is in progress.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -160,21 +170,26 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
|
|||||||
Configuration config = mContext.getResources().getConfiguration();
|
Configuration config = mContext.getResources().getConfiguration();
|
||||||
if (config.keyboard == Configuration.KEYBOARD_NOKEYS
|
if (config.keyboard == Configuration.KEYBOARD_NOKEYS
|
||||||
|| config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
|
|| config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
|
||||||
// launch the search activity
|
if (isUserSetupComplete()) {
|
||||||
Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
|
// launch the search activity
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
|
||||||
try {
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
try {
|
||||||
sendCloseSystemWindows();
|
mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||||
getSearchManager().stopSearch();
|
sendCloseSystemWindows();
|
||||||
mContext.startActivity(intent);
|
getSearchManager().stopSearch();
|
||||||
// Only clear this if we successfully start the
|
mContext.startActivity(intent);
|
||||||
// activity; otherwise we will allow the normal short
|
// Only clear this if we successfully start the
|
||||||
// press action to be performed.
|
// activity; otherwise we will allow the normal short
|
||||||
dispatcher.performedLongPress(event);
|
// press action to be performed.
|
||||||
return true;
|
dispatcher.performedLongPress(event);
|
||||||
} catch (ActivityNotFoundException e) {
|
return true;
|
||||||
// Ignore
|
} catch (ActivityNotFoundException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Not dispatching SEARCH long press because user "
|
||||||
|
+ "setup is in progress.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +201,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
|
|||||||
|
|
||||||
boolean onKeyUp(int keyCode, KeyEvent event) {
|
boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "up " + keyCode);
|
Log.d(TAG, "up " + keyCode);
|
||||||
}
|
}
|
||||||
final KeyEvent.DispatcherState dispatcher = mView.getKeyDispatcherState();
|
final KeyEvent.DispatcherState dispatcher = mView.getKeyDispatcherState();
|
||||||
if (dispatcher != null) {
|
if (dispatcher != null) {
|
||||||
@@ -234,7 +249,12 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (event.isTracking() && !event.isCanceled()) {
|
if (event.isTracking() && !event.isCanceled()) {
|
||||||
startCallActivity();
|
if (isUserSetupComplete()) {
|
||||||
|
startCallActivity();
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "Not starting call activity because user "
|
||||||
|
+ "setup is in progress.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -249,7 +269,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
|
|||||||
try {
|
try {
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
Slog.w(TAG, "No activity found for android.intent.action.CALL_BUTTON.");
|
Log.w(TAG, "No activity found for android.intent.action.CALL_BUTTON.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,5 +309,10 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
|
|||||||
private void handleMediaKeyEvent(KeyEvent keyEvent) {
|
private void handleMediaKeyEvent(KeyEvent keyEvent) {
|
||||||
MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(keyEvent, false);
|
MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(keyEvent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isUserSetupComplete() {
|
||||||
|
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.USER_SETUP_COMPLETE, 0) != 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import android.provider.Settings;
|
|||||||
import android.speech.RecognizerIntent;
|
import android.speech.RecognizerIntent;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Slog;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
@@ -715,11 +716,19 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
Log.w(TAG, "Attempted to dispatch null or non-media key event.");
|
Log.w(TAG, "Attempted to dispatch null or non-media key event.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int pid = Binder.getCallingPid();
|
final int pid = Binder.getCallingPid();
|
||||||
final int uid = Binder.getCallingUid();
|
final int uid = Binder.getCallingUid();
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!isUserSetupComplete()) {
|
||||||
|
// Global media key handling can have the side-effect of starting new
|
||||||
|
// activities which is undesirable while setup is in progress.
|
||||||
|
Slog.i(TAG, "Not dispatching media key event because user "
|
||||||
|
+ "setup is in progress.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
// If we don't have a media button receiver to fall back on
|
// If we don't have a media button receiver to fall back on
|
||||||
// include non-playing sessions for dispatching
|
// include non-playing sessions for dispatching
|
||||||
@@ -1007,6 +1016,11 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
return keyCode == KeyEvent.KEYCODE_HEADSETHOOK;
|
return keyCode == KeyEvent.KEYCODE_HEADSETHOOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isUserSetupComplete() {
|
||||||
|
return Settings.Secure.getIntForUser(getContext().getContentResolver(),
|
||||||
|
Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
// we only handle public stream types, which are 0-5
|
// we only handle public stream types, which are 0-5
|
||||||
private boolean isValidLocalStreamType(int streamType) {
|
private boolean isValidLocalStreamType(int streamType) {
|
||||||
return streamType >= AudioManager.STREAM_VOICE_CALL
|
return streamType >= AudioManager.STREAM_VOICE_CALL
|
||||||
|
|||||||
Reference in New Issue
Block a user