代码路径: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java frameworks\base\core\res\res\values\config.xml 一、隐藏状态栏耳机图标 在PhoneStatusBarPolicy.java文件中注册广播,该广播中主要监听耳机是否插入、SIM卡的变化等
IntentFilter filter = new IntentFilter();
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
在PhoneStatusBarPolicy.java文件中updateHeadsetPlug()中就是修改耳机图标的
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case AudioManager.RINGER_MODE_CHANGED_ACTION:
case AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION:
updateVolumeZen();
break;
case TelephonyIntents.ACTION_SIM_STATE_CHANGED:
// Avoid rebroadcast because SysUI is direct boot aware.
if (intent.getBooleanExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK,
false)) {
break;
}
updateSimState(intent);
break;
case TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED:
updateTTY(intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
TelecomManager.TTY_MODE_OFF));
break;
case Intent.ACTION_MANAGED_PROFILE_AVAILABLE:
case Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE:
case Intent.ACTION_MANAGED_PROFILE_REMOVED:
updateManagedProfile();
break;
case AudioManager.ACTION_HEADSET_PLUG:
updateHeadsetPlug(intent);
break;
}
}
};
private void updateHeadsetPlug(Intent intent) {
boolean connected = intent.getIntExtra("state", 0) != 0;
boolean hasMic = intent.getIntExtra("microphone", 0) != 0;
if (connected) {
String contentDescription = mContext.getString(hasMic
? R.string.accessibility_status_bar_headset
: R.string.accessibility_status_bar_headphones);
mIconController.setIcon(mSlotHeadset, hasMic ? R.drawable.stat_sys_headset_mic
: R.drawable.stat_sys_headset, contentDescription);
mIconController.setIconVisibility(mSlotHeadset, false);
} else {
/*UNISOC: Add for bug 1130932 {@ */
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
if (!audioManager.isWiredHeadsetOn()) {
mIconController.setIconVisibility(mSlotHeadset, false);
}
/* @} */
}
}
二、状态栏隐藏定位位置图标 在PhoneStatusBarPolicy.java文件中onLocationActiveChanged()方法中监听定位开关是否打开和关闭
@Override
public void onLocationActiveChanged(boolean active) {
updateLocation();
}
// Updates the status view based on the current state of location requests.
private void updateLocation() {
if (mLocationController.isLocationActive()) {
mIconController.setIconVisibility(mSlotLocation, false);
} else {
mIconController.setIconVisibility(mSlotLocation, false);
}
}
|