Merge "Route GPS notifications to all users." into jb-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3750db176a
@@ -26,6 +26,7 @@ import android.content.Intent;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.R;
|
||||
@@ -89,7 +90,6 @@ public class GpsNetInitiatedHandler {
|
||||
|
||||
// configuration of notificaiton behavior
|
||||
private boolean mPlaySounds = false;
|
||||
private boolean visible = true;
|
||||
private boolean mPopupImmediately = true;
|
||||
|
||||
// Set to true if string from HAL is encoded as Hex, e.g., "3F0039"
|
||||
@@ -213,11 +213,8 @@ public class GpsNetInitiatedHandler {
|
||||
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, intent, 0);
|
||||
mNiNotification.setLatestEventInfo(mContext, title, message, pi);
|
||||
|
||||
if (visible) {
|
||||
notificationManager.notify(notif.notificationId, mNiNotification);
|
||||
} else {
|
||||
notificationManager.cancel(notif.notificationId);
|
||||
}
|
||||
notificationManager.notifyAsUser(null, notif.notificationId, mNiNotification,
|
||||
UserHandle.ALL);
|
||||
}
|
||||
|
||||
// Opens the notification dialog and waits for user input
|
||||
|
||||
@@ -97,7 +97,6 @@ public class LocationController extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
try {
|
||||
// XXX WHAT TO DO ABOUT MULTI-USER?
|
||||
if (visible) {
|
||||
Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
gpsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
@@ -126,7 +125,7 @@ public class LocationController extends BroadcastReceiver {
|
||||
GPS_NOTIFICATION_ID,
|
||||
n,
|
||||
idOut,
|
||||
UserHandle.USER_CURRENT);
|
||||
UserHandle.USER_ALL);
|
||||
|
||||
for (LocationGpsStateChangeCallback cb : mChangeCallbacks) {
|
||||
cb.onLocationGpsStateChanged(true, text);
|
||||
@@ -134,7 +133,7 @@ public class LocationController extends BroadcastReceiver {
|
||||
} else {
|
||||
mNotificationService.cancelNotificationWithTag(
|
||||
mContext.getPackageName(), null,
|
||||
GPS_NOTIFICATION_ID, UserHandle.USER_CURRENT);
|
||||
GPS_NOTIFICATION_ID, UserHandle.USER_ALL);
|
||||
|
||||
for (LocationGpsStateChangeCallback cb : mChangeCallbacks) {
|
||||
cb.onLocationGpsStateChanged(false, null);
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package com.android.server;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
@@ -171,6 +173,9 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
||||
private final ArrayList<LocationProviderProxy> mProxyProviders =
|
||||
new ArrayList<LocationProviderProxy>();
|
||||
|
||||
// current active user on the device - other users are denied location data
|
||||
private int mCurrentUserId = UserHandle.USER_OWNER;
|
||||
|
||||
public LocationManagerService(Context context) {
|
||||
super();
|
||||
mContext = context;
|
||||
@@ -224,6 +229,20 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
||||
});
|
||||
mPackageMonitor.register(mContext, Looper.myLooper(), true);
|
||||
|
||||
// listen for user change
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
|
||||
mContext.registerReceiverAsUser(new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
|
||||
switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
|
||||
}
|
||||
}
|
||||
}, UserHandle.ALL, intentFilter, null, null);
|
||||
|
||||
updateProvidersLocked();
|
||||
}
|
||||
|
||||
@@ -301,6 +320,19 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the device's active user changes.
|
||||
* @param userId the new active user's UserId
|
||||
*/
|
||||
private void switchUser(int userId) {
|
||||
//Log.d("LocationManagerService", "switchUser(" + mCurrentUserId + " -> " + userId + ")"); // TODO: remove this
|
||||
synchronized (mLock) {
|
||||
// TODO: inform previous user's Receivers that they will no longer receive updates
|
||||
mCurrentUserId = userId;
|
||||
// TODO: inform new user's Receivers that they are back on the update train
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper class holding either an ILocationListener or a PendingIntent to receive
|
||||
* location updates.
|
||||
|
||||
Reference in New Issue
Block a user