diff options
8 files changed, 166 insertions, 26 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index ad6d85f2712b..44fe797ffb28 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -17039,6 +17039,15 @@ public final class Settings { */ public static final String CLOCKWORK_SYSUI_MAIN_ACTIVITY = "clockwork_sysui_main_activity"; + + /** + * Setting to disable power button long press launching Assistant. It's boolean, i.e. + * enabled = 1, disabled = 0. By default, this setting is enabled. + * + * @hide + */ + public static final String CLOCKWORK_LONG_PRESS_TO_ASSISTANT_ENABLED = + "clockwork_long_press_to_assistant_enabled"; } } diff --git a/core/java/com/android/internal/policy/IKeyguardService.aidl b/core/java/com/android/internal/policy/IKeyguardService.aidl index 76aa7a015d2f..36b7ee5b3b62 100644 --- a/core/java/com/android/internal/policy/IKeyguardService.aidl +++ b/core/java/com/android/internal/policy/IKeyguardService.aidl @@ -15,6 +15,7 @@ */ package com.android.internal.policy; +import android.content.Intent; import com.android.internal.policy.IKeyguardDrawnCallback; import com.android.internal.policy.IKeyguardDismissCallback; import com.android.internal.policy.IKeyguardStateCallback; @@ -113,7 +114,20 @@ oneway interface IKeyguardService { /** * Notifies the Keyguard that the power key was pressed while locked and launched Home rather - * than putting the device to sleep or waking up. + * than putting the device to sleep or waking up. Note that it's called only if the device is + * interactive. */ void onShortPowerPressedGoHome(); + + /** + * Notifies the Keyguard that it needs to bring up a bouncer and then launch the intent as soon + * as user unlocks the watch. + */ + void dismissKeyguardToLaunch(in Intent intentToLaunch); + + /** + * Notifies the Keyguard that a key was pressed while locked so the Keyguard can handle it. + * Note that it's called only if the device is interactive. + */ + void onSystemKeyPressed(int keycode); } diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java index fb8ffbd476a6..e738b0248127 100644 --- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java @@ -656,6 +656,7 @@ public class SettingsBackupTest { Settings.Global.Wearable.WRIST_ORIENTATION_MODE, Settings.Global.Wearable.CLOCKWORK_SYSUI_PACKAGE, Settings.Global.Wearable.CLOCKWORK_SYSUI_MAIN_ACTIVITY, + Settings.Global.Wearable.CLOCKWORK_LONG_PRESS_TO_ASSISTANT_ENABLED, Settings.Global.Wearable.WEAR_ACTIVITY_AUTO_RESUME_TIMEOUT_SET_BY_USER); private static final Set<String> BACKUP_DENY_LIST_SECURE_SETTINGS = diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java index 22a69d4012fa..fb31d8870151 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java @@ -583,6 +583,18 @@ public class KeyguardService extends Service { checkPermission(); mKeyguardViewMediator.onShortPowerPressedGoHome(); } + + @Override + public void dismissKeyguardToLaunch(Intent intentToLaunch) { + checkPermission(); + mKeyguardViewMediator.dismissKeyguardToLaunch(intentToLaunch); + } + + @Override + public void onSystemKeyPressed(int keycode) { + checkPermission(); + mKeyguardViewMediator.onSystemKeyPressed(keycode); + } }; } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index c14d32ed5a6e..3ba926b54c83 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -2746,6 +2746,14 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, // do nothing } + public void dismissKeyguardToLaunch(Intent intentToLaunch) { + // do nothing + } + + public void onSystemKeyPressed(int keycode) { + // do nothing + } + public ViewMediatorCallback getViewMediatorCallback() { return mViewMediatorCallback; } diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 298f102e26cd..4cced17917f6 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -363,6 +363,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { public static final int TOAST_WINDOW_TIMEOUT = 3500 + TOAST_WINDOW_ANIM_BUFFER; /** + * Action for launching assistant in retail mode + */ + private static final String ACTION_VOICE_ASSIST_RETAIL = + "android.intent.action.VOICE_ASSIST_RETAIL"; + + /** * Lock protecting internal state. Must not call out into window * manager with lock held. (This lock will be acquired in places * where the window manager is calling in with its own lock held.) @@ -1090,29 +1096,35 @@ public class PhoneWindowManager implements WindowManagerPolicy { mPowerManager.boostScreenBrightness(eventTime); break; case MULTI_PRESS_POWER_LAUNCH_TARGET_ACTIVITY: - if (DEBUG_INPUT) { - Slog.d(TAG, "Executing the double press power action."); - } + launchTargetActivityOnMultiPressPower(); + break; + } + } + + private void launchTargetActivityOnMultiPressPower() { + if (DEBUG_INPUT) { + Slog.d(TAG, "Executing the double press power action."); + } + if (mPowerDoublePressTargetActivity != null) { + Intent intent = new Intent(); + intent.setComponent(mPowerDoublePressTargetActivity); + ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity( + intent, /* flags= */0); + if (resolveInfo != null) { final boolean keyguardActive = mKeyguardDelegate != null && mKeyguardDelegate.isShowing(); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); if (!keyguardActive) { - Intent intent = new Intent(); - if (mPowerDoublePressTargetActivity != null) { - intent.setComponent(mPowerDoublePressTargetActivity); - ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity( - intent, /* flags= */0); - if (resolveInfo != null) { - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); - startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); - } else { - Slog.e(TAG, "Could not resolve activity with : " - + mPowerDoublePressTargetActivity.flattenToString() - + " name."); - } - } + startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); + } else { + mKeyguardDelegate.dismissKeyguardToLaunch(intent); } - break; + } else { + Slog.e(TAG, "Could not resolve activity with : " + + mPowerDoublePressTargetActivity.flattenToString() + + " name."); + } } } @@ -1242,6 +1254,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { return LONG_PRESS_POWER_GLOBAL_ACTIONS; } + // If long press to launch assistant is disabled in settings, do nothing. + if (mLongPressOnPowerBehavior == LONG_PRESS_POWER_GO_TO_VOICE_ASSIST + && !isLongPressToAssistantEnabled(mContext)) { + return LONG_PRESS_POWER_NOTHING; + } + return mLongPressOnPowerBehavior; } @@ -1273,6 +1291,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); + } else { + // If keyguarded then notify the keyguard. + mKeyguardDelegate.onSystemKeyPressed(KeyEvent.KEYCODE_STEM_PRIMARY); } break; } @@ -3218,17 +3239,50 @@ public class PhoneWindowManager implements WindowManagerPolicy { .getSystemService(Context.SEARCH_SERVICE)).launchAssist(args); } - /** Launches ACTION_VOICE_ASSIST. Does nothing on keyguard. */ + /** + * Launches ACTION_VOICE_ASSIST_RETAIL if in retail mode, or ACTION_VOICE_ASSIST otherwise + * Does nothing on keyguard except for watches. Delegates it to keyguard if present on watch. + */ private void launchVoiceAssist(boolean allowDuringSetup) { - final boolean keyguardActive = mKeyguardDelegate == null - ? false - : mKeyguardDelegate.isShowing(); + final boolean keyguardActive = + mKeyguardDelegate != null && mKeyguardDelegate.isShowing(); if (!keyguardActive) { - Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); - startActivityAsUser(intent, null, UserHandle.CURRENT_OR_SELF, + if (mHasFeatureWatch && isInRetailMode()) { + launchRetailVoiceAssist(allowDuringSetup); + } else { + startVoiceAssistIntent(allowDuringSetup); + } + } else { + mKeyguardDelegate.dismissKeyguardToLaunch(new Intent(Intent.ACTION_VOICE_ASSIST)); + } + } + + private void launchRetailVoiceAssist(boolean allowDuringSetup) { + Intent retailIntent = new Intent(ACTION_VOICE_ASSIST_RETAIL); + ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity( + retailIntent, /* flags= */0); + if (resolveInfo != null) { + retailIntent.setComponent( + new ComponentName(resolveInfo.activityInfo.packageName, + resolveInfo.activityInfo.name)); + startActivityAsUser(retailIntent, null, UserHandle.CURRENT_OR_SELF, allowDuringSetup); + } else { + Slog.w(TAG, "Couldn't find an app to process " + ACTION_VOICE_ASSIST_RETAIL + + ". Fall back to start " + Intent.ACTION_VOICE_ASSIST); + startVoiceAssistIntent(allowDuringSetup); } + } + private void startVoiceAssistIntent(boolean allowDuringSetup) { + Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); + startActivityAsUser(intent, null, UserHandle.CURRENT_OR_SELF, + allowDuringSetup); + } + + private boolean isInRetailMode() { + return Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.DEVICE_DEMO_MODE, 0) == 1; } private void startActivityAsUser(Intent intent, UserHandle handle) { @@ -5824,6 +5878,18 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } + public static boolean isLongPressToAssistantEnabled(Context context) { + ContentResolver resolver = context.getContentResolver(); + int longPressToAssistant = Settings.System.getIntForUser(resolver, + Settings.Global.Wearable.CLOCKWORK_LONG_PRESS_TO_ASSISTANT_ENABLED, + /* def= */ 1, + UserHandle.USER_CURRENT); + if(Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "longPressToAssistant = " + longPressToAssistant); + } + return (longPressToAssistant == 1); + } + private class HdmiVideoExtconUEventObserver extends ExtconStateObserver<Boolean> { private static final String HDMI_EXIST = "HDMI=1"; private static final String NAME = "hdmi"; diff --git a/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java b/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java index 0080ec6cc989..97a57e066fc7 100644 --- a/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java +++ b/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java @@ -415,6 +415,17 @@ public class KeyguardServiceDelegate { } } + public void dismissKeyguardToLaunch(Intent intentToLaunch) { + if (mKeyguardService != null) { + mKeyguardService.dismissKeyguardToLaunch(intentToLaunch); + } + } + public void onSystemKeyPressed(int keycode) { + if (mKeyguardService != null) { + mKeyguardService.onSystemKeyPressed(keycode); + } + } + public void dumpDebug(ProtoOutputStream proto, long fieldId) { final long token = proto.start(fieldId); proto.write(SHOWING, mKeyguardState.showing); diff --git a/services/core/java/com/android/server/policy/keyguard/KeyguardServiceWrapper.java b/services/core/java/com/android/server/policy/keyguard/KeyguardServiceWrapper.java index 2029f869802e..774e26178db3 100644 --- a/services/core/java/com/android/server/policy/keyguard/KeyguardServiceWrapper.java +++ b/services/core/java/com/android/server/policy/keyguard/KeyguardServiceWrapper.java @@ -17,6 +17,7 @@ package com.android.server.policy.keyguard; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.os.IBinder; import android.os.PowerManager; @@ -254,6 +255,24 @@ public class KeyguardServiceWrapper implements IKeyguardService { } } + @Override + public void dismissKeyguardToLaunch(Intent intentToLaunch) { + try { + mService.dismissKeyguardToLaunch(intentToLaunch); + } catch (RemoteException e) { + Slog.w(TAG , "Remote Exception", e); + } + } + + @Override + public void onSystemKeyPressed(int keycode) { + try { + mService.onSystemKeyPressed(keycode); + } catch (RemoteException e) { + Slog.w(TAG , "Remote Exception", e); + } + } + @Override // Binder interface public IBinder asBinder() { return mService.asBinder(); |