1 /* 2 * Copyright (C) 2023 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.wm.shell.common.bubbles; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 27 /** 28 * Represents an update to bubbles state. This is passed through 29 * {@link com.android.wm.shell.bubbles.IBubblesListener} to launcher so that taskbar may render 30 * bubbles. This should be kept this as minimal as possible in terms of data. 31 */ 32 public class BubbleBarUpdate implements Parcelable { 33 34 public static final String BUNDLE_KEY = "update"; 35 36 public boolean expandedChanged; 37 public boolean expanded; 38 @Nullable 39 public String selectedBubbleKey; 40 @Nullable 41 public BubbleInfo addedBubble; 42 @Nullable 43 public BubbleInfo updatedBubble; 44 @Nullable 45 public String suppressedBubbleKey; 46 @Nullable 47 public String unsupressedBubbleKey; 48 49 // This is only populated if bubbles have been removed. 50 public List<RemovedBubble> removedBubbles = new ArrayList<>(); 51 52 // This is only populated if the order of the bubbles has changed. 53 public List<String> bubbleKeysInOrder = new ArrayList<>(); 54 55 // This is only populated the first time a listener is connected so it gets the current state. 56 public List<BubbleInfo> currentBubbleList = new ArrayList<>(); 57 BubbleBarUpdate()58 public BubbleBarUpdate() { 59 } 60 BubbleBarUpdate(Parcel parcel)61 public BubbleBarUpdate(Parcel parcel) { 62 expandedChanged = parcel.readBoolean(); 63 expanded = parcel.readBoolean(); 64 selectedBubbleKey = parcel.readString(); 65 addedBubble = parcel.readParcelable(BubbleInfo.class.getClassLoader(), 66 BubbleInfo.class); 67 updatedBubble = parcel.readParcelable(BubbleInfo.class.getClassLoader(), 68 BubbleInfo.class); 69 suppressedBubbleKey = parcel.readString(); 70 unsupressedBubbleKey = parcel.readString(); 71 removedBubbles = parcel.readParcelableList(new ArrayList<>(), 72 RemovedBubble.class.getClassLoader()); 73 parcel.readStringList(bubbleKeysInOrder); 74 currentBubbleList = parcel.readParcelableList(new ArrayList<>(), 75 BubbleInfo.class.getClassLoader()); 76 } 77 78 /** 79 * Returns whether anything has changed in this update. 80 */ anythingChanged()81 public boolean anythingChanged() { 82 return expandedChanged 83 || selectedBubbleKey != null 84 || addedBubble != null 85 || updatedBubble != null 86 || !removedBubbles.isEmpty() 87 || !bubbleKeysInOrder.isEmpty() 88 || suppressedBubbleKey != null 89 || unsupressedBubbleKey != null 90 || !currentBubbleList.isEmpty(); 91 } 92 93 @Override toString()94 public String toString() { 95 return "BubbleBarUpdate{ expandedChanged=" + expandedChanged 96 + " expanded=" + expanded 97 + " selectedBubbleKey=" + selectedBubbleKey 98 + " addedBubble=" + addedBubble 99 + " updatedBubble=" + updatedBubble 100 + " suppressedBubbleKey=" + suppressedBubbleKey 101 + " unsuppressedBubbleKey=" + unsupressedBubbleKey 102 + " removedBubbles=" + removedBubbles 103 + " bubbles=" + bubbleKeysInOrder 104 + " currentBubbleList=" + currentBubbleList 105 + " }"; 106 } 107 108 @Override describeContents()109 public int describeContents() { 110 return 0; 111 } 112 113 @Override writeToParcel(Parcel parcel, int flags)114 public void writeToParcel(Parcel parcel, int flags) { 115 parcel.writeBoolean(expandedChanged); 116 parcel.writeBoolean(expanded); 117 parcel.writeString(selectedBubbleKey); 118 parcel.writeParcelable(addedBubble, flags); 119 parcel.writeParcelable(updatedBubble, flags); 120 parcel.writeString(suppressedBubbleKey); 121 parcel.writeString(unsupressedBubbleKey); 122 parcel.writeParcelableList(removedBubbles, flags); 123 parcel.writeStringList(bubbleKeysInOrder); 124 parcel.writeParcelableList(currentBubbleList, flags); 125 } 126 127 @NonNull 128 public static final Creator<BubbleBarUpdate> CREATOR = 129 new Creator<BubbleBarUpdate>() { 130 public BubbleBarUpdate createFromParcel(Parcel source) { 131 return new BubbleBarUpdate(source); 132 } 133 public BubbleBarUpdate[] newArray(int size) { 134 return new BubbleBarUpdate[size]; 135 } 136 }; 137 } 138