• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.phone;
18 
19 import android.annotation.IntDef;
20 import android.annotation.Nullable;
21 import android.content.Context;
22 import android.graphics.drawable.Icon;
23 import android.os.UserHandle;
24 
25 import com.android.internal.statusbar.StatusBarIcon;
26 import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.CallIndicatorIconState;
27 import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState;
28 import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState;
29 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.MobileIconViewModel;
30 
31 import java.lang.annotation.Retention;
32 import java.lang.annotation.RetentionPolicy;
33 
34 /**
35  * Wraps {@link com.android.internal.statusbar.StatusBarIcon} so we can still have a uniform list
36  */
37 public class StatusBarIconHolder {
38     public static final int TYPE_ICON = 0;
39     public static final int TYPE_WIFI = 1;
40     public static final int TYPE_MOBILE = 2;
41     /**
42      * TODO (b/249790733): address this once the new pipeline is in place
43      * This type exists so that the new pipeline (see {@link MobileIconViewModel}) can be used
44      * to inform the old view system about changes to the data set (the list of mobile icons). The
45      * design of the new pipeline should allow for removal of this icon holder type, and obsolete
46      * the need for this entire class.
47      *
48      * @deprecated This field only exists so the new status bar pipeline can interface with the
49      * view holder system.
50      */
51     @Deprecated
52     public static final int TYPE_MOBILE_NEW = 3;
53 
54     /**
55      * TODO (b/238425913): address this once the new pipeline is in place
56      * This type exists so that the new wifi pipeline can be used to inform the old view system
57      * about the existence of the wifi icon. The design of the new pipeline should allow for removal
58      * of this icon holder type, and obsolete the need for this entire class.
59      *
60      * @deprecated This field only exists so the new status bar pipeline can interface with the
61      * view holder system.
62      */
63     @Deprecated
64     public static final int TYPE_WIFI_NEW = 4;
65 
66     @IntDef({
67             TYPE_ICON,
68             TYPE_WIFI,
69             TYPE_MOBILE,
70             TYPE_MOBILE_NEW,
71             TYPE_WIFI_NEW
72     })
73     @Retention(RetentionPolicy.SOURCE)
74     @interface IconType {}
75 
76     private StatusBarIcon mIcon;
77     private WifiIconState mWifiState;
78     private MobileIconState mMobileState;
79     private @IconType int mType = TYPE_ICON;
80     private int mTag = 0;
81 
82     /** Returns a human-readable string representing the given type. */
getTypeString(@conType int type)83     public static String getTypeString(@IconType int type) {
84         switch(type) {
85             case TYPE_ICON: return "ICON";
86             case TYPE_WIFI: return "WIFI_OLD";
87             case TYPE_MOBILE: return "MOBILE_OLD";
88             case TYPE_MOBILE_NEW: return "MOBILE_NEW";
89             case TYPE_WIFI_NEW: return "WIFI_NEW";
90             default: return "UNKNOWN";
91         }
92     }
93 
StatusBarIconHolder()94     private StatusBarIconHolder() {
95     }
96 
fromIcon(StatusBarIcon icon)97     public static StatusBarIconHolder fromIcon(StatusBarIcon icon) {
98         StatusBarIconHolder wrapper = new StatusBarIconHolder();
99         wrapper.mIcon = icon;
100 
101         return wrapper;
102     }
103 
104     /** */
fromResId( Context context, int resId, CharSequence contentDescription)105     public static StatusBarIconHolder fromResId(
106             Context context,
107             int resId,
108             CharSequence contentDescription) {
109         StatusBarIconHolder holder = new StatusBarIconHolder();
110         holder.mIcon = new StatusBarIcon(UserHandle.SYSTEM, context.getPackageName(),
111                 Icon.createWithResource( context, resId), 0, 0, contentDescription);
112         return holder;
113     }
114 
115     /** */
fromWifiIconState(WifiIconState state)116     public static StatusBarIconHolder fromWifiIconState(WifiIconState state) {
117         StatusBarIconHolder holder = new StatusBarIconHolder();
118         holder.mWifiState = state;
119         holder.mType = TYPE_WIFI;
120         return holder;
121     }
122 
123     /** Creates a new holder with for the new wifi icon. */
forNewWifiIcon()124     public static StatusBarIconHolder forNewWifiIcon() {
125         StatusBarIconHolder holder = new StatusBarIconHolder();
126         holder.mType = TYPE_WIFI_NEW;
127         return holder;
128     }
129 
130     /** */
fromMobileIconState(MobileIconState state)131     public static StatusBarIconHolder fromMobileIconState(MobileIconState state) {
132         StatusBarIconHolder holder = new StatusBarIconHolder();
133         holder.mMobileState = state;
134         holder.mType = TYPE_MOBILE;
135         holder.mTag = state.subId;
136         return holder;
137     }
138 
139     /**
140      * ONLY for use with the new connectivity pipeline, where we only need a subscriptionID to
141      * determine icon ordering and building the correct view model
142      */
fromSubIdForModernMobileIcon(int subId)143     public static StatusBarIconHolder fromSubIdForModernMobileIcon(int subId) {
144         StatusBarIconHolder holder = new StatusBarIconHolder();
145         holder.mType = TYPE_MOBILE_NEW;
146         holder.mTag = subId;
147 
148         return holder;
149     }
150 
151     /**
152      * Creates a new StatusBarIconHolder from a CallIndicatorIconState.
153      */
fromCallIndicatorState( Context context, CallIndicatorIconState state)154     public static StatusBarIconHolder fromCallIndicatorState(
155             Context context,
156             CallIndicatorIconState state) {
157         StatusBarIconHolder holder = new StatusBarIconHolder();
158         int resId = state.isNoCalling ? state.noCallingResId : state.callStrengthResId;
159         String contentDescription = state.isNoCalling
160                 ? state.noCallingDescription : state.callStrengthDescription;
161         holder.mIcon = new StatusBarIcon(UserHandle.SYSTEM, context.getPackageName(),
162                 Icon.createWithResource(context, resId), 0, 0, contentDescription);
163         holder.mTag = state.subId;
164         return holder;
165     }
166 
getType()167     public @IconType int getType() {
168         return mType;
169     }
170 
171     @Nullable
getIcon()172     public StatusBarIcon getIcon() {
173         return mIcon;
174     }
175 
setIcon(StatusBarIcon icon)176     public void setIcon(StatusBarIcon icon) {
177         mIcon = icon;
178     }
179 
180     @Nullable
getWifiState()181     public WifiIconState getWifiState() {
182         return mWifiState;
183     }
184 
setWifiState(WifiIconState state)185     public void setWifiState(WifiIconState state) {
186         mWifiState = state;
187     }
188 
189     @Nullable
getMobileState()190     public MobileIconState getMobileState() {
191         return mMobileState;
192     }
193 
setMobileState(MobileIconState state)194     public void setMobileState(MobileIconState state) {
195         mMobileState = state;
196     }
197 
isVisible()198     public boolean isVisible() {
199         switch (mType) {
200             case TYPE_ICON:
201                 return mIcon.visible;
202             case TYPE_WIFI:
203                 return mWifiState.visible;
204             case TYPE_MOBILE:
205                 return mMobileState.visible;
206             case TYPE_MOBILE_NEW:
207             case TYPE_WIFI_NEW:
208                 // The new pipeline controls visibilities via the view model and view binder, so
209                 // this is effectively an unused return value.
210                 return true;
211             default:
212                 return true;
213         }
214     }
215 
setVisible(boolean visible)216     public void setVisible(boolean visible) {
217         if (isVisible() == visible) {
218             return;
219         }
220 
221         switch (mType) {
222             case TYPE_ICON:
223                 mIcon.visible = visible;
224                 break;
225 
226             case TYPE_WIFI:
227                 mWifiState.visible = visible;
228                 break;
229 
230             case TYPE_MOBILE:
231                 mMobileState.visible = visible;
232                 break;
233 
234             case TYPE_MOBILE_NEW:
235             case TYPE_WIFI_NEW:
236                 // The new pipeline controls visibilities via the view model and view binder, so
237                 // ignore setVisible.
238                 break;
239         }
240     }
241 
getTag()242     public int getTag() {
243         return mTag;
244     }
245 
246     @Override
toString()247     public String toString() {
248         return "StatusBarIconHolder(type=" + getTypeString(mType)
249                 + " tag=" + getTag()
250                 + " visible=" + isVisible() + ")";
251     }
252 }
253