Fix location status bar icon
It should have been in PhoneStatusBarPolicy, since it wasn't it
wouldn't listen until something else touched the LocationController
like QS.
Test: Open app that uses location
Change-Id: I70d1aff2a1c9bf7be53aeb72ba285b49d98c5362
Fixes: 36747248
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java
index a444934..c499619 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java
@@ -81,7 +81,7 @@
}
String location = args.getString("location");
if (location != null) {
- int iconId = location.equals("show") ? LocationControllerImpl.LOCATION_STATUS_ICON_ID
+ int iconId = location.equals("show") ? PhoneStatusBarPolicy.LOCATION_STATUS_ICON_ID
: 0;
updateSlot("location", null, iconId);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
index 53ec8c5..5910557 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
@@ -73,6 +73,8 @@
import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
+import com.android.systemui.statusbar.policy.LocationController;
+import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback;
import com.android.systemui.statusbar.policy.NextAlarmController;
import com.android.systemui.statusbar.policy.RotationLockController;
import com.android.systemui.statusbar.policy.RotationLockController.RotationLockControllerCallback;
@@ -86,11 +88,13 @@
* strictly doesn't need to.
*/
public class PhoneStatusBarPolicy implements Callback, Callbacks,
- RotationLockControllerCallback, Listener,
+ RotationLockControllerCallback, Listener, LocationChangeCallback,
ZenModeController.Callback, DeviceProvisionedListener, KeyguardMonitor.Callback {
private static final String TAG = "PhoneStatusBarPolicy";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ public static final int LOCATION_STATUS_ICON_ID = R.drawable.stat_sys_location;
+
private final String mSlotCast;
private final String mSlotHotspot;
private final String mSlotBluetooth;
@@ -102,6 +106,7 @@
private final String mSlotRotate;
private final String mSlotHeadset;
private final String mSlotDataSaver;
+ private final String mSlotLocation;
private final Context mContext;
private final Handler mHandler = new Handler();
@@ -117,6 +122,7 @@
private final ZenModeController mZenController;
private final DeviceProvisionedController mProvisionedController;
private final KeyguardMonitor mKeyguardMonitor;
+ private final LocationController mLocationController;
private final ArraySet<Pair<String, Integer>> mCurrentNotifs = new ArraySet<>();
// Assume it's all good unless we hear otherwise. We don't always seem
@@ -147,6 +153,7 @@
mZenController = Dependency.get(ZenModeController.class);
mProvisionedController = Dependency.get(DeviceProvisionedController.class);
mKeyguardMonitor = Dependency.get(KeyguardMonitor.class);
+ mLocationController = Dependency.get(LocationController.class);
mSlotCast = context.getString(com.android.internal.R.string.status_bar_cast);
mSlotHotspot = context.getString(com.android.internal.R.string.status_bar_hotspot);
@@ -160,7 +167,7 @@
mSlotRotate = context.getString(com.android.internal.R.string.status_bar_rotate);
mSlotHeadset = context.getString(com.android.internal.R.string.status_bar_headset);
mSlotDataSaver = context.getString(com.android.internal.R.string.status_bar_data_saver);
-
+ mSlotLocation = context.getString(com.android.internal.R.string.status_bar_location);
// listen for broadcasts
IntentFilter filter = new IntentFilter();
@@ -229,6 +236,7 @@
mNextAlarm.addCallback(mNextAlarmCallback);
mDataSaver.addCallback(this);
mKeyguardMonitor.addCallback(this);
+ mLocationController.addCallback(this);
SysUiServiceProvider.getComponent(mContext, CommandQueue.class).addCallbacks(this);
SystemServicesProxy.getInstance(mContext).registerTaskStackListener(mTaskListener);
@@ -252,6 +260,7 @@
mNextAlarm.removeCallback(mNextAlarmCallback);
mDataSaver.removeCallback(this);
mKeyguardMonitor.removeCallback(this);
+ mLocationController.removeCallback(this);
SysUiServiceProvider.getComponent(mContext, CommandQueue.class).removeCallbacks(this);
mContext.unregisterReceiver(mIntentReceiver);
@@ -265,6 +274,21 @@
updateVolumeZen();
}
+ @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.setIcon(mSlotLocation, LOCATION_STATUS_ICON_ID,
+ mContext.getString(R.string.accessibility_location_active));
+ } else {
+ mIconController.removeIcon(mSlotLocation);
+ }
+ }
+
private void updateAlarm() {
final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
index 9a5f1b8..8e8a285 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
@@ -16,22 +16,29 @@
package com.android.systemui.statusbar.policy;
-import com.android.systemui.statusbar.policy.LocationController.LocationSettingsChangeCallback;
+import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback;
-public interface LocationController extends CallbackController<LocationSettingsChangeCallback> {
+public interface LocationController extends CallbackController<LocationChangeCallback> {
+ boolean isLocationActive();
boolean isLocationEnabled();
boolean setLocationEnabled(boolean enabled);
/**
* A callback for change in location settings (the user has enabled/disabled location).
*/
- public interface LocationSettingsChangeCallback {
+ public interface LocationChangeCallback {
+ /**
+ * Called whenever location's state changes.
+ * @param active
+ */
+ default void onLocationActiveChanged(boolean active) {}
+
/**
* Called whenever location settings change.
*
* @param locationEnabled A value of true indicates that at least one type of location
* is enabled in settings.
*/
- void onLocationSettingsChanged(boolean locationEnabled);
+ default void onLocationSettingsChanged(boolean locationEnabled) {}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
index cc61605..3f5f5a0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
@@ -41,9 +41,6 @@
* A controller to manage changes of location related states and update the views accordingly.
*/
public class LocationControllerImpl extends BroadcastReceiver implements LocationController {
- // The name of the placeholder corresponding to the location request status icon.
- // This string corresponds to config_statusBarIcons in core/res/res/values/config.xml.
- public static final int LOCATION_STATUS_ICON_ID = R.drawable.stat_sys_location;
private static final int[] mHighPowerRequestAppOpArray
= new int[] {AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION};
@@ -55,14 +52,12 @@
private boolean mAreActiveLocationRequests;
- private ArrayList<LocationSettingsChangeCallback> mSettingsChangeCallbacks =
- new ArrayList<LocationSettingsChangeCallback>();
+ private ArrayList<LocationChangeCallback> mSettingsChangeCallbacks =
+ new ArrayList<LocationChangeCallback>();
private final H mHandler = new H();
- public final String mSlotLocation;
public LocationControllerImpl(Context context, Looper bgLooper) {
mContext = context;
- mSlotLocation = mContext.getString(com.android.internal.R.string.status_bar_location);
// Register to listen for changes in location settings.
IntentFilter filter = new IntentFilter();
@@ -76,18 +71,17 @@
// Examine the current location state and initialize the status view.
updateActiveLocationRequests();
- refreshViews();
}
/**
* Add a callback to listen for changes in location settings.
*/
- public void addCallback(LocationSettingsChangeCallback cb) {
+ public void addCallback(LocationChangeCallback cb) {
mSettingsChangeCallbacks.add(cb);
mHandler.sendEmptyMessage(H.MSG_LOCATION_SETTINGS_CHANGED);
}
- public void removeCallback(LocationSettingsChangeCallback cb) {
+ public void removeCallback(LocationChangeCallback cb) {
mSettingsChangeCallbacks.remove(cb);
}
@@ -130,6 +124,11 @@
return mode != Settings.Secure.LOCATION_MODE_OFF;
}
+ @Override
+ public boolean isLocationActive() {
+ return mAreActiveLocationRequests;
+ }
+
/**
* Returns true if the current user is restricted from using location.
*/
@@ -170,22 +169,12 @@
return false;
}
- // Updates the status view based on the current state of location requests.
- private void refreshViews() {
- if (mAreActiveLocationRequests) {
- mStatusBarManager.setIcon(mSlotLocation, LOCATION_STATUS_ICON_ID,
- 0, mContext.getString(R.string.accessibility_location_active));
- } else {
- mStatusBarManager.removeIcon(mSlotLocation);
- }
- }
-
// Reads the active location requests and updates the status view if necessary.
private void updateActiveLocationRequests() {
boolean hadActiveLocationRequests = mAreActiveLocationRequests;
mAreActiveLocationRequests = areActiveHighPowerLocationRequests();
if (mAreActiveLocationRequests != hadActiveLocationRequests) {
- refreshViews();
+ mHandler.sendEmptyMessage(H.MSG_LOCATION_ACTIVE_CHANGED);
}
}
@@ -201,6 +190,7 @@
private final class H extends Handler {
private static final int MSG_LOCATION_SETTINGS_CHANGED = 1;
+ private static final int MSG_LOCATION_ACTIVE_CHANGED = 2;
@Override
public void handleMessage(Message msg) {
@@ -208,12 +198,21 @@
case MSG_LOCATION_SETTINGS_CHANGED:
locationSettingsChanged();
break;
+ case MSG_LOCATION_ACTIVE_CHANGED:
+ locationActiveChanged();
+ break;
+ }
+ }
+
+ private void locationActiveChanged() {
+ for (LocationChangeCallback cb : mSettingsChangeCallbacks) {
+ cb.onLocationActiveChanged(mAreActiveLocationRequests);
}
}
private void locationSettingsChanged() {
boolean isEnabled = isLocationEnabled();
- for (LocationSettingsChangeCallback cb : mSettingsChangeCallbacks) {
+ for (LocationChangeCallback cb : mSettingsChangeCallbacks) {
cb.onLocationSettingsChanged(isEnabled);
}
}