am ca2cb184
: Merge "Suppress location information for non-active users." into jb-mr1-dev
* commit 'ca2cb1841099c7206af93149d0326308e0d3f81a': Suppress location information for non-active users.
This commit is contained in:
@ -148,6 +148,7 @@ class ServerThread extends Thread {
|
|||||||
NetworkTimeUpdateService networkTimeUpdater = null;
|
NetworkTimeUpdateService networkTimeUpdater = null;
|
||||||
CommonTimeManagementService commonTimeMgmtService = null;
|
CommonTimeManagementService commonTimeMgmtService = null;
|
||||||
InputManagerService inputManager = null;
|
InputManagerService inputManager = null;
|
||||||
|
TelephonyRegistry telephonyRegistry = null;
|
||||||
|
|
||||||
// Create a shared handler thread for UI within the system server.
|
// Create a shared handler thread for UI within the system server.
|
||||||
// This thread is used by at least the following components:
|
// This thread is used by at least the following components:
|
||||||
@ -218,7 +219,8 @@ class ServerThread extends Thread {
|
|||||||
ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
|
ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
|
||||||
|
|
||||||
Slog.i(TAG, "Telephony Registry");
|
Slog.i(TAG, "Telephony Registry");
|
||||||
ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
|
telephonyRegistry = new TelephonyRegistry(context);
|
||||||
|
ServiceManager.addService("telephony.registry", telephonyRegistry);
|
||||||
|
|
||||||
Slog.i(TAG, "Scheduling Policy");
|
Slog.i(TAG, "Scheduling Policy");
|
||||||
ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE,
|
ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE,
|
||||||
@ -844,6 +846,7 @@ class ServerThread extends Thread {
|
|||||||
final StatusBarManagerService statusBarF = statusBar;
|
final StatusBarManagerService statusBarF = statusBar;
|
||||||
final DreamManagerService dreamyF = dreamy;
|
final DreamManagerService dreamyF = dreamy;
|
||||||
final InputManagerService inputManagerF = inputManager;
|
final InputManagerService inputManagerF = inputManager;
|
||||||
|
final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
|
||||||
|
|
||||||
// We now tell the activity manager it is okay to run third party
|
// We now tell the activity manager it is okay to run third party
|
||||||
// code. It will call back into us once it has gotten to the state
|
// code. It will call back into us once it has gotten to the state
|
||||||
@ -971,6 +974,11 @@ class ServerThread extends Thread {
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
reportWtf("making InputManagerService ready", e);
|
reportWtf("making InputManagerService ready", e);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
reportWtf("making TelephonyRegistry ready", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -16,14 +16,19 @@
|
|||||||
|
|
||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.LinkCapabilities;
|
import android.net.LinkCapabilities;
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.telephony.CellLocation;
|
import android.telephony.CellLocation;
|
||||||
@ -39,13 +44,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.NetworkInterface;
|
|
||||||
|
|
||||||
import com.android.internal.app.IBatteryStats;
|
import com.android.internal.app.IBatteryStats;
|
||||||
import com.android.internal.telephony.ITelephonyRegistry;
|
import com.android.internal.telephony.ITelephonyRegistry;
|
||||||
import com.android.internal.telephony.IPhoneStateListener;
|
import com.android.internal.telephony.IPhoneStateListener;
|
||||||
import com.android.internal.telephony.DefaultPhoneNotifier;
|
import com.android.internal.telephony.DefaultPhoneNotifier;
|
||||||
import com.android.internal.telephony.Phone;
|
|
||||||
import com.android.internal.telephony.PhoneConstants;
|
import com.android.internal.telephony.PhoneConstants;
|
||||||
import com.android.internal.telephony.ServiceStateTracker;
|
import com.android.internal.telephony.ServiceStateTracker;
|
||||||
import com.android.internal.telephony.TelephonyIntents;
|
import com.android.internal.telephony.TelephonyIntents;
|
||||||
@ -58,6 +61,7 @@ import com.android.server.am.BatteryStatsService;
|
|||||||
class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
||||||
private static final String TAG = "TelephonyRegistry";
|
private static final String TAG = "TelephonyRegistry";
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
|
private static final boolean DBG_LOC = false;
|
||||||
|
|
||||||
private static class Record {
|
private static class Record {
|
||||||
String pkgForDebug;
|
String pkgForDebug;
|
||||||
@ -66,7 +70,15 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
|
|
||||||
IPhoneStateListener callback;
|
IPhoneStateListener callback;
|
||||||
|
|
||||||
|
int callerUid;
|
||||||
|
|
||||||
int events;
|
int events;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid +
|
||||||
|
" events=" + Integer.toHexString(events) + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@ -120,6 +132,32 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
|
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
|
||||||
PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR;
|
PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR;
|
||||||
|
|
||||||
|
private static final int MSG_USER_SWITCHED = 1;
|
||||||
|
|
||||||
|
private final Handler mHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case MSG_USER_SWITCHED: {
|
||||||
|
Slog.d(TAG, "MSG_USER_SWITCHED userId=" + msg.arg1);
|
||||||
|
TelephonyRegistry.this.notifyCellLocation(mCellLocation);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_SWITCHED,
|
||||||
|
intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// we keep a copy of all of the state so we can send it out when folks
|
// we keep a copy of all of the state so we can send it out when folks
|
||||||
// register for it
|
// register for it
|
||||||
//
|
//
|
||||||
@ -140,10 +178,24 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
mConnectedApns = new ArrayList<String>();
|
mConnectedApns = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void systemReady() {
|
||||||
|
// Watch for interesting updates
|
||||||
|
final IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||||
|
filter.addAction(Intent.ACTION_USER_REMOVED);
|
||||||
|
mContext.registerReceiver(mBroadcastReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
|
public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
|
||||||
boolean notifyNow) {
|
boolean notifyNow) {
|
||||||
// Slog.d(TAG, "listen pkg=" + pkgForDebug + " events=0x" +
|
int callerUid = UserHandle.getCallingUserId();
|
||||||
// Integer.toHexString(events));
|
int myUid = UserHandle.myUserId();
|
||||||
|
if (DBG) {
|
||||||
|
Slog.d(TAG, "listen: E pkg=" + pkgForDebug + " events=0x" + Integer.toHexString(events)
|
||||||
|
+ " myUid=" + myUid
|
||||||
|
+ " callerUid=" + callerUid);
|
||||||
|
}
|
||||||
if (events != 0) {
|
if (events != 0) {
|
||||||
/* Checks permission and throws Security exception */
|
/* Checks permission and throws Security exception */
|
||||||
checkListenerPermission(events);
|
checkListenerPermission(events);
|
||||||
@ -164,7 +216,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
r.binder = b;
|
r.binder = b;
|
||||||
r.callback = callback;
|
r.callback = callback;
|
||||||
r.pkgForDebug = pkgForDebug;
|
r.pkgForDebug = pkgForDebug;
|
||||||
|
r.callerUid = callerUid;
|
||||||
mRecords.add(r);
|
mRecords.add(r);
|
||||||
|
if (DBG) Slog.i(TAG, "listen: add new record=" + r);
|
||||||
}
|
}
|
||||||
int send = events & (events ^ r.events);
|
int send = events & (events ^ r.events);
|
||||||
r.events = events;
|
r.events = events;
|
||||||
@ -199,8 +253,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
remove(r.binder);
|
remove(r.binder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
|
if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
|
||||||
try {
|
try {
|
||||||
|
if (DBG_LOC) Slog.d(TAG, "listen: mCellLocation=" + mCellLocation);
|
||||||
r.callback.onCellLocationChanged(new Bundle(mCellLocation));
|
r.callback.onCellLocationChanged(new Bundle(mCellLocation));
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
remove(r.binder);
|
remove(r.binder);
|
||||||
@ -242,8 +297,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
remove(r.binder);
|
remove(r.binder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
|
if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
|
||||||
try {
|
try {
|
||||||
|
if (DBG_LOC) Slog.d(TAG, "listen: mCellInfo=" + mCellInfo);
|
||||||
r.callback.onCellInfoChanged(mCellInfo);
|
r.callback.onCellInfoChanged(mCellInfo);
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
remove(r.binder);
|
remove(r.binder);
|
||||||
@ -346,8 +402,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
synchronized (mRecords) {
|
synchronized (mRecords) {
|
||||||
mCellInfo = cellInfo;
|
mCellInfo = cellInfo;
|
||||||
for (Record r : mRecords) {
|
for (Record r : mRecords) {
|
||||||
if ((r.events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
|
if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) {
|
||||||
try {
|
try {
|
||||||
|
if (DBG_LOC) {
|
||||||
|
Slog.d(TAG, "notifyCellInfo: mCellInfo=" + mCellInfo + " r=" + r);
|
||||||
|
}
|
||||||
r.callback.onCellInfoChanged(cellInfo);
|
r.callback.onCellInfoChanged(cellInfo);
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
mRemoveList.add(r.binder);
|
mRemoveList.add(r.binder);
|
||||||
@ -424,7 +483,8 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.i(TAG, "notifyDataConnection: state=" + state + " isDataConnectivityPossible="
|
Slog.i(TAG, "notifyDataConnection: state=" + state + " isDataConnectivityPossible="
|
||||||
+ isDataConnectivityPossible + " reason='" + reason
|
+ isDataConnectivityPossible + " reason='" + reason
|
||||||
+ "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType);
|
+ "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType
|
||||||
|
+ " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords);
|
||||||
}
|
}
|
||||||
synchronized (mRecords) {
|
synchronized (mRecords) {
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
@ -506,8 +566,12 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
synchronized (mRecords) {
|
synchronized (mRecords) {
|
||||||
mCellLocation = cellLocation;
|
mCellLocation = cellLocation;
|
||||||
for (Record r : mRecords) {
|
for (Record r : mRecords) {
|
||||||
if ((r.events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
|
if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) {
|
||||||
try {
|
try {
|
||||||
|
if (DBG_LOC) {
|
||||||
|
Slog.d(TAG, "notifyCellLocation: mCellLocation=" + mCellLocation
|
||||||
|
+ " r=" + r);
|
||||||
|
}
|
||||||
r.callback.onCellLocationChanged(new Bundle(cellLocation));
|
r.callback.onCellLocationChanged(new Bundle(cellLocation));
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
mRemoveList.add(r.binder);
|
mRemoveList.add(r.binder);
|
||||||
@ -712,4 +776,22 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
mRemoveList.clear();
|
mRemoveList.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean validateEventsAndUserLocked(Record r, int events) {
|
||||||
|
int foregroundUser;
|
||||||
|
long callingIdentity = Binder.clearCallingIdentity();
|
||||||
|
boolean valid = false;
|
||||||
|
try {
|
||||||
|
foregroundUser = ActivityManager.getCurrentUser();
|
||||||
|
valid = r.callerUid == foregroundUser && (r.events & events) != 0;
|
||||||
|
if (DBG | DBG_LOC) {
|
||||||
|
Slog.d(TAG, "validateEventsAndUserLocked: valid=" + valid
|
||||||
|
+ " r.callerUid=" + r.callerUid + " foregroundUser=" + foregroundUser
|
||||||
|
+ " r.events=" + r.events + " events=" + events);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(callingIdentity);
|
||||||
|
}
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,7 @@ public class TelephonyManager {
|
|||||||
public CellLocation getCellLocation() {
|
public CellLocation getCellLocation() {
|
||||||
try {
|
try {
|
||||||
Bundle bundle = getITelephony().getCellLocation();
|
Bundle bundle = getITelephony().getCellLocation();
|
||||||
|
if (bundle.isEmpty()) return null;
|
||||||
CellLocation cl = CellLocation.newFromBundle(bundle);
|
CellLocation cl = CellLocation.newFromBundle(bundle);
|
||||||
if (cl.isEmpty())
|
if (cl.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user