The display refresh of Android's network signal bar is also part of the System UI. The main business logic is also in the System UI module. The whole process begins in PhoneStatusBar.java.
frameworks/base/packages/SystemUI/src/com/Android/systemui/statusbar/phone/PhoneStatusBar.Java;
Starting with the layout:
makeStatusBarView() of PhoneStatusBar.java loads super_status_bar.xml uniformly. In Android, there are three main places on the system UI to display the signal status bar, namely the status bar, the status bar under the lock screen interface and the quick setting area of the drop-down notification bar. The three references are status_bar.xml, keyguard_status_bar.xml, status_bar_expanded_header.xml, and the three layout files all go to include a system_icons.xml layout.
This layout is where the network signal bar display and battery icon display view are sought.
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:id="@+id/system_icons"
-
android:layout_width="wrap_content"
-
android:layout_height="match_parent"
-
android:gravity="center_vertical">
-
-
<com.android.keyguard.AlphaOptimizedLinearLayout android:id="@+id/statusIcons"
-
android:layout_width="wrap_content"
-
android:layout_height="match_parent"
-
android:gravity="center_vertical"
-
android:orientation="horizontal"/>
-
-
<include layout="@layout/signal_cluster_view"
-
android:id="@+id/signal_cluster"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:layout_marginStart="2.5dp"/>
-
-
-
<com.android.systemui.BatteryMeterView android:id="@+id/battery"
-
android:layout_height="14.5dp"
-
android:layout_width="9.5dp"
-
android:layout_marginBottom="@dimen/battery_margin_bottom"/>
-
</LinearLayout>
This layout will include a signal_cluster_view.xml layout, that is, this layout is the layout file of the specific signal bar.
-
<com.android.systemui.statusbar.SignalClusterView
-
xmlns:android="http://schemas.android.com/apk/res/android"
-
android:layout_height="match_parent"
-
android:layout_width="wrap_content"
-
android:gravity="center_vertical"
-
android:orientation="horizontal"
-
android:paddingEnd="@dimen/signal_cluster_battery_padding"
-
>
-
<ImageView
-
android:id="@+id/vpn"
-
android:layout_height="wrap_content"
-
android:layout_width="wrap_content"
-
android:paddingEnd="6dp"
-
android:src="@drawable/stat_sys_vpn_ic"
-
/>
-
<FrameLayout
-
android:id="@+id/wifi_combo"
-
android:layout_height="wrap_content"
-
android:layout_width="wrap_content"
-
>
-
<ImageView
-
android:id="@+id/wifi_signal"
-
android:layout_height="wrap_content"
-
android:layout_width="wrap_content"
-
/>
-
</FrameLayout>
-
<View
-
android:id="@+id/wifi_signal_spacer"
-
android:layout_width="4dp"
-
android:layout_height="4dp"
-
android:visibility="gone"
-
/>
-
<LinearLayout
-
android:id="@+id/mobile_signal_group"
-
android:layout_height="wrap_content"
-
android:layout_width="wrap_content"
-
>
-
</LinearLayout>
-
<ImageView
-
android:id="@+id/no_sims"
-
android:layout_height="wrap_content"
-
android:layout_width="wrap_content"
-
android:src="@drawable/stat_sys_no_sims"
-
/>
-
<View
-
android:id="@+id/wifi_airplane_spacer"
-
android:layout_width="4dp"
-
android:layout_height="4dp"
-
android:visibility="gone"
-
/>
-
<ImageView
-
android:id="@+id/airplane"
-
android:layout_height="wrap_content"
-
android:layout_width="wrap_content"
-
/>
-
</com.android.systemui.statusbar.SignalClusterView>
Code logic:
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
makeStatusBarView() method:
In this method, we first create two controllers, mNetwork Controller and mSecurity Controller.
-
mNetworkController = new NetworkControllerImpl(mContext, mHandlerThread.getLooper());
-
mSecurityController = new SecurityControllerImpl(mContext);
NetworkController Impl. Java inherits from Broadcast Receiver. Look at how NetworkController Impl is constructed:
-
public NetworkControllerImpl(Context context, Looper bgLooper) {
-
this(context, (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE),
-
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE),
-
(WifiManager) context.getSystemService(Context.WIFI_SERVICE),
-
SubscriptionManager.from(context), Config.readConfig(context), bgLooper,
-
new CallbackHandler(),
-
new AccessPointControllerImpl(context, bgLooper),
-
new MobileDataControllerImpl(context),
-
new SubscriptionDefaults());
-
mReceiverHandler.post(mRegisterListeners);
-
}
In this constructor, another constructor will be called first.
-
@VisibleForTesting
-
NetworkControllerImpl(Context context, ConnectivityManager connectivityManager,
-
TelephonyManager telephonyManager, WifiManager wifiManager,
-
SubscriptionManager subManager, Config config, Looper bgLooper,
-
CallbackHandler callbackHandler,
-
AccessPointControllerImpl accessPointController,
-
MobileDataControllerImpl mobileDataController,
-
SubscriptionDefaults defaultsHandler) {
-
mContext = context;
-
mConfig = config;
-
mReceiverHandler = new Handler(bgLooper);
-
mCallbackHandler = callbackHandler;
-
-
mSubscriptionManager = subManager;
-
mSubDefaults = defaultsHandler;
-
mConnectivityManager = connectivityManager;
-
mHasMobileDataFeature =
-
mConnectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
-
-
-
mPhone = telephonyManager;
-
-
-
mWifiManager = wifiManager;
-
-
mLocale = mContext.getResources().getConfiguration().locale;
-
mAccessPoints = accessPointController;
-
mMobileDataController = mobileDataController;
-
mMobileDataController.setNetworkController(this);
-
-
mMobileDataController.setCallback(new MobileDataControllerImpl.Callback() {
-
@Override
-
public void onMobileDataEnabled(boolean enabled) {
-
mCallbackHandler.setMobileDataEnabled(enabled);
-
}
-
});
-
mWifiSignalController = new WifiSignalController(mContext, mHasMobileDataFeature,
-
mCallbackHandler, this);
-
-
mEthernetSignalController = new EthernetSignalController(mContext, mCallbackHandler, this);
-
-
-
updateAirplaneMode(true );
-
}
1. Assigning the corresponding member variables;
2. Create handler, mReceiver Handler, mCallbackHandler;
3. Create mMobile Data Controller controller and set callbacks for it.
4. Create mWifiSignalController, mEthernetSignalController controller;
5. Check and update flight mode;
After executing this internal construction method, we will use mReceiver Handler to perform a registered broadcast operation, which is responsible for monitoring wifi, SIM card status, service state, flight mode and so on. Finally, we call the updateMobileControllers() method to initialize the signal bar display:
-
mReceiverHandler.post(mRegisterListeners);
-
-
-
-
-
private final Runnable mRegisterListeners = new Runnable() {
-
@Override
-
public void run() {
-
registerListeners();
-
}
-
};
-
private void registerListeners() {
-
for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) {
-
mobileSignalController.registerListener();
-
}
-
if (mSubscriptionListener == null) {
-
mSubscriptionListener = new SubListener();
-
}
-
mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);
-
-
-
IntentFilter filter = new IntentFilter();
-
filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
-
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
-
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
-
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
-
filter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
-
filter.addAction(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED);
-
filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
-
filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
-
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
-
filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);
-
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
-
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
-
if (carrier != null && (CarrierAppUtils.CARRIER.TELEPHONY_CARRIER_ONE
-
== carrier)) {
-
filter.addAction(ACTION_EMBMS_STATUS);
-
}
-
mContext.registerReceiver(this, filter, null, mReceiverHandler);
-
mListening = true;
-
-
updateMobileControllers();
-
}
After analyzing the construction method of Network Controller Impl. java, we can basically know that Network Controller Impl. Java is a data control class as a signal bar, responsible for monitoring wifi, service state, flight mode and so on.
Look at the construction method of SecurityController Impl. java. First we get some instances of system services, then we register a network callback interface when users switch.
-
public SecurityControllerImpl(Context context) {
-
mContext = context;
-
mDevicePolicyManager = (DevicePolicyManager)
-
context.getSystemService(Context.DEVICE_POLICY_SERVICE);
-
mConnectivityManager = (ConnectivityManager)
-
context.getSystemService(Context.CONNECTIVITY_SERVICE);
-
mConnectivityManagerService = IConnectivityManager.Stub.asInterface(
-
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
-
mUserManager = (UserManager)
-
context.getSystemService(Context.USER_SERVICE);
-
-
-
mConnectivityManager.registerNetworkCallback(REQUEST, mNetworkCallback);
-
onUserSwitched(ActivityManager.getCurrentUser());
-
}
Returning to PhoneStatusBar.java's makeStatusBarView() method, we instantiate the custom view object SignalClusterView. As mentioned above, we need to use the network signal status bar in all three parts of the Android System UI, so we instantiate it three times and add corresponding interfaces to it.
-
final SignalClusterView signalCluster =
-
(SignalClusterView) mStatusBarView.findViewById(R.id.signal_cluster);
-
final SignalClusterView signalClusterKeyguard =
-
(SignalClusterView) mKeyguardStatusBar.findViewById(R.id.signal_cluster);
-
final SignalClusterView signalClusterQs =
-
(SignalClusterView) mHeader.findViewById(R.id.signal_cluster);
-
mNetworkController.addSignalCallback(signalCluster);
-
mNetworkController.addSignalCallback(signalClusterKeyguard);
-
mNetworkController.addSignalCallback(signalClusterQs);
-
signalCluster.setSecurityController(mSecurityController);
-
signalCluster.setNetworkController(mNetworkController);
-
signalClusterKeyguard.setSecurityController(mSecurityController);
-
signalClusterKeyguard.setNetworkController(mNetworkController);
-
signalClusterQs.setSecurityController(mSecurityController);
-
signalClusterQs.setNetworkController(mNetworkController);
Let's first look at the addSignalCallback() method, which passes in an object with the parameter SignalClusterView.java. That is to say, it can be boldly assumed that the function of this method should be to establish callback calls between SignalClusterView.java and NetworkController Impl. java. Specifically, the main implementation of this method is in NetworkController Impl. java.
-
public void addSignalCallback(SignalCallback cb) {
-
mCallbackHandler.setListening(cb, true);
-
mCallbackHandler.setSubs(mCurrentSubscriptions);
-
mCallbackHandler.setIsAirplaneMode(new IconState(mAirplaneMode,
-
TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext));
-
mCallbackHandler.setNoSims(mHasNoSims);
-
mWifiSignalController.notifyListeners();
-
mEthernetSignalController.notifyListeners();
-
for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) {
-
mobileSignalController.notifyListeners();
-
}
-
}
Call the CallbackHandler.setXXX() method, which mainly performs the corresponding operation by sending an msg to handler. Take the setListening() method as an example:
Send a message to handler that msg is MSG_ADD_REMOVE_SIGNAL:
-
public void setListening(SignalCallback listener, boolean listening) {
-
obtainMessage(MSG_ADD_REMOVE_SIGNAL, listening ? 1 : 0, 0, listener).sendToTarget();
-
}
Add callback to the collection and store it in handler to complete the setListening() method:
-
case MSG_ADD_REMOVE_SIGNAL:
-
if (msg.arg1 != 0) {
-
mSignalCallbacks.add((SignalCallback) msg.obj);
-
} else {
-
mSignalCallbacks.remove((SignalCallback) msg.obj);
-
}
-
break;
Through the analysis of these setXXX() methods, it is found that CallBackHandler.java class is mainly used for message transmission between Network Controller Impl. Java and SignalClusterView.java, which is realized by callback of Network Controller. SignalCallback interface.
Next, we call the notifyListeners() method of wifi, Ethernet signal and mobile signal controller respectively to perform the initialization information status operation.
Go back to PhoneStatusBar.java's makeStatusBarView() method, and then continue calling SignalClusterView.java's method:
-
signalCluster.setSecurityController(mSecurityController);
-
signalCluster.setNetworkController(mNetworkController);
-
setNetworkController()The main method is to instantiate this class. NetworkControllerImpl control object;
-
public void setNetworkController(NetworkControllerImpl nc) {
-
if (DEBUG) Log.d(TAG, "NetworkController=" + nc);
-
mNC = nc;
-
}
-
-
public void setSecurityController(SecurityController sc) {
-
if (DEBUG) Log.d(TAG, "SecurityController=" + sc);
-
mSC = sc;
-
mSC.addCallback(this);
-
mVpnVisible = mSC.isVpnEnabled();
-
}
The setSecurityController() method not only needs to assign values to member variables, but also needs to call the addCallback() method of SecurityController Impl. java to add the callback object of the controller to the set mCallbacks to save.
-
@Override
-
public void addCallback(SecurityControllerCallback callback) {
-
synchronized (mCallbacks) {
-
if (callback == null || mCallbacks.contains(callback)) return;
-
if (DEBUG) Log.d(TAG, "addCallback " + callback);
-
mCallbacks.add(callback);
-
}
-
}
This completes the signal bar analysis in PhoneStatusBar.java's makeStatusBarView().
Summary of Process Execution in PhoneStatusBar.java's makeStatusBarView():
1. Instantiate two controller implementation objects, NetworkController Impl. Java and SecurityController Impl. java. Register the broadcasting of corresponding state changes in the construction method of NetworkController Impl. java, and register the monitoring callback of network state changes when users switch in SecurityController Impl. java.
2. Initialize the signal bar object, SignalClusterView.java;
3. Connect Network Controller Impl. java with ignalClusterView. Java through CallbackHandler.java, and control communication between Network Controller Impl. Java and SignalClusterView.java through callback.
4. SignalClusterView.java calls setSecurityController() to implement the SecurityController Callback interface. By calling back onStateChanged(), it can monitor the changes of network state when switching users.
5. Network Controller Impl. Java is a data control class of signal bar, inherited from Broadcast Receiver, responsible for monitoring wifi, SIM card status, service state, flight mode and so on.
6. SignalClusterView.java is used to refresh and display the interface.
Next, we will analyze the process of system UI execution when some states change. Take inserting SIM card as an example:
1. When the SIM card is inserted, the android system will send Telephone Intents. ACTION_SIM_STATE_CHANGED broadcasting.
2. Network Controller Impl. Java inherits from Broadcast Receiver and monitors some corresponding system broadcasts.
3. Call the onReceiver() method of NetworkController Impl. Java and the updateMobileControllers() method after receiving the broadcast of TelephonyIntents.ACTION_SIM_STATE_CHANGED.
-
if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
-
-
updateMobileControllers();
-
}
4. Internally call the doUpdateMobileControllers() method;
-
private void updateMobileControllers() {
-
if (!mListening) {
-
return;
-
}
-
doUpdateMobileControllers();
-
}
5. Get the information of the sim card in the current device and empty the set if it returns. If the subscription information of the sim card does not change, it will enter the if() statement and then call the updateNoSims() method and return. Because the current analysis is to insert the sim card, it will not enter the if() statement.
-
@VisibleForTesting
-
void doUpdateMobileControllers() {
-
List<SubscriptionInfo> subscriptions = mSubscriptionManager.getActiveSubscriptionInfoList();
-
if (subscriptions == null) {
-
subscriptions = Collections.emptyList();
-
}
-
-
if (hasCorrectMobileControllers(subscriptions)) {
-
-
-
-
updateNoSims();
-
return;
-
}
-
setCurrentSubscriptions(subscriptions);
-
updateNoSims();
-
recalculateEmergency();
-
}
The setCurrentSubscriptions() method is called, which constructs the Mobile Signal Controller based on the returned sim card subscription information set and stores it with the set Map < Integer, Mobile Signal Controller > mMobile Signal Controllers.
-
@VisibleForTesting
-
void setCurrentSubscriptions(List<SubscriptionInfo> subscriptions) {
-
Collections.sort(subscriptions, new Comparator<SubscriptionInfo>() {
-
@Override
-
public int compare(SubscriptionInfo lhs, SubscriptionInfo rhs) {
-
return lhs.getSimSlotIndex() == rhs.getSimSlotIndex()
-
? lhs.getSubscriptionId() - rhs.getSubscriptionId()
-
: lhs.getSimSlotIndex() - rhs.getSimSlotIndex();
-
}
-
});
-
mCurrentSubscriptions = subscriptions;
-
-
HashMap<Integer, MobileSignalController> cachedControllers =
-
new HashMap<Integer, MobileSignalController>(mMobileSignalControllers);
-
mMobileSignalControllers.clear();
-
final int num = subscriptions.size();
-
for (int i = 0; i < num; i++) {
-
int subId = subscriptions.get(i).getSubscriptionId();
-
-
if (cachedControllers.containsKey(subId)) {
-
mMobileSignalControllers.put(subId, cachedControllers.remove(subId));
-
} else {
-
MobileSignalController controller = new MobileSignalController(mContext, mConfig,
-
mHasMobileDataFeature, mPhone, mCallbackHandler,
-
this, subscriptions.get(i), mSubDefaults, mReceiverHandler.getLooper());
-
mMobileSignalControllers.put(subId, controller);
-
if (subscriptions.get(i).getSimSlotIndex() == 0) {
-
mDefaultSignalController = controller;
-
}
-
if (mListening) {
-
controller.registerListener();
-
}
-
}
-
}
-
if (mListening) {
-
for (Integer key : cachedControllers.keySet()) {
-
if (cachedControllers.get(key) == mDefaultSignalController) {
-
mDefaultSignalController = null;
-
}
-
cachedControllers.get(key).unregisterListener();
-
}
-
}
-
mCallbackHandler.setSubs(subscriptions);
-
notifyAllListeners();
-
-
-
-
pushConnectivityToSignals();
-
updateAirplaneMode(true );
-
}
MobileSignalController.java is a class used to encapsulate Icon controllers based on signal strength, operator, network type, etc.
-
public MobileSignalController(Context context, Config config, boolean hasMobileData,
-
TelephonyManager phone, CallbackHandler callbackHandler,
-
NetworkControllerImpl networkController, SubscriptionInfo info,
-
SubscriptionDefaults defaults, Looper receiverLooper) {
-
super("MobileSignalController(" + info.getSubscriptionId() + ")", context,
-
NetworkCapabilities.TRANSPORT_CELLULAR, callbackHandler,
-
networkController);
-
mNetworkToIconLookup = new SparseArray<>();
-
mConfig = config;
-
mPhone = phone;
-
mDefaults = defaults;
-
mSubscriptionInfo = info;
-
mPhoneStateListener = new MobilePhoneStateListener(info.getSubscriptionId(),
-
receiverLooper);
-
mNetworkNameSeparator = getStringIfExists(R.string.status_bar_network_name_separator);
-
mNetworkNameDefault = getStringIfExists(
-
com.android.internal.R.string.lockscreen_carrier_default);
-
mIsDataSignalControlEnabled = mContext.getResources()
-
.getBoolean(R.bool.config_data_signal_control);
-
if (mIsDataSignalControlEnabled) {
-
mDataEnabledSettingObserver =
-
new DataEnabledSettingObserver(new Handler(), context);
-
mLastState.isForbidden = mCurrentState.isForbidden =
-
!(isMobileDataEnabled(mSubscriptionInfo.getSubscriptionId()));
-
}
-
if (config.readIconsFromXml) {
-
TelephonyIcons.readIconsFromXml(context);
-
mDefaultIcons = !mConfig.showAtLeast3G ? TelephonyIcons.G : TelephonyIcons.THREE_G;
-
} else {
-
mapIconSets();
-
}
-
-
if (carrier != null && (CarrierAppUtils.CARRIER.TELEPHONY_CARRIER_ONE
-
== carrier)) {
-
mStyle = context.getResources().getInteger(R.integer.status_bar_style_extended);
-
} else {
-
mStyle = context.getResources().getInteger(R.integer.status_bar_style);
-
}
-
-
String networkName = info.getCarrierName() != null ? info.getCarrierName().toString()
-
: mNetworkNameDefault;
-
mLastState.networkName = mCurrentState.networkName = networkName;
-
mLastState.networkNameData = mCurrentState.networkNameData = networkName;
-
mLastState.enabled = mCurrentState.enabled = hasMobileData;
-
mLastState.iconGroup = mCurrentState.iconGroup = mDefaultIcons;
-
-
updateDataSim();
-
}
1. Mobile Phone StateListener is used to monitor signal strength, mobile data links, etc. updateTelephony() method is called to update current state to set network type, icon, signal strength, etc. when signal strength and mobile data connection are detected to change. Then notifyListeners IfNecessary () method is called to call notifyListeners() method, and setMobileDataIndica in SignalClusterView.java is called through CallbackHandler object. The tors () method completes the refresh display of icons.
2. mapIconSets() is used to set the Icon map set of network type.
3. After this construction method is executed, it will return to the setCurrentSubscriptions() method of NetworkController Impl. Java and execute the controller.registerListener() statement to register the MobilePhoneStateListener listener for each MobileSignalController object.
Then call mCallbackHandler.setSubs() to pass the subscription information set of the sim card to the setSubs() method of SignalClusterView.java. First remove the previous mPhoneStatus information and mMobile Signal Group view, and then call the inflatePhoneState() method.
-
@Override
-
public void setSubs(List<SubscriptionInfo> subs) {
-
if (hasCorrectSubs(subs)) {
-
return;
-
}
-
-
mPhoneStates.clear();
-
if (mMobileSignalGroup != null) {
-
mMobileSignalGroup.removeAllViews();
-
}
-
final int n = subs.size();
-
boolean imsOverWiFi = false;
-
for (int i = 0; i < n; i++) {
-
inflatePhoneState(subs.get(i).getSubscriptionId());
-
imsOverWiFi |= getImsOverWifiStatus(subs.get(i).getSubscriptionId());
-
}
-
mImsOverWifi = imsOverWiFi;
-
if (isAttachedToWindow()) {
-
applyIconTint();
-
}
-
}
Call the inflatePhoneState() method to add state and view again.
-
private PhoneState inflatePhoneState(int subId) {
-
PhoneState state = new PhoneState(subId, mContext);
-
if (mMobileSignalGroup != null) {
-
mMobileSignalGroup.addView(state.mMobileGroup);
-
}
-
mPhoneStates.add(state);
-
return state;
-
}
Then go back to the setSubs() method and call the applyIconTint() method to set some Icon colors.
-
private void applyIconTint() {
-
setTint(mVpn, mIconTint);
-
setTint(mAirplane, mIconTint);
-
applyDarkIntensity(mDarkIntensity, mNoSims, mNoSimsDark);
-
applyDarkIntensity(mDarkIntensity, mWifi, mWifiDark);
-
applyDarkIntensity(mDarkIntensity, mEthernet, mEthernetDark);
-
for (int i = 0; i < mPhoneStates.size(); i++) {
-
mPhoneStates.get(i).setIconTint(mIconTint, mDarkIntensity);
-
}
-
}
Continue back to the setCurrentSubscriptions() method of NetworkController Impl. java, and then call notify AllListeners () method to notify mWifiSignalController(wifi), mEthernet SignalController (ethernet) and all mobile SignalController (mobile phone signal) to execute their respective fyListeners () methods;
-
notifyAllListeners();
-
-
-
-
-
private void notifyAllListeners() {
-
notifyListeners();
-
for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) {
-
mobileSignalController.notifyListeners();
-
}
-
mWifiSignalController.notifyListeners();
-
mEthernetSignalController.notifyListeners();
-
}
The notifyListeners() method of Mobile SignalController. Java is mainly used to set the display Icon image attributes of the current sim card attributes, and then call the setMobile Data Indicators () method in SignalClusterView.java through the CallbackHandler object.
-
@Override
-
public void notifyListeners() {
-
if (mConfig.readIconsFromXml) {
-
generateIconGroup();
-
}
-
MobileIconGroup icons = getIcons();
-
-
String contentDescription = getStringIfExists(getContentDescription());
-
String dataContentDescription = getStringIfExists(icons.mDataContentDescription);
-
-
-
boolean showDataIcon = false;
-
if (mContext.getResources().getBoolean(R.bool.show_roaming_and_network_icons)) {
-
showDataIcon = mCurrentState.dataConnected;
-
} else {
-
showDataIcon = mCurrentState.dataConnected
-
|| (mCurrentState.iconGroup == TelephonyIcons.ROAMING || isRoaming());
-
}
-
IconState statusIcon = new IconState(mCurrentState.enabled && !mCurrentState.airplaneMode,
-
getCurrentIconId(), contentDescription);
-
-
int qsTypeIcon = 0;
-
IconState qsIcon = null;
-
String description = null;
-
-
if (mCurrentState.dataSim) {
-
qsTypeIcon = showDataIcon ? icons.mQsDataType : 0;
-
qsIcon = new IconState(mCurrentState.enabled
-
&& !mCurrentState.isEmergency, getQsCurrentIconId(), contentDescription);
-
description = mCurrentState.isEmergency ? null : mCurrentState.networkName;
-
}
-
boolean activityIn = mCurrentState.dataConnected
-
&& !mCurrentState.carrierNetworkChangeMode
-
&& mCurrentState.activityIn;
-
boolean activityOut = mCurrentState.dataConnected
-
&& !mCurrentState.carrierNetworkChangeMode
-
&& mCurrentState.activityOut;
-
if (!mContext.getResources().getBoolean(R.bool.show_roaming_and_network_icons)) {
-
showDataIcon &= mCurrentState.isDefault
-
|| (mCurrentState.iconGroup == TelephonyIcons.ROAMING || isRoaming());
-
}
-
showDataIcon &= (mStyle == STATUS_BAR_STYLE_ANDROID_DEFAULT
-
|| mStyle == STATUS_BAR_STYLE_EXTENDED);
-
int typeIcon = showDataIcon ? icons.mDataType : 0;
-
int dataActivityId = showMobileActivity() ? 0 : icons.mActivityId;
-
int mobileActivityId = showMobileActivity() ? icons.mActivityId : 0;
-
int dataNetworkTypeInRoamingId = 0;
-
if (mStyle == STATUS_BAR_STYLE_EXTENDED && isRoaming()) {
-
dataNetworkTypeInRoamingId = mCurrentState.dataConnected ? typeIcon : 0;
-
typeIcon = TelephonyIcons.ROAMING_ICON;
-
qsTypeIcon = mCurrentState.dataConnected ? qsTypeIcon : 0;
-
}
-
mCallbackHandler.setMobileDataIndicators(statusIcon, qsIcon, typeIcon, qsTypeIcon,
-
activityIn, activityOut, dataActivityId, mobileActivityId,
-
icons.mStackedDataIcon, icons.mStackedVoiceIcon,
-
dataContentDescription, description, icons.mIsWide,
-
mSubscriptionInfo.getSubscriptionId(), getImsIconId(),
-
isImsRegisteredInWifi(), dataNetworkTypeInRoamingId,
-
getEmbmsIconId());
-
-
mCallbackHandler.post(new Runnable() {
-
@Override
-
public void run() {
-
mNetworkController.updateNetworkLabelView();
-
}
-
});
-
}
Call the setMobile Data Indicators () method in SignalClusterView.java to refresh the status of the current PhoneState object, and finally call the apply() method to refresh the Icon icon on the interface.
-
@Override
-
public void setMobileDataIndicators(IconState statusIcon, IconState qsIcon, int statusType,
-
int qsType, boolean activityIn, boolean activityOut, int dataActivityId,
-
int mobileActivityId, int stackedDataId, int stackedVoiceId,
-
String typeContentDescription, String description, boolean isWide, int subId) {
-
PhoneState state = getState(subId);
-
if (state == null) {
-
return;
-
}
-
state.mMobileVisible = statusIcon.visible && !mBlockMobile;
-
state.mMobileStrengthId = statusIcon.icon;
-
state.mMobileTypeId = statusType;
-
state.mMobileDescription = statusIcon.contentDescription;
-
state.mMobileTypeDescription = typeContentDescription;
-
state.mIsMobileTypeIconWide = statusType != 0 && isWide;
-
state.mDataActivityId = dataActivityId;
-
state.mMobileActivityId = mobileActivityId;
-
state.mStackedDataId = stackedDataId;
-
state.mStackedVoiceId = stackedVoiceId;
-
-
apply();
-
}
Perhaps in the course of the above operation, the network connection state has changed, and all of them finally go back to the NetworkController Impl. Java class to continue pushConnectivityToSignals() method to push the current network connection state to all the SignalControllers object controllers.
Signal bar summary:
1. The layout is loaded by PhoneStatusBar.java's makeStatusBarView() method. Because in Android system, the signal bar (status bar, status bar under lock screen interface and the quick setting area of drop-down notification bar) is used in three places, the three references are status_bar.xml, keyguard_status_bar.xml, status_bar_expanded_header.xml, instantiate three objects, and bind two controls for each SignalClusterView.java object in this method. Objects, NetworkController Impl. java, SecurityController Impl. java;
2. Network Controller Impl. Java object is mainly responsible for data control class as signal bar, inherited from Broadcast Receiver, responsible for monitoring wifi, SIM card status, service state, flight mode, etc.
SecurityController Impl. Java object is mainly responsible for the data control class of the signal bar when the user switches, and is responsible for monitoring the network state change callback when the user switches.
3. NetworkController Impl. Java links itself to SignalClusterView.java through CallbackHandler.java. In the middle, it controls communication between NetworkController Impl. Java and SignalClusterView.java by calling SignalClusterView.java in the object of CallbackHandler.java.
On the other hand, SignalClusterView.java implements the communication function by directly implementing the interface of SecurityController.java. In SecurityController Impl. java, SignalClusterView.java notifies SignalClusterView.java to do the corresponding operation by directly calling back onStateChanged().
4. Network Controller Impl. Java is inherited from Broadcast Receiver. It monitors SIM card events by monitoring system broadcasting and so on. When the SIM card is inserted, the subscription information set of the current SIM card is retrieved, and then the set is traversed to set up a MobileSignalController.java for subscription information.
5. Mobile SignalController. Java class mainly implements PhoneStateListener interface to monitor service state, signal strength, call status, mobile data connection status, and set corresponding display icons. These status and icon display properties are then passed to the SignalClusterView.java object through CallbackHandler.java.
6. SignalClusterView.java completes the final interface refresh by calling apply() method and application () method of internal PhoneState class.