blob: 6e7477fbac386d6b30b5bdf3c4a66b95ed9e1353 [file] [log] [blame]
Selim Cinek6fd06b52017-03-07 15:54:10 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.systemui.statusbar;
18
19import android.app.ActivityManager;
Selim Cinek5ba22542017-04-20 15:16:10 -070020import android.app.Instrumentation;
Selim Cinek6fd06b52017-03-07 15:54:10 -080021import android.app.Notification;
22import android.content.Context;
23import android.os.UserHandle;
24import android.service.notification.StatusBarNotification;
Selim Cinek5ba22542017-04-20 15:16:10 -070025import android.support.test.InstrumentationRegistry;
Selim Cinek6fd06b52017-03-07 15:54:10 -080026import android.view.LayoutInflater;
Selim Cinek5cf1d052017-06-01 17:36:46 -070027import android.widget.FrameLayout;
Selim Cinek6fd06b52017-03-07 15:54:10 -080028import android.widget.RemoteViews;
29
30import com.android.systemui.R;
Selim Cinek5cf1d052017-06-01 17:36:46 -070031import com.android.systemui.statusbar.notification.AboveShelfChangedListener;
32import com.android.systemui.statusbar.notification.AboveShelfObserver;
Selim Cinek6fd06b52017-03-07 15:54:10 -080033import com.android.systemui.statusbar.notification.InflationException;
Selim Cinek5ba22542017-04-20 15:16:10 -070034import com.android.systemui.statusbar.notification.NotificationInflaterTest;
Selim Cinek6fd06b52017-03-07 15:54:10 -080035import com.android.systemui.statusbar.phone.NotificationGroupManager;
Selim Cinek5cf1d052017-06-01 17:36:46 -070036import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek6fd06b52017-03-07 15:54:10 -080037
38/**
39 * A helper class to create {@link ExpandableNotificationRow}
40 */
41public class NotificationTestHelper {
42
43 private final Context mContext;
Selim Cinek5ba22542017-04-20 15:16:10 -070044 private final Instrumentation mInstrumentation;
Selim Cinek6fd06b52017-03-07 15:54:10 -080045 private int mId;
46 private final NotificationGroupManager mGroupManager = new NotificationGroupManager();
Selim Cinek5ba22542017-04-20 15:16:10 -070047 private ExpandableNotificationRow mRow;
48 private InflationException mException;
Selim Cinek5cf1d052017-06-01 17:36:46 -070049 private HeadsUpManager mHeadsUpManager;
Selim Cinek6fd06b52017-03-07 15:54:10 -080050
51 public NotificationTestHelper(Context context) {
52 mContext = context;
Selim Cinek5ba22542017-04-20 15:16:10 -070053 mInstrumentation = InstrumentationRegistry.getInstrumentation();
yoshiki iguchi0adf6a62018-02-01 13:46:26 +090054 mHeadsUpManager = new HeadsUpManager(mContext, null, mGroupManager);
Selim Cinek6fd06b52017-03-07 15:54:10 -080055 }
56
Selim Cinek5ba22542017-04-20 15:16:10 -070057 public ExpandableNotificationRow createRow() throws Exception {
Selim Cinek6fd06b52017-03-07 15:54:10 -080058 Notification publicVersion = new Notification.Builder(mContext).setSmallIcon(
59 R.drawable.ic_person)
60 .setCustomContentView(new RemoteViews(mContext.getPackageName(),
61 R.layout.custom_view_dark))
62 .build();
63 Notification notification = new Notification.Builder(mContext).setSmallIcon(
64 R.drawable.ic_person)
65 .setContentTitle("Title")
66 .setContentText("Text")
67 .setPublicVersion(publicVersion)
68 .build();
Selim Cinek10790672017-03-08 16:33:05 -080069 return createRow(notification);
70 }
71
Selim Cinek5ba22542017-04-20 15:16:10 -070072 public ExpandableNotificationRow createRow(Notification notification) throws Exception {
Selim Cinek10790672017-03-08 16:33:05 -080073 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
74 mContext.LAYOUT_INFLATER_SERVICE);
Selim Cinek5ba22542017-04-20 15:16:10 -070075 mInstrumentation.runOnMainSync(() -> {
76 mRow = (ExpandableNotificationRow) inflater.inflate(
77 R.layout.status_bar_notification_row,
78 null, false);
79 });
80 ExpandableNotificationRow row = mRow;
Selim Cinek10790672017-03-08 16:33:05 -080081 row.setGroupManager(mGroupManager);
Selim Cinek5cf1d052017-06-01 17:36:46 -070082 row.setHeadsUpManager(mHeadsUpManager);
83 row.setAboveShelfChangedListener(aboveShelf -> {});
Selim Cinek6fd06b52017-03-07 15:54:10 -080084 UserHandle mUser = UserHandle.of(ActivityManager.getCurrentUser());
85 StatusBarNotification sbn = new StatusBarNotification("com.android.systemui",
86 "com.android.systemui", mId++, null, 1000,
87 2000, notification, mUser, null, System.currentTimeMillis());
88 NotificationData.Entry entry = new NotificationData.Entry(sbn);
89 entry.row = row;
Selim Cinek5ba22542017-04-20 15:16:10 -070090 entry.createIcons(mContext, sbn);
91 NotificationInflaterTest.runThenWaitForInflation(() -> row.updateNotification(entry),
92 row.getNotificationInflater());
Selim Cinek6fd06b52017-03-07 15:54:10 -080093 return row;
94 }
95
Selim Cinek5ba22542017-04-20 15:16:10 -070096 public ExpandableNotificationRow createGroup() throws Exception {
Selim Cinek6fd06b52017-03-07 15:54:10 -080097 ExpandableNotificationRow row = createRow();
98 row.addChildNotification(createRow());
99 row.addChildNotification(createRow());
100 return row;
101 }
102}