Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8315904e authored by Anna Zappone's avatar Anna Zappone Committed by Android (Google) Code Review
Browse files

Merge "Handle work profile, DND state, app pauses" into sc-dev

parents 0be45a9f 1b12d3d4
Loading
Loading
Loading
Loading
+106 −1
Original line number Diff line number Diff line
@@ -43,6 +43,12 @@ import java.util.List;
 */
public class PeopleSpaceTile implements Parcelable {

    public static final int SHOW_CONVERSATIONS = 1 << 0;
    public static final int BLOCK_CONVERSATIONS =  1 << 1;
    public static final int SHOW_IMPORTANT_CONVERSATIONS = 1 << 2;
    public static final int SHOW_STARRED_CONTACTS = 1 << 3;
    public static final int SHOW_CONTACTS = 1 << 4;

    private String mId;
    private CharSequence mUserName;
    private Icon mUserIcon;
@@ -61,6 +67,11 @@ public class PeopleSpaceTile implements Parcelable {
    private Intent mIntent;
    private long mNotificationTimestamp;
    private List<ConversationStatus> mStatuses;
    private boolean mCanBypassDnd;
    private boolean mIsPackageSuspended;
    private boolean mIsUserQuieted;
    private int mNotificationPolicyState;
    private float mContactAffinity;

    private PeopleSpaceTile(Builder b) {
        mId = b.mId;
@@ -81,6 +92,11 @@ public class PeopleSpaceTile implements Parcelable {
        mIntent = b.mIntent;
        mNotificationTimestamp = b.mNotificationTimestamp;
        mStatuses = b.mStatuses;
        mCanBypassDnd = b.mCanBypassDnd;
        mIsPackageSuspended = b.mIsPackageSuspended;
        mIsUserQuieted = b.mIsUserQuieted;
        mNotificationPolicyState = b.mNotificationPolicyState;
        mContactAffinity = b.mContactAffinity;
    }

    public String getId() {
@@ -173,6 +189,41 @@ public class PeopleSpaceTile implements Parcelable {
        return mStatuses;
    }

    /**
     * Whether the app associated with the conversation can bypass DND.
     */
    public boolean canBypassDnd() {
        return mCanBypassDnd;
    }

    /**
     * Whether the app associated with the conversation is suspended.
     */
    public boolean isPackageSuspended() {
        return mIsPackageSuspended;
    }

    /**
     * Whether the user associated with the conversation is quieted.
     */
    public boolean isUserQuieted() {
        return mIsUserQuieted;
    }

    /**
     * Returns the state of notifications for the conversation.
     */
    public int getNotificationPolicyState() {
        return mNotificationPolicyState;
    }

    /**
     * Returns the contact affinity (whether the contact is starred).
     */
    public float getContactAffinity() {
        return mContactAffinity;
    }

    /** Converts a {@link PeopleSpaceTile} into a {@link PeopleSpaceTile.Builder}. */
    public Builder toBuilder() {
        Builder builder =
@@ -192,6 +243,11 @@ public class PeopleSpaceTile implements Parcelable {
        builder.setIntent(mIntent);
        builder.setNotificationTimestamp(mNotificationTimestamp);
        builder.setStatuses(mStatuses);
        builder.setCanBypassDnd(mCanBypassDnd);
        builder.setIsPackageSuspended(mIsPackageSuspended);
        builder.setIsUserQuieted(mIsUserQuieted);
        builder.setNotificationPolicyState(mNotificationPolicyState);
        builder.setContactAffinity(mContactAffinity);
        return builder;
    }

@@ -215,6 +271,11 @@ public class PeopleSpaceTile implements Parcelable {
        private Intent mIntent;
        private long mNotificationTimestamp;
        private List<ConversationStatus> mStatuses;
        private boolean mCanBypassDnd;
        private boolean mIsPackageSuspended;
        private boolean mIsUserQuieted;
        private int mNotificationPolicyState;
        private float mContactAffinity;

        /** Builder for use only if a shortcut is not available for the tile. */
        public Builder(String id, CharSequence userName, Icon userIcon, Intent intent) {
@@ -223,6 +284,7 @@ public class PeopleSpaceTile implements Parcelable {
            mUserIcon = userIcon;
            mIntent = intent;
            mPackageName = intent == null ? null : intent.getPackage();
            mNotificationPolicyState = SHOW_CONVERSATIONS;
        }

        public Builder(ShortcutInfo info, LauncherApps launcherApps) {
@@ -232,6 +294,7 @@ public class PeopleSpaceTile implements Parcelable {
            mUserHandle = info.getUserHandle();
            mPackageName = info.getPackage();
            mContactUri = getContactUri(info);
            mNotificationPolicyState = SHOW_CONVERSATIONS;
        }

        public Builder(ConversationChannel channel, LauncherApps launcherApps) {
@@ -246,6 +309,9 @@ public class PeopleSpaceTile implements Parcelable {
            mLastInteractionTimestamp = channel.getLastEventTimestamp();
            mIsImportantConversation = channel.getParentNotificationChannel() != null
                    && channel.getParentNotificationChannel().isImportantConversation();
            mCanBypassDnd = channel.getParentNotificationChannel() != null
                    && channel.getParentNotificationChannel().canBypassDnd();
            mNotificationPolicyState = SHOW_CONVERSATIONS;
        }

        /** Returns the Contact's Uri if present. */
@@ -366,6 +432,36 @@ public class PeopleSpaceTile implements Parcelable {
            return this;
        }

        /** Sets whether the conversation channel can bypass DND. */
        public Builder setCanBypassDnd(boolean canBypassDnd) {
            mCanBypassDnd = canBypassDnd;
            return this;
        }

        /** Sets whether the package is suspended. */
        public Builder setIsPackageSuspended(boolean isPackageSuspended) {
            mIsPackageSuspended = isPackageSuspended;
            return this;
        }

        /** Sets whether the user has been quieted. */
        public Builder setIsUserQuieted(boolean isUserQuieted) {
            mIsUserQuieted = isUserQuieted;
            return this;
        }

        /** Sets the state of blocked notifications for the conversation. */
        public Builder setNotificationPolicyState(int notificationPolicyState) {
            mNotificationPolicyState = notificationPolicyState;
            return this;
        }

        /** Sets the contact's affinity. */
        public Builder setContactAffinity(float contactAffinity) {
            mContactAffinity = contactAffinity;
            return this;
        }

        /** Builds a {@link PeopleSpaceTile}. */
        @NonNull
        public PeopleSpaceTile build() {
@@ -393,6 +489,11 @@ public class PeopleSpaceTile implements Parcelable {
        mNotificationTimestamp = in.readLong();
        mStatuses = new ArrayList<>();
        in.readParcelableList(mStatuses, ConversationStatus.class.getClassLoader());
        mCanBypassDnd = in.readBoolean();
        mIsPackageSuspended = in.readBoolean();
        mIsUserQuieted = in.readBoolean();
        mNotificationPolicyState = in.readInt();
        mContactAffinity = in.readFloat();
    }

    @Override
@@ -420,6 +521,11 @@ public class PeopleSpaceTile implements Parcelable {
        dest.writeParcelable(mIntent, flags);
        dest.writeLong(mNotificationTimestamp);
        dest.writeParcelableList(mStatuses, flags);
        dest.writeBoolean(mCanBypassDnd);
        dest.writeBoolean(mIsPackageSuspended);
        dest.writeBoolean(mIsUserQuieted);
        dest.writeInt(mNotificationPolicyState);
        dest.writeFloat(mContactAffinity);
    }

    public static final @android.annotation.NonNull
@@ -427,7 +533,6 @@ public class PeopleSpaceTile implements Parcelable {
                public PeopleSpaceTile createFromParcel(Parcel source) {
                    return new PeopleSpaceTile(source);
                }

                public PeopleSpaceTile[] newArray(int size) {
                    return new PeopleSpaceTile[size];
                }
+79 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.app.people;

import static android.app.people.PeopleSpaceTile.SHOW_CONVERSATIONS;
import static android.app.people.PeopleSpaceTile.SHOW_IMPORTANT_CONVERSATIONS;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertFalse;
@@ -177,6 +180,71 @@ public class PeopleSpaceTileTest {
        assertTrue(tile.isImportantConversation());
    }

    @Test
    public void testUserQuieted() {
        PeopleSpaceTile tile = new PeopleSpaceTile.Builder(
                new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build();
        assertFalse(tile.isUserQuieted());

        tile = new PeopleSpaceTile
                .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps)
                .setIsUserQuieted(true)
                .build();
        assertTrue(tile.isUserQuieted());
    }

    @Test
    public void testCanBypassDnd() {
        PeopleSpaceTile tile = new PeopleSpaceTile.Builder(
                new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build();
        assertFalse(tile.canBypassDnd());

        tile = new PeopleSpaceTile
                .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps)
                .setCanBypassDnd(true)
                .build();
        assertTrue(tile.canBypassDnd());
    }

    @Test
    public void testNotificationPolicyState() {
        PeopleSpaceTile tile = new PeopleSpaceTile.Builder(
                new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build();
        assertThat(tile.getNotificationPolicyState()).isEqualTo(SHOW_CONVERSATIONS);

        tile = new PeopleSpaceTile
                .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps)
                .setNotificationPolicyState(SHOW_IMPORTANT_CONVERSATIONS)
                .build();
        assertThat(tile.getNotificationPolicyState()).isEqualTo(SHOW_IMPORTANT_CONVERSATIONS);
    }

    @Test
    public void testPackageSuspended() {
        PeopleSpaceTile tile = new PeopleSpaceTile.Builder(
                new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build();
        assertFalse(tile.isPackageSuspended());

        tile = new PeopleSpaceTile
                .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps)
                .setIsPackageSuspended(true)
                .build();
        assertTrue(tile.isPackageSuspended());
    }

    @Test
    public void testContactAffinity() {
        PeopleSpaceTile tile = new PeopleSpaceTile.Builder(
                new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps).build();
        assertThat(tile.getContactAffinity()).isEqualTo(0f);

        tile = new PeopleSpaceTile
                .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps)
                .setContactAffinity(1f)
                .build();
        assertThat(tile.getContactAffinity()).isEqualTo(1f);
    }

    @Test
    public void testStatuses() {
        PeopleSpaceTile tile = new PeopleSpaceTile.Builder(
@@ -238,6 +306,11 @@ public class PeopleSpaceTileTest {
                .setNotificationDataUri(Uri.parse("data"))
                .setMessagesCount(2)
                .setIntent(new Intent())
                .setIsUserQuieted(true)
                .setCanBypassDnd(false)
                .setNotificationPolicyState(SHOW_IMPORTANT_CONVERSATIONS)
                .setIsPackageSuspended(true)
                .setContactAffinity(1f)
                .build();

        Parcel parcel = Parcel.obtain();
@@ -261,6 +334,12 @@ public class PeopleSpaceTileTest {
        assertThat(readTile.getNotificationDataUri()).isEqualTo(tile.getNotificationDataUri());
        assertThat(readTile.getMessagesCount()).isEqualTo(tile.getMessagesCount());
        assertThat(readTile.getIntent().toString()).isEqualTo(tile.getIntent().toString());
        assertThat(readTile.isUserQuieted()).isEqualTo(tile.isUserQuieted());
        assertThat(readTile.canBypassDnd()).isEqualTo(tile.canBypassDnd());
        assertThat(readTile.getNotificationPolicyState()).isEqualTo(
                tile.getNotificationPolicyState());
        assertThat(readTile.isPackageSuspended()).isEqualTo(tile.isPackageSuspended());
        assertThat(readTile.getContactAffinity()).isEqualTo(tile.getContactAffinity());
    }

    @Test
+29 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2021 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.
  -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:theme="@android:style/Theme.DeviceDefault.DayNight"
    android:background="@drawable/people_space_tile_view_card"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/item"
        android:gravity="center"
        android:layout_gravity="center"
        android:padding="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</FrameLayout>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -26,5 +26,5 @@
    android:previewLayout="@layout/people_space_placeholder_layout"
    android:resizeMode="horizontal|vertical"
    android:configure="com.android.systemui.people.PeopleSpaceActivity"
    android:initialLayout="@layout/people_space_initial_layout">
    android:initialLayout="@layout/people_tile_empty_layout">
</appwidget-provider>
+10 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.BroadcastReceiver;

import com.android.systemui.media.dialog.MediaOutputDialogReceiver;
import com.android.systemui.people.widget.PeopleSpaceWidgetPinnedReceiver;
import com.android.systemui.people.widget.PeopleSpaceWidgetProvider;
import com.android.systemui.screenshot.ActionProxyReceiver;
import com.android.systemui.screenshot.DeleteScreenshotReceiver;
import com.android.systemui.screenshot.SmartActionsReceiver;
@@ -79,4 +80,13 @@ public abstract class DefaultBroadcastReceiverBinder {
    public abstract BroadcastReceiver bindPeopleSpaceWidgetPinnedReceiver(
            PeopleSpaceWidgetPinnedReceiver broadcastReceiver);

    /**
     *
     */
    @Binds
    @IntoMap
    @ClassKey(PeopleSpaceWidgetProvider.class)
    public abstract BroadcastReceiver bindPeopleSpaceWidgetProvider(
            PeopleSpaceWidgetProvider broadcastReceiver);

}
Loading