Merge "Dismiss dream when activities are started while dreaming." into tm-dev

This commit is contained in:
Lucas Silva
2022-04-28 20:55:18 +00:00
committed by Android (Google) Code Review
4 changed files with 51 additions and 2 deletions

View File

@@ -2415,8 +2415,12 @@
<!-- Is the system user the only user allowed to dream. --> <!-- Is the system user the only user allowed to dream. -->
<bool name="config_dreamsOnlyEnabledForSystemUser">false</bool> <bool name="config_dreamsOnlyEnabledForSystemUser">false</bool>
<!-- Whether to dismiss the active dream when an activity is started. Doesn't apply to
assistant activities (ACTIVITY_TYPE_ASSISTANT) -->
<bool name="config_dismissDreamOnActivityStart">true</bool>
<!-- The prefix of dream component names that are loggable. If empty, logs "other" for all. --> <!-- The prefix of dream component names that are loggable. If empty, logs "other" for all. -->
<string name ="config_loggable_dream_prefix" translatable="false"></string> <string name="config_loggable_dream_prefix" translatable="false"></string>
<!-- ComponentName of a dream to show whenever the system would otherwise have <!-- ComponentName of a dream to show whenever the system would otherwise have
gone to sleep. When the PowerManager is asked to go to sleep, it will instead gone to sleep. When the PowerManager is asked to go to sleep, it will instead

View File

@@ -2221,6 +2221,7 @@
<java-symbol type="array" name="config_supportedDreamComplications" /> <java-symbol type="array" name="config_supportedDreamComplications" />
<java-symbol type="array" name="config_dreamComplicationsEnabledByDefault" /> <java-symbol type="array" name="config_dreamComplicationsEnabledByDefault" />
<java-symbol type="array" name="config_disabledDreamComponents" /> <java-symbol type="array" name="config_disabledDreamComponents" />
<java-symbol type="bool" name="config_dismissDreamOnActivityStart" />
<java-symbol type="string" name="config_loggable_dream_prefix" /> <java-symbol type="string" name="config_loggable_dream_prefix" />
<java-symbol type="string" name="config_dozeComponent" /> <java-symbol type="string" name="config_dozeComponent" />
<java-symbol type="string" name="enable_explore_by_touch_warning_title" /> <java-symbol type="string" name="enable_explore_by_touch_warning_title" />

View File

