Add Stub implementation for DreamOverlayService.
This changelist introduces a stub implementation for DreamOverlayService for test purposes. It also allows DreamManager to set the DreamOverlay. Bug: 204890435 Test: atest DreamOverlayTest Change-Id: Ia59e70d08f76d5928e72e815c990195934292ad5
This commit is contained in:
@@ -257,7 +257,8 @@ package android.app {
|
||||
|
||||
public class DreamManager {
|
||||
method @RequiresPermission(android.Manifest.permission.READ_DREAM_STATE) public boolean isDreaming();
|
||||
method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void setActiveDream(@NonNull android.content.ComponentName);
|
||||
method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void setActiveDream(@Nullable android.content.ComponentName);
|
||||
method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void setDreamOverlay(@Nullable android.content.ComponentName);
|
||||
method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void startDream(@NonNull android.content.ComponentName);
|
||||
method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void stopDream();
|
||||
}
|
||||
@@ -2364,6 +2365,17 @@ package android.service.autofill.augmented {
|
||||
|
||||
}
|
||||
|
||||
package android.service.dreams {
|
||||
|
||||
public abstract class DreamOverlayService extends android.app.Service {
|
||||
ctor public DreamOverlayService();
|
||||
method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
|
||||
method public abstract void onStartDream(@NonNull android.view.WindowManager.LayoutParams);
|
||||
method public final void requestExit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package android.service.notification {
|
||||
|
||||
@Deprecated public abstract class ConditionProviderService extends android.app.Service {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.app;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SystemService;
|
||||
import android.annotation.TestApi;
|
||||
@@ -91,10 +92,30 @@ public class DreamManager {
|
||||
@TestApi
|
||||
@UserHandleAware
|
||||
@RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE)
|
||||
public void setActiveDream(@NonNull ComponentName dreamComponent) {
|
||||
public void setActiveDream(@Nullable ComponentName dreamComponent) {
|
||||
ComponentName[] dreams = {dreamComponent};
|
||||
|
||||
try {
|
||||
mService.setDreamComponentsForUser(mContext.getUserId(), dreams);
|
||||
mService.setDreamComponentsForUser(mContext.getUserId(),
|
||||
dreamComponent != null ? dreams : null);
|
||||
} catch (RemoteException e) {
|
||||
e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the active dream on the device to be "dreamComponent".
|
||||
*
|
||||
* <p>This is only used for testing the dream service APIs.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@UserHandleAware
|
||||
@RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE)
|
||||
public void setDreamOverlay(@Nullable ComponentName dreamOverlayComponent) {
|
||||
try {
|
||||
mService.registerDreamOverlayService(dreamOverlayComponent);
|
||||
} catch (RemoteException e) {
|
||||
e.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
77
core/java/android/service/dreams/DreamOverlayService.java
Normal file
77
core/java/android/service/dreams/DreamOverlayService.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.service.dreams;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.TestApi;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
|
||||
/**
|
||||
* Basic implementation of for {@link IDreamOverlay} for testing.
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
public abstract class DreamOverlayService extends Service {
|
||||
private static final String TAG = "DreamOverlayService";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
|
||||
@Override
|
||||
public void startDream(WindowManager.LayoutParams layoutParams,
|
||||
IDreamOverlayCallback callback) {
|
||||
mDreamOverlayCallback = callback;
|
||||
onStartDream(layoutParams);
|
||||
}
|
||||
};
|
||||
|
||||
IDreamOverlayCallback mDreamOverlayCallback;
|
||||
|
||||
public DreamOverlayService() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public final IBinder onBind(@NonNull Intent intent) {
|
||||
return mDreamOverlay.asBinder();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is overridden by implementations to handle when the dream has started and the
|
||||
* window is ready to be interacted with.
|
||||
* @param layoutParams The {@link android.view.WindowManager.LayoutParams} associated with the
|
||||
* dream window.
|
||||
*/
|
||||
public abstract void onStartDream(@NonNull WindowManager.LayoutParams layoutParams);
|
||||
|
||||
/**
|
||||
* This method is invoked to request the dream exit.
|
||||
*/
|
||||
public final void requestExit() {
|
||||
try {
|
||||
mDreamOverlayCallback.onExitRequested();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Could not request exit:" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user