Add Callback to wake up from Dream when DreamActivity is destroyed.

When a DreamActivity is destroyed, the devices remains in a dream state.
This makes it look like the DreamActivity is stuck in the background but
it is actually destroyed and DreamService does not allow another Dream
to take its place.

Bug: 242368903
Bug: 241569844
Test: Manually tested by checking that when a DreamActivity is destroyed
the device wakes up from dreaming.

Change-Id: Idcb38f2332f3a8dea0add78a4ca506877aeca8f7
This commit is contained in:
Victor Truong
2022-08-24 13:55:04 -04:00
committed by Lucas Silva
parent a122bd8f40
commit feb3aa71f9
2 changed files with 23 additions and 7 deletions

View File

@@ -44,6 +44,8 @@ import android.text.TextUtils;
public class DreamActivity extends Activity {
static final String EXTRA_CALLBACK = "binder";
static final String EXTRA_DREAM_TITLE = "title";
@Nullable
private DreamService.DreamActivityCallbacks mCallback;
public DreamActivity() {}
@@ -57,11 +59,19 @@ public class DreamActivity extends Activity {
}
final Bundle extras = getIntent().getExtras();
final DreamService.DreamActivityCallback callback =
(DreamService.DreamActivityCallback) extras.getBinder(EXTRA_CALLBACK);
mCallback = (DreamService.DreamActivityCallbacks) extras.getBinder(EXTRA_CALLBACK);
if (callback != null) {
callback.onActivityCreated(this);
if (mCallback != null) {
mCallback.onActivityCreated(this);
}
}
@Override
public void onDestroy() {
if (mCallback != null) {
mCallback.onActivityDestroyed();
}
super.onDestroy();
}
}

View File

@@ -1295,7 +1295,7 @@ public class DreamService extends Service implements Window.Callback {
Intent i = new Intent(this, DreamActivity.class);
i.setPackage(getApplicationContext().getPackageName());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(DreamActivity.EXTRA_CALLBACK, new DreamActivityCallback(mDreamToken));
i.putExtra(DreamActivity.EXTRA_CALLBACK, new DreamActivityCallbacks(mDreamToken));
final ServiceInfo serviceInfo = fetchServiceInfo(this,
new ComponentName(this, getClass()));
i.putExtra(DreamActivity.EXTRA_DREAM_TITLE, fetchDreamLabel(this, serviceInfo));
@@ -1488,10 +1488,10 @@ public class DreamService extends Service implements Window.Callback {
}
/** @hide */
final class DreamActivityCallback extends Binder {
final class DreamActivityCallbacks extends Binder {
private final IBinder mActivityDreamToken;
DreamActivityCallback(IBinder token) {
DreamActivityCallbacks(IBinder token) {
mActivityDreamToken = token;
}
@@ -1516,6 +1516,12 @@ public class DreamService extends Service implements Window.Callback {
mActivity = activity;
onWindowCreated(activity.getWindow());
}
// If DreamActivity is destroyed, wake up from Dream.
void onActivityDestroyed() {
mActivity = null;
onDestroy();
}
}
/**