Loading services/java/com/android/server/SystemServer.java +9 −1 Original line number Diff line number Diff line Loading @@ -148,6 +148,7 @@ class ServerThread extends Thread { NetworkTimeUpdateService networkTimeUpdater = null; CommonTimeManagementService commonTimeMgmtService = null; InputManagerService inputManager = null; TelephonyRegistry telephonyRegistry = null; // Create a shared handler thread for UI within the system server. // This thread is used by at least the following components: Loading Loading @@ -218,7 +219,8 @@ class ServerThread extends Thread { ServiceManager.addService(Context.DISPLAY_SERVICE, display, true); 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"); ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE, Loading Loading @@ -844,6 +846,7 @@ class ServerThread extends Thread { final StatusBarManagerService statusBarF = statusBar; final DreamManagerService dreamyF = dreamy; final InputManagerService inputManagerF = inputManager; final TelephonyRegistry telephonyRegistryF = telephonyRegistry; // 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 Loading Loading @@ -971,6 +974,11 @@ class ServerThread extends Thread { } catch (Throwable e) { reportWtf("making InputManagerService ready", e); } try { if (telephonyRegistryF != null) telephonyRegistryF.systemReady(); } catch (Throwable e) { reportWtf("making TelephonyRegistry ready", e); } } }); Loading services/java/com/android/server/TelephonyRegistry.java +91 −9 Original line number Diff line number Diff line Loading @@ -16,14 +16,19 @@ package com.android.server; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.net.LinkCapabilities; import android.net.LinkProperties; import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.RemoteException; import android.os.UserHandle; import android.telephony.CellLocation; Loading @@ -39,13 +44,11 @@ import java.util.ArrayList; import java.util.List; import java.io.FileDescriptor; import java.io.PrintWriter; import java.net.NetworkInterface; import com.android.internal.app.IBatteryStats; import com.android.internal.telephony.ITelephonyRegistry; import com.android.internal.telephony.IPhoneStateListener; import com.android.internal.telephony.DefaultPhoneNotifier; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.ServiceStateTracker; import com.android.internal.telephony.TelephonyIntents; Loading @@ -58,6 +61,7 @@ import com.android.server.am.BatteryStatsService; class TelephonyRegistry extends ITelephonyRegistry.Stub { private static final String TAG = "TelephonyRegistry"; private static final boolean DBG = false; private static final boolean DBG_LOC = false; private static class Record { String pkgForDebug; Loading @@ -66,7 +70,15 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { IPhoneStateListener callback; int callerUid; int events; @Override public String toString() { return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid + " events=" + Integer.toHexString(events) + "}"; } } private final Context mContext; Loading Loading @@ -120,6 +132,32 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | 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 // register for it // Loading @@ -140,10 +178,24 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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, boolean notifyNow) { // Slog.d(TAG, "listen pkg=" + pkgForDebug + " events=0x" + // Integer.toHexString(events)); int callerUid = UserHandle.getCallingUserId(); 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) { /* Checks permission and throws Security exception */ checkListenerPermission(events); Loading @@ -164,7 +216,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { r.binder = b; r.callback = callback; r.pkgForDebug = pkgForDebug; r.callerUid = callerUid; mRecords.add(r); if (DBG) Slog.i(TAG, "listen: add new record=" + r); } int send = events & (events ^ r.events); r.events = events; Loading Loading @@ -199,8 +253,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { remove(r.binder); } } if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { try { if (DBG_LOC) Slog.d(TAG, "listen: mCellLocation=" + mCellLocation); r.callback.onCellLocationChanged(new Bundle(mCellLocation)); } catch (RemoteException ex) { remove(r.binder); Loading Loading @@ -242,8 +297,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { remove(r.binder); } } if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { try { if (DBG_LOC) Slog.d(TAG, "listen: mCellInfo=" + mCellInfo); r.callback.onCellInfoChanged(mCellInfo); } catch (RemoteException ex) { remove(r.binder); Loading Loading @@ -346,8 +402,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { synchronized (mRecords) { mCellInfo = cellInfo; for (Record r : mRecords) { if ((r.events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { try { if (DBG_LOC) { Slog.d(TAG, "notifyCellInfo: mCellInfo=" + mCellInfo + " r=" + r); } r.callback.onCellInfoChanged(cellInfo); } catch (RemoteException ex) { mRemoveList.add(r.binder); Loading Loading @@ -424,7 +483,8 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { if (DBG) { Slog.i(TAG, "notifyDataConnection: state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible + " reason='" + reason + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType); + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords); } synchronized (mRecords) { boolean modified = false; Loading Loading @@ -506,8 +566,12 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { synchronized (mRecords) { mCellLocation = cellLocation; for (Record r : mRecords) { if ((r.events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { try { if (DBG_LOC) { Slog.d(TAG, "notifyCellLocation: mCellLocation=" + mCellLocation + " r=" + r); } r.callback.onCellLocationChanged(new Bundle(cellLocation)); } catch (RemoteException ex) { mRemoveList.add(r.binder); Loading Loading @@ -712,4 +776,22 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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; } } telephony/java/android/telephony/TelephonyManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -220,6 +220,7 @@ public class TelephonyManager { public CellLocation getCellLocation() { try { Bundle bundle = getITelephony().getCellLocation(); if (bundle.isEmpty()) return null; CellLocation cl = CellLocation.newFromBundle(bundle); if (cl.isEmpty()) return null; Loading Loading
services/java/com/android/server/SystemServer.java +9 −1 Original line number Diff line number Diff line Loading @@ -148,6 +148,7 @@ class ServerThread extends Thread { NetworkTimeUpdateService networkTimeUpdater = null; CommonTimeManagementService commonTimeMgmtService = null; InputManagerService inputManager = null; TelephonyRegistry telephonyRegistry = null; // Create a shared handler thread for UI within the system server. // This thread is used by at least the following components: Loading Loading @@ -218,7 +219,8 @@ class ServerThread extends Thread { ServiceManager.addService(Context.DISPLAY_SERVICE, display, true); 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"); ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE, Loading Loading @@ -844,6 +846,7 @@ class ServerThread extends Thread { final StatusBarManagerService statusBarF = statusBar; final DreamManagerService dreamyF = dreamy; final InputManagerService inputManagerF = inputManager; final TelephonyRegistry telephonyRegistryF = telephonyRegistry; // 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 Loading Loading @@ -971,6 +974,11 @@ class ServerThread extends Thread { } catch (Throwable e) { reportWtf("making InputManagerService ready", e); } try { if (telephonyRegistryF != null) telephonyRegistryF.systemReady(); } catch (Throwable e) { reportWtf("making TelephonyRegistry ready", e); } } }); Loading
services/java/com/android/server/TelephonyRegistry.java +91 −9 Original line number Diff line number Diff line Loading @@ -16,14 +16,19 @@ package com.android.server; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.net.LinkCapabilities; import android.net.LinkProperties; import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.RemoteException; import android.os.UserHandle; import android.telephony.CellLocation; Loading @@ -39,13 +44,11 @@ import java.util.ArrayList; import java.util.List; import java.io.FileDescriptor; import java.io.PrintWriter; import java.net.NetworkInterface; import com.android.internal.app.IBatteryStats; import com.android.internal.telephony.ITelephonyRegistry; import com.android.internal.telephony.IPhoneStateListener; import com.android.internal.telephony.DefaultPhoneNotifier; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.ServiceStateTracker; import com.android.internal.telephony.TelephonyIntents; Loading @@ -58,6 +61,7 @@ import com.android.server.am.BatteryStatsService; class TelephonyRegistry extends ITelephonyRegistry.Stub { private static final String TAG = "TelephonyRegistry"; private static final boolean DBG = false; private static final boolean DBG_LOC = false; private static class Record { String pkgForDebug; Loading @@ -66,7 +70,15 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { IPhoneStateListener callback; int callerUid; int events; @Override public String toString() { return "{pkgForDebug=" + pkgForDebug + " callerUid=" + callerUid + " events=" + Integer.toHexString(events) + "}"; } } private final Context mContext; Loading Loading @@ -120,6 +132,32 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | 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 // register for it // Loading @@ -140,10 +178,24 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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, boolean notifyNow) { // Slog.d(TAG, "listen pkg=" + pkgForDebug + " events=0x" + // Integer.toHexString(events)); int callerUid = UserHandle.getCallingUserId(); 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) { /* Checks permission and throws Security exception */ checkListenerPermission(events); Loading @@ -164,7 +216,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { r.binder = b; r.callback = callback; r.pkgForDebug = pkgForDebug; r.callerUid = callerUid; mRecords.add(r); if (DBG) Slog.i(TAG, "listen: add new record=" + r); } int send = events & (events ^ r.events); r.events = events; Loading Loading @@ -199,8 +253,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { remove(r.binder); } } if ((events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { try { if (DBG_LOC) Slog.d(TAG, "listen: mCellLocation=" + mCellLocation); r.callback.onCellLocationChanged(new Bundle(mCellLocation)); } catch (RemoteException ex) { remove(r.binder); Loading Loading @@ -242,8 +297,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { remove(r.binder); } } if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { try { if (DBG_LOC) Slog.d(TAG, "listen: mCellInfo=" + mCellInfo); r.callback.onCellInfoChanged(mCellInfo); } catch (RemoteException ex) { remove(r.binder); Loading Loading @@ -346,8 +402,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { synchronized (mRecords) { mCellInfo = cellInfo; for (Record r : mRecords) { if ((r.events & PhoneStateListener.LISTEN_CELL_INFO) != 0) { if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO)) { try { if (DBG_LOC) { Slog.d(TAG, "notifyCellInfo: mCellInfo=" + mCellInfo + " r=" + r); } r.callback.onCellInfoChanged(cellInfo); } catch (RemoteException ex) { mRemoveList.add(r.binder); Loading Loading @@ -424,7 +483,8 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { if (DBG) { Slog.i(TAG, "notifyDataConnection: state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible + " reason='" + reason + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType); + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType + " mRecords.size()=" + mRecords.size() + " mRecords=" + mRecords); } synchronized (mRecords) { boolean modified = false; Loading Loading @@ -506,8 +566,12 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { synchronized (mRecords) { mCellLocation = cellLocation; for (Record r : mRecords) { if ((r.events & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) { if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION)) { try { if (DBG_LOC) { Slog.d(TAG, "notifyCellLocation: mCellLocation=" + mCellLocation + " r=" + r); } r.callback.onCellLocationChanged(new Bundle(cellLocation)); } catch (RemoteException ex) { mRemoveList.add(r.binder); Loading Loading @@ -712,4 +776,22 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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; } }
telephony/java/android/telephony/TelephonyManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -220,6 +220,7 @@ public class TelephonyManager { public CellLocation getCellLocation() { try { Bundle bundle = getITelephony().getCellLocation(); if (bundle.isEmpty()) return null; CellLocation cl = CellLocation.newFromBundle(bundle); if (cl.isEmpty()) return null; Loading