mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-12-22 22:19:21 -05:00
293f97d678
Signed-off-by: Tad <tad@spotco.us>
129 lines
6.0 KiB
Diff
129 lines
6.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Ioana Alexandru <aioana@google.com>
|
|
Date: Thu, 27 Apr 2023 12:36:05 +0000
|
|
Subject: [PATCH] Visit URIs in landscape/portrait custom remote views.
|
|
|
|
Bug: 277740848
|
|
Test: atest RemoteViewsTest NotificationManagerServiceTest & tested with POC from bug
|
|
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e8acb2f660bdb03616989852f9dbbf1726f8237e)
|
|
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:43e1ae4e0d408604b9e3c18ac0e9bf87529b92a8)
|
|
Merged-In: I7d3d35df0ec38945019f71755bed8797b7af4517
|
|
Change-Id: I7d3d35df0ec38945019f71755bed8797b7af4517
|
|
---
|
|
core/java/android/widget/RemoteViews.java | 6 ++
|
|
.../src/android/widget/RemoteViewsTest.java | 65 +++++++++++++++++++
|
|
2 files changed, 71 insertions(+)
|
|
|
|
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
|
|
index 4865dab6056a..10053dddb0fb 100644
|
|
--- a/core/java/android/widget/RemoteViews.java
|
|
+++ b/core/java/android/widget/RemoteViews.java
|
|
@@ -543,6 +543,12 @@ public class RemoteViews implements Parcelable, Filter {
|
|
mActions.get(i).visitUris(visitor);
|
|
}
|
|
}
|
|
+ if (mLandscape != null) {
|
|
+ mLandscape.visitUris(visitor);
|
|
+ }
|
|
+ if (mPortrait != null) {
|
|
+ mPortrait.visitUris(visitor);
|
|
+ }
|
|
}
|
|
|
|
private static void visitIconUri(Icon icon, @NonNull Consumer<Uri> visitor) {
|
|
diff --git a/core/tests/coretests/src/android/widget/RemoteViewsTest.java b/core/tests/coretests/src/android/widget/RemoteViewsTest.java
|
|
index 70cf097f42a3..7d2e07ecbd71 100644
|
|
--- a/core/tests/coretests/src/android/widget/RemoteViewsTest.java
|
|
+++ b/core/tests/coretests/src/android/widget/RemoteViewsTest.java
|
|
@@ -19,6 +19,10 @@ package android.widget;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertSame;
|
|
import static org.junit.Assert.assertTrue;
|
|
+import static org.mockito.ArgumentMatchers.eq;
|
|
+import static org.mockito.Mockito.spy;
|
|
+import static org.mockito.Mockito.times;
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
import android.app.PendingIntent;
|
|
import android.content.Context;
|
|
@@ -26,6 +30,8 @@ import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
+import android.graphics.drawable.Icon;
|
|
+import android.net.Uri;
|
|
import android.os.AsyncTask;
|
|
import android.os.Binder;
|
|
import android.os.Parcel;
|
|
@@ -46,6 +52,7 @@ import org.junit.runner.RunWith;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.concurrent.CountDownLatch;
|
|
+import java.util.function.Consumer;
|
|
|
|
/**
|
|
* Tests for RemoteViews.
|
|
@@ -444,4 +451,62 @@ public class RemoteViewsTest {
|
|
}
|
|
return found[0];
|
|
}
|
|
+
|
|
+
|
|
+ @Test
|
|
+ public void visitUris() {
|
|
+ RemoteViews views = new RemoteViews(mPackage, R.layout.remote_views_test);
|
|
+
|
|
+ final Uri imageUri = Uri.parse("content://media/image");
|
|
+ final Icon icon1 = Icon.createWithContentUri("content://media/icon1");
|
|
+ final Icon icon2 = Icon.createWithContentUri("content://media/icon2");
|
|
+ final Icon icon3 = Icon.createWithContentUri("content://media/icon3");
|
|
+ final Icon icon4 = Icon.createWithContentUri("content://media/icon4");
|
|
+ views.setImageViewUri(R.id.image, imageUri);
|
|
+ views.setTextViewCompoundDrawables(R.id.text, icon1, icon2, icon3, icon4);
|
|
+
|
|
+ Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
|
|
+ views.visitUris(visitor);
|
|
+ verify(visitor, times(1)).accept(eq(imageUri));
|
|
+ verify(visitor, times(1)).accept(eq(icon1.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon2.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon3.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon4.getUri()));
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void visitUris_separateOrientation() {
|
|
+ final RemoteViews landscape = new RemoteViews(mPackage, R.layout.remote_views_test);
|
|
+ final Uri imageUriL = Uri.parse("content://landscape/image");
|
|
+ final Icon icon1L = Icon.createWithContentUri("content://landscape/icon1");
|
|
+ final Icon icon2L = Icon.createWithContentUri("content://landscape/icon2");
|
|
+ final Icon icon3L = Icon.createWithContentUri("content://landscape/icon3");
|
|
+ final Icon icon4L = Icon.createWithContentUri("content://landscape/icon4");
|
|
+ landscape.setImageViewUri(R.id.image, imageUriL);
|
|
+ landscape.setTextViewCompoundDrawables(R.id.text, icon1L, icon2L, icon3L, icon4L);
|
|
+
|
|
+ final RemoteViews portrait = new RemoteViews(mPackage, 33);
|
|
+ final Uri imageUriP = Uri.parse("content://portrait/image");
|
|
+ final Icon icon1P = Icon.createWithContentUri("content://portrait/icon1");
|
|
+ final Icon icon2P = Icon.createWithContentUri("content://portrait/icon2");
|
|
+ final Icon icon3P = Icon.createWithContentUri("content://portrait/icon3");
|
|
+ final Icon icon4P = Icon.createWithContentUri("content://portrait/icon4");
|
|
+ portrait.setImageViewUri(R.id.image, imageUriP);
|
|
+ portrait.setTextViewCompoundDrawables(R.id.text, icon1P, icon2P, icon3P, icon4P);
|
|
+
|
|
+ RemoteViews views = new RemoteViews(landscape, portrait);
|
|
+
|
|
+ Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
|
|
+ views.visitUris(visitor);
|
|
+ verify(visitor, times(1)).accept(eq(imageUriL));
|
|
+ verify(visitor, times(1)).accept(eq(icon1L.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon2L.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon3L.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon4L.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(imageUriP));
|
|
+ verify(visitor, times(1)).accept(eq(icon1P.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon2P.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon3P.getUri()));
|
|
+ verify(visitor, times(1)).accept(eq(icon4P.getUri()));
|
|
+ }
|
|
}
|