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

Commit f72baf17 authored by Selim Cinek's avatar Selim Cinek Committed by Android (Google) Code Review
Browse files

Merge changes I6823a613,I7763b473

* changes:
  Fixed a bug where the low-priority header wasn't cleared
  Fixes an issue where the notification header could be invisible
parents 9c2886ba 6fd06b5b
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -1268,7 +1268,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        if (mChildrenContainer != null) {
            mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
                    : INVISIBLE);
            mChildrenContainer.setHeaderVisible(!mShowingPublic && mIsSummaryWithChildren);
        }
        // The limits might have changed if the view suddenly became a group or vice versa
        updateLimits();
+4 −9
Original line number Diff line number Diff line
@@ -89,7 +89,6 @@ public class NotificationChildrenContainer extends ViewGroup {
    private ViewState mHeaderViewState;
    private int mClipBottomAmount;
    private boolean mIsLowPriority;
    private boolean mHeaderVisible = true;
    private OnClickListener mHeaderClickListener;
    private boolean mShowingNormalHeader;

@@ -324,6 +323,7 @@ public class NotificationChildrenContainer extends ViewGroup {
            }
            mNotificationHeaderWrapperLowPriority.notifyContentUpdated(mContainingNotification);
        } else {
            removeView(mNotificationHeaderLowPriority);
            mNotificationHeaderLowPriority = null;
            mNotificationHeaderWrapperLowPriority = null;
        }
