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

Commit

Permalink
Added restrictions for UsageStatsManager
Browse files Browse the repository at this point in the history
Refs #1757
  • Loading branch information
M66B committed Dec 15, 2014
1 parent ef2944b commit 8757d12
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Changelog
* Added restriction *getInstalledProvidersForProfile* ([issue](/../../issues/1757))
* Allow white listing / show parameter of *getExternalStorageState* ([issue](/../../issues/1757))
* Added quirk *nousage* to disable usage data for specific applications ([issue](/../../issues/2085))
* Added restrictions for [UsageStatsManager](https://developer.android.com/reference/android/app/usage/UsageStatsManager.html) ([issue](/../../issues/1757))

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)

Expand Down
7 changes: 7 additions & 0 deletions res/values/functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@
<string name="system_checkPermission" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/content/pm/PackageManager.html#checkPermission(java.lang.String,%20java.lang.String)">Google documentation</a>]]></string>
<string name="system_checkUidPermission" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/content/pm/PackageManager.html#checkPermission(java.lang.String,%20java.lang.String)">Google documentation</a>]]></string>
<string name="system_IntentFirewall" translatable="false"><![CDATA[<a href="http://www.cis.syr.edu/~wedu/android/IntentFirewall/">Documentation</a>]]></string>
<string name="system_queryAndAggregateUsageStats" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryAndAggregateUsageStats(long, long)">Documentation</a>]]></string>
<string name="system_queryConfigurations" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryConfigurations(int, long, long)">Documentation</a>]]></string>
<string name="system_queryEvents" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryEvents(long, long)">Documentation</a>]]></string>
<string name="system_queryUsageStats" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryUsageStats(int, long, long)">Documentation</a>]]></string>
<string name="system_Srv_queryConfigurationStats" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryConfigurations(int, long, long)">Documentation</a>]]></string>
<string name="system_Srv_queryEvents" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryEvents(long, long)">Documentation</a>]]></string>
<string name="system_Srv_queryUsageStats" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryUsageStats(int, long, long)">Documentation</a>]]></string>

