themes: Relabel theme dir after creation

After creating the theme directory it will be labeled as a
system_data_file.  By calling SELinux.restorecon() the directory
will be correctly labeled as a themeservice_app_data_file

Change-Id: I73a28da883a467bf8859d879dbe22962424e4a23
TICKET: NIGHTLIES-3349
This commit is contained in:
d34d 2016-09-14 15:23:14 -07:00 committed by Clark Scheff
parent fceb077b6f
commit 06aec1f6f2
1 changed files with 8 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import android.os.FileUtils;
import android.os.IBinder;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.SELinux;
import android.system.ErrnoException;
import android.system.Os;
import android.system.StructStat;
@ -257,7 +258,10 @@ public class ThemeManagerServiceBroker extends BrokerableCMSystemService<IThemeS
public void onBootPhase(int phase) {
if (phase == PHASE_SYSTEM_SERVICES_READY) {
// create the main theme directory for brokered service
createDirIfNotExists(ThemeUtils.SYSTEM_THEME_PATH);
if (createDirIfNotExists(ThemeUtils.SYSTEM_THEME_PATH)) {
// ensure it has the correct selinux label after creation
SELinux.restorecon(ThemeUtils.SYSTEM_THEME_PATH);
}
if (shouldMigrateFilePermissions()) {
migrateFilePermissions();
@ -354,13 +358,15 @@ public class ThemeManagerServiceBroker extends BrokerableCMSystemService<IThemeS
return false;
}
private static void createDirIfNotExists(String dirPath) {
private static boolean createDirIfNotExists(String dirPath) {
final File dir = new File(dirPath);
if (!dir.exists()) {
if (dir.mkdir()) {
FileUtils.setPermissions(dir, FileUtils.S_IRWXU |
FileUtils.S_IRWXG| FileUtils.S_IRWXO, -1, -1);
return true;
}
}
return false;
}
}