Skip to content

Commit

Permalink
Hook telephony registry
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Jan 12, 2014
1 parent 109ccb6 commit 71ed0af
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 3 deletions.
7 changes: 6 additions & 1 deletion assets/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
<Hook restriction="location" method="Srv.getCellLocation" permissions="ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION" sdk="10" />
<Hook restriction="location" method="Srv.getNeighboringCellInfo" permissions="ACCESS_COARSE_UPDATES,ACCESS_FINE_LOCATION" sdk="10" />

<Hook restriction="location" method="listen" permissions="READ_PHONE_STATE,ACCESS_COARSE_LOCATION" sdk="10" />
<Hook restriction="location" method="Srv.listen" permissions="READ_PHONE_STATE,ACCESS_COARSE_LOCATION" sdk="10" />

<Hook restriction="media" method="startRecording" permissions="RECORD_AUDIO" sdk="10" />
<Hook restriction="media" method="setPreviewCallback" permissions="CAMERA" sdk="10" />
<Hook restriction="media" method="setPreviewCallbackWithBuffer" permissions="CAMERA" sdk="10" />
Expand Down Expand Up @@ -159,7 +162,7 @@
<Hook restriction="phone" method="getSubscriberId" permissions="READ_PHONE_STATE" sdk="10" />
<Hook restriction="phone" method="getVoiceMailAlphaTag" permissions="READ_PHONE_STATE" sdk="10" />
<Hook restriction="phone" method="getVoiceMailNumber" permissions="READ_PHONE_STATE" sdk="10" />
<Hook restriction="phone" method="listen" permissions="READ_PHONE_STATE" sdk="10" />
<Hook restriction="phone" method="listen" permissions="READ_PHONE_STATE,ACCESS_COARSE_LOCATION" sdk="10" />
<Hook restriction="phone" method="getNetworkCountryIso" permissions="" sdk="10" />
<Hook restriction="phone" method="getNetworkOperator" permissions="" sdk="10" />
<Hook restriction="phone" method="getNetworkOperatorName" permissions="" sdk="10" />
Expand Down Expand Up @@ -197,6 +200,8 @@
<Hook restriction="phone" method="Srv.getVoiceMailAlphaTag" permissions="READ_PHONE_STATE" sdk="10" />
<Hook restriction="phone" method="Srv.getVoiceMailNumber" permissions="READ_PHONE_STATE" sdk="10" />

<Hook restriction="phone" method="Srv.listen" permissions="READ_PHONE_STATE,ACCESS_COARSE_LOCATION" sdk="10" />

<Hook restriction="sensors" method="getDefaultSensor" permissions="" sdk="3" />
<Hook restriction="sensors" method="getSensorList" permissions="" sdk="3" />

