From 547ceb81c3565213dfef753d26678ac7ce1af7da Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 25 Feb 2014 18:11:28 +0100 Subject: [PATCH] System server will create database folder Refs #1437 --- CHANGELOG.md | 1 + src/biz/bokhorst/xprivacy/PrivacyService.java | 110 +++++++++--------- src/biz/bokhorst/xprivacy/XPrivacy.java | 2 - 3 files changed, 57 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 729d6cb2e..a138ca994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/biz/bokhorst/xprivacy/PrivacyService.java b/src/biz/bokhorst/xprivacy/PrivacyService.java index e2f5a7256..2c66b1efa 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyService.java +++ b/src/biz/bokhorst/xprivacy/PrivacyService.java @@ -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 listError, String secret) { // Store secret and errors mSecret = secret; @@ -148,6 +94,8 @@ public static void register(List 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); @@ -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); diff --git a/src/biz/bokhorst/xprivacy/XPrivacy.java b/src/biz/bokhorst/xprivacy/XPrivacy.java index fa195eec8..78690c650 100644 --- a/src/biz/bokhorst/xprivacy/XPrivacy.java +++ b/src/biz/bokhorst/xprivacy/XPrivacy.java @@ -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