Skip to content

Commit 3750db1

Browse files
Victoria LeaseAndroid (Google) Code Review
authored andcommitted
Merge "Route GPS notifications to all users." into jb-mr1-dev
2 parents 6f354ed + 38389b6 commit 3750db1

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

location/java/com/android/internal/location/GpsNetInitiatedHandler.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.location.LocationManager;
2727
import android.os.Bundle;
2828
import android.os.RemoteException;
29+
import android.os.UserHandle;
2930
import android.util.Log;
3031

3132
import com.android.internal.R;
@@ -89,7 +90,6 @@ public class GpsNetInitiatedHandler {
8990

9091
// configuration of notificaiton behavior
9192
private boolean mPlaySounds = false;
92-
private boolean visible = true;
9393
private boolean mPopupImmediately = true;
9494

9595
// Set to true if string from HAL is encoded as Hex, e.g., "3F0039"
@@ -213,11 +213,8 @@ private synchronized void setNiNotification(GpsNiNotification notif) {
213213
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, intent, 0);
214214
mNiNotification.setLatestEventInfo(mContext, title, message, pi);
215215

216-
if (visible) {
217-
notificationManager.notify(notif.notificationId, mNiNotification);
218-
} else {
219-
notificationManager.cancel(notif.notificationId);
220-
}
216+
notificationManager.notifyAsUser(null, notif.notificationId, mNiNotification,
217+
UserHandle.ALL);
221218
}
222219

223220
// Opens the notification dialog and waits for user input

packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public void onReceive(Context context, Intent intent) {
9797
}
9898

9999
try {
100-
// XXX WHAT TO DO ABOUT MULTI-USER?
101100
if (visible) {
102101
Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
103102
gpsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -126,15 +125,15 @@ public void onReceive(Context context, Intent intent) {
126125
GPS_NOTIFICATION_ID,
127126
n,
128127
idOut,
129-
UserHandle.USER_CURRENT);
128+
UserHandle.USER_ALL);
130129

131130
for (LocationGpsStateChangeCallback cb : mChangeCallbacks) {
132131
cb.onLocationGpsStateChanged(true, text);
133132
}
134133
} else {
135134
mNotificationService.cancelNotificationWithTag(
136135
mContext.getPackageName(), null,
137-
GPS_NOTIFICATION_ID, UserHandle.USER_CURRENT);
136+
GPS_NOTIFICATION_ID, UserHandle.USER_ALL);
138137

139138
for (LocationGpsStateChangeCallback cb : mChangeCallbacks) {
140139
cb.onLocationGpsStateChanged(false, null);

services/java/com/android/server/LocationManagerService.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package com.android.server;
1818

1919
import android.app.PendingIntent;
20+
import android.content.BroadcastReceiver;
2021
import android.content.ContentResolver;
2122
import android.content.Context;
2223
import android.content.Intent;
24+
import android.content.IntentFilter;
2325
import android.content.pm.ApplicationInfo;
2426
import android.content.pm.PackageManager;
2527
import android.content.pm.PackageManager.NameNotFoundException;
@@ -171,6 +173,9 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
171173
private final ArrayList<LocationProviderProxy> mProxyProviders =
172174
new ArrayList<LocationProviderProxy>();
173175

176+
// current active user on the device - other users are denied location data
177+
private int mCurrentUserId = UserHandle.USER_OWNER;
178+
174179
public LocationManagerService(Context context) {
175180
super();
176181
mContext = context;
@@ -224,6 +229,20 @@ public void onChange(boolean selfChange) {
224229
});
225230
mPackageMonitor.register(mContext, Looper.myLooper(), true);
226231

232+
// listen for user change
233+
IntentFilter intentFilter = new IntentFilter();
234+
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
235+
236+
mContext.registerReceiverAsUser(new BroadcastReceiver() {
237+
@Override
238+
public void onReceive(Context context, Intent intent) {
239+
String action = intent.getAction();
240+
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
241+
switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
242+
}
243+
}
244+
}, UserHandle.ALL, intentFilter, null, null);
245+
227246
updateProvidersLocked();
228247
}
229248

@@ -301,6 +320,19 @@ Load package name(s) containing location provider support.
301320
}
302321
}
303322

323+
/**
324+
* Called when the device's active user changes.
325+
* @param userId the new active user's UserId
326+
*/
327+
private void switchUser(int userId) {
328+
//Log.d("LocationManagerService", "switchUser(" + mCurrentUserId + " -> " + userId + ")"); // TODO: remove this
329+
synchronized (mLock) {
330+
// TODO: inform previous user's Receivers that they will no longer receive updates
331+
mCurrentUserId = userId;
332+
// TODO: inform new user's Receivers that they are back on the update train
333+
}
334+
}
335+
304336
/**
305337
* A wrapper class holding either an ILocationListener or a PendingIntent to receive
306338
* location updates.

0 commit comments

Comments
 (0)