Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
| 19 | import android.app.ActivityManager; |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 20 | import android.app.Instrumentation; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 21 | import android.app.Notification; |
| 22 | import android.content.Context; |
| 23 | import android.os.UserHandle; |
| 24 | import android.service.notification.StatusBarNotification; |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 25 | import android.support.test.InstrumentationRegistry; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 26 | import android.view.LayoutInflater; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 27 | import android.widget.FrameLayout; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 28 | import android.widget.RemoteViews; |
| 29 | |
| 30 | import com.android.systemui.R; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.AboveShelfChangedListener; |
| 32 | import com.android.systemui.statusbar.notification.AboveShelfObserver; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 33 | import com.android.systemui.statusbar.notification.InflationException; |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 34 | import com.android.systemui.statusbar.notification.NotificationInflaterTest; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 35 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 36 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * A helper class to create {@link ExpandableNotificationRow} |
| 40 | */ |
| 41 | public class NotificationTestHelper { |
| 42 | |
| 43 | private final Context mContext; |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 44 | private final Instrumentation mInstrumentation; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 45 | private int mId; |
| 46 | private final NotificationGroupManager mGroupManager = new NotificationGroupManager(); |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 47 | private ExpandableNotificationRow mRow; |
| 48 | private InflationException mException; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 49 | private HeadsUpManager mHeadsUpManager; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 50 | |
| 51 | public NotificationTestHelper(Context context) { |
| 52 | mContext = context; |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 53 | mInstrumentation = InstrumentationRegistry.getInstrumentation(); |
yoshiki iguchi | 0adf6a6 | 2018-02-01 13:46:26 +0900 | [diff] [blame] | 54 | mHeadsUpManager = new HeadsUpManager(mContext, null, mGroupManager); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 57 | public ExpandableNotificationRow createRow() throws Exception { |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 58 | 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 Cinek | 1079067 | 2017-03-08 16:33:05 -0800 | [diff] [blame] | 69 | return createRow(notification); |
| 70 | } |
| 71 | |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 72 | public ExpandableNotificationRow createRow(Notification notification) throws Exception { |
Selim Cinek | 1079067 | 2017-03-08 16:33:05 -0800 | [diff] [blame] | 73 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( |
| 74 | mContext.LAYOUT_INFLATER_SERVICE); |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 75 | mInstrumentation.runOnMainSync(() -> { |
| 76 | mRow = (ExpandableNotificationRow) inflater.inflate( |
| 77 | R.layout.status_bar_notification_row, |
| 78 | null, false); |
| 79 | }); |
| 80 | ExpandableNotificationRow row = mRow; |
Selim Cinek | 1079067 | 2017-03-08 16:33:05 -0800 | [diff] [blame] | 81 | row.setGroupManager(mGroupManager); |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 82 | row.setHeadsUpManager(mHeadsUpManager); |
| 83 | row.setAboveShelfChangedListener(aboveShelf -> {}); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 84 | 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 Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 90 | entry.createIcons(mContext, sbn); |
| 91 | NotificationInflaterTest.runThenWaitForInflation(() -> row.updateNotification(entry), |
| 92 | row.getNotificationInflater()); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 93 | return row; |
| 94 | } |
| 95 | |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 96 | public ExpandableNotificationRow createGroup() throws Exception { |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 97 | ExpandableNotificationRow row = createRow(); |
| 98 | row.addChildNotification(createRow()); |
| 99 | row.addChildNotification(createRow()); |
| 100 | return row; |
| 101 | } |
| 102 | } |