@@ -794,11 +794,6 @@ public class NotificationChildrenContainer extends ViewGroup {
        return mNotificationHeaderLowPriority;
    }

    public void setHeaderVisible(boolean visible) {
        mHeaderVisible = visible;
        updateHeaderVisibility(false /* animate */);
    }

    private void updateHeaderVisibility(boolean animate) {
        NotificationHeaderView visibleHeader = mNotificationHeader;
        NotificationHeaderView hiddenHeader = mNotificationHeaderLowPriority;
@@ -809,7 +804,7 @@ public class NotificationChildrenContainer extends ViewGroup {
            normalHeaderVisible = false;
        }
        if (animate) {
            if (mHeaderVisible && visibleHeader != null && hiddenHeader != null
            if (visibleHeader != null && hiddenHeader != null
                    && mShowingNormalHeader != normalHeaderVisible) {
                hiddenHeader.setVisibility(VISIBLE);
                visibleHeader.setVisibility(VISIBLE);
@@ -825,7 +820,7 @@ public class NotificationChildrenContainer extends ViewGroup {
        if (!animate) {
            if (visibleHeader != null) {
                getWrapperForView(visibleHeader).setVisible(true);
                visibleHeader.setVisibility(mHeaderVisible ? VISIBLE : INVISIBLE);
                visibleHeader.setVisibility(VISIBLE);
            }
            if (hiddenHeader != null) {
                getWrapperForView(hiddenHeader).setVisible(false);
@@ -855,7 +850,7 @@ public class NotificationChildrenContainer extends ViewGroup {


    private void updateHeaderTransformation() {
        if (mUserLocked && mHeaderVisible && showingAsLowPriority()) {
        if (mUserLocked && showingAsLowPriority()) {
            float fraction = getGroupExpandFraction();
            mNotificationHeaderWrapper.transformFrom(mNotificationHeaderWrapperLowPriority,
                    fraction);
+16 −57
Original line number Diff line number Diff line
@@ -17,28 +17,13 @@
package com.android.systemui.statusbar;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.ActivityManager;
import android.app.Notification;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.support.test.InstrumentationRegistry;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RemoteViews;

import com.android.systemui.R;
import com.android.systemui.statusbar.notification.InflationException;
import com.android.systemui.statusbar.notification.NotificationCustomViewWrapper;
import com.android.systemui.statusbar.notification.NotificationInflater;
import com.android.systemui.statusbar.notification.NotificationViewWrapper;
import com.android.systemui.statusbar.phone.NotificationGroupManager;

import org.junit.Assert;
import org.junit.Before;
@@ -50,58 +35,32 @@ import org.junit.runner.RunWith;
public class ExpandableNotificationRowTest {

    private Context mContext;
    private ExpandableNotificationRow mRow;
    private NotificationGroupManager mGroupManager = new NotificationGroupManager();
    private int mId;
    private ExpandableNotificationRow mGroup;
    private NotificationTestHelper mNotificationTestHelper;

    @Before
    @UiThreadTest
    public void setUp() {
        mContext = InstrumentationRegistry.getTargetContext();
        mRow = createNotification();
        mNotificationTestHelper = new NotificationTestHelper(mContext);
        mGroup = mNotificationTestHelper.createGroup();
    }

    private ExpandableNotificationRow createNotification() {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        ExpandableNotificationRow row = (ExpandableNotificationRow) inflater.inflate(
                R.layout.status_bar_notification_row,
                null, false);
        row.setGroupManager(mGroupManager);
        Notification publicVersion = new Notification.Builder(mContext).setSmallIcon(
                R.drawable.ic_person)
                .setCustomContentView(new RemoteViews(mContext.getPackageName(),
                        R.layout.custom_view_dark))
                .build();
        Notification notification = new Notification.Builder(mContext).setSmallIcon(
                R.drawable.ic_person)
                .setContentTitle("Title")
                .setContentText("Text")
                .setPublicVersion(publicVersion)
                .build();
        UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser());
        StatusBarNotification sbn = new StatusBarNotification("com.android.systemui",
                "com.android.systemui", mId++, null, 1000,
                2000, notification, mUser, null, System.currentTimeMillis());
        NotificationData.Entry entry = new NotificationData.Entry(sbn);
        entry.row = row;
        try {
            entry.createIcons(mContext, sbn);
            row.updateNotification(entry);
        } catch (InflationException e) {
            throw new RuntimeException(e.getMessage());
        }
        return row;
    @Test
    public void testGroupSummaryNotShowingIconWhenPublic() {
        mGroup.setSensitive(true, true);
        mGroup.setHideSensitive(true, false, 0, 0);
        Assert.assertTrue(mGroup.isSummaryWithChildren());
        Assert.assertFalse(mGroup.isShowingIcon());
    }

    @Test
    public void testGroupSummaryNotShowingIconWhenPublic() {
        mRow.setSensitive(true, true);
        mRow.addChildNotification(createNotification());
        mRow.addChildNotification(createNotification());
        mRow.setHideSensitive(true, false, 0, 0);
        Assert.assertTrue(mRow.isSummaryWithChildren());
        Assert.assertFalse(mRow.isShowingIcon());
    public void testNotificationHeaderVisibleWhenAnimating() {
        mGroup.setSensitive(true, true);
        mGroup.setHideSensitive(true, false, 0, 0);
        mGroup.setHideSensitive(false, true, 0, 0);
        Assert.assertTrue(mGroup.getChildrenContainer().getVisibleHeader().getVisibility()
                == View.VISIBLE);
    }

}
+83 −0
Original line number Diff line number Diff line
/*
 * 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 com.android.systemui.statusbar;

import android.app.ActivityManager;
import android.app.Notification;
import android.content.Context;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.view.LayoutInflater;
import android.widget.RemoteViews;

import com.android.systemui.R;
import com.android.systemui.statusbar.notification.InflationException;
import com.android.systemui.statusbar.phone.NotificationGroupManager;

/**
 * A helper class to create {@link ExpandableNotificationRow}
 */
public class NotificationTestHelper {

    private final Context mContext;
    private int mId;
    private final NotificationGroupManager mGroupManager = new NotificationGroupManager();

    public NotificationTestHelper(Context context) {
        mContext = context;
    }

    public ExpandableNotificationRow createRow() {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
                mContext.LAYOUT_INFLATER_SERVICE);
        ExpandableNotificationRow row = (ExpandableNotificationRow) inflater.inflate(
                R.layout.status_bar_notification_row,
                null, false);
        row.setGroupManager(mGroupManager);
        Notification publicVersion = new Notification.Builder(mContext).setSmallIcon(
                R.drawable.ic_person)
                .setCustomContentView(new RemoteViews(mContext.getPackageName(),
                        R.layout.custom_view_dark))
                .build();
        Notification notification = new Notification.Builder(mContext).setSmallIcon(
                R.drawable.ic_person)
                .setContentTitle("Title")
                .setContentText("Text")
                .setPublicVersion(publicVersion)
                .build();
        UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser());
        StatusBarNotification sbn = new StatusBarNotification("com.android.systemui",
                "com.android.systemui", mId++, null, 1000,
                2000, notification, mUser, null, System.currentTimeMillis());
        NotificationData.Entry entry = new NotificationData.Entry(sbn);
        entry.row = row;
        try {
            entry.createIcons(mContext, sbn);
            row.updateNotification(entry);
        } catch (InflationException e) {
            throw new RuntimeException(e.getMessage());
        }
        return row;
    }

    public ExpandableNotificationRow createGroup() {
        ExpandableNotificationRow row = createRow();
        row.addChildNotification(createRow());
        row.addChildNotification(createRow());
        return row;
    }
}
+63 −0
Original line number Diff line number Diff line
/*
 * 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 com.android.systemui.statusbar.stack;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.NotificationHeaderView;
import android.view.View;

import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class NotificationChildrenContainerTest {

    private Context mContext;
    private ExpandableNotificationRow mGroup;
    private int mId;
    private NotificationTestHelper mNotificationTestHelper;

    @Before
    @UiThreadTest
    public void setUp() {
        mContext = InstrumentationRegistry.getTargetContext();
        mNotificationTestHelper = new NotificationTestHelper(mContext);
        mGroup = mNotificationTestHelper.createGroup();
    }

    @Test
    public void testLowPriorityHeaderCleared() {
        mGroup.setIsLowPriority(true);
        NotificationChildrenContainer childrenContainer = mGroup.getChildrenContainer();
        NotificationHeaderView lowPriorityHeaderView = childrenContainer.getLowPriorityHeaderView();
        Assert.assertTrue(lowPriorityHeaderView.getVisibility() == View.VISIBLE);
        Assert.assertTrue(lowPriorityHeaderView.getParent() == childrenContainer);
        mGroup.setIsLowPriority(false);
        Assert.assertTrue(lowPriorityHeaderView.getParent() == null);
        Assert.assertTrue(childrenContainer.getLowPriorityHeaderView() == null);
    }
}