Merge "Fix SystemUI crash" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-04-13 23:28:07 +00:00
committed by Android (Google) Code Review
2 changed files with 28 additions and 2 deletions

View File

@@ -706,7 +706,7 @@ public class PeopleTileViewHelper {
Drawable drawable = resolveImage(imageUri, mContext);
Bitmap bitmap = convertDrawableToBitmap(drawable);
views.setImageViewBitmap(R.id.image, bitmap);
} catch (IOException e) {
} catch (IOException | SecurityException e) {
Log.e(TAG, "Could not decode image: " + e);
// If we couldn't load the image, show text that we have a new image.
views.setTextViewText(R.id.text_content, newImageDescription);
@@ -754,7 +754,7 @@ public class PeopleTileViewHelper {
return views;
}
private Drawable resolveImage(Uri uri, Context context) throws IOException {
Drawable resolveImage(Uri uri, Context context) throws IOException {
final ImageDecoder.Source source =
ImageDecoder.createSource(context.getContentResolver(), uri);
final Drawable drawable =

View File

@@ -33,8 +33,12 @@ import static com.android.systemui.people.PeopleSpaceUtils.VALID_CONTACT;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.people.ConversationStatus;
@@ -44,6 +48,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.UserHandle;
@@ -580,6 +585,27 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
assertEquals(result.getSourceLayoutResId(), R.layout.people_tile_suppressed_layout);
}
@Test
public void testCreateRemoteViewsWithNotificationContent() throws Exception {
PeopleTileViewHelper helper = spy(getPeopleTileViewHelper(PERSON_TILE));
doReturn(new BitmapDrawable()).when(helper).resolveImage(any(), any());
RemoteViews views = helper.getViews();
View result = views.apply(mContext, null);
assertEquals(View.VISIBLE, result.findViewById(R.id.image).getVisibility());
}
@Test
public void testCreateRemoteViewsWithInvalidNotificationContent() throws Exception {
PeopleTileViewHelper helper = spy(getPeopleTileViewHelper(PERSON_TILE));
doThrow(SecurityException.class).when(helper).resolveImage(any(), any());
RemoteViews views = helper.getViews();
View result = views.apply(mContext, null);
assertEquals(View.GONE, result.findViewById(R.id.image).getVisibility());
assertEquals(View.VISIBLE, result.findViewById(R.id.text_content).getVisibility());
}
@Test
public void testCreateRemoteViewsWithUserQuieted() {
PeopleSpaceTile tile = PERSON_TILE.toBuilder()