Merge "[Status Bar] Stop using Utils.safeForeach in LocationControllerImpl." into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f4cdc01a52
@@ -55,7 +55,6 @@ import com.android.systemui.dagger.qualifiers.Background;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.util.DeviceConfigProxy;
|
||||
import com.android.systemui.util.Utils;
|
||||
import com.android.systemui.util.settings.SecureSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -362,7 +361,8 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
|
||||
private static final int MSG_ADD_CALLBACK = 3;
|
||||
private static final int MSG_REMOVE_CALLBACK = 4;
|
||||
|
||||
private ArrayList<LocationChangeCallback> mSettingsChangeCallbacks = new ArrayList<>();
|
||||
private final ArrayList<LocationChangeCallback> mSettingsChangeCallbacks =
|
||||
new ArrayList<>();
|
||||
|
||||
H(Looper looper) {
|
||||
super(looper);
|
||||
@@ -388,14 +388,23 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
|
||||
}
|
||||
|
||||
private void locationActiveChanged() {
|
||||
Utils.safeForeach(mSettingsChangeCallbacks,
|
||||
cb -> cb.onLocationActiveChanged(mAreActiveLocationRequests));
|
||||
synchronized (mSettingsChangeCallbacks) {
|
||||
final int n = mSettingsChangeCallbacks.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
mSettingsChangeCallbacks.get(i)
|
||||
.onLocationActiveChanged(mAreActiveLocationRequests);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void locationSettingsChanged() {
|
||||
boolean isEnabled = isLocationEnabled();
|
||||
Utils.safeForeach(mSettingsChangeCallbacks,
|
||||
cb -> cb.onLocationSettingsChanged(isEnabled));
|
||||
synchronized (mSettingsChangeCallbacks) {
|
||||
final int n = mSettingsChangeCallbacks.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
mSettingsChangeCallbacks.get(i).onLocationSettingsChanged(isEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,10 @@ public class Utils {
|
||||
/**
|
||||
* Allows lambda iteration over a list. It is done in reverse order so it is safe
|
||||
* to add or remove items during the iteration. Skips over null items.
|
||||
*
|
||||
* @deprecated According to b/286841705, this is *not* safe: If an item is removed from the
|
||||
* list, then list.get(i) could throw an IndexOutOfBoundsException. This method should not be
|
||||
* used; try using `synchronized` or making a copy of the list instead.
|
||||
*/
|
||||
public static <T> void safeForeach(List<T> list, Consumer<T> c) {
|
||||
for (int i = list.size() - 1; i >= 0; i--) {
|
||||
|
||||
Reference in New Issue
Block a user