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

Commit

Permalink
Attempt to fix Note 2 boot loop
Browse files Browse the repository at this point in the history
Refs #995
  • Loading branch information
M66B committed Dec 22, 2013
1 parent 25ad620 commit f85c0c7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog

**Next release**

* Attempt to fix Note 2 boot loop

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

**Version 1.10.50 BETA**
Expand Down
42 changes: 24 additions & 18 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,8 @@ public static boolean getRestricted(final XHook hook, Context context, int uid,
}
}

// Check if usage data enabled
if (!isUsageDataEnabled(uid))
context = null;

// Check if isolated process
if (isIsolated(android.os.Process.myUid()))
// Check if privacy provider usable
if (!isProviderUsable(context))
context = null;

// Check if restricted
Expand Down Expand Up @@ -392,16 +388,6 @@ public static boolean getRestricted(XHook hook, int uid, String permission) {
return allRestricted;
}

public static boolean isUsageDataEnabled(int uid) {
if (SystemClock.elapsedRealtime() < cUseProviderAfterMs)
return false;

if (uid == cAndroidUid)
return PrivacyManager.getSettingBool(null, null, 0, PrivacyManager.cSettingAndroidUsage, false, false);
else
return true;
}

// TODO: Waiting for SDK 20 ...
public static final int FIRST_ISOLATED_UID = 99000;
public static final int LAST_ISOLATED_UID = 99999;
Expand All @@ -420,7 +406,27 @@ public static boolean isIsolated(int uid) {
return (uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID);
}

private static boolean isProviderUsable(Context context) {
if (context == null)
return false;

if (SystemClock.elapsedRealtime() < cUseProviderAfterMs)
return false;

if (isIsolated(Process.myUid()))
return false;

if (Process.myUid() == cAndroidUid)
if (!PrivacyManager.getSettingBool(null, null, 0, PrivacyManager.cSettingAndroidUsage, false, false))
return false;

return true;
}

public static void sendUsageData(final XHook hook, Context context) {
if (!isProviderUsable(context))
return;

int qSize = 0;
synchronized (mUsageQueue) {
qSize = mUsageQueue.size();
Expand Down Expand Up @@ -713,8 +719,8 @@ private static String getSetting(XHook hook, Context context, String name, Strin
}
}

// Check if isolated process
if (isIsolated(android.os.Process.myUid()))
// Check if privacy provider usable
if (!isProviderUsable(context))
context = null;

// Get setting
Expand Down
4 changes: 1 addition & 3 deletions src/biz/bokhorst/xprivacy/XActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.provider.MediaStore;
import android.util.Log;
Expand Down Expand Up @@ -158,8 +157,7 @@ protected void after(MethodHookParam param) throws Throwable {
}
} else if (mMethod == Methods.onDestroy || mMethod == Methods.onPause) {
try {
if (PrivacyManager.isUsageDataEnabled(Binder.getCallingUid()))
PrivacyManager.sendUsageData(this, (Context) param.thisObject);
PrivacyManager.sendUsageData(this, (Context) param.thisObject);
} catch (Throwable ex) {
Util.bug(this, ex);
}
Expand Down
28 changes: 12 additions & 16 deletions src/biz/bokhorst/xprivacy/XApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.Process;
import android.util.Log;

import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
Expand Down Expand Up @@ -62,18 +62,18 @@ protected void after(MethodHookParam param) throws Throwable {
// Install uncaught exception handler
Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
if (!(defaultHandler instanceof XUncaughtExceptionHandler)) {
Util.log(this, Log.INFO, "Installing XUncaughtExceptionHandler uid=" + Binder.getCallingUid());
Util.log(this, Log.INFO, "Installing XUncaughtExceptionHandler uid=" + Process.myUid());
Thread.setDefaultUncaughtExceptionHandler(new XUncaughtExceptionHandler(this, app, defaultHandler));
}

// Install receiver for package management
if (Binder.getCallingUid() != PrivacyManager.cAndroidUid) {
boolean experimental = PrivacyManager.getSettingBool(null, app, 0, PrivacyManager.cSettingExperimental,
false, true);
if (Process.myUid() != PrivacyManager.cAndroidUid) {
boolean experimental = PrivacyManager.getSettingBool(null, null, 0,
PrivacyManager.cSettingExperimental, false, true);
if (experimental && !mReceiverInstalled)
try {
mReceiverInstalled = true;
Util.log(this, Log.INFO, "Installing receiver uid=" + Binder.getCallingUid());
Util.log(this, Log.INFO, "Installing receiver uid=" + Process.myUid());
app.registerReceiver(new Receiver(app), new IntentFilter(ACTION_MANAGE_PACKAGE),
PERMISSION_MANAGE_PACKAGES, null);
} catch (Throwable ex) {
Expand Down Expand Up @@ -120,11 +120,11 @@ public Receiver(Application app) {
public void onReceive(Context context, Intent intent) {
try {
String action = intent.getExtras().getString(cAction);
Util.log(null, Log.WARN, "Managing uid=" + android.os.Process.myUid() + " action=" + action);
Util.log(null, Log.WARN, "Managing uid=" + Process.myUid() + " action=" + action);
if (cActionKillProcess.equals(action))
android.os.Process.killProcess(android.os.Process.myPid());
android.os.Process.killProcess(Process.myPid());
else if (cActionFlushCache.equals(action))
PrivacyManager.flush(mApplication, android.os.Process.myUid());
PrivacyManager.flush(mApplication, Process.myUid());
else
Util.log(null, Log.WARN, "Unknown management action=" + action);
} catch (Throwable ex) {
Expand All @@ -149,19 +149,15 @@ public Thread.UncaughtExceptionHandler getDefaultHandler() {
}

public void setDefaultHandler(Thread.UncaughtExceptionHandler handler) {
Util.log(mHook, Log.WARN, "Setting new default handler uid=" + Binder.getCallingUid());
Util.log(mHook, Log.WARN, "Setting new default handler uid=" + Process.myUid());
mDefaultHandler = handler;
}

@Override
public void uncaughtException(Thread thread, Throwable ex) {
try {
int uid = Binder.getCallingUid();
Util.log(mHook, Log.WARN, "Uncaught exception uid=" + uid + ": " + ex);

// Update usage data
if (PrivacyManager.isUsageDataEnabled(uid))
PrivacyManager.sendUsageData(null, mContext);
Util.log(mHook, Log.WARN, "Uncaught exception uid=" + Process.myUid() + ": " + ex);
PrivacyManager.sendUsageData(null, mContext);
} catch (Throwable exex) {
Util.bug(mHook, exex);
}
Expand Down
8 changes: 3 additions & 5 deletions src/biz/bokhorst/xprivacy/XService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

import android.content.Context;
import android.os.Binder;
import android.os.Process;
import android.util.Log;

import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
Expand Down Expand Up @@ -44,11 +44,9 @@ protected void before(MethodHookParam param) throws Throwable {
@Override
protected void after(MethodHookParam param) throws Throwable {
if (mMethod == Methods.onDestroy) {
int uid = Binder.getCallingUid();
Util.log(this, Log.INFO, "Service destroyed uid=" + uid);
Util.log(this, Log.INFO, "Service destroyed uid=" + Process.myUid());
try {
if (PrivacyManager.isUsageDataEnabled(uid))
PrivacyManager.sendUsageData(this, (Context) param.thisObject);
PrivacyManager.sendUsageData(this, (Context) param.thisObject);
} catch (Throwable ex) {
Util.bug(this, ex);
}
Expand Down

0 comments on commit f85c0c7

Please sign in to comment.