public int getNotifCountFor(String pkg) { if (pkg == null) return 0; int count = 0; try { Map<?,?> entries = (Map<?,?>) XposedHelpers.getObjectField(mNotifData, "mEntries"); for (Object entry : entries.values()) { StatusBarNotification sbn = (StatusBarNotification) XposedHelpers.getObjectField(entry, "notification"); if (pkg.equals(sbn.getPackageName())) { final Notification n = sbn.getNotification(); count += (n.number > 0 ? n.number : 1); } } } catch (Throwable t) { XposedBridge.log(t); } if (DEBUG) log("getNotifCountFor: " + pkg + "=" + count); return count; }
private static void launchClockAction(String uri) { if (mContext == null) return; try { final Intent intent = Intent.parseUri(uri, 0); if (intent != null) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); mContext.startActivity(intent); if (mPhoneStatusBar != null) { XposedHelpers.callMethod(mPhoneStatusBar, "animateCollapsePanels"); } } } catch (ActivityNotFoundException e) { log("Error launching assigned app for long-press on clock: " + e.getMessage()); } catch (Throwable t) { XposedBridge.log(t); } }
private static void updateSettingsButton() { if (mPhoneStatusBar == null || SysUiManagers.IconManager == null) return; try { Object header = XposedHelpers.getObjectField(mPhoneStatusBar, "mHeader"); ImageView settingsButton = (ImageView) XposedHelpers.getObjectField( header, Utils.isSamsungRom() ? "mSettingButton" : "mSettingsButton"); if (SysUiManagers.IconManager.isColoringEnabled()) { settingsButton.setColorFilter(SysUiManagers.IconManager.getIconColor(), PorterDuff.Mode.SRC_IN); } else { settingsButton.clearColorFilter(); } } catch (Throwable t) { XposedBridge.log(t); } }
private static void changeSmartRadioState(Intent intent) { try { if (intent.hasExtra(AShortcut.EXTRA_ENABLE)) { mSmartRadioEnabled = intent.getBooleanExtra(AShortcut.EXTRA_ENABLE, false); } else { mSmartRadioEnabled = !mSmartRadioEnabled; } Settings.System.putInt(mContext.getContentResolver(), SETTING_SMART_RADIO_ENABLED, mSmartRadioEnabled ? 1 : 0); if (mSmartRadioEnabled) { if (shouldSwitchToNormalState()) { switchToState(State.NORMAL); } else { switchToState(State.POWER_SAVING); } } if (intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) { Utils.postToast(mContext, mSmartRadioEnabled ? R.string.smart_radio_on : R.string.smart_radio_off); } if (DEBUG) log("mSmartRadioEnabled=" + mSmartRadioEnabled); } catch (Throwable t) { XposedBridge.log(t); } }
/** * Prints all declared fields of a object * * @param start Object to analyze */ public static void printDeclaredFields(Object start) { int lenlen = start.getClass().getDeclaredFields().length; for (int i = 0; i < lenlen; i++) { try { String name = start.getClass().getDeclaredFields()[i].getName(); Object found = getObjField(start, name); if (found != null) { XposedBridge.log("Declared field " + i + "(" + name + "): " + found.toString()); } } catch (Exception ignored) { } } }
@Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable { if (!lpparam.packageName.equals("com.tencent.tmgp.sgame")) return; if (BuildConfig.DEBUG) { XposedBridge.log("dreamtobe in king of glory!"); } final Class<?> crashNotifyHandler = findClass("com.tsf4g.apollo.report.CrashNotifyHandler", lpparam.classLoader); findAndHookMethod(crashNotifyHandler, "Instance", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); param.setResult(null); } }); }
private static void init() { Context sysContext = (Context) XposedHelpers.callMethod( XposedHelpers.callStaticMethod( XposedHelpers.findClass("android.app.ActivityThread", null), "currentActivityThread"), "getSystemContext"); try { PackageInfo pkgInfo = sysContext.getPackageManager().getPackageInfo(PKG_NAME, 0); XposedBridge.log(String.format(Locale.getDefault(), "WCFP: Found WeChat version : %s (%d)", pkgInfo.versionName, pkgInfo.versionCode)); if ((isVersionSupported = VersionInfo.checkVersion(pkgInfo.versionCode))) { VersionInfo.initMinify(pkgInfo.versionCode); } } catch (PackageManager.NameNotFoundException e) { XposedBridge.log(e); } }
private static void initReflections(Class<?> classPhoneWindowManager) { try { if (mLaunchAssistAction == null) { mLaunchAssistAction = classPhoneWindowManager.getDeclaredMethod( "launchAssistAction", String.class, int.class); mLaunchAssistAction.setAccessible(true); } if (mLaunchAssistLongPressAction == null) { mLaunchAssistLongPressAction = classPhoneWindowManager.getDeclaredMethod( "launchAssistLongPressAction"); mLaunchAssistLongPressAction.setAccessible(true); } } catch (Throwable t) { XposedBridge.log(t); } }
private String getLollipopRecentTask() { /** @hide Process is hosting the current top activities. Note that this covers * all activities that are visible to the user. */ final int PROCESS_STATE_TOP = 2; try { Field processStateField = ActivityManager.RunningAppProcessInfo.class.getDeclaredField("processState"); List<ActivityManager.RunningAppProcessInfo> processes = ((ActivityManager) AndroidAppHelper.currentApplication().getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo process : processes) { if (process.importance <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && process.importanceReasonCode == 0) { int state = processStateField.getInt(process); if (state == PROCESS_STATE_TOP) { String[] packname = process.pkgList; return packname[0]; } } } } catch (Exception e) { XposedBridge.log(e); } return ""; }
public static void initResources(final XSharedPreferences prefs, final InitPackageResourcesParam resparam) { try { // Lockscreen: disable menu key in lock screen Utils.TriState triState = Utils.TriState.valueOf(prefs.getString( GravityBoxSettings.PREF_KEY_LOCKSCREEN_MENU_KEY, "DEFAULT")); if (DEBUG) log(GravityBoxSettings.PREF_KEY_LOCKSCREEN_MENU_KEY + ": " + triState); if (triState != Utils.TriState.DEFAULT) { resparam.res.setReplacement(PACKAGE_NAME, "bool", "config_disableMenuKeyInLockScreen", triState == Utils.TriState.DISABLED); if (DEBUG) log("config_disableMenuKeyInLockScreen: " + (triState == Utils.TriState.DISABLED)); } } catch (Throwable t) { XposedBridge.log(t); } }
private void createHooks() { if (Utils.isOxygenOs35Rom()) return; try { mLongClickHook = XposedHelpers.findAndHookMethod(mTile.getClass().getName(), mContext.getClassLoader(), "handleLongClick", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { if (handleLongClick()) { param.setResult(null); } } }); } catch (Throwable t) { XposedBridge.log(t); } }
private static void setNotificationPanelState(Intent intent, boolean withQs) { try { if (!intent.hasExtra(AShortcut.EXTRA_ENABLE)) { Object notifPanel = XposedHelpers.getObjectField(mPhoneStatusBar, "mNotificationPanel"); if ((boolean) XposedHelpers.callMethod(notifPanel, "isFullyCollapsed")) { expandNotificationPanel(withQs); } else { collapseNotificationPanel(); } } else { if (intent.getBooleanExtra(AShortcut.EXTRA_ENABLE, false)) { expandNotificationPanel(withQs); } else { collapseNotificationPanel(); } } } catch (Throwable t) { XposedBridge.log(t); } }
public static void init(final XSharedPreferences prefs, final ClassLoader classLoader) { try { final Class<?> classDownloadService = XposedHelpers.findClass(CLASS_DOWNLOAD_SERVICE, classLoader); XposedHelpers.findAndHookMethod(classDownloadService, "updateLocked", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { final boolean isActive = (Boolean) param.getResult(); if (mIsActive != isActive) { mIsActive = isActive; if (DEBUG) log("Download state changed; active=" + mIsActive); final Context context = (Context) param.thisObject; Intent intent = new Intent(ACTION_DOWNLOAD_STATE_CHANGED); intent.putExtra(EXTRA_ACTIVE, mIsActive); context.sendBroadcast(intent); } } }); } catch (Throwable t) { XposedBridge.log(t); } }
private static synchronized final void clearAll() { if (mRecentsView == null) return; try { int childCount = mRecentsView.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = mRecentsView.getChildAt(i); if (child.getClass().getName().equals(CLASS_TASK_STACK_VIEW)) { clearStack((ViewGroup) child); } } updateRamBarMemoryUsage(); } catch (Throwable t) { XposedBridge.log(t); } }
private Object getResourceIcon() { if (sResourceIconClass == null || icon == null) return null; try { Object resourceIcon = XposedHelpers.callStaticMethod( sResourceIconClass, "get", icon.hashCode()); XposedHelpers.setAdditionalInstanceField(resourceIcon, TILE_KEY_NAME, mKey); if (DEBUG) log("getting resource icon for " + mKey); return resourceIcon; } catch (Throwable t) { log("Error creating resource icon:"); XposedBridge.log(t); return null; } }
public static void init(final XSharedPreferences prefs, final ClassLoader classLoader) { try { final Class<?> classDevSettings = XposedHelpers.findClass(CLASS_DEV_SETTINGS, classLoader); if (DEBUG) log("hooking DeveloperSettings.onCreate method"); XposedHelpers.findAndHookMethod(classDevSettings, "onCreate", Bundle.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(final MethodHookParam param) throws Throwable { PreferenceFragment pf = (PreferenceFragment) param.thisObject; mResId = pf.getResources().getIdentifier("development_prefs", "xml", PACKAGE_NAME); if (DEBUG) log("mResId=" + mResId); } }); } catch (Throwable t) { XposedBridge.log(t); } }
public static void injectKey(final int keyCode) { Handler handler = (Handler) XposedHelpers.getObjectField(mPhoneWindowManager, "mHandler"); if (handler == null) return; handler.post(new Runnable() { @Override public void run() { try { final long eventTime = SystemClock.uptimeMillis(); final InputManager inputManager = (InputManager) mContext.getSystemService(Context.INPUT_SERVICE); int flags = KeyEvent.FLAG_FROM_SYSTEM; XposedHelpers.callMethod(inputManager, "injectInputEvent", new KeyEvent(eventTime - 50, eventTime - 50, KeyEvent.ACTION_DOWN, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0); XposedHelpers.callMethod(inputManager, "injectInputEvent", new KeyEvent(eventTime - 50, eventTime - 25, KeyEvent.ACTION_UP, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0); } catch (Throwable t) { XposedBridge.log(t); } } }); }
private static void changeMobileDataState(Intent intent) { if (mTelephonyManager == null) return; try { boolean enabled; if (intent.hasExtra(AShortcut.EXTRA_ENABLE)) { enabled = intent.getBooleanExtra(AShortcut.EXTRA_ENABLE, false); } else { enabled = !(Boolean) XposedHelpers.callMethod( mTelephonyManager, "getDataEnabled"); } setMobileDataEnabled(enabled); if (intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) { Utils.postToast(mContext, enabled ? R.string.mobile_data_on : R.string.mobile_data_off); } } catch (Throwable t) { XposedBridge.log(t); } }
private void startActivity(Intent intent) { // if intent is a GB action of broadcast type, handle it directly here if (ShortcutActivity.isGbBroadcastShortcut(intent)) { boolean isLaunchBlocked = mKgMonitor.isShowing() && mKgMonitor.isLocked() && !ShortcutActivity.isActionSafe(intent.getStringExtra( ShortcutActivity.EXTRA_ACTION)); if (DEBUG) log("isLaunchBlocked: " + isLaunchBlocked); if (!isLaunchBlocked) { Intent newIntent = new Intent(intent.getStringExtra(ShortcutActivity.EXTRA_ACTION)); newIntent.putExtras(intent); mContext.sendBroadcast(newIntent); } // otherwise start activity dismissing keyguard } else { try { XposedHelpers.callMethod(mStatusBar, "postStartActivityDismissingKeyguard", intent, 0); } catch (Throwable t) { XposedBridge.log(t); } } }
private static Object getOldNotificationRecord(Object pkg, Object tag, Object id, Object userId) { Object oldNotifRecord = null; try { ArrayList<?> notifList = (ArrayList<?>) XposedHelpers.getObjectField( mNotifManagerService, "mNotificationList"); synchronized (notifList) { int index = (Integer) XposedHelpers.callMethod( mNotifManagerService, "indexOfNotificationLocked", pkg, tag, id, userId); if (index >= 0) { oldNotifRecord = notifList.get(index); } } } catch (Throwable t) { log("Error in getOldNotificationRecord: " + t.getMessage()); if (DEBUG) XposedBridge.log(t); } if (DEBUG) log("getOldNotificationRecord: has old record: " + (oldNotifRecord != null)); return oldNotifRecord; }
private static void sendNfcState(ResultReceiver receiver) { if (mContext == null || receiver == null) return; int nfcState = NFC_STATE_UNKNOWN; try { NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext); if (adapter != null) { nfcState = (Integer) XposedHelpers.callMethod(adapter, "getAdapterState"); } } catch (Throwable t) { XposedBridge.log(t); } finally { Bundle b = new Bundle(); b.putInt("nfcState", nfcState); receiver.send(0, b); } }
@SuppressWarnings("deprecation") private static int getDefaultNotificationProp(String resName, String resType, int defVal) { int val = defVal; try { Context ctx = (Context) XposedHelpers.callMethod( mNotifManagerService, "getContext"); Resources res = ctx.getResources(); int resId = res.getIdentifier(resName, resType, "android"); if (resId != 0) { switch (resType) { case "color": val = res.getColor(resId); break; case "integer": val = res.getInteger(resId); break; } } } catch (Throwable t) { if (DEBUG) XposedBridge.log(t); } return val; }
private static void updateNavbarDimensions() { try { Resources res = mContext.getResources(); int resWidthId = res.getIdentifier( "navigation_bar_width", "dimen", "android"); int resHeightId = res.getIdentifier( "navigation_bar_height", "dimen", "android"); int resHeightLandscapeId = res.getIdentifier( "navigation_bar_height_landscape", "dimen", "android"); mNavbarDimensions = new NavbarDimensions( (int) (res.getDimensionPixelSize(resWidthId) * mNavbarWidthScaleFactor), (int) (res.getDimensionPixelSize(resHeightId) * mNavbarHeightScaleFactor), (int) (res.getDimensionPixelSize(resHeightLandscapeId) * mNavbarHeightLandscapeScaleFactor)); updateSettings(); } catch (Throwable t) { XposedBridge.log(t); } }
public static boolean hasMsimSupport() { if (mHasMsimSupport != null) return mHasMsimSupport; try { Object mtm = XposedHelpers.callStaticMethod(getTelephonyManagerClass(), "getDefault"); mHasMsimSupport = (Boolean) XposedHelpers.callMethod(mtm, "isMultiSimEnabled") && getPhoneCount() > 1; if (DEBUG) log("isMultiSimEnabled: " + (Boolean) XposedHelpers.callMethod(mtm, "isMultiSimEnabled")); if (DEBUG) log("getPhoneCount: " + getPhoneCount()); } catch (Throwable t) { if (DEBUG) XposedBridge.log(t); mHasMsimSupport = false; } if (DEBUG) log("hasMsimSupport: " + mHasMsimSupport); return mHasMsimSupport; }
private static void dismissKeyguard() { try { XposedHelpers.callMethod(mPhoneWindowManager, "dismissKeyguardLw"); } catch (Throwable t) { if (DEBUG) XposedBridge.log(t); } }
final boolean isBlocked(ArrayList<BlockModel> arrayList, Object o) { Pair<Boolean, Integer> pair = isBlock(arrayList, o); if (onlyOnce && pair.second != null && pair.second >= 0) { BlockModel blockModel = arrayList.remove((int) pair.second); XposedBridge.log("净眼:删除规则 -->" + blockModel); } return pair.first; }
private static void updateRecentsKeyCode() { if (mRecentsKeys == null) return; try { final boolean hasAction = recentsKeyHasAction(); for (Object o : mRecentsKeys) { if (o != null) { XposedHelpers.setIntField(o, "mCode", hasAction ? KeyEvent.KEYCODE_APP_SWITCH : 0); } } } catch (Throwable t) { XposedBridge.log(t); } }
@Override protected void onPostExecute(Boolean found) { if (!found) { XposedBridge.log(TAG + "WhatsApp " + versionCode + " is incompatible with module version " + moduleVersionCode); } }
public static int getPhoneCount() { if (mPhoneCount != -1) return mPhoneCount; try { Object mtm = XposedHelpers.callStaticMethod(getTelephonyManagerClass(), "getDefault"); mPhoneCount = (int) XposedHelpers.callMethod(mtm, "getPhoneCount"); } catch (Throwable t) { if (DEBUG) XposedBridge.log(t); mPhoneCount = -1; } if (DEBUG) log("getPhoneCount: " + mPhoneCount); return mPhoneCount; }
public void overwriteResults(String classname, String method, final Object result){ try { Class<?> aClass = cloader.loadClass(classname); XposedBridge.hookAllMethods(aClass, method, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { param.setResult(result); } }); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
@Override protected void afterHookedMethod(final MethodHookParam param) throws Throwable { try { if (!prepareUnicodeFilter()) return; if (DEBUG) log("ComposeMessageActivity created. Hooking to TextEditorWatcher"); final TextWatcher textEditorWatcher = (TextWatcher) XposedHelpers.getObjectField( param.thisObject, "mTextEditorWatcher"); if (textEditorWatcher != null) { XposedHelpers.findAndHookMethod(textEditorWatcher.getClass(), "onTextChanged", CharSequence.class, int.class, int.class, int.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param2) throws Throwable { if (param2.thisObject != textEditorWatcher) return; CharSequence s = (CharSequence) param2.args[0]; if (DEBUG) log("TextEditorWatcher.onTextChanged: original ='" + s + "'"); s = mUnicodeFilter.filter(s); if (DEBUG) log("TextEditorWatcher.onTextChanged: stripped ='" + s + "'"); param2.args[0] = s; } }); } } catch (Throwable t) { XposedBridge.log(t); } }
@Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam param) throws Throwable { if (!param.packageName.equals("com.sina.weibo")) { return; } log("Fixer handleLoadPackage: " + param.packageName); Class<?> instrumentation = XposedHelpers.findClass("android.app.Instrumentation", param.classLoader); Method method = instrumentation.getMethod("newActivity", ClassLoader.class, String.class, Intent.class); XposedBridge.hookMethod(method, new ActivityHook()); XposedHelpers.findAndHookMethod("android.content.ClipboardManager", param.classLoader, "setPrimaryClip", ClipData.class, new ClipboardHook()); }
private int getZenMode() { try { return (int) XposedHelpers.callMethod(getZenCtrl(), "getZen"); } catch (Throwable t) { XposedBridge.log(t); return ZEN_MODE_OFF; } }
@Override protected void beforeHookedMethod(MethodHookParam methodHookParam) { XposedBridge.log("AllTrans: in OnCreate of Application"); Application application = (Application) methodHookParam.thisObject; alltrans.context = application.getApplicationContext(); if (PreferenceList.Caching) { try { FileInputStream fileInputStream = alltrans.context.openFileInput("AllTransCache"); ObjectInputStream s = new ObjectInputStream(fileInputStream); alltrans.cacheAccess.acquireUninterruptibly(); //noinspection unchecked alltrans.cache = (HashMap<String, String>) s.readObject(); alltrans.cacheAccess.release(); utils.debugLog("Successfully read old cache"); s.close(); } catch (Exception e) { utils.debugLog("Could not read cache "); alltrans.cacheAccess.acquireUninterruptibly(); alltrans.cache = new HashMap<>(10000); alltrans.cacheAccess.release(); } } MyActivityLifecycleCallbacks myActivityLifecycleCallbacks = new MyActivityLifecycleCallbacks(); application.registerActivityLifecycleCallbacks(myActivityLifecycleCallbacks); }
@Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable { final Class<?> phoneWindowManager; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { phoneWindowManager = XposedHelpers.findClass("com.android.server.policy.PhoneWindowManager", lpparam.classLoader); } else { phoneWindowManager = XposedHelpers.findClass("com.android.internal.policy.impl.PhoneWindowManager", lpparam.classLoader); } XposedBridge.hookAllMethods(phoneWindowManager, "interceptKeyBeforeQueueing", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { int keyCode = ((KeyEvent) param.args[0]).getKeyCode(); if (keyCode == KeyEvent.KEYCODE_POWER) { XSharedPreferences mXsp = new XSharedPreferences(PACKAGE_NAME); Log.d("isBlockPowerButton", "=================" + mXsp.getBoolean("isBlockPowerButton", true)); XposedBridge.log("isBlockPowerButton" + "=================" + mXsp.getBoolean("isBlockPowerButton", true)); if (mXsp.getBoolean("isBlockPowerButton", true)) { param.setResult(0); } } } }); }
public void collapsePanels() { try { XposedHelpers.callMethod(mHost, "collapsePanels"); } catch (Throwable t) { log("Error in collapsePanels: "); XposedBridge.log(t); } }
private static boolean isIncomingCall() { try { TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); return (phone.getCallState() == TelephonyManager.CALL_STATE_RINGING); } catch (Throwable t) { XposedBridge.log(t); return false; } }
public void update() { try { ContentResolver resolver = mContext.getContentResolver(); int brightnessMode = (Integer) XposedHelpers.callStaticMethod(Settings.System.class, "getIntForUser", resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, 0, -2); mAutomaticBrightness = brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; } catch (Throwable t) { XposedBridge.log(t); } }
public static void initResources(final XSharedPreferences prefs, final InitPackageResourcesParam resparam) { try { StatusbarSignalCluster.initResources(prefs, resparam); } catch (Throwable t) { XposedBridge.log(t); } }
private static void prepareBrightnessControl() { try { Class<?> powerManagerClass = XposedHelpers.findClass(CLASS_POWER_MANAGER, mContext.getClassLoader()); Resources res = mContext.getResources(); mMinBrightness = res.getInteger(res.getIdentifier( "config_screenBrightnessSettingMinimum", "integer", "android")); mPeekHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 84, res.getDisplayMetrics()); BRIGHTNESS_ON = XposedHelpers.getStaticIntField(powerManagerClass, "BRIGHTNESS_ON"); } catch (Throwable t) { XposedBridge.log(t); } }