@@ -17,13 +17,21 @@
package com.android.server.dreams; package com.android.server.dreams;
import static android.Manifest.permission.BIND_DREAM_SERVICE; import static android.Manifest.permission.BIND_DREAM_SERVICE;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static com.android.server.wm.ActivityInterceptorCallback.DREAM_MANAGER_ORDERED_ID;
import android.annotation.Nullable;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.TaskInfo;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
@@ -54,6 +62,7 @@ import com.android.internal.util.DumpUtils;
import com.android.server.FgThread; import com.android.server.FgThread;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.SystemService; import com.android.server.SystemService;
import com.android.server.wm.ActivityInterceptorCallback;
import com.android.server.wm.ActivityTaskManagerInternal; import com.android.server.wm.ActivityTaskManagerInternal;
import java.io.FileDescriptor; import java.io.FileDescriptor;
@@ -83,6 +92,7 @@ public final class DreamManagerService extends SystemService {
private final UiEventLogger mUiEventLogger; private final UiEventLogger mUiEventLogger;
private final DreamUiEventLogger mDreamUiEventLogger; private final DreamUiEventLogger mDreamUiEventLogger;
private final ComponentName mAmbientDisplayComponent; private final ComponentName mAmbientDisplayComponent;
private final boolean mDismissDreamOnActivityStart;
private Binder mCurrentDreamToken; private Binder mCurrentDreamToken;
private ComponentName mCurrentDreamName; private ComponentName mCurrentDreamName;
@@ -99,6 +109,26 @@ public final class DreamManagerService extends SystemService {
private ComponentName mDreamOverlayServiceName; private ComponentName mDreamOverlayServiceName;
private AmbientDisplayConfiguration mDozeConfig; private AmbientDisplayConfiguration mDozeConfig;
private final ActivityInterceptorCallback mActivityInterceptorCallback =
new ActivityInterceptorCallback() {
@Nullable
@Override
public ActivityInterceptResult intercept(ActivityInterceptorInfo info) {
return null;
}
@Override
public void onActivityLaunched(TaskInfo taskInfo, ActivityInfo activityInfo,
ActivityInterceptorInfo info) {
final int activityType = taskInfo.getActivityType();
final boolean activityAllowed = activityType == ACTIVITY_TYPE_HOME
|| activityType == ACTIVITY_TYPE_DREAM
|| activityType == ACTIVITY_TYPE_ASSISTANT;
if (mCurrentDreamToken != null && !mCurrentDreamIsWaking && !activityAllowed) {
stopDreamInternal(false, "activity starting: " + activityInfo.name);
}
}
};
public DreamManagerService(Context context) { public DreamManagerService(Context context) {
super(context); super(context);
@@ -118,6 +148,8 @@ public final class DreamManagerService extends SystemService {
mAmbientDisplayComponent = ComponentName.unflattenFromString(adc.ambientDisplayComponent()); mAmbientDisplayComponent = ComponentName.unflattenFromString(adc.ambientDisplayComponent());
mDreamsOnlyEnabledForSystemUser = mDreamsOnlyEnabledForSystemUser =
mContext.getResources().getBoolean(R.bool.config_dreamsOnlyEnabledForSystemUser); mContext.getResources().getBoolean(R.bool.config_dreamsOnlyEnabledForSystemUser);
mDismissDreamOnActivityStart = mContext.getResources().getBoolean(
R.bool.config_dismissDreamOnActivityStart);
} }
@Override @Override
@@ -145,6 +177,12 @@ public final class DreamManagerService extends SystemService {
Settings.Secure.getUriFor(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE), false, Settings.Secure.getUriFor(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE), false,
mDozeEnabledObserver, UserHandle.USER_ALL); mDozeEnabledObserver, UserHandle.USER_ALL);
writePulseGestureEnabled(); writePulseGestureEnabled();
if (mDismissDreamOnActivityStart) {
mAtmInternal.registerActivityStartInterceptor(
DREAM_MANAGER_ORDERED_ID,
mActivityInterceptorCallback);
}
} }
} }

View File

@@ -61,6 +61,7 @@ public abstract class ActivityInterceptorCallback {
PERMISSION_POLICY_ORDERED_ID, PERMISSION_POLICY_ORDERED_ID,
INTENT_RESOLVER_ORDERED_ID, INTENT_RESOLVER_ORDERED_ID,
VIRTUAL_DEVICE_SERVICE_ORDERED_ID, VIRTUAL_DEVICE_SERVICE_ORDERED_ID,
DREAM_MANAGER_ORDERED_ID,
LAST_ORDERED_ID // Update this when adding new ids LAST_ORDERED_ID // Update this when adding new ids
}) })
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@@ -87,11 +88,16 @@ public abstract class ActivityInterceptorCallback {
*/ */
public static final int VIRTUAL_DEVICE_SERVICE_ORDERED_ID = 3; public static final int VIRTUAL_DEVICE_SERVICE_ORDERED_ID = 3;
/**
* The identifier for {@link com.android.server.dreams.DreamManagerService} interceptor.
*/
public static final int DREAM_MANAGER_ORDERED_ID = 4;
/** /**
* The final id, used by the framework to determine the valid range of ids. Update this when * The final id, used by the framework to determine the valid range of ids. Update this when
* adding new ids. * adding new ids.
*/ */
static final int LAST_ORDERED_ID = VIRTUAL_DEVICE_SERVICE_ORDERED_ID; static final int LAST_ORDERED_ID = DREAM_MANAGER_ORDERED_ID;
/** /**
* Data class for storing the various arguments needed for activity interception. * Data class for storing the various arguments needed for activity interception.