Merge "Add special label to denote dream in preview mode" into tm-qpr-dev
This commit is contained in:
@@ -1306,7 +1306,8 @@ public class DreamService extends Service implements Window.Callback {
|
|||||||
* @param dreamToken Token for this dream service.
|
* @param dreamToken Token for this dream service.
|
||||||
* @param started A callback that will be invoked once onDreamingStarted has completed.
|
* @param started A callback that will be invoked once onDreamingStarted has completed.
|
||||||
*/
|
*/
|
||||||
private void attach(IBinder dreamToken, boolean canDoze, IRemoteCallback started) {
|
private void attach(IBinder dreamToken, boolean canDoze, boolean isPreviewMode,
|
||||||
|
IRemoteCallback started) {
|
||||||
if (mDreamToken != null) {
|
if (mDreamToken != null) {
|
||||||
Slog.e(mTag, "attach() called when dream with token=" + mDreamToken
|
Slog.e(mTag, "attach() called when dream with token=" + mDreamToken
|
||||||
+ " already attached");
|
+ " already attached");
|
||||||
@@ -1354,7 +1355,8 @@ public class DreamService extends Service implements Window.Callback {
|
|||||||
i.putExtra(DreamActivity.EXTRA_CALLBACK, new DreamActivityCallbacks(mDreamToken));
|
i.putExtra(DreamActivity.EXTRA_CALLBACK, new DreamActivityCallbacks(mDreamToken));
|
||||||
final ServiceInfo serviceInfo = fetchServiceInfo(this,
|
final ServiceInfo serviceInfo = fetchServiceInfo(this,
|
||||||
new ComponentName(this, getClass()));
|
new ComponentName(this, getClass()));
|
||||||
i.putExtra(DreamActivity.EXTRA_DREAM_TITLE, fetchDreamLabel(this, serviceInfo));
|
i.putExtra(DreamActivity.EXTRA_DREAM_TITLE,
|
||||||
|
fetchDreamLabel(this, serviceInfo, isPreviewMode));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!ActivityTaskManager.getService().startDreamActivity(i)) {
|
if (!ActivityTaskManager.getService().startDreamActivity(i)) {
|
||||||
@@ -1470,10 +1472,18 @@ public class DreamService extends Service implements Window.Callback {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static CharSequence fetchDreamLabel(Context context,
|
private static CharSequence fetchDreamLabel(Context context,
|
||||||
@Nullable ServiceInfo serviceInfo) {
|
@Nullable ServiceInfo serviceInfo,
|
||||||
if (serviceInfo == null) return null;
|
boolean isPreviewMode) {
|
||||||
|
if (serviceInfo == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final PackageManager pm = context.getPackageManager();
|
final PackageManager pm = context.getPackageManager();
|
||||||
return serviceInfo.loadLabel(pm);
|
final CharSequence dreamLabel = serviceInfo.loadLabel(pm);
|
||||||
|
if (!isPreviewMode || dreamLabel == null) {
|
||||||
|
return dreamLabel;
|
||||||
|
}
|
||||||
|
// When in preview mode, return a special label indicating the dream is in preview.
|
||||||
|
return context.getResources().getString(R.string.dream_preview_title, dreamLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -1529,8 +1539,9 @@ public class DreamService extends Service implements Window.Callback {
|
|||||||
final class DreamServiceWrapper extends IDreamService.Stub {
|
final class DreamServiceWrapper extends IDreamService.Stub {
|
||||||
@Override
|
@Override
|
||||||
public void attach(final IBinder dreamToken, final boolean canDoze,
|
public void attach(final IBinder dreamToken, final boolean canDoze,
|
||||||
IRemoteCallback started) {
|
final boolean isPreviewMode, IRemoteCallback started) {
|
||||||
mHandler.post(() -> DreamService.this.attach(dreamToken, canDoze, started));
|
mHandler.post(
|
||||||
|
() -> DreamService.this.attach(dreamToken, canDoze, isPreviewMode, started));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import android.os.IRemoteCallback;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
oneway interface IDreamService {
|
oneway interface IDreamService {
|
||||||
void attach(IBinder windowToken, boolean canDoze, IRemoteCallback started);
|
void attach(IBinder windowToken, boolean canDoze, boolean isPreviewMode, IRemoteCallback started);
|
||||||
void detach();
|
void detach();
|
||||||
void wakeUp();
|
void wakeUp();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -975,6 +975,11 @@
|
|||||||
<!-- Description for the capability of an accessibility service to take screenshot. [CHAR LIMIT=NONE] -->
|
<!-- Description for the capability of an accessibility service to take screenshot. [CHAR LIMIT=NONE] -->
|
||||||
<string name="capability_desc_canTakeScreenshot">Can take a screenshot of the display.</string>
|
<string name="capability_desc_canTakeScreenshot">Can take a screenshot of the display.</string>
|
||||||
|
|
||||||
|
<!-- Dream -->
|
||||||
|
|
||||||
|
<!-- The title to use when a dream is opened in preview mode. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="dream_preview_title">Preview, <xliff:g id="dream_name" example="Clock">%1$s</xliff:g></string>
|
||||||
|
|
||||||
<!-- Permissions -->
|
<!-- Permissions -->
|
||||||
|
|
||||||
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
|
|||||||
@@ -4285,6 +4285,8 @@
|
|||||||
<java-symbol type="string" name="capability_desc_canTakeScreenshot" />
|
<java-symbol type="string" name="capability_desc_canTakeScreenshot" />
|
||||||
<java-symbol type="string" name="capability_title_canTakeScreenshot" />
|
<java-symbol type="string" name="capability_title_canTakeScreenshot" />
|
||||||
|
|
||||||
|
<java-symbol type="string" name="dream_preview_title" />
|
||||||
|
|
||||||
<java-symbol type="string" name="config_servicesExtensionPackage" />
|
<java-symbol type="string" name="config_servicesExtensionPackage" />
|
||||||
|
|
||||||
<!-- For app process exit info tracking -->
|
<!-- For app process exit info tracking -->
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ final class DreamController {
|
|||||||
try {
|
try {
|
||||||
service.asBinder().linkToDeath(mCurrentDream, 0);
|
service.asBinder().linkToDeath(mCurrentDream, 0);
|
||||||
service.attach(mCurrentDream.mToken, mCurrentDream.mCanDoze,
|
service.attach(mCurrentDream.mToken, mCurrentDream.mCanDoze,
|
||||||
mCurrentDream.mDreamingStartedCallback);
|
mCurrentDream.mIsPreviewMode, mCurrentDream.mDreamingStartedCallback);
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
Slog.e(TAG, "The dream service died unexpectedly.", ex);
|
Slog.e(TAG, "The dream service died unexpectedly.", ex);
|
||||||
stopDream(true /*immediate*/, "attach failed");
|
stopDream(true /*immediate*/, "attach failed");
|
||||||
|
|||||||
@@ -99,7 +99,24 @@ public class DreamControllerTest {
|
|||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
|
|
||||||
// Verify that dream service is called to attach.
|
// Verify that dream service is called to attach.
|
||||||
verify(mIDreamService).attach(eq(mToken), eq(false) /*doze*/, any());
|
verify(mIDreamService).attach(eq(mToken), eq(false) /*doze*/,
|
||||||
|
eq(false) /*preview*/, any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startDream_attachOnServiceConnectedInPreviewMode() throws RemoteException {
|
||||||
|
// Call dream controller to start dreaming.
|
||||||
|
mDreamController.startDream(mToken, mDreamName, true /*isPreview*/, false /*doze*/,
|
||||||
|
0 /*userId*/, null /*wakeLock*/, mOverlayName, "test" /*reason*/);
|
||||||
|
|
||||||
|
// Mock service connected.
|
||||||
|
final ServiceConnection serviceConnection = captureServiceConnection();
|
||||||
|
serviceConnection.onServiceConnected(mDreamName, mIBinder);
|
||||||
|
mLooper.dispatchAll();
|
||||||
|
|
||||||
|
// Verify that dream service is called to attach.
|
||||||
|
verify(mIDreamService).attach(eq(mToken), eq(false) /*doze*/,
|
||||||
|
eq(true) /*preview*/, any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -129,7 +146,7 @@ public class DreamControllerTest {
|
|||||||
|
|
||||||
// Mock second dream started.
|
// Mock second dream started.
|
||||||
verify(newDreamService).attach(eq(newToken), eq(false) /*doze*/,
|
verify(newDreamService).attach(eq(newToken), eq(false) /*doze*/,
|
||||||
mRemoteCallbackCaptor.capture());
|
eq(false) /*preview*/, mRemoteCallbackCaptor.capture());
|
||||||
mRemoteCallbackCaptor.getValue().sendResult(null /*data*/);
|
mRemoteCallbackCaptor.getValue().sendResult(null /*data*/);
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user