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

Commit

Permalink
System server will create database folder
Browse files Browse the repository at this point in the history
Refs #1437
  • Loading branch information
M66B committed Feb 25, 2014
1 parent a75b1e5 commit 547ceb8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog
**Next release**

* Fixed submitting restrictions ([issue](/../../issues/1452))
* System server will create database folder ([issue](/../../issues/1437))

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)

Expand Down
110 changes: 56 additions & 54 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,60 +73,6 @@ public class PrivacyService {
// TODO: define column names
// sqlite3 /data/system/xprivacy/xprivacy.db

public static void setupDatabase() {
// This is run from Zygote with root permissions
// SELinix needs to be taken into account
try {
File dbFile = getDbFile();

// Create database folder
dbFile.getParentFile().mkdirs();

// Check database folder
if (dbFile.getParentFile().isDirectory())
Util.log(null, Log.WARN, "Database folder=" + dbFile.getParentFile());
else
Util.log(null, Log.ERROR, "Does not exist folder=" + dbFile.getParentFile());

// Move database from data/xprivacy folder
File folder = new File(Environment.getDataDirectory() + File.separator + "xprivacy");
File[] oldFiles = folder.listFiles();
if (oldFiles != null)
for (File file : oldFiles)
if (file.getName().startsWith("xprivacy.db") || file.getName().startsWith("usage.db")) {
File target = new File(dbFile.getParentFile() + File.separator + file.getName());
boolean status = file.renameTo(target);
Util.log(null, Log.WARN, "Moving " + file + " to " + target + " ok=" + status);
}

// Move database from data/application folder
folder = new File(Environment.getDataDirectory() + File.separator + "data" + File.separator
+ PrivacyService.class.getPackage().getName());
oldFiles = folder.listFiles();
if (oldFiles != null)
for (File file : oldFiles)
if (file.getName().startsWith("xprivacy.db")) {
File target = new File(dbFile.getParentFile() + File.separator + file.getName());
boolean status = file.renameTo(target);
Util.log(null, Log.WARN, "Moving " + file + " to " + target + " ok=" + status);
}

// Set database file permissions
// Owner: rwx (system)
// Group: rwx (system)
// World: ---
Util.setPermissions(dbFile.getParentFile().getAbsolutePath(), 0770, Process.SYSTEM_UID, Process.SYSTEM_UID);
File[] files = dbFile.getParentFile().listFiles();
if (files != null)
for (File file : files)
if (file.getName().startsWith("xprivacy.db") || file.getName().startsWith("usage.db"))
Util.setPermissions(file.getAbsolutePath(), 0770, Process.SYSTEM_UID, Process.SYSTEM_UID);

} catch (Throwable ex) {
Util.bug(null, ex);
}
}

public static void register(List<String> listError, String secret) {
// Store secret and errors
mSecret = secret;
Expand All @@ -148,6 +94,8 @@ public static void register(List<String> listError, String secret) {
mAddService.invoke(null, cServiceName, mPrivacyService);
}

setupDatabase();

// This will and should open the database
mRegistered = true;
Util.log(null, Log.WARN, "Service registered name=" + cServiceName);
Expand Down Expand Up @@ -233,6 +181,60 @@ private static File getDbUsageFile() {
+ File.separator + "usage.db");
}

private static void setupDatabase() {
// This is run from Zygote with root permissions
// SELinix needs to be taken into account
try {
File dbFile = getDbFile();

// Create database folder
dbFile.getParentFile().mkdirs();

// Check database folder
if (dbFile.getParentFile().isDirectory())
Util.log(null, Log.WARN, "Database folder=" + dbFile.getParentFile());
else
Util.log(null, Log.ERROR, "Does not exist folder=" + dbFile.getParentFile());

// Move database from data/xprivacy folder
File folder = new File(Environment.getDataDirectory() + File.separator + "xprivacy");
File[] oldFiles = folder.listFiles();
if (oldFiles != null)
for (File file : oldFiles)
if (file.getName().startsWith("xprivacy.db") || file.getName().startsWith("usage.db")) {
File target = new File(dbFile.getParentFile() + File.separator + file.getName());
boolean status = file.renameTo(target);
Util.log(null, Log.WARN, "Moving " + file + " to " + target + " ok=" + status);
}

// Move database from data/application folder
folder = new File(Environment.getDataDirectory() + File.separator + "data" + File.separator
+ PrivacyService.class.getPackage().getName());
oldFiles = folder.listFiles();
if (oldFiles != null)
for (File file : oldFiles)
if (file.getName().startsWith("xprivacy.db")) {
File target = new File(dbFile.getParentFile() + File.separator + file.getName());
boolean status = file.renameTo(target);
Util.log(null, Log.WARN, "Moving " + file + " to " + target + " ok=" + status);
}

// Set database file permissions
// Owner: rwx (system)
// Group: rwx (system)
// World: ---
Util.setPermissions(dbFile.getParentFile().getAbsolutePath(), 0770, Process.SYSTEM_UID, Process.SYSTEM_UID);
File[] files = dbFile.getParentFile().listFiles();
if (files != null)
for (File file : files)
if (file.getName().startsWith("xprivacy.db") || file.getName().startsWith("usage.db"))
Util.setPermissions(file.getAbsolutePath(), 0770, Process.SYSTEM_UID, Process.SYSTEM_UID);

} catch (Throwable ex) {
Util.bug(null, ex);
}
}

public static void reportErrorInternal(String message) {
synchronized (mListError) {
mListError.add(message);
Expand Down
2 changes: 0 additions & 2 deletions src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public void initZygote(StartupParam startupParam) throws Throwable {
// Generate secret
mSecret = Long.toHexString(new Random().nextLong());

PrivacyService.setupDatabase();

// System server
try {
// frameworks/base/services/java/com/android/server/SystemServer.java
Expand Down

0 comments on commit 547ceb8

Please sign in to comment.