| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import static org.junit.Assert.assertEquals; |
| 20 |
import static org.junit.Assert.assertTrue; |
| 21 |
|
| 22 |
import android.content.Context; |
| 23 |
import android.content.Intent; |
| 24 |
import android.content.pm.PackageManager; |
| 25 |
import android.content.pm.ResolveInfo; |
| 26 |
import android.net.Uri; |
| 27 |
import android.os.Parcel; |
| 28 |
import android.service.wallpaper.WallpaperService; |
| 29 |
|
| 30 |
import androidx.test.InstrumentationRegistry; |
| 31 |
import androidx.test.filters.SmallTest; |
| 32 |
import androidx.test.runner.AndroidJUnit4; |
| 33 |
|
| 34 |
import org.junit.Test; |
| 35 |
import org.junit.runner.RunWith; |
| 36 |
|
| 37 |
import java.util.List; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
@RunWith(AndroidJUnit4.class) |
| 43 |
@SmallTest |
| 44 |
public class WallpaperInfoTest { |
| 45 |
|
| 46 |
@Test |
| 47 |
public void testSupportsAmbientMode() throws Exception { |
| 48 |
Context context = InstrumentationRegistry.getTargetContext(); |
| 49 |
|
| 50 |
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); |
| 51 |
intent.setPackage("com.android.internal.tests"); |
| 52 |
PackageManager pm = context.getPackageManager(); |
| 53 |
List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA); |
| 54 |
assertEquals(1, result.size()); |
| 55 |
ResolveInfo info = result.get(0); |
| 56 |
WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info); |
| 57 |
|
| 58 |
|
| 59 |
assertTrue("supportsAmbientMode should be true, as defined in the XML.", |
| 60 |
wallpaperInfo.supportsAmbientMode()); |
| 61 |
Parcel parcel = Parcel.obtain(); |
| 62 |
wallpaperInfo.writeToParcel(parcel, 0 ); |
| 63 |
parcel.setDataPosition(0); |
| 64 |
WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel); |
| 65 |
assertTrue("supportsAmbientMode should have been restored from parcelable", |
| 66 |
fromParcel.supportsAmbientMode()); |
| 67 |
parcel.recycle(); |
| 68 |
} |
| 69 |
|
| 70 |
@Test |
| 71 |
public void testGetSettingsSliceUri() throws Exception { |
| 72 |
Context context = InstrumentationRegistry.getTargetContext(); |
| 73 |
|
| 74 |
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); |
| 75 |
intent.setPackage("com.android.internal.tests"); |
| 76 |
PackageManager pm = context.getPackageManager(); |
| 77 |
List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA); |
| 78 |
assertEquals(1, result.size()); |
| 79 |
ResolveInfo info = result.get(0); |
| 80 |
WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info); |
| 81 |
|
| 82 |
|
| 83 |
Uri expectedUri = Uri.parse("content://com.android.internal.tests/slice"); |
| 84 |
Uri settingsUri = wallpaperInfo.getSettingsSliceUri(); |
| 85 |
assertEquals("The loaded URI should equal to the string in livewallpaper.xml", |
| 86 |
0, expectedUri.compareTo(settingsUri)); |
| 87 |
Parcel parcel = Parcel.obtain(); |
| 88 |
wallpaperInfo.writeToParcel(parcel, 0 ); |
| 89 |
parcel.setDataPosition(0); |
| 90 |
WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel); |
| 91 |
assertEquals("settingsSliceUri should be restorable from parcelable", |
| 92 |
0, expectedUri.compareTo(fromParcel.getSettingsSliceUri())); |
| 93 |
parcel.recycle(); |
| 94 |
} |
| 95 |
} |
| 96 |
|