From f85c0c74477999b8817f96209f79839d7d0b4f73 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 22 Dec 2013 07:32:31 +0100 Subject: [PATCH] Attempt to fix Note 2 boot loop Refs #995 --- CHANGELOG.md | 2 + src/biz/bokhorst/xprivacy/PrivacyManager.java | 42 +++++++++++-------- src/biz/bokhorst/xprivacy/XActivity.java | 4 +- src/biz/bokhorst/xprivacy/XApplication.java | 28 ++++++------- src/biz/bokhorst/xprivacy/XService.java | 8 ++-- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc272c944..63aeda4aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** diff --git a/src/biz/bokhorst/xprivacy/PrivacyManager.java b/src/biz/bokhorst/xprivacy/PrivacyManager.java index 038168e64..81dbbc08e 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyManager.java +++ b/src/biz/bokhorst/xprivacy/PrivacyManager.java @@ -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 @@ -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; @@ -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(); @@ -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 diff --git a/src/biz/bokhorst/xprivacy/XActivity.java b/src/biz/bokhorst/xprivacy/XActivity.java index 550d3da70..1bdccc22b 100644 --- a/src/biz/bokhorst/xprivacy/XActivity.java +++ b/src/biz/bokhorst/xprivacy/XActivity.java @@ -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; @@ -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); } diff --git a/src/biz/bokhorst/xprivacy/XApplication.java b/src/biz/bokhorst/xprivacy/XApplication.java index 2fe8f2d7b..e6ad9469e 100644 --- a/src/biz/bokhorst/xprivacy/XApplication.java +++ b/src/biz/bokhorst/xprivacy/XApplication.java @@ -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; @@ -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) { @@ -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) { @@ -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); } diff --git a/src/biz/bokhorst/xprivacy/XService.java b/src/biz/bokhorst/xprivacy/XService.java index 1e902ec12..34c41af81 100644 --- a/src/biz/bokhorst/xprivacy/XService.java +++ b/src/biz/bokhorst/xprivacy/XService.java @@ -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; @@ -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); }