Expand Down
4 changes: 2 additions & 2 deletions src/android/location/ILocationListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
public interface ILocationListener extends android.os.IInterface {
void onLocationChanged(Location location);

void onProviderDisabled(String provider);
void onStatusChanged(String provider, int status, Bundle extras);

void onProviderEnabled(String provider);

void onStatusChanged(String provider, int status, Bundle extras);
void onProviderDisabled(String provider);
}
3 changes: 3 additions & 0 deletions src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public void initZygote(StartupParam startupParam) throws Throwable {
// System properties
hookAll(XSystemProperties.getInstances());

// Telephony registry
hookAll(XTelephonyRegistry.getInstances());

// Thread
hookAll(XThread.getInstances());

Expand Down
2 changes: 2 additions & 0 deletions src/biz/bokhorst/xprivacy/XTelephonyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public static List<XHook> getInstances(Object instance) {
listHook.add(new XTelephonyManager(Methods.getSubscriberId, PrivacyManager.cPhone, className));
listHook.add(new XTelephonyManager(Methods.getVoiceMailAlphaTag, PrivacyManager.cPhone, className));
listHook.add(new XTelephonyManager(Methods.getVoiceMailNumber, PrivacyManager.cPhone, className));

listHook.add(new XTelephonyManager(Methods.listen, PrivacyManager.cLocation, className));
listHook.add(new XTelephonyManager(Methods.listen, PrivacyManager.cPhone, className));

// No permissions required
Expand Down
189 changes: 189 additions & 0 deletions src/biz/bokhorst/xprivacy/XTelephonyRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package biz.bokhorst.xprivacy;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

import com.android.internal.telephony.IPhoneStateListener;

import android.content.Context;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.telephony.CellInfo;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.util.Log;

import de.robv.android.xposed.XC_MethodHook.MethodHookParam;

import static de.robv.android.xposed.XposedHelpers.findField;

public class XTelephonyRegistry extends XHook {
private Methods mMethod;
private static final Map<IPhoneStateListener, XIPhoneStateListener> mListener = new WeakHashMap<IPhoneStateListener, XIPhoneStateListener>();

private XTelephonyRegistry(Methods method, String restrictionName) {
super(restrictionName, method.name(), String.format("Srv.%s", method.name()));
mMethod = method;
}

private XTelephonyRegistry(Methods method, String restrictionName, int sdk) {
super(restrictionName, method.name(), String.format("Srv.%s", method.name()), sdk);
mMethod = method;
}

public String getClassName() {
return "com.android.server.TelephonyRegistry";
}

// @formatter:off

// public void listen(String pkgForDebug, IPhoneStateListener callback, int events, boolean notifyNow)
// frameworks/base/services/java/com/android/server/TelephonyRegistry.java
// http://developer.android.com/reference/android/telephony/TelephonyManager.html

// @formatter:on

private enum Methods {
listen
};

public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XTelephonyRegistry(Methods.listen, PrivacyManager.cLocation));
listHook.add(new XTelephonyRegistry(Methods.listen, PrivacyManager.cPhone));
return listHook;
}

@Override
protected void before(MethodHookParam param) throws Throwable {
if (mMethod == Methods.listen)
replacePhoneStateListener(param);
else
Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}

private void replacePhoneStateListener(MethodHookParam param) throws Throwable {
if (param.args.length > 2 && param.args[1] != null) {
IPhoneStateListener listener = (IPhoneStateListener) param.args[1];
int event = (Integer) param.args[2];
if (listener != null)
if (isRestricted(param)) {
if (event == PhoneStateListener.LISTEN_NONE) {
// Remove
synchronized (mListener) {
XIPhoneStateListener xlistener = mListener.get(listener);
if (xlistener == null)
Util.log(this, Log.WARN, "Not found count=" + mListener.size());
else {
param.args[1] = xlistener;
mListener.remove(listener);
}
}
} else {
// Replace
XIPhoneStateListener xListener = new XIPhoneStateListener(listener);
synchronized (mListener) {
mListener.put(listener, xListener);
Util.log(this, Log.INFO, "Added count=" + mListener.size());
}
param.args[1] = xListener;
}
}
}
}

@Override
protected void after(MethodHookParam param) throws Throwable {
// Do nothing
}

@Override
protected boolean isRestricted(MethodHookParam param) throws Throwable {
Context context = null;

try {
Field fieldContext = findField(param.thisObject.getClass(), "mContext");
context = (Context) fieldContext.get(param.thisObject);
} catch (NoSuchFieldError ex) {
} catch (Throwable ex) {
Util.bug(this, ex);
}

int uid = Binder.getCallingUid();
return getRestricted(context, uid, true);
}

private class XIPhoneStateListener implements IPhoneStateListener {
private IPhoneStateListener mListener;

public XIPhoneStateListener(IPhoneStateListener listener) {
mListener = listener;
}

@Override
public void onCallForwardingIndicatorChanged(boolean cfi) {
mListener.onCallForwardingIndicatorChanged(cfi);
}

@Override
public void onCallStateChanged(int state, String incomingNumber) {
mListener.onCallStateChanged(state,
(String) PrivacyManager.getDefacedProp(Binder.getCallingUid(), "PhoneNumber"));
}

@Override
public void onCellInfoChanged(List<CellInfo> cellInfo) {
mListener.onCellInfoChanged(new ArrayList<CellInfo>());
}

@Override
public void onCellLocationChanged(Bundle location) {
mListener.onCellLocationChanged(new Bundle());
}

@Override
public void onDataActivity(int direction) {
mListener.onDataActivity(direction);
}

@Override
public void onDataConnectionStateChanged(int state, int networkType) {
mListener.onDataConnectionStateChanged(state, networkType);
}

@Override
public void onMessageWaitingIndicatorChanged(boolean mwi) {
mListener.onMessageWaitingIndicatorChanged(mwi);
}

@Override
public void onServiceStateChanged(ServiceState serviceState) {
mListener.onServiceStateChanged(serviceState);
}

@Override
public void onSignalStrengthChanged(int asu) {
mListener.onSignalStrengthChanged(asu);
}

@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
mListener.onSignalStrengthsChanged(signalStrength);
}

@Override
public void onOtaspChanged(int otaspMode) {
mListener.onOtaspChanged(otaspMode);
}

@Override
public IBinder asBinder() {
return mListener.asBinder();
}
}
}
34 changes: 34 additions & 0 deletions src/com/android/internal/telephony/IPhoneStateListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.android.internal.telephony;

import java.util.List;

import android.os.Bundle;
import android.telephony.CellInfo;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;

public interface IPhoneStateListener extends android.os.IInterface {
void onServiceStateChanged(ServiceState serviceState);

void onSignalStrengthChanged(int asu);

void onMessageWaitingIndicatorChanged(boolean mwi);

void onCallForwardingIndicatorChanged(boolean cfi);

// we use bundle here instead of CellLocation so it can get the right
// subclass
void onCellLocationChanged(Bundle location);

void onCallStateChanged(int state, String incomingNumber);

void onDataConnectionStateChanged(int state, int networkType);

void onDataActivity(int direction);

void onSignalStrengthsChanged(SignalStrength signalStrength);

void onOtaspChanged(int otaspMode);

void onCellInfoChanged(List<CellInfo> cellInfo);
}

0 comments on commit 71ed0af

Please sign in to comment.