Merge "Upstream Wear Keyguard changes"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c2dc611aca
@@ -17058,6 +17058,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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -657,6 +657,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 =
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2750,6 +2750,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;
|
||||
}
|
||||
|
||||
@@ -362,6 +362,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
|
||||
@@ -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,
|
||||
allowDuringSetup);
|
||||
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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user