Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Improved media restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Aug 14, 2014
1 parent 96faad9 commit 70af091
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ Changelog

**Next release**

* Added restriction *MediaRecorder.setOutputFile* ([issue](/../../issues/1874))
* Restored restriction *MediaRecorder.setOutputFile* ([issue](/../../issues/1874))
* Restored restriction *Camera.setPreviewCallback*
* Added restrictions *Camera.setPreviewCallbackWithBuffer*, *Camera.setPreviewDisplay*, *Camera.setPreviewTexture* and *Camera.setOneShotPreviewCallback*
* Handling *Camera.stopPreview*
* Handling *MediaRecorder.prepare* and *MediaRecorder.stop*
* Handling *Audio.stop*
* Updated Japanese translation

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)
Expand All @@ -49,7 +54,7 @@ Version 2.99.x and version 3.x will be available with a [pro license](http://www

**Version 2.99.20 BETA**

* Added restriction *MediaRecorder.setOutputFile* ([issue](/../../issues/1874))
* Restored restriction *MediaRecorder.setOutputFile* ([issue](/../../issues/1874))

**Version 2.99.19 BETA**

Expand Down
5 changes: 5 additions & 0 deletions res/values/functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@

<!-- media -->
<string name="media_Audio_startRecording" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/media/AudioRecord.html#startRecording()">Google documentation</a>]]></string>
<string name="media_Camera_setPreviewCallback" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/hardware/Camera.html#setPreviewCallback(android.hardware.Camera.PreviewCallback)">Google documentation</a>]]></string>
<string name="media_Camera_setPreviewCallbackWithBuffer" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/hardware/Camera.html#setPreviewCallbackWithBuffer(android.hardware.Camera.PreviewCallback)">Google documentation</a>]]></string>
<string name="media_Camera_setPreviewDisplay" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/hardware/Camera.html#setPreviewDisplay(android.view.SurfaceHolder)">Google documentation</a>]]></string>
<string name="media_Camera_setPreviewTexture" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/hardware/Camera.html#setPreviewTexture(android.graphics.SurfaceTexture)">Google documentation</a>]]></string>
<string name="media_Camera_setOneShotPreviewCallback" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/hardware/Camera.html#setOneShotPreviewCallback(android.hardware.Camera.PreviewCallback)">Google documentation</a>]]></string>
<string name="media_Camera_startPreview" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/hardware/Camera.html#startPreview()">Google documentation</a>]]></string>
<string name="media_Camera_takePicture" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/hardware/Camera.html#takePicture(android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback)">Google documentation</a>]]></string>
<string name="media_MediaRecorder_setOutputFile" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/media/MediaRecorder.html#setOutputFile(java.io.FileDescriptor)">Google documentation</a>]]></string>
Expand Down
27 changes: 20 additions & 7 deletions src/biz/bokhorst/xprivacy/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ public static List<Hook> get() {
mListHook.add(new Hook("location", "MapV2.setOnMyLocationChangeListener", "ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION", 1, "2.1.25", null).unsafe().optional());

mListHook.add(new Hook("media", "Audio.startRecording", "RECORD_AUDIO", 3, "2.2.3", "startRecording").unsafe().doNotify());
mListHook.add(new Hook("media", "Camera.setPreviewCallback", "CAMERA", 1, "2.99.21", "setPreviewCallback").unsafe().doNotify());
mListHook.add(new Hook("media", "Camera.setPreviewCallbackWithBuffer", "CAMERA", 8, "2.99.21", null).unsafe().doNotify());
mListHook.add(new Hook("media", "Camera.setPreviewDisplay", "CAMERA", 1, "2.99.21", null).unsafe().doNotify());
mListHook.add(new Hook("media", "Camera.setPreviewTexture", "CAMERA", 11, "2.99.21", null).unsafe().doNotify());
mListHook.add(new Hook("media", "Camera.setOneShotPreviewCallback", "CAMERA", 11, "2.99.21", null).unsafe().doNotify());
mListHook.add(new Hook("media", "Camera.startPreview", "CAMERA", 1, "2.2.3", "setPreviewCallback").unsafe().doNotify());
mListHook.add(new Hook("media", "Camera.takePicture", "CAMERA", 1, "2.2.3", "takePicture").unsafe().doNotify());
mListHook.add(new Hook("media", "MediaRecorder.start", "RECORD_AUDIO,RECORD_VIDEO", 1, "2.2.3", "setOutputFile").unsafe().doNotify());
Expand Down Expand Up @@ -475,7 +480,7 @@ public static List<Hook> get() {
mListHook.add(new Hook(null, "startActivityIfNeeded", "", 1, null, null).notAOSP(19));
mListHook.add(new Hook(null, "startNextMatchingActivity", "", 1, null, null).notAOSP(19));

// ActivityManager // ActivityManagerService
// ActivityManager(Service)
mListHook.add(new Hook(null, "Srv_startActivities", "", 19, null, null).AOSP(19));
mListHook.add(new Hook(null, "Srv_startActivity", "", 19, null, null).AOSP(19));
mListHook.add(new Hook(null, "Srv_startActivityAsUser", "", 19, null, null).AOSP(19));
Expand All @@ -494,19 +499,25 @@ public static List<Hook> get() {
// Application
mListHook.add(new Hook(null, "onCreate", "", 1, null, null));

// AudioRecord
mListHook.add(new Hook(null, "Audio.stop", "", 3, null, null));

// Binder
mListHook.add(new Hook(null, "execTransact", "", 1, null, null).notAOSP(19));
mListHook.add(new Hook(null, "transact", "", 1, null, null).notAOSP(19));

// ClipboardManager / ClipboardService
// ClipboardManager/Service
mListHook.add(new Hook(null, "removePrimaryClipChangedListener", "", 11, null, null));
mListHook.add(new Hook(null, "Srv_removePrimaryClipChangedListener", "", 11, null, null));

// Provider
// Content resolvers
mListHook.add(new Hook(null, "query", "", 1, null, null).notAOSP(19));
mListHook.add(new Hook(null, "Srv_call", "", 1, null, null).AOSP(19));
mListHook.add(new Hook(null, "Srv_query", "", 1, null, null).AOSP(19));

// Camera
mListHook.add(new Hook(null, "Camera.stopPreview", "", 1, null, null));

// ContextImpl
mListHook.add(new Hook(null, "getPackageManager", "", 1, null, null).notAOSP(19));

Expand All @@ -516,13 +527,17 @@ public static List<Hook> get() {
// IntentFirewall
mListHook.add(new Hook(null, "checkIntent", "", 19, null, null));

// LocationManager / LocationManagerService
// LocationManager/Service
mListHook.add(new Hook(null, "removeUpdates", "", 3, null, null));
mListHook.add(new Hook(null, "Srv_removeUpdates", "", 19, null, null));
mListHook.add(new Hook(null, "Srv_removeGeofence", "", 19, null, null));
mListHook.add(new Hook(null, "Srv_removeGpsStatusListener", "", 19, null, null));
mListHook.add(new Hook(null, "MapV1.disableMyLocation", "", 1, null, null).optional());

// MediaRecorder
mListHook.add(new Hook(null, "MediaRecorder.prepare", "", 1, null, null));
mListHook.add(new Hook(null, "MediaRecorder.stop", "", 1, null, null));

// Resources
mListHook.add(new Hook(null, "updateConfiguration", "", 1, null, null));

Expand All @@ -537,10 +552,8 @@ public static List<Hook> get() {
mListHook.add(new Hook(null, "removeView", "", 1, null, null));
mListHook.add(new Hook(null, "updateViewLayout", "", 1, null, null));

// ActivityRecognitionClient
// LocationClient / ActivityRecognitionClient
mListHook.add(new Hook(null, "GMS.removeActivityUpdates", "", 1, null, null));

// LocationClient
mListHook.add(new Hook(null, "GMS.removeGeofences", "", 1, null, null).optional());
mListHook.add(new Hook(null, "GMS.removeLocationUpdates", "", 1, null, null).optional());

Expand Down
17 changes: 11 additions & 6 deletions src/biz/bokhorst/xprivacy/XAudioRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import android.util.Log;

public class XAudioRecord extends XHook {
private Methods mMethod;

Expand All @@ -19,27 +17,34 @@ public String getClassName() {

// public void startRecording()
// public void startRecording(MediaSyncEvent syncEvent)
// public void stop()
// frameworks/base/media/java/android/media/AudioRecord.java
// http://developer.android.com/reference/android/media/AudioRecord.html

private enum Methods {
startRecording
startRecording, stop
};

public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XAudioRecord(Methods.startRecording, PrivacyManager.cMedia));
listHook.add(new XAudioRecord(Methods.stop, null));
return listHook;
}

@Override
protected void before(XParam param) throws Throwable {
if (mMethod == Methods.startRecording) {
switch (mMethod) {
case startRecording:
if (isRestricted(param))
param.setResult(null);
break;

} else
Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
case stop:
if (isRestricted(param, PrivacyManager.cMedia, "Audio.startRecording"))
param.setResult(null);
break;
}
}

@Override
Expand Down
21 changes: 19 additions & 2 deletions src/biz/bokhorst/xprivacy/XCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ public String getClassName() {

// @formatter:off

// public void setPreviewCallback(Camera.PreviewCallback cb)
// public void setPreviewCallbackWithBuffer(Camera.PreviewCallback cb)
// public void setPreviewDisplay(SurfaceHolder holder)
// public void setPreviewTexture(SurfaceTexture surfaceTexture)
// public final void setOneShotPreviewCallback (Camera.PreviewCallback cb)
// public native final void startPreview()
// public void stopPreview()
// public final void takePicture(ShutterCallback shutter, PictureCallback raw, PictureCallback jpeg)
// public final void takePicture(ShutterCallback shutter, PictureCallback raw, PictureCallback postview, PictureCallback jpeg)
// frameworks/base/core/java/android/hardware/Camera.java
Expand All @@ -26,23 +32,34 @@ public String getClassName() {
// @formatter:on

private enum Methods {
startPreview, takePicture
setPreviewCallback, setPreviewCallbackWithBuffer, setPreviewDisplay, setPreviewTexture, setOneShotPreviewCallback, startPreview, stopPreview, takePicture
};

public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
for (Methods cam : Methods.values())
listHook.add(new XCamera(cam, PrivacyManager.cMedia));
listHook.add(new XCamera(cam, cam == Methods.stopPreview ? null : PrivacyManager.cMedia));
return listHook;
}

@Override
protected void before(XParam param) throws Throwable {
switch (mMethod) {
case setPreviewCallback:
case setPreviewCallbackWithBuffer:
case setPreviewDisplay:
case setPreviewTexture:
case setOneShotPreviewCallback:
case startPreview:
case takePicture:
if (isRestricted(param))
param.setResult(null);
break;

case stopPreview:
if (isRestricted(param, PrivacyManager.cMedia, "Camera.stopPreview"))
param.setResult(null);
break;
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/biz/bokhorst/xprivacy/XMediaRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@ public String getClassName() {
return "android.media.MediaRecorder";
}

// void setOutputFile(FileDescriptor fd)
// void setOutputFile(String path)
// public prepare()
// public native void start()
// void stop()
// frameworks/base/media/java/android/media/MediaRecorder.java
// http://developer.android.com/reference/android/media/MediaRecorder.html

private enum Methods {
setOutputFile, start
setOutputFile, prepare, start, stop
};

public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XMediaRecorder(Methods.setOutputFile, PrivacyManager.cMedia));
listHook.add(new XMediaRecorder(Methods.prepare, null));
listHook.add(new XMediaRecorder(Methods.start, PrivacyManager.cMedia));
listHook.add(new XMediaRecorder(Methods.stop, null));
return listHook;
}

Expand All @@ -38,6 +44,12 @@ protected void before(XParam param) throws Throwable {
if (isRestricted(param))
param.setResult(null);
break;

case prepare:
case stop:
if (isRestricted(param, PrivacyManager.cMedia, "MediaRecorder.start"))
param.setResult(null);
break;
}
}

Expand Down

0 comments on commit 70af091

Please sign in to comment.