<!-- view -->
<string name="view_loadUrl" translatable="false"><![CDATA[<a href="https://developer.android.com/reference/android/webkit/WebView.html#loadUrl(java.lang.String)">Google documentation</a>]]></string>
Expand Down
8 changes: 8 additions & 0 deletions src/biz/bokhorst/xprivacy/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ public static List<Hook> get() {

mListHook.add(new Hook("system", "IntentFirewall", "", 19, "2.2.2", null).AOSP(19).dangerous().whitelist(cTypeAction));

mListHook.add(new Hook("system", "queryAndAggregateUsageStats", null, 21, "3.5.6", null).notAOSP(21));
mListHook.add(new Hook("system", "queryConfigurations", null, 21, "3.5.6", null).notAOSP(21));
mListHook.add(new Hook("system", "queryEvents", null, 21, "3.5.6", null).notAOSP(21));
mListHook.add(new Hook("system", "queryUsageStats", null, 21, "3.5.6", null).notAOSP(21));
mListHook.add(new Hook("system", "Srv_queryConfigurationStats", null, 21, "3.5.6", null).AOSP(21));
mListHook.add(new Hook("system", "Srv_queryEvents", null, 21, "3.5.6", null).AOSP(21));
mListHook.add(new Hook("system", "Srv_queryUsageStats", null, 21, "3.5.6", null).AOSP(21));

mListHook.add(new Hook("view", "loadUrl", "", 1, null, null).unsafe().whitelist(cTypeUrl));
mListHook.add(new Hook("view", "WebView", "", 1, null, null).unsafe());
mListHook.add(new Hook("view", "getDefaultUserAgent", "", 17, null, null).unsafe());
Expand Down
3 changes: 3 additions & 0 deletions src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// Telephone service
hookAll(XTelephonyManager.getInstances(null), null, mSecret);

// Usage statistics manager
hookAll(XUsageStatsManager.getInstances(), null, mSecret);

// USB device
hookAll(XUsbDevice.getInstances(), null, mSecret);

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.usage.ConfigurationStats;
import android.app.usage.UsageStats;

import biz.bokhorst.xprivacy.XHook;

public class XUsageStatsManager extends XHook {
private Methods mMethod;

private XUsageStatsManager(Methods method, String restrictionName) {
super(restrictionName, method.name(), null);
mMethod = method;
}

public String getClassName() {
if (mMethod.name().startsWith("Srv_"))
return "com.android.server.usage.UserUsageStatsService";
else
return "android.app.usage.UsageStatsManager";
}

// @formatter:off

// public Map<String, UsageStats> queryAndAggregateUsageStats(long beginTime, long endTime)
// public List<ConfigurationStats> queryConfigurations(int intervalType, long beginTime, long endTime)
// public UsageEvents queryEvents(long beginTime, long endTime)
// public List<UsageStats> queryUsageStats(int intervalType, long beginTime, long endTime)
// https://developer.android.com/reference/android/app/usage/UsageStatsManager.html

// List<ConfigurationStats> queryConfigurationStats(int userId, int bucketType, long beginTime, long endTime)
// UsageEvents queryEvents(int userId, long beginTime, long endTime)
// List<UsageStats> queryUsageStats(int userId, int bucketType, long beginTime, long endTime)
// http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/com/android/server/usage/UsageStatsService.java

private enum Methods {
queryAndAggregateUsageStats, queryConfigurations, queryEvents, queryUsageStats,
Srv_queryConfigurationStats, Srv_queryEvents, Srv_queryUsageStats
};

// @formatter:on

public static List<XHook> getInstances() {
List<XHook> listHook = new ArrayList<XHook>();
listHook.add(new XUsageStatsManager(Methods.queryAndAggregateUsageStats, PrivacyManager.cSystem));
listHook.add(new XUsageStatsManager(Methods.queryConfigurations, PrivacyManager.cSystem));
listHook.add(new XUsageStatsManager(Methods.queryEvents, PrivacyManager.cSystem));
listHook.add(new XUsageStatsManager(Methods.queryUsageStats, PrivacyManager.cSystem));

listHook.add(new XUsageStatsManager(Methods.Srv_queryConfigurationStats, PrivacyManager.cSystem));
listHook.add(new XUsageStatsManager(Methods.Srv_queryEvents, PrivacyManager.cSystem));
listHook.add(new XUsageStatsManager(Methods.Srv_queryUsageStats, PrivacyManager.cSystem));
return listHook;
}

@Override
protected void before(XParam param) throws Throwable {
switch (mMethod) {
case queryAndAggregateUsageStats:
case queryConfigurations:
case queryUsageStats:
case Srv_queryConfigurationStats:
case Srv_queryUsageStats:
// Do nothing
break;
case queryEvents:
if (isRestricted(param))
if (param.args.length > 1) {
param.args[0] = 0;
param.args[1] = 0;
}
break;

case Srv_queryEvents:
if (isRestricted(param))
if (param.args.length > 2) {
param.args[1] = 0;
param.args[2] = 0;
}
break;
}
}

@Override
protected void after(XParam param) throws Throwable {
switch (mMethod) {
case queryAndAggregateUsageStats:
if (isRestricted(param))
param.setResult(new HashMap<String, UsageStats>());
break;
case queryConfigurations:
case Srv_queryConfigurationStats:
if (isRestricted(param))
param.setResult(new ArrayList<ConfigurationStats>());
break;
case queryEvents:
case Srv_queryEvents:
// Do nothing
break;
case queryUsageStats:
case Srv_queryUsageStats:
if (isRestricted(param))
param.setResult(new ArrayList<UsageStats>());
break;
}
}
}

0 comments on commit 8757d12

Please sign in to comment.