Merge "VDM demo for android:turnScreenOn and android:showWhenLocked" into main
diff --git a/samples/VirtualDeviceManager/README.md b/samples/VirtualDeviceManager/README.md
index 0c799f9..1f4f11c 100644
--- a/samples/VirtualDeviceManager/README.md
+++ b/samples/VirtualDeviceManager/README.md
@@ -405,7 +405,8 @@
use. By default, will use the sensors of the device it's shown on.
- **Display Power**: A simple activity showcasing the behavior of proximity
- locks, screen brightness override and requesting the screen to be kept on.
+ locks, screen brightness override and requesting the screen to be kept on
+ or turned on.
- **Rotation**: A simple activity that is in landscape by default and can send
orientation change requests on demand. Showcases the display rotation on the
diff --git a/samples/VirtualDeviceManager/demos/AndroidManifest.xml b/samples/VirtualDeviceManager/demos/AndroidManifest.xml
index 1702404..ab5fc50 100644
--- a/samples/VirtualDeviceManager/demos/AndroidManifest.xml
+++ b/samples/VirtualDeviceManager/demos/AndroidManifest.xml
@@ -130,6 +130,13 @@
android:exported="false"
android:label="@string/turn_screen_on_activity" />
+ <activity
+ android:name=".TurnScreenOnShowWhenLockedActivity"
+ android:turnScreenOn="true"
+ android:showWhenLocked="true"
+ android:exported="false"
+ android:label="@string/turn_screen_on_show_when_locked_activity" />
+
</application>
<!-- LINT.ThenChange(/samples/VirtualDeviceManager/README.md:demos) -->
</manifest>
\ No newline at end of file
diff --git a/samples/VirtualDeviceManager/demos/res/layout/display_power_demo_activity.xml b/samples/VirtualDeviceManager/demos/res/layout/display_power_demo_activity.xml
index f3489a5..e7ec66b 100644
--- a/samples/VirtualDeviceManager/demos/res/layout/display_power_demo_activity.xml
+++ b/samples/VirtualDeviceManager/demos/res/layout/display_power_demo_activity.xml
@@ -42,4 +42,10 @@
android:onClick="onLaunchTurnScreenOnActivity"
android:text="Launch Turn Screen On Activity" />
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="onLaunchTurnScreenOnShowWhenLockedActivity"
+ android:text="Launch Turn Screen On Show When Locked Activity" />
+
</LinearLayout>
\ No newline at end of file
diff --git a/samples/VirtualDeviceManager/demos/res/values/strings.xml b/samples/VirtualDeviceManager/demos/res/values/strings.xml
index 3f747fb..adc209a 100644
--- a/samples/VirtualDeviceManager/demos/res/values/strings.xml
+++ b/samples/VirtualDeviceManager/demos/res/values/strings.xml
@@ -17,6 +17,7 @@
<string name="opted_out_activity" translatable="false">VDM Opted Out Activity</string>
<string name="blocked_activity" translatable="false">VDM Blocked Activity</string>
<string name="turn_screen_on_activity" translatable="false">VDM Turn Screen On Activity</string>
+ <string name="turn_screen_on_show_when_locked_activity" translatable="false">VDM Turn Screen On Show When Locked Activity</string>
<string name="display_category" translatable="false">com.example.android.vdmdemo.DISPLAY_CATEGORY</string>
@@ -36,7 +37,8 @@
<string name="opted_out_activity_text" translatable="false">This activity can not be launched on the virtual device because cas opted out via canDisplayOnRemoteDevices</string>
<string name="blocked_activity_text" translatable="false">This activity can not be launched on the virtual device because of the activity policy of the virtual device</string>
<string name="calculator_text" translatable="false">This \"calculator\" activity can only be shown on displays with the matching category</string>
- <string name="turn_screen_on_activity_text" translatable="false">This activity should turn the screen on</string>
+ <string name="turn_screen_on_activity_text" translatable="false">This activity should turn the screen on if the device is not locked</string>
+ <string name="turn_screen_on_show_when_locked_activity_text" translatable="false">This activity should turn the screen on even when the device is locked</string>
<string name="request_device_aware_permissions" translatable="false">Request device aware permissions</string>
<string name="revoke_device_aware_permissions" translatable="false">Revoke device aware permissions</string>
diff --git a/samples/VirtualDeviceManager/demos/src/com/example/android/vdmdemo/demos/DisplayPowerDemoActivity.java b/samples/VirtualDeviceManager/demos/src/com/example/android/vdmdemo/demos/DisplayPowerDemoActivity.java
index 174d526..8770c2b 100644
--- a/samples/VirtualDeviceManager/demos/src/com/example/android/vdmdemo/demos/DisplayPowerDemoActivity.java
+++ b/samples/VirtualDeviceManager/demos/src/com/example/android/vdmdemo/demos/DisplayPowerDemoActivity.java
@@ -96,7 +96,16 @@
/** Launches an activity with android:turnScreenOn */
public void onLaunchTurnScreenOnActivity(View v) {
- Intent intent = new Intent(this, TurnScreenOnActivity.class);
+ chooseDisplayAndStartActivity(TurnScreenOnActivity.class);
+ }
+
+ /** Launches an activity with android:turnScreenOn and android:showWhenLocked */
+ public void onLaunchTurnScreenOnShowWhenLockedActivity(View v) {
+ chooseDisplayAndStartActivity(TurnScreenOnShowWhenLockedActivity.class);
+ }
+
+ private void chooseDisplayAndStartActivity(Class<?> cls) {
+ Intent intent = new Intent(this, cls);
DisplayManager displayManager = getSystemService(DisplayManager.class);
Display[] displays = displayManager.getDisplays();
diff --git a/samples/VirtualDeviceManager/demos/src/com/example/android/vdmdemo/demos/TurnScreenOnShowWhenLockedActivity.java b/samples/VirtualDeviceManager/demos/src/com/example/android/vdmdemo/demos/TurnScreenOnShowWhenLockedActivity.java
new file mode 100644
index 0000000..b08271a
--- /dev/null
+++ b/samples/VirtualDeviceManager/demos/src/com/example/android/vdmdemo/demos/TurnScreenOnShowWhenLockedActivity.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2024 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 com.example.android.vdmdemo.demos;
+
+import android.os.Bundle;
+import android.widget.TextView;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+/** Activity that has android:turnScreenOn and android:showWhenLocked. */
+public final class TurnScreenOnShowWhenLockedActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.text_demo_activity);
+ ((TextView) requireViewById(R.id.text))
+ .setText(R.string.turn_screen_on_show_when_locked_activity_text);
+ }
+}