-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
157 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package deltazero.amarok.utils; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.util.Log; | ||
|
||
import java.util.Objects; | ||
|
||
import deltazero.amarok.Hider; | ||
import deltazero.amarok.PrefMgr; | ||
import deltazero.amarok.xposed.utils.XPref; | ||
|
||
public class XHideUtil { | ||
private static final String TAG = "XHideUtil"; | ||
|
||
private static SharedPreferences xpref; | ||
private static SharedPreferences.Editor xprefEditor; | ||
private static SharedPreferences.OnSharedPreferenceChangeListener hidePkgNamesChangeListener; | ||
|
||
public static boolean isModuleActive = false; /* Hooked by module */ | ||
public static boolean isAvailable = false; | ||
public static int xposedVersion = 0; /* Hooked by module */ | ||
|
||
public static boolean isXHideAvailable() { | ||
return isAvailable; | ||
} | ||
|
||
@SuppressLint("WorldReadableFiles") | ||
public static void init(Context context) { | ||
|
||
if (!isModuleActive) { | ||
Log.i(TAG, "Xposed module not active"); | ||
return; | ||
} else { | ||
Log.i(TAG, "Xposed module active, version = " + xposedVersion); | ||
} | ||
|
||
try { | ||
xpref = context.getSharedPreferences(XPref.XPREF_PATH, Context.MODE_WORLD_READABLE); | ||
} catch (SecurityException ignored) { | ||
// The new XSharedPreferences is not enabled or module's not loading | ||
Log.w(TAG, "Unsupported Xposed framework. Disabling XHide"); | ||
return; | ||
} | ||
|
||
xprefEditor = xpref.edit(); | ||
|
||
// Initialize the XPref with the current values | ||
xprefEditor.putStringSet(XPref.HIDE_PKG_NAMES, PrefMgr.getHideApps()); | ||
xprefEditor.putBoolean(XPref.IS_HIDDEN, Hider.getState() == Hider.State.HIDDEN); | ||
xprefEditor.putBoolean(XPref.ENABLE_X_HIDE, PrefMgr.isXHideEnabled()); | ||
xprefEditor.commit(); | ||
|
||
// Setup listeners for changes in the preferences | ||
hidePkgNamesChangeListener = (sharedPreferences, key) -> { | ||
if (Objects.equals(key, PrefMgr.HIDE_PKG_NAMES)) { | ||
Log.d(TAG, "Hide package name changed."); | ||
xprefEditor.putStringSet(XPref.HIDE_PKG_NAMES, PrefMgr.getHideApps()); | ||
xprefEditor.commit(); | ||
} else if (Objects.equals(key, PrefMgr.ENABLE_X_HIDE)) { | ||
Log.d(TAG, "XHide enabled changed."); | ||
xprefEditor.putBoolean(XPref.ENABLE_X_HIDE, PrefMgr.isXHideEnabled()); | ||
xprefEditor.commit(); | ||
} | ||
}; | ||
PrefMgr.getPrefs().registerOnSharedPreferenceChangeListener(hidePkgNamesChangeListener); | ||
Hider.state.observeForever(state -> { | ||
Log.d(TAG, "Hider state changed."); | ||
xprefEditor.putBoolean(XPref.IS_HIDDEN, state == Hider.State.HIDDEN); | ||
xprefEditor.commit(); | ||
}); | ||
|
||
Log.i(TAG, "Xposed module activated."); | ||
isAvailable = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 31 additions & 8 deletions
39
app/src/main/java/deltazero/amarok/xposed/utils/XPref.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,54 @@ | ||
package deltazero.amarok.xposed.utils; | ||
|
||
import com.github.kyuubiran.ezxhelper.Log; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import de.robv.android.xposed.XSharedPreferences; | ||
import deltazero.amarok.BuildConfig; | ||
|
||
public class XPref { | ||
public static final String XPREF_PATH = "deltazero.amarok.xposed.prefs"; | ||
private static XSharedPreferences pref; | ||
|
||
public static final String HIDE_PKG_NAMES = "hidePkgNames"; | ||
public static final String IS_HIDDEN = "isHidden"; | ||
public static final String ENABLE_X_HIDE = "enableXHide"; | ||
|
||
private static XSharedPreferences pref; | ||
private static Set<String> hidePkgNamesCache = Collections.emptySet(); | ||
private static boolean isHiddenCache = false; | ||
private static boolean enableXHideCache = false; | ||
|
||
public static void init() { | ||
pref = new XSharedPreferences(BuildConfig.APPLICATION_ID, XPREF_PATH); | ||
if (!pref.getFile().canRead()) pref = null; | ||
if (!pref.getFile().canRead()) { | ||
Log.w("No XPref found. Launch Amarok once and reboot to activate XHide.", null); | ||
pref = null; | ||
return; | ||
} | ||
|
||
assert pref != null; | ||
//noinspection deprecation /* Supported since API 93 by LSPosed & EdXposed */ | ||
pref.registerOnSharedPreferenceChangeListener( | ||
(sharedPreferences, ignore) -> { | ||
Log.i("XPref changed. Refreshing cache.", null); | ||
// Note that by design it is not possible to determine which particular preference changed | ||
// and thus preference key in listener's callback invocation will always be null. | ||
pref.reload(); | ||
enableXHideCache = pref.getBoolean(ENABLE_X_HIDE, false); | ||
isHiddenCache = pref.getBoolean(IS_HIDDEN, false); | ||
hidePkgNamesCache = pref.getStringSet(HIDE_PKG_NAMES, Collections.emptySet()); | ||
Log.i("XPref cache refreshed. isXHideActive = " + isXHideActive(), null); | ||
} | ||
); | ||
} | ||
|
||
public static boolean isXHideEnabled() { | ||
if (pref == null) return false; | ||
return pref.getBoolean(ENABLE_X_HIDE, false); | ||
public static boolean isXHideActive() { | ||
return isHiddenCache /*&& enableXHideCache*/; | ||
} | ||
|
||
public static boolean shouldHide(String pkgName) { | ||
if (pref == null) return false; | ||
return pref.getBoolean(ENABLE_X_HIDE, false) | ||
&& pref.getStringSet(HIDE_PKG_NAMES, Collections.emptySet()).contains(pkgName); | ||
return isHiddenCache /*&& enableXHideCache*/ && hidePkgNamesCache.contains(pkgName); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.