diff options
author | Jason Monk <jmonk@google.com> | 2015-05-19 14:21:28 -0400 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2015-05-26 13:11:35 -0400 |
commit | 05b86bc02767e1714712dd0e612068b6da1eee51 (patch) | |
tree | c90b4d883aacb654d3ae1c5f340954aabe551ee2 /packages/SystemUI | |
parent | 327c364113c18c9d5a05df0c912b65788461da41 (diff) | |
download | frameworks_base-05b86bc02767e1714712dd0e612068b6da1eee51.zip frameworks_base-05b86bc02767e1714712dd0e612068b6da1eee51.tar.gz frameworks_base-05b86bc02767e1714712dd0e612068b6da1eee51.tar.bz2 |
SysUI: Move LocationControllerImpl receiver to bg
Bug: 19520495
Change-Id: Ia0fbfb663076c296c65bcefdad62d36f98c9e757
Diffstat (limited to 'packages/SystemUI')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java | 3 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java | 61 |
2 files changed, 34 insertions, 30 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 50cdbb6..1e4aa61 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -745,7 +745,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mHandlerThread.start(); // Other icons - mLocationController = new LocationControllerImpl(mContext); // will post a notification + mLocationController = new LocationControllerImpl(mContext, + mHandlerThread.getLooper()); // will post a notification mBatteryController = new BatteryController(mContext); mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() { @Override 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 d8d7042..93a8fd8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java @@ -26,6 +26,8 @@ import android.content.Intent; import android.content.IntentFilter; import android.location.LocationManager; import android.os.Handler; +import android.os.Looper; +import android.os.Message; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; @@ -56,31 +58,21 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio private ArrayList<LocationSettingsChangeCallback> mSettingsChangeCallbacks = new ArrayList<LocationSettingsChangeCallback>(); + private final H mHandler = new H(); - public LocationControllerImpl(Context context) { + public LocationControllerImpl(Context context, Looper bgLooper) { mContext = context; + // Register to listen for changes in location settings. IntentFilter filter = new IntentFilter(); filter.addAction(LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION); - context.registerReceiverAsUser(this, UserHandle.ALL, filter, null, null); + filter.addAction(LocationManager.MODE_CHANGED_ACTION); + context.registerReceiverAsUser(this, UserHandle.ALL, filter, null, new Handler(bgLooper)); mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE); - // Register to listen for changes in location settings. - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION); - context.registerReceiverAsUser(new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (LocationManager.MODE_CHANGED_ACTION.equals(action)) { - locationSettingsChanged(); - } - } - }, UserHandle.ALL, intentFilter, null, new Handler()); - // Examine the current location state and initialize the status view. updateActiveLocationRequests(); refreshViews(); @@ -91,7 +83,7 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio */ public void addSettingsChangedCallback(LocationSettingsChangeCallback cb) { mSettingsChangeCallbacks.add(cb); - locationSettingsChanged(cb); + mHandler.sendEmptyMessage(H.MSG_LOCATION_SETTINGS_CHANGED); } public void removeSettingsChangedCallback(LocationSettingsChangeCallback cb) { @@ -181,8 +173,8 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio // Updates the status view based on the current state of location requests. private void refreshViews() { if (mAreActiveLocationRequests) { - mStatusBarManager.setIcon(LOCATION_STATUS_ICON_PLACEHOLDER, LOCATION_STATUS_ICON_ID, 0, - mContext.getString(R.string.accessibility_location_active)); + mStatusBarManager.setIcon(LOCATION_STATUS_ICON_PLACEHOLDER, LOCATION_STATUS_ICON_ID, + 0, mContext.getString(R.string.accessibility_location_active)); } else { mStatusBarManager.removeIcon(LOCATION_STATUS_ICON_PLACEHOLDER); } @@ -197,22 +189,33 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio } } - private void locationSettingsChanged() { - boolean isEnabled = isLocationEnabled(); - for (LocationSettingsChangeCallback cb : mSettingsChangeCallbacks) { - cb.onLocationSettingsChanged(isEnabled); - } - } - - private void locationSettingsChanged(LocationSettingsChangeCallback cb) { - cb.onLocationSettingsChanged(isLocationEnabled()); - } - @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION.equals(action)) { updateActiveLocationRequests(); + } else if (LocationManager.MODE_CHANGED_ACTION.equals(action)) { + mHandler.sendEmptyMessage(H.MSG_LOCATION_SETTINGS_CHANGED); + } + } + + private final class H extends Handler { + private static final int MSG_LOCATION_SETTINGS_CHANGED = 1; + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_LOCATION_SETTINGS_CHANGED: + locationSettingsChanged(); + break; + } + } + + private void locationSettingsChanged() { + boolean isEnabled = isLocationEnabled(); + for (LocationSettingsChangeCallback cb : mSettingsChangeCallbacks) { + cb.onLocationSettingsChanged(isEnabled); + } } } } |