public final class

XSharedPreferences

extends Object
implements SharedPreferences
java.lang.Object
   ↳ de.robv.android.xposed.XSharedPreferences

Class Overview

This class is basically the same as SharedPreferencesImpl from AOSP, but read-only and without listeners support. Instead, it is made to be compatible with all ROMs.

Summary

Public Constructors
XSharedPreferences(File prefFile)
Read settings from the specified file.
XSharedPreferences(String packageName)
Read settings from the default preferences for a package.
XSharedPreferences(String packageName, String prefFileName)
Read settings from a custom preferences file for a package.
Public Methods
SharedPreferences.Editor edit()
This method is deprecated. Not supported by this implementation.
File getFile()
Returns the file that is backing these preferences.
boolean hasFileChanged()
Check whether the file has changed since the last time it has been loaded.
boolean makeWorldReadable()
Tries to make the preferences file world-readable.
void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener)
This method is deprecated. Not supported by this implementation.
void reload()
Reload the settings from file if they have changed.
void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener)
This method is deprecated. Not supported by this implementation.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.content.SharedPreferences

Public Constructors

public XSharedPreferences (File prefFile)

Read settings from the specified file.

Parameters
prefFile The file to read the preferences from.

public XSharedPreferences (String packageName)

Read settings from the default preferences for a package. These preferences are returned by PreferenceManager.getDefaultSharedPreferences(Context).

Parameters
packageName The package name.

public XSharedPreferences (String packageName, String prefFileName)

Read settings from a custom preferences file for a package. These preferences are returned by Context.getSharedPreferences(String, int).

Parameters
packageName The package name.
prefFileName The file name without ".xml".

Public Methods

public SharedPreferences.Editor edit ()

This method is deprecated.
Not supported by this implementation.

Create a new Editor for these preferences, through which you can make modifications to the data in the preferences and atomically commit those changes back to the SharedPreferences object.

Note that you must call SharedPreferences.Editor.commit() to have any changes you perform in the Editor actually show up in the SharedPreferences.

Returns
  • Returns a new instance of the SharedPreferences.Editor interface, allowing you to modify the values in this SharedPreferences object.

public File getFile ()

Added in API level 53

Returns the file that is backing these preferences.

Warning: The file might not be accessible directly.

public boolean hasFileChanged ()

Added in API level 53

Check whether the file has changed since the last time it has been loaded.

Warning: With enforcing SELinux, this call might be quite expensive.

public boolean makeWorldReadable ()

Tries to make the preferences file world-readable.

Warning: This is only meant to work around permission "fix" functions that are part of some recoveries. It doesn't replace the need to open preferences with MODE_WORLD_READABLE in the module's UI code. Otherwise, Android will set stricter permissions again during the next save.

This will only work if executed as root (e.g. initZygote()) and only if SELinux is disabled.

Returns
  • true in case the file could be made world-readable.

public void registerOnSharedPreferenceChangeListener (SharedPreferences.OnSharedPreferenceChangeListener listener)

This method is deprecated.
Not supported by this implementation.

Registers a callback to be invoked when a change happens to a preference.

Caution: The preference manager does not currently store a strong reference to the listener. You must store a strong reference to the listener, or it will be susceptible to garbage collection. We recommend you keep a reference to the listener in the instance data of an object that will exist as long as you need the listener.

Parameters
listener The callback that will run.

public void reload ()

Reload the settings from file if they have changed.

Warning: With enforcing SELinux, this call might be quite expensive.

public void unregisterOnSharedPreferenceChangeListener (SharedPreferences.OnSharedPreferenceChangeListener listener)

This method is deprecated.
Not supported by this implementation.

Unregisters a previous callback.

Parameters
listener The callback that should be unregistered.