diff options
author | Lucas Dupin <dupin@google.com> | 2017-08-22 12:51:25 -0700 |
---|---|---|
committer | Lucas Dupin <dupin@google.com> | 2017-12-18 11:28:16 -0800 |
commit | 7517b5dcce8dde3a22177857b8fff6439fd98d82 (patch) | |
tree | 900e0ee61f60bdae4980648e1c73ca45c140fb48 /tests/Internal | |
parent | 53b2d749240f8c689b04155a960b75c40c00aba8 (diff) |
Support wallpapers in AoD
Such wallpaper has to define supportsAmbientMode,
and set it to true on its android.service.wallpaper
meta data.
Also introduces WallpaperService.Engine#onAmbientModeChanged
to notify a live wallpaper that the display state has changed.
Change-Id: I49e846069a698b3cc3bb6e7cda98172920eaae4c
Bug: 64155983
Test: runtest -x frameworks/base/packages/SystemUI/tests/src/com/android/systemui/doze/DozeWallpaperStateTest.java
Test: runtest -x frameworks/base/tests/Internal/src/android/app/WallpaperInfoTest.java
Test: runtest -x frameworks/base/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java
Test: set AoD wallpaper, go to aod, lock screen, launcher
Test: set regular wallpaper, go to aod, lock screen, launcher
Diffstat (limited to 'tests/Internal')
-rw-r--r-- | tests/Internal/Android.mk | 1 | ||||
-rw-r--r-- | tests/Internal/AndroidManifest.xml | 16 | ||||
-rw-r--r-- | tests/Internal/res/xml/livewallpaper.xml | 20 | ||||
-rw-r--r-- | tests/Internal/src/android/app/WallpaperInfoTest.java | 68 | ||||
-rw-r--r-- | tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java | 61 | ||||
-rw-r--r-- | tests/Internal/src/stub/DummyWallpaperService.java | 29 |
6 files changed, 195 insertions, 0 deletions
diff --git a/tests/Internal/Android.mk b/tests/Internal/Android.mk index 73181ec36e17..b69e3e4fdd4b 100644 --- a/tests/Internal/Android.mk +++ b/tests/Internal/Android.mk @@ -14,6 +14,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := junit \ android-support-test \ mockito-target-minus-junit4 +LOCAL_JAVA_RESOURCE_DIRS := res LOCAL_CERTIFICATE := platform LOCAL_PACKAGE_NAME := InternalTests diff --git a/tests/Internal/AndroidManifest.xml b/tests/Internal/AndroidManifest.xml index a2c95fbbfc0b..e5a56949fe4e 100644 --- a/tests/Internal/AndroidManifest.xml +++ b/tests/Internal/AndroidManifest.xml @@ -18,8 +18,24 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.internal.tests"> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> + <uses-permission android:name="android.permission.BIND_WALLPAPER" /> <application> <uses-library android:name="android.test.runner" /> + + <service android:name="stub.DummyWallpaperService" + android:enabled="true" + android:directBootAware="true" + android:label="Dummy wallpaper" + android:permission="android.permission.BIND_WALLPAPER"> + + <intent-filter> + <action android:name="android.service.wallpaper.WallpaperService" /> + </intent-filter> + + <!-- Link to XML that defines the wallpaper info. --> + <meta-data android:name="android.service.wallpaper" + android:resource="@xml/livewallpaper" /> + </service> </application> <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner" diff --git a/tests/Internal/res/xml/livewallpaper.xml b/tests/Internal/res/xml/livewallpaper.xml new file mode 100644 index 000000000000..dbb0e4761cba --- /dev/null +++ b/tests/Internal/res/xml/livewallpaper.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2017 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 + --> +<wallpaper + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" + androidprv:supportsAmbientMode="true"/>
\ No newline at end of file diff --git a/tests/Internal/src/android/app/WallpaperInfoTest.java b/tests/Internal/src/android/app/WallpaperInfoTest.java new file mode 100644 index 000000000000..9d26270fb96a --- /dev/null +++ b/tests/Internal/src/android/app/WallpaperInfoTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2017 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.app; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.os.Parcel; +import android.service.wallpaper.WallpaperService; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.List; + +/** + * Tests for hidden WallpaperInfo methods. + */ +@RunWith(AndroidJUnit4.class) +@SmallTest +public class WallpaperInfoTest { + + @Test + public void testSupportsAmbientMode() throws Exception { + Context context = InstrumentationRegistry.getTargetContext(); + + Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); + intent.setPackage("com.android.internal.tests"); + PackageManager pm = context.getPackageManager(); + List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA); + assertEquals(1, result.size()); + ResolveInfo info = result.get(0); + WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info); + + // Defined as true in the XML + assertTrue("supportsAmbientMode should be true, as defined in the XML.", + wallpaperInfo.getSupportsAmbientMode()); + Parcel parcel = Parcel.obtain(); + wallpaperInfo.writeToParcel(parcel, 0 /* flags */); + parcel.setDataPosition(0); + WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel); + assertTrue("supportsAmbientMode should have been restored from parcelable", + fromParcel.getSupportsAmbientMode()); + parcel.recycle(); + } +} + diff --git a/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java b/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java new file mode 100644 index 000000000000..f7ce2c72d37e --- /dev/null +++ b/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017 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.wallpaper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.support.test.filters.SmallTest; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@SmallTest +@RunWith(JUnit4.class) +public class WallpaperServiceTest { + + @Test + public void testDeliversAmbientModeChanged() { + int[] ambientModeChangedCount = {0}; + WallpaperService service = new WallpaperService() { + @Override + public Engine onCreateEngine() { + return new Engine() { + @Override + public void onAmbientModeChanged(boolean inAmbientMode) { + ambientModeChangedCount[0]++; + } + }; + } + }; + WallpaperService.Engine engine = service.onCreateEngine(); + engine.setCreated(true); + + engine.doAmbientModeChanged(false); + assertFalse("ambient mode should be false", engine.isInAmbientMode()); + assertEquals("onAmbientModeChanged should have been called", + ambientModeChangedCount[0], 1); + + engine.doAmbientModeChanged(true); + assertTrue("ambient mode should be false", engine.isInAmbientMode()); + assertEquals("onAmbientModeChanged should have been called", + ambientModeChangedCount[0], 2); + } + +} diff --git a/tests/Internal/src/stub/DummyWallpaperService.java b/tests/Internal/src/stub/DummyWallpaperService.java new file mode 100644 index 000000000000..084c036bea26 --- /dev/null +++ b/tests/Internal/src/stub/DummyWallpaperService.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2017 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 stub; + +import android.service.wallpaper.WallpaperService; + +/** + * Dummy wallpaper service only for test purposes, won't draw anything. + */ +public class DummyWallpaperService extends WallpaperService { + @Override + public Engine onCreateEngine() { + return new Engine(); + } +} |