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

Commit

Permalink
Fix settings fallback multi-user
Browse files Browse the repository at this point in the history
Refs #357
  • Loading branch information
M66B committed Dec 27, 2013
1 parent 3a1ac56 commit 2d5c0cf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class PrivacyManager {
static {
// Scan meta data
try {
File in = new File(Util.getUserDataDirectory() + File.separator + "meta.xml");
File in = new File(Util.getUserDataDirectory(Process.myUid()) + File.separator + "meta.xml");
Util.log(null, Log.INFO, "Reading meta=" + in.getAbsolutePath());
FileInputStream fis = null;
try {
Expand Down
19 changes: 12 additions & 7 deletions src/biz/bokhorst/xprivacy/PrivacyProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ public static boolean getRestrictedFallback(XHook hook, int uid, String restrict
try {
long now = new Date().getTime();
File file = new File(getPrefFileName(PREF_RESTRICTION, uid));
if (!file.exists())
Util.log(null, Log.INFO, "Not found file=" + file.getAbsolutePath());

synchronized (mFallbackRestrictionLock) {
if (mFallbackRestrictions == null || mFallbackRestrictionsUid != uid) {
Expand Down Expand Up @@ -472,6 +474,8 @@ public static String getSettingFallback(String name, String defaultValue) {
try {
long now = new Date().getTime();
File file = new File(getPrefFileName(PREF_SETTINGS));
if (!file.exists())
Util.log(null, Log.INFO, "Not found file=" + file.getAbsolutePath());

synchronized (mFallbackSettingsLock) {
// Initial load
Expand Down Expand Up @@ -517,12 +521,13 @@ private void enforcePermission() throws SecurityException {
}

private static String getPrefFileName(String preference) {
return Util.getUserDataDirectory() + File.separator + "shared_prefs" + File.separator + preference + ".xml";
return Util.getUserDataDirectory(Process.myUid()) + File.separator + "shared_prefs" + File.separator
+ preference + ".xml";
}

private static String getPrefFileName(String preference, int uid) {
return Util.getUserDataDirectory() + File.separator + "shared_prefs" + File.separator + preference + "." + uid
+ ".xml";
return Util.getUserDataDirectory(uid) + File.separator + "shared_prefs" + File.separator + preference + "."
+ uid + ".xml";
}

private static void setPrefFileReadable(String preference) {
Expand All @@ -534,7 +539,7 @@ private static void setPrefFileReadable(String preference, int uid) {
}

public static void fixFilePermissions() {
File folder = new File(Util.getUserDataDirectory() + File.separator + "shared_prefs");
File folder = new File(Util.getUserDataDirectory(Process.myUid()) + File.separator + "shared_prefs");
folder.setReadable(true, false);
File list[] = folder.listFiles();
if (list != null)
Expand Down Expand Up @@ -565,7 +570,7 @@ private static String getSettingName(String settingKey) {
}

private void writeMetaData() throws IOException, FileNotFoundException {
File out = new File(Util.getUserDataDirectory() + File.separator + "meta.xml");
File out = new File(Util.getUserDataDirectory(Process.myUid()) + File.separator + "meta.xml");
Util.log(null, Log.INFO, "Writing meta=" + out.getAbsolutePath());
InputStream is = getContext().getAssets().open("meta.xml");
OutputStream os = new FileOutputStream(out.getAbsolutePath());
Expand All @@ -580,8 +585,8 @@ private void writeMetaData() throws IOException, FileNotFoundException {
}

private void convertRestrictions() throws IOException {
File source = new File(Util.getUserDataDirectory() + File.separator + "shared_prefs" + File.separator
+ "biz.bokhorst.xprivacy.provider.xml");
File source = new File(Util.getUserDataDirectory(Process.myUid()) + File.separator + "shared_prefs"
+ File.separator + "biz.bokhorst.xprivacy.provider.xml");
File backup = new File(source.getAbsoluteFile() + ".orig");
if (source.exists() && !backup.exists()) {
Util.log(null, Log.INFO, "Converting restrictions");
Expand Down
5 changes: 3 additions & 2 deletions src/biz/bokhorst/xprivacy/SharedPreferencesEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Set;

import android.content.SharedPreferences;
import android.os.Process;
import android.util.Log;

import com.android.internal.util.XmlUtils;
Expand Down Expand Up @@ -38,8 +39,8 @@ public SharedPreferencesEx(String packageName) {
}

public SharedPreferencesEx(String packageName, String prefFileName) {
mFile = new File(Util.getUserDataDirectory() + File.pathSeparator + "shared_prefs" + File.pathSeparator
+ prefFileName + ".xml");
mFile = new File(Util.getUserDataDirectory(Process.myUid()) + File.pathSeparator + "shared_prefs"
+ File.pathSeparator + prefFileName + ".xml");
mBackupFile = makeBackupFile(mFile);
startLoadFromDisk();
}
Expand Down
6 changes: 3 additions & 3 deletions src/biz/bokhorst/xprivacy/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ public static int getUserId(int uid) {
return userId;
}

public static String getUserDataDirectory() {
public static String getUserDataDirectory(int uid) {
// Build data directory
String dataDir = Environment.getDataDirectory() + File.separator;
int userId = getUserId(Process.myUid());
int userId = getUserId(uid);
if (userId == 0)
dataDir += "data";
else
Expand All @@ -194,7 +194,7 @@ public static String[] getProLicense() {
licenseFile = new File(storageDir + File.separator + ".xprivacy" + File.separator + LICENSE_FILE_NAME);

// Get imported license file name
String importedLicense = getUserDataDirectory() + File.separator + LICENSE_FILE_NAME;
String importedLicense = getUserDataDirectory(Process.myUid()) + File.separator + LICENSE_FILE_NAME;

// Import license file
if (licenseFile.exists()) {
Expand Down

0 comments on commit 2d5c0cf

Please sign in to comment.