Release 23: Introduce the rootless solution for Masquerade [3/3]
Huge thanks to @bigrushdog, @iskandar1023 and @Surge1223 for all
the hard work put into this.
Clean-up commit by @nicholaschum
- Introduce Java8 integration
- Remove all the receivers
- Remove all the unused imports, methods and permissions.
- Reformat and optimize all Java files, drawables and XML files.
- Make sure the project is Android Studio ready
- Ensure that all permissions are declared Protected if in AS.
To build this in Android Studio (without platform key), you must copy
the "android.jar" built from your AOSP+OMS build environment to
%AndroidSDK%/platforms/android-25/android.jar (back up your original
copy). Then all you have to do is import masquerade as a gradle
project to Android Studio and you are set!
Change-Id: I10d989ece8650926f874ffd75074b5d756822dae
diff --git a/app/build.gradle b/app/build.gradle
index 265096a..a2694a8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 23
+ compileSdkVersion 25
buildToolsVersion "23.0.3"
lintOptions {
@@ -12,25 +12,41 @@
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
- output.outputFile.parent, "masquerade_beta_testers" + versionCode + ".apk")
+ output.outputFile.parent, "masquerade_" + versionCode + ".apk")
}
}
defaultConfig {
applicationId "masquerade.substratum"
- minSdkVersion 21
- targetSdkVersion 23
- versionCode 20
- versionName "twenty - procyon"
+ minSdkVersion 25
+ targetSdkVersion 25
+ versionCode 23
+ versionName "twenty three"
+ }
+
+ defaultConfig {
+ jackOptions {
+ enabled true
+ }
+ }
+
+ compileOptions {
+ incremental true
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+
+ dexOptions {
+ javaMaxHeapSize '2048m'
}
buildTypes {
debug {
- minifyEnabled true
+ minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
- minifyEnabled true
+ minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 13db0f9..2554839 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,40 +1,39 @@
+<!--suppress AndroidUnknownAttribute -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="masquerade.substratum"
- android:versionCode="21"
- android:versionName="twentyone - something"
+ xmlns:tools="http://schemas.android.com/tools"
coreApp="true"
- android:sharedUserId="android.uid.system">
+ package="masquerade.substratum"
+ android:sharedUserId="android.uid.system"
+ android:versionCode="23"
+ android:versionName="twenty three"
+ tools:ignore="GradleOverrides">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>
- <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
- <uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"/>
- <uses-permission android:name="android.permission.DELETE_PACKAGES"/>
- <uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
+ <uses-permission
+ android:name="android.permission.FORCE_STOP_PACKAGES"
+ tools:ignore="ProtectedPermissions"/>
+ <uses-permission
+ android:name="android.permission.DELETE_PACKAGES"
+ tools:ignore="ProtectedPermissions"/>
+ <uses-permission
+ android:name="android.permission.INSTALL_PACKAGES"
+ tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS"/>
<uses-permission android:name="android.permission.MODIFY_OVERLAYS"/>
<application
- android:allowBackup="true"
- android:icon="@mipmap/substratum_masquerade"
+ android:allowBackup="false"
+ android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <receiver android:name=".receivers.BootReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED"/>
- </intent-filter>
- </receiver>
- <receiver android:name=".receivers.UninstallReceiver">
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_REMOVED"/>
- <data android:scheme="package"/>
- </intent-filter>
- </receiver>
- <service android:name=".services.JobService"
+ android:theme="@style/AppTheme"
+ tools:ignore="GoogleAppIndexingWarning">
+ <service
+ android:name=".services.JobService"
android:exported="true"
- android:permission="android.permission.MODIFY_OVERLAYS" />
+ android:permission="android.permission.MODIFY_OVERLAYS"/>
</application>
</manifest>
diff --git a/app/src/main/java/masquerade/substratum/receivers/BootReceiver.java b/app/src/main/java/masquerade/substratum/receivers/BootReceiver.java
deleted file mode 100644
index ebc0c8b..0000000
--- a/app/src/main/java/masquerade/substratum/receivers/BootReceiver.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package masquerade.substratum.receivers;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-
-public class BootReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- // do something
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/masquerade/substratum/receivers/UninstallReceiver.java b/app/src/main/java/masquerade/substratum/receivers/UninstallReceiver.java
deleted file mode 100644
index b377e27..0000000
--- a/app/src/main/java/masquerade/substratum/receivers/UninstallReceiver.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package masquerade.substratum.receivers;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Environment;
-import android.util.Log;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class UninstallReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- if ("android.intent.action.PACKAGE_REMOVED".equals(intent.getAction())) {
- Uri packageName = intent.getData();
- if (packageName.toString().substring(8).equals("projekt.substratum")) {
-// new performUninstalls().execute("");
- }
- }
- }
-/*
- public class performUninstalls extends AsyncTask<String, Integer, String> {
- @Override
- protected String doInBackground(String... sUrl) {
- // Substratum was uninstalled, uninstall all remaining overlays
- Log.d("Masquerade",
- "Substratum was uninstalled, so all remaining overlays will be removed...");
- String[] state4 = {Environment.getExternalStorageDirectory()
- .getAbsolutePath() + "/.substratum/current_overlays.xml", "4"};
- String[] state5 = {Environment.getExternalStorageDirectory()
- .getAbsolutePath() + "/.substratum/current_overlays.xml", "5"};
- List<String> state5overlays = ReadOverlaysFile.main(state5);
- ArrayList<String> all_overlays = new ArrayList<>(ReadOverlaysFile.main(state4));
- all_overlays.addAll(state5overlays);
- for (int i = 0; i < all_overlays.size(); i++) {
- Log.d("Masquerade", "Uninstalling overlay: " + all_overlays.get(i));
- Root.runCommand("pm uninstall " + all_overlays.get(i));
- }
- return null;
- }
- }
- */
-}
\ No newline at end of file
diff --git a/app/src/main/java/masquerade/substratum/services/JobService.java b/app/src/main/java/masquerade/substratum/services/JobService.java
index 20cf166..9e6ef3f 100644
--- a/app/src/main/java/masquerade/substratum/services/JobService.java
+++ b/app/src/main/java/masquerade/substratum/services/JobService.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2017 Project Substratum
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * Also add information on how to contact you by electronic and paper mail.
+ *
+ */
+
package masquerade.substratum.services;
import android.app.ActivityManager;
@@ -7,24 +27,19 @@
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
-import android.content.IIntentReceiver;
-import android.content.IIntentSender;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.IntentSender;
import android.content.om.IOverlayManager;
import android.content.om.OverlayInfo;
import android.content.pm.IPackageDeleteObserver;
import android.content.pm.IPackageInstallObserver2;
import android.content.pm.IPackageManager;
-import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.media.RingtoneManager;
-import android.os.Binder;
import android.os.Bundle;
import android.os.Environment;
import android.os.FileUtils;
@@ -42,42 +57,21 @@
import android.text.TextUtils;
import android.util.Log;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
+import java.util.stream.Collectors;
import masquerade.substratum.utils.IOUtils;
import masquerade.substratum.utils.SoundUtils;
-import com.android.internal.statusbar.IStatusBarService;
-
public class JobService extends Service {
- private static final String TAG = JobService.class.getSimpleName();
- private static final boolean DEBUG = true;
-
- private static final String MASQUERADE_TOKEN = "masquerade_token";
- private static final String SUBSTRATUM_PACKAGE = "projekt.substratum";
- private static final String[] AUTHORIZED_CALLERS = new String[] {
- SUBSTRATUM_PACKAGE,
- "masquerade.substratum"
- };
-
public static final String INTENT_STATUS_CHANGED = "masquerade.substratum.STATUS_CHANGED";
-
public static final String PRIMARY_COMMAND_KEY = "primary_command_key";
public static final String JOB_TIME_KEY = "job_time_key";
public static final String INSTALL_LIST_KEY = "install_list";
@@ -109,20 +103,47 @@
public static final String COMMAND_VALUE_MOVE = "move";
public static final String COMMAND_VALUE_DELETE = "delete";
public static final String COMMAND_VALUE_PROFILE = "profile";
-
+ private static final String TAG = JobService.class.getSimpleName();
+ private static final boolean DEBUG = true;
+ private static final String MASQUERADE_TOKEN = "masquerade_token";
+ private static final String MASQUERADE_PACKAGE = "masquerade.substratum";
+ private static final String SUBSTRATUM_PACKAGE = "projekt.substratum";
+ private static final String[] AUTHORIZED_CALLERS = new String[]{
+ MASQUERADE_PACKAGE,
+ SUBSTRATUM_PACKAGE,
+ };
private static IOverlayManager mOMS;
private static IPackageManager mPM;
-
- private HandlerThread mWorker;
+ private final List<Runnable> mJobQueue = new ArrayList<>(0);
private JobHandler mJobHandler;
private MainHandler mMainHandler;
- private final List<Runnable> mJobQueue = new ArrayList<>(0);
private long mLastJobTime;
private boolean mIsRunning;
+ private static IOverlayManager getOMS() {
+ if (mOMS == null) {
+ mOMS = IOverlayManager.Stub.asInterface(
+ ServiceManager.getService("overlay"));
+ }
+ return mOMS;
+ }
+
+ private static IPackageManager getPM() {
+ if (mPM == null) {
+ mPM = IPackageManager.Stub.asInterface(
+ ServiceManager.getService("package"));
+ }
+ return mPM;
+ }
+
+ public static void log(String msg) {
+ if (DEBUG) Log.e(TAG, msg);
+ }
+
@Override
public void onCreate() {
- mWorker = new HandlerThread("BackgroundWorker", Process.THREAD_PRIORITY_BACKGROUND);
+ HandlerThread mWorker = new HandlerThread("BackgroundWorker", Process
+ .THREAD_PRIORITY_BACKGROUND);
mWorker.start();
mJobHandler = new JobHandler(mWorker.getLooper());
mMainHandler = new MainHandler(Looper.getMainLooper());
@@ -137,39 +158,33 @@
}
// Don't run job if there is another running job
- mIsRunning = false;
- if (isProcessing()) mIsRunning = true;
+ mIsRunning = isProcessing();
- // filter out duplicate intents
+ // Filter out duplicate intents
long jobTime = intent.getLongExtra(JOB_TIME_KEY, 1);
if (jobTime == 1 || jobTime == mLastJobTime) {
- log("got empty jobtime or duplicate job time, aborting");
+ log("Received empty job time or duplicate job time, aborting");
return START_NOT_STICKY;
}
mLastJobTime = jobTime;
- // must have a primary command
+ // Must have a primary command
String command = intent.getStringExtra(PRIMARY_COMMAND_KEY);
if (TextUtils.isEmpty(command)) {
- log("Got empty primary command, aborting");
+ log("Received empty primary command, aborting");
return START_NOT_STICKY;
}
- // queue up the job
-
+ // Queue up the job
List<Runnable> jobs_to_add = new ArrayList<>(0);
- log("Starting job with primary command " + command + " With job time " + jobTime);
+ log("Starting job with primary command \'" + command + "\', with job time: " + jobTime);
if (TextUtils.equals(command, COMMAND_VALUE_INSTALL)) {
List<String> paths = intent.getStringArrayListExtra(INSTALL_LIST_KEY);
- for (String path : paths) {
- jobs_to_add.add(new Installer(path));
- }
+ jobs_to_add.addAll(paths.stream().map(Installer::new).collect(Collectors.toList()));
} else if (TextUtils.equals(command, COMMAND_VALUE_UNINSTALL)) {
List<String> packages = intent.getStringArrayListExtra(UNINSTALL_LIST_KEY);
- for (String _package : packages) {
- jobs_to_add.add(new Remover(_package));
- }
+ jobs_to_add.addAll(packages.stream().map(Remover::new).collect(Collectors.toList()));
if (shouldRestartUi(packages)) jobs_to_add.add(new UiResetJob());
} else if (TextUtils.equals(command, COMMAND_VALUE_RESTART_UI)) {
jobs_to_add.add(new UiResetJob());
@@ -194,15 +209,11 @@
jobs_to_add.add(new UiResetJob());
} else if (TextUtils.equals(command, COMMAND_VALUE_ENABLE)) {
List<String> packages = intent.getStringArrayListExtra(ENABLE_LIST_KEY);
- for (String _package : packages) {
- jobs_to_add.add(new Enabler(_package));
- }
+ jobs_to_add.addAll(packages.stream().map(Enabler::new).collect(Collectors.toList()));
if (shouldRestartUi(packages)) jobs_to_add.add(new UiResetJob());
} else if (TextUtils.equals(command, COMMAND_VALUE_DISABLE)) {
List<String> packages = intent.getStringArrayListExtra(DISABLE_LIST_KEY);
- for (String _package : packages) {
- jobs_to_add.add(new Disabler(_package));
- }
+ jobs_to_add.addAll(packages.stream().map(Disabler::new).collect(Collectors.toList()));
if (shouldRestartUi(packages)) jobs_to_add.add(new UiResetJob());
} else if (TextUtils.equals(command, COMMAND_VALUE_PRIORITY)) {
List<String> packages = intent.getStringArrayListExtra(PRIORITY_LIST_KEY);
@@ -241,7 +252,6 @@
mJobHandler.sendEmptyMessage(JobHandler.MESSAGE_CHECK_QUEUE);
}
}
-
return START_NOT_STICKY;
}
@@ -252,35 +262,13 @@
@Override
public void onDestroy() {
-
}
private boolean isProcessing() {
return mJobQueue.size() > 0;
}
- private class LocalService extends Binder {
- public JobService getService() {
- return JobService.this;
- }
- }
-
- private static IOverlayManager getOMS() {
- if (mOMS == null) {
- mOMS = IOverlayManager.Stub.asInterface(
- ServiceManager.getService("overlay"));
- }
- return mOMS;
- }
-
- private static IPackageManager getPM() {
- if (mPM == null) {
- mPM = IPackageManager.Stub.asInterface(
- ServiceManager.getService("package"));
- }
- return mPM;
- }
-
+ @SuppressWarnings("deprecation")
private void install(String path, IPackageInstallObserver2 observer) {
try {
getPM().installPackageAsUser(path, observer,
@@ -292,6 +280,7 @@
}
}
+ @SuppressWarnings("deprecation")
private void uninstall(String packageName, IPackageDeleteObserver observer) {
try {
getPM().deletePackageAsUser(packageName, observer, 0, UserHandle.USER_SYSTEM);
@@ -315,7 +304,7 @@
if (info != null) {
enabled = info.isEnabled();
} else {
- log("info is null");
+ log("OverlayInfo is null.");
}
} catch (RemoteException e) {
e.printStackTrace();
@@ -331,24 +320,25 @@
}
private void copyFonts(String pid, String zipFileName) {
- // prepare local cache dir for font package assembly
+ // Prepare local cache dir for font package assembly
log("Copy Fonts - Package ID = " + pid + " filename = " + zipFileName);
File cacheDir = new File(getCacheDir(), "/FontCache/");
if (cacheDir.exists()) {
IOUtils.deleteRecursive(cacheDir);
}
- cacheDir.mkdir();
+ boolean created = cacheDir.mkdir();
+ if (!created) log("Could not create cache directory...");
- // copy system fonts into our cache dir
+ // Copy system fonts into our cache dir
IOUtils.copyFolder("/system/fonts", cacheDir.getAbsolutePath());
- // append zip to filename since it is probably removed
+ // Append zip to filename since it is probably removed
// for list presentation
if (!zipFileName.endsWith(".zip")) {
zipFileName = zipFileName + ".zip";
}
- // copy target themed fonts zip to our cache dir
+ // Copy target themed fonts zip to our cache dir
Context themeContext = getAppContext(pid);
AssetManager am = themeContext.getAssets();
try {
@@ -360,12 +350,13 @@
e.printStackTrace();
}
- // unzip new fonts and delete zip file, overwriting any system fonts
+ // Unzip new fonts and delete zip file, overwriting any system fonts
File fontZip = new File(getCacheDir(), "/FontCache/" + zipFileName);
IOUtils.unzip(fontZip.getAbsolutePath(), cacheDir.getAbsolutePath());
- fontZip.delete();
+ boolean deleted = fontZip.delete();
+ if (!deleted) log("Could not delete ZIP file...");
- // check if theme zip included a fonts.xml. If not, Substratum
+ // Check if theme zip included a fonts.xml. If not, Substratum
// is kind enough to provide one for us in it's assets
try {
File testConfig = new File(getCacheDir(), "/FontCache/" + "fonts.xml");
@@ -380,12 +371,12 @@
e.printStackTrace();
}
- // prepare system theme fonts folder and copy new fonts folder from our cache
+ // Prepare system theme fonts folder and copy new fonts folder from our cache
IOUtils.deleteThemedFonts();
IOUtils.createFontDirIfNotExists();
IOUtils.copyFolder(cacheDir.getAbsolutePath(), IOUtils.SYSTEM_THEME_FONT_PATH);
- // let system know it's time for a font change
+ // Let system know it's time for a font change
refreshFonts();
}
@@ -395,7 +386,7 @@
}
private void refreshFonts() {
- // set permissions on font files and config xml
+ // Set permissions on font files and config xml
File themeFonts = new File(IOUtils.SYSTEM_THEME_FONT_PATH);
if (themeFonts.exists()) {
// Set permissions
@@ -404,7 +395,7 @@
FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IROTH | FileUtils.S_IXOTH);
}
- // let system know it's time for a font change
+ // Let system know it's time for a font change
SystemProperties.set("sys.refresh_theme", "1");
Typeface.recreateDefaults();
float fontSize = Float.valueOf(Settings.System.getString(
@@ -414,21 +405,23 @@
}
private void applyThemedSounds(String pid, String zipFileName) {
- // prepare local cache dir for font package assembly
- log("Copy sounds - Package ID = " + pid + " filename = " + zipFileName);
+ // Prepare local cache dir for font package assembly
+ log("CopySounds - Package ID = \'" + pid + "\'");
+ log("CopySounds - File name = \'" + zipFileName + "\'");
File cacheDir = new File(getCacheDir(), "/SoundsCache/");
if (cacheDir.exists()) {
IOUtils.deleteRecursive(cacheDir);
}
- cacheDir.mkdir();
+ boolean created = cacheDir.mkdir();
+ if (!created) log("Could not create cache directory...");
- // append zip to filename since it is probably removed
+ // Append zip to filename since it is probably removed
// for list presentation
if (!zipFileName.endsWith(".zip")) {
zipFileName = zipFileName + ".zip";
}
- // copy target themed sounds zip to our cache dir
+ // Copy target themed sounds zip to our cache dir
Context themeContext = getAppContext(pid);
AssetManager am = themeContext.getAssets();
try {
@@ -440,10 +433,11 @@
e.printStackTrace();
}
- // unzip new sounds and delete zip file
+ // Unzip new sounds and delete zip file
File soundsZip = new File(getCacheDir(), "/SoundsCache/" + zipFileName);
IOUtils.unzip(soundsZip.getAbsolutePath(), cacheDir.getAbsolutePath());
- soundsZip.delete();
+ boolean deleted = soundsZip.delete();
+ if (!deleted) log("Could not delete ZIP file...");
clearSounds(this);
IOUtils.createAudioDirIfNotExists();
@@ -454,30 +448,38 @@
File effect_tick_mp3 = new File(getCacheDir(), "/SoundsCache/ui/Effect_Tick.mp3");
File effect_tick_ogg = new File(getCacheDir(), "/SoundsCache/ui/Effect_Tick.ogg");
if (effect_tick_ogg.exists()) {
- IOUtils.bufferedCopy(effect_tick_ogg, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "Effect_Tick.ogg"));
+ IOUtils.bufferedCopy(effect_tick_ogg, new File(IOUtils
+ .SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "Effect_Tick.ogg"));
} else if (effect_tick_mp3.exists()) {
- IOUtils.bufferedCopy(effect_tick_mp3, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "Effect_Tick.mp3"));
+ IOUtils.bufferedCopy(effect_tick_mp3, new File(IOUtils
+ .SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "Effect_Tick.mp3"));
}
File new_lock_mp3 = new File(getCacheDir(), "/SoundsCache/ui/Lock.mp3");
File new_lock_ogg = new File(getCacheDir(), "/SoundsCache/ui/Lock.ogg");
if (new_lock_ogg.exists()) {
- IOUtils.bufferedCopy(new_lock_ogg, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "Lock.ogg"));
+ IOUtils.bufferedCopy(new_lock_ogg, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH +
+ File.separator + "Lock.ogg"));
} else if (new_lock_mp3.exists()) {
- IOUtils.bufferedCopy(new_lock_mp3, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "Lock.mp3"));
+ IOUtils.bufferedCopy(new_lock_mp3, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH +
+ File.separator + "Lock.mp3"));
}
File new_unlock_mp3 = new File(getCacheDir(), "/SoundsCache/ui/Unlock.mp3");
File new_unlock_ogg = new File(getCacheDir(), "/SoundsCache/ui/Unlock.ogg");
if (new_unlock_ogg.exists()) {
- IOUtils.bufferedCopy(new_unlock_ogg, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "Unlock.ogg"));
+ IOUtils.bufferedCopy(new_unlock_ogg, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH
+ + File.separator + "Unlock.ogg"));
} else if (new_unlock_mp3.exists()) {
- IOUtils.bufferedCopy(new_unlock_mp3, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "Unlock.mp3"));
+ IOUtils.bufferedCopy(new_unlock_mp3, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH
+ + File.separator + "Unlock.mp3"));
}
File new_lowbattery_mp3 = new File(getCacheDir(), "/SoundsCache/ui/LowBattery.mp3");
File new_lowbattery_ogg = new File(getCacheDir(), "/SoundsCache/ui/LowBattery.ogg");
if (new_lowbattery_ogg.exists()) {
- IOUtils.bufferedCopy(new_lowbattery_ogg, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "LowBattery.ogg"));
+ IOUtils.bufferedCopy(new_lowbattery_ogg, new File(IOUtils
+ .SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "LowBattery.ogg"));
} else if (new_lowbattery_mp3.exists()) {
- IOUtils.bufferedCopy(new_lowbattery_mp3, new File(IOUtils.SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "LowBattery.mp3"));
+ IOUtils.bufferedCopy(new_lowbattery_mp3, new File(IOUtils
+ .SYSTEM_THEME_UI_SOUNDS_PATH + File.separator + "LowBattery.mp3"));
}
}
File alarmCache = new File(getCacheDir(), "/SoundsCache/alarms/");
@@ -486,20 +488,26 @@
File new_alarm_mp3 = new File(getCacheDir(), "/SoundsCache/alarms/alarm.mp3");
File new_alarm_ogg = new File(getCacheDir(), "/SoundsCache/alarms/alarm.ogg");
if (new_alarm_ogg.exists()) {
- IOUtils.bufferedCopy(new_alarm_ogg, new File(IOUtils.SYSTEM_THEME_ALARM_PATH + File.separator + "alarm.ogg"));
+ IOUtils.bufferedCopy(new_alarm_ogg, new File(IOUtils.SYSTEM_THEME_ALARM_PATH +
+ File.separator + "alarm.ogg"));
} else if (new_alarm_mp3.exists()) {
- IOUtils.bufferedCopy(new_alarm_mp3, new File(IOUtils.SYSTEM_THEME_ALARM_PATH + File.separator + "alarm.mp3"));
+ IOUtils.bufferedCopy(new_alarm_mp3, new File(IOUtils.SYSTEM_THEME_ALARM_PATH +
+ File.separator + "alarm.mp3"));
}
}
File notifCache = new File(getCacheDir(), "/SoundsCache/notifications/");
if (notifCache.exists() && notifCache.isDirectory()) {
IOUtils.createNotificationDirIfNotExists();
- File new_notif_mp3 = new File(getCacheDir(), "/SoundsCache/notifications/notification.mp3");
- File new_notif_ogg = new File(getCacheDir(), "/SoundsCache/notifications/notification.ogg");
+ File new_notif_mp3 = new File(getCacheDir(), "/SoundsCache/notifications/notification" +
+ ".mp3");
+ File new_notif_ogg = new File(getCacheDir(), "/SoundsCache/notifications/notification" +
+ ".ogg");
if (new_notif_ogg.exists()) {
- IOUtils.bufferedCopy(new_notif_ogg, new File(IOUtils.SYSTEM_THEME_NOTIFICATION_PATH + File.separator + "notification.ogg"));
+ IOUtils.bufferedCopy(new_notif_ogg, new File(IOUtils
+ .SYSTEM_THEME_NOTIFICATION_PATH + File.separator + "notification.ogg"));
} else if (new_notif_mp3.exists()) {
- IOUtils.bufferedCopy(new_notif_mp3, new File(IOUtils.SYSTEM_THEME_NOTIFICATION_PATH + File.separator + "notification.mp3"));
+ IOUtils.bufferedCopy(new_notif_mp3, new File(IOUtils
+ .SYSTEM_THEME_NOTIFICATION_PATH + File.separator + "notification.mp3"));
}
}
File ringtoneCache = new File(getCacheDir(), "/SoundsCache/ringtones/");
@@ -508,28 +516,30 @@
File new_ring_mp3 = new File(getCacheDir(), "/SoundsCache/ringtones/ringtone.mp3");
File new_ring_ogg = new File(getCacheDir(), "/SoundsCache/ringtones/ringtone.ogg");
if (new_ring_ogg.exists()) {
- IOUtils.bufferedCopy(new_ring_ogg, new File(IOUtils.SYSTEM_THEME_RINGTONE_PATH + File.separator + "ringtone.ogg"));
+ IOUtils.bufferedCopy(new_ring_ogg, new File(IOUtils.SYSTEM_THEME_RINGTONE_PATH +
+ File.separator + "ringtone.ogg"));
} else if (new_ring_mp3.exists()) {
- IOUtils.bufferedCopy(new_ring_mp3, new File(IOUtils.SYSTEM_THEME_RINGTONE_PATH + File.separator + "ringtone.mp3"));
+ IOUtils.bufferedCopy(new_ring_mp3, new File(IOUtils.SYSTEM_THEME_RINGTONE_PATH +
+ File.separator + "ringtone.mp3"));
}
}
- // let system know it's time for a sound change
+ // Let system know it's time for a sound change
refreshSounds();
}
private void clearSounds(Context ctx) {
IOUtils.deleteThemedAudio();
- SoundUtils.setDefaultAudible(JobService.this, RingtoneManager.TYPE_ALARM);
- SoundUtils.setDefaultAudible(JobService.this, RingtoneManager.TYPE_NOTIFICATION);
- SoundUtils.setDefaultAudible(JobService.this, RingtoneManager.TYPE_RINGTONE);
+ SoundUtils.setDefaultAudible(ctx, RingtoneManager.TYPE_ALARM);
+ SoundUtils.setDefaultAudible(ctx, RingtoneManager.TYPE_NOTIFICATION);
+ SoundUtils.setDefaultAudible(ctx, RingtoneManager.TYPE_RINGTONE);
SoundUtils.setDefaultUISounds(getContentResolver(), "lock_sound", "Lock.ogg");
SoundUtils.setDefaultUISounds(getContentResolver(), "unlock_sound", "Unlock.ogg");
SoundUtils.setDefaultUISounds(getContentResolver(), "low_battery_sound",
"LowBattery.ogg");
}
- private void refreshSounds () {
+ private void refreshSounds() {
File soundsDir = new File(IOUtils.SYSTEM_THEME_AUDIO_PATH);
if (soundsDir.exists()) {
// Set permissions
@@ -644,13 +654,15 @@
}
}
}
+
private void copyBootAnimation(String fileName) {
try {
clearBootAnimation();
File source = new File(fileName);
File dest = new File(IOUtils.SYSTEM_THEME_BOOTANIMATION_PATH);
IOUtils.bufferedCopy(source, dest);
- source.delete();
+ boolean deleted = source.delete();
+ if (!deleted) log("Could not delete source file...");
IOUtils.setPermissions(dest,
FileUtils.S_IRWXU | FileUtils.S_IRGRP | FileUtils.S_IROTH);
} catch (Exception e) {
@@ -662,21 +674,25 @@
try {
File f = new File(IOUtils.SYSTEM_THEME_BOOTANIMATION_PATH);
if (f.exists()) {
- f.delete();
+ boolean deleted = f.delete();
+ if (!deleted) log("Could not delete themed boot animation...");
}
} catch (Exception e) {
e.printStackTrace();
}
}
+ @SuppressWarnings({"unchecked", "ConfusingArgumentToVarargsMethod"})
private void restartUi() {
try {
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
Class ActivityManagerNative = Class.forName("android.app.ActivityManagerNative");
Method getDefault = ActivityManagerNative.getDeclaredMethod("getDefault", null);
Object amn = getDefault.invoke(null, null);
- Method killApplicationProcess = amn.getClass().getDeclaredMethod("killApplicationProcess", String.class, int.class);
- stopService(new Intent().setComponent(new ComponentName("com.android.systemui", "com.android.systemui.SystemUIService")));
+ Method killApplicationProcess = amn.getClass().getDeclaredMethod
+ ("killApplicationProcess", String.class, int.class);
+ stopService(new Intent().setComponent(new ComponentName("com.android.systemui", "com" +
+ ".android.systemui.SystemUIService")));
am.killBackgroundProcesses("com.android.systemui");
for (ActivityManager.RunningAppProcessInfo app : am.getRunningAppProcesses()) {
if ("com.android.systemui".equals(app.processName)) {
@@ -689,15 +705,6 @@
}
}
- private void killPackage(String packageName) {
- try {
- ActivityManagerNative.getDefault().forceStopPackage(packageName,
- UserHandle.USER_SYSTEM);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
-
private Context getSubsContext() {
return getAppContext(SUBSTRATUM_PACKAGE);
}
@@ -713,45 +720,38 @@
return ctx;
}
- public static void log(String msg) {
- if (DEBUG) {
- Log.e(TAG, msg);
- }
- }
-
private boolean isCallerAuthorized(Intent intent) {
PendingIntent token = null;
try {
- token = (PendingIntent) intent.getParcelableExtra(MASQUERADE_TOKEN);
+ token = intent.getParcelableExtra(MASQUERADE_TOKEN);
} catch (Exception e) {
- log("Attempt to start serivce without a token, unauthorized");
+ log("Attempting to start service without a token - unauthorized!");
}
- if (token == null) {
- return false;
- }
- // SECOND: we got a token, validate originating package
- // if not in our whitelist, return null
+ if (token == null) return false;
+ // SECOND: We got a token, validate originating package
+ // if not in our white list, return null
String callingPackage = token.getCreatorPackage();
boolean isValidPackage = false;
- for (int i = 0; i < AUTHORIZED_CALLERS.length; i++) {
- if (TextUtils.equals(callingPackage, AUTHORIZED_CALLERS[i])) {
- log(callingPackage
- + " is an authorized calling package, next validate calling package perms");
+ for (String AUTHORIZED_CALLER : AUTHORIZED_CALLERS) {
+ if (TextUtils.equals(callingPackage, AUTHORIZED_CALLER)) {
+ log("\'" + callingPackage
+ + "\' is an authorized calling package, validating calling package " +
+ "permissions...");
isValidPackage = true;
break;
}
}
if (!isValidPackage) {
- log(callingPackage + " is not an authorized calling package");
+ log("\'" + callingPackage + "\' is not an authorized calling package.");
return false;
}
return true;
}
private class MainHandler extends Handler {
- public static final int MSG_JOB_QUEUE_EMPTY = 1;
+ static final int MSG_JOB_QUEUE_EMPTY = 1;
- public MainHandler(Looper looper) {
+ MainHandler(Looper looper) {
super(looper);
}
@@ -771,7 +771,7 @@
private static final int MESSAGE_CHECK_QUEUE = 1;
private static final int MESSAGE_DEQUEUE = 2;
- public JobHandler(Looper looper) {
+ JobHandler(Looper looper) {
super(looper);
}
@@ -783,9 +783,7 @@
synchronized (mJobQueue) {
job = mJobQueue.get(0);
}
- if (job != null && !mIsRunning) {
- job.run();
- }
+ if (job != null && !mIsRunning) job.run();
break;
case MESSAGE_DEQUEUE:
Runnable toRemove = (Runnable) msg.obj;
@@ -796,7 +794,7 @@
this.sendEmptyMessage(MESSAGE_CHECK_QUEUE);
} else {
mIsRunning = false;
- log("Job queue empty! All done");
+ log("Job queue is empty. All done!");
mMainHandler.sendEmptyMessage(MainHandler.MSG_JOB_QUEUE_EMPTY);
}
}
@@ -808,23 +806,6 @@
}
}
- private class StopPackageJob implements Runnable {
- String mPackage;
-
- public void StopPackageJob(String _package) {
- mPackage = _package;
- }
-
- @Override
- public void run() {
- killPackage(mPackage);
- log("Killed package " + mPackage);
- Message message = mJobHandler.obtainMessage(JobHandler.MESSAGE_DEQUEUE,
- StopPackageJob.this);
- mJobHandler.sendMessage(message);
- }
- }
-
private class UiResetJob implements Runnable {
@Override
public void run() {
@@ -841,7 +822,7 @@
String mPid;
String mFileName;
- public FontsJob(String pid, String fileName) {
+ FontsJob(String pid, String fileName) {
if (pid == null) {
mClear = true;
} else {
@@ -853,10 +834,10 @@
@Override
public void run() {
if (mClear) {
- log("Resetting system font");
+ log("Restoring system font...");
clearFonts();
} else {
- log("Setting theme font");
+ log("Configuring theme font...");
copyFonts(mPid, mFileName);
}
Intent intent = new Intent(INTENT_STATUS_CHANGED);
@@ -873,7 +854,7 @@
String mPid;
String mFileName;
- public SoundsJob(String pid, String fileName) {
+ SoundsJob(String pid, String fileName) {
if (pid == null) {
mClear = true;
} else {
@@ -885,10 +866,10 @@
@Override
public void run() {
if (mClear) {
- log("Resetting system sounds");
+ log("Restoring system sounds...");
clearSounds(JobService.this);
} else {
- log("Setting theme sounds");
+ log("Configuring theme sounds...");
applyThemedSounds(mPid, mFileName);
}
Intent intent = new Intent(INTENT_STATUS_CHANGED);
@@ -901,14 +882,14 @@
}
private class BootAnimationJob implements Runnable {
- String mFileName;
final boolean mClear;
+ String mFileName;
- public BootAnimationJob(boolean clear) {
- mClear = true;
+ BootAnimationJob(boolean clear) {
+ mClear = clear;
}
- public BootAnimationJob(String fileName) {
+ BootAnimationJob(String fileName) {
mFileName = fileName;
mClear = false;
}
@@ -916,10 +897,10 @@
@Override
public void run() {
if (mClear) {
- log("Resetting system boot animation");
+ log("Restoring system boot animation...");
clearBootAnimation();
} else {
- log("Setting themed boot animation");
+ log("Configuring themed boot animation...");
copyBootAnimation(mFileName);
}
Intent intent = new Intent(INTENT_STATUS_CHANGED);
@@ -934,13 +915,13 @@
private class Installer implements Runnable {
String mPath;
- public Installer(String path) {
+ Installer(String path) {
mPath = path;
}
@Override
public void run() {
- log("Installer - installing " + mPath);
+ log("Installer - installing \'" + mPath + "\'...");
PackageInstallObserver observer = new PackageInstallObserver(Installer.this);
install(mPath, observer);
}
@@ -949,7 +930,7 @@
private class PackageInstallObserver extends IPackageInstallObserver2.Stub {
Object mObject;
- public PackageInstallObserver(Object _object) {
+ PackageInstallObserver(Object _object) {
mObject = _object;
}
@@ -957,8 +938,9 @@
log("Installer - user action required callback");
}
- public void onPackageInstalled(String packageName, int returnCode, String msg, Bundle extras) {
- log("Installer - successfully installed " + packageName);
+ public void onPackageInstalled(String packageName, int returnCode, String msg, Bundle
+ extras) {
+ log("Installer - successfully installed \'" + packageName + "\'!");
Message message = mJobHandler.obtainMessage(JobHandler.MESSAGE_DEQUEUE, mObject);
mJobHandler.sendMessage(message);
}
@@ -967,20 +949,19 @@
private class Remover implements Runnable {
String mPackage;
- public Remover(String _package) {
+ Remover(String _package) {
mPackage = _package;
}
@Override
public void run() {
-
// TODO: Fix isOverlayEnabled function, for now it's causing NPE
if (isOverlayEnabled(mPackage)) {
- log("Remover - disabling overlay for " + mPackage);
+ log("Remover - disabling overlay for \'" + mPackage + "\'...");
switchOverlay(mPackage, false);
}
- log("Remover - uninstalling " + mPackage);
+ log("Remover - uninstalling \'" + mPackage + "\'...");
PackageDeleteObserver observer = new PackageDeleteObserver(Remover.this);
uninstall(mPackage, observer);
}
@@ -989,12 +970,12 @@
private class PackageDeleteObserver extends IPackageDeleteObserver.Stub {
Object mObject;
- public PackageDeleteObserver(Object _object) {
+ PackageDeleteObserver(Object _object) {
mObject = _object;
}
public void packageDeleted(String packageName, int returnCode) {
- log("Remover - successfully removed " + packageName);
+ log("Remover - successfully removed \'" + packageName + "\'");
Message message = mJobHandler.obtainMessage(JobHandler.MESSAGE_DEQUEUE, mObject);
mJobHandler.sendMessage(message);
}
@@ -1003,13 +984,13 @@
private class Enabler implements Runnable {
String mPackage;
- public Enabler(String _package) {
+ Enabler(String _package) {
mPackage = _package;
}
@Override
public void run() {
- log("Enabler - enabling overlay for " + mPackage);
+ log("Enabler - enabling overlay for \'" + mPackage + "\'...");
switchOverlay(mPackage, true);
Message message = mJobHandler.obtainMessage(JobHandler.MESSAGE_DEQUEUE,
Enabler.this);
@@ -1020,13 +1001,13 @@
private class Disabler implements Runnable {
String mPackage;
- public Disabler(String _package) {
+ Disabler(String _package) {
mPackage = _package;
}
@Override
public void run() {
- log("Disabler - disabling overlay for " + mPackage);
+ log("Disabler - disabling overlay for \'" + mPackage + "\'...");
switchOverlay(mPackage, false);
Message message = mJobHandler.obtainMessage(JobHandler.MESSAGE_DEQUEUE,
Disabler.this);
@@ -1037,18 +1018,18 @@
private class PriorityJob implements Runnable {
List<String> mPackages;
- public PriorityJob(List<String> _packages) {
+ PriorityJob(List<String> _packages) {
mPackages = _packages;
}
@Override
public void run() {
- log("PriorityJob - processing priority changes");
+ log("PriorityJob - processing priority changes...");
try {
int size = mPackages.size();
- for (int i = 0; i < size-1; i++) {
+ for (int i = 0; i < size - 1; i++) {
String parentName = mPackages.get(i);
- String packageName = mPackages.get(i+1);
+ String packageName = mPackages.get(i + 1);
getOMS().setPriority(packageName, parentName, UserHandle.USER_SYSTEM);
}
} catch (RemoteException e) {
@@ -1064,14 +1045,14 @@
String mSource;
String mDestination;
- public CopyJob(String _source, String _destination) {
+ CopyJob(String _source, String _destination) {
mSource = _source;
mDestination = _destination;
}
@Override
public void run() {
- log("CopyJob - copying " + mSource + " to " + mDestination);
+ log("CopyJob - copying \'" + mSource + "\' to \'" + mDestination + "\'...");
File sourceFile = new File(mSource);
if (sourceFile.exists()) {
if (sourceFile.isFile()) {
@@ -1080,7 +1061,7 @@
IOUtils.copyFolder(mSource, mDestination);
}
} else {
- log("CopyJob - " + mSource + " is not exist! aborting...");
+ log("CopyJob - \'" + mSource + "\' does not exist, aborting...");
}
Message message = mJobHandler.obtainMessage(JobHandler.MESSAGE_DEQUEUE,
CopyJob.this);
@@ -1092,14 +1073,14 @@
String mSource;
String mDestination;
- public MoveJob(String _source, String _destination) {
+ MoveJob(String _source, String _destination) {
mSource = _source;
mDestination = _destination;
}
@Override
public void run() {
- log("MoveJob - moving " + mSource + " to " + mDestination);
+ log("MoveJob - moving \'" + mSource + "\' to \'" + mDestination + "\'...");
File sourceFile = new File(mSource);
if (sourceFile.exists()) {
if (sourceFile.isFile()) {
@@ -1109,7 +1090,7 @@
}
IOUtils.deleteRecursive(sourceFile);
} else {
- log("MoveJob - " + mSource + " is not exist! aborting...");
+ log("MoveJob - \'" + mSource + "\' does not exist, aborting...");
}
Message message = mJobHandler.obtainMessage(JobHandler.MESSAGE_DEQUEUE,
MoveJob.this);
@@ -1120,18 +1101,18 @@
private class DeleteJob implements Runnable {
String mFileOrDirectory;
- public DeleteJob(String _directory) {
+ DeleteJob(String _directory) {
mFileOrDirectory = _directory;
}
@Override
public void run() {
- log("DeleteJob - deleting " + mFileOrDirectory);
+ log("DeleteJob - deleting \'" + mFileOrDirectory + "\'...");
File file = new File(mFileOrDirectory);
if (file.exists()) {
IOUtils.deleteRecursive(file);
} else {
- log("DeleteJob - " + mFileOrDirectory + " is already deleted!");
+ log("DeleteJob - \'" + mFileOrDirectory + "\' is already deleted.");
}
Message message = mJobHandler.obtainMessage(JobHandler.MESSAGE_DEQUEUE,
DeleteJob.this);
@@ -1144,7 +1125,7 @@
List<String> mToBeDisabled;
List<String> mToBeEnabled;
- public ProfileJob(String _name, List<String> _toBeDisabled, List<String> _toBeEnabled) {
+ ProfileJob(String _name, List<String> _toBeDisabled, List<String> _toBeEnabled) {
mProfileName = _name;
mToBeDisabled = _toBeDisabled;
mToBeEnabled = _toBeEnabled;
@@ -1152,11 +1133,10 @@
@Override
public void run() {
- boolean restartUi = false;
log("Applying profile...");
// Need to restart SystemUI?
- restartUi = shouldRestartUi(mToBeEnabled) || shouldRestartUi(mToBeDisabled);
+ boolean restartUi = shouldRestartUi(mToBeDisabled);
// Clear system theme folder content
File themeDir = new File(IOUtils.SYSTEM_THEME_PATH);
@@ -1201,7 +1181,7 @@
// Restart SystemUI when needed
if (restartUi) {
- synchronized(mJobQueue) {
+ synchronized (mJobQueue) {
mJobQueue.add(new UiResetJob());
}
}
@@ -1214,7 +1194,6 @@
private class LocaleChanger extends BroadcastReceiver implements Runnable {
private boolean mIsRegistered;
- private boolean mDoRestore;
private Context mContext;
private Handler mHandler;
private Locale mCurrentLocale;
@@ -1229,12 +1208,7 @@
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
mContext.startActivity(i);
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- spoofLocale();
- }
- }, 500);
+ mHandler.postDelayed(this::spoofLocale, 500);
}
private void register() {
@@ -1253,9 +1227,10 @@
}
}
+ @SuppressWarnings("deprecation")
private void spoofLocale() {
Configuration config;
- log("LocaleChanger - spoofing locale for configuation change shim");
+ log("LocaleChanger - spoofing locale for configuration change shim...");
try {
register();
config = ActivityManagerNative.getDefault().getConfiguration();
@@ -1269,13 +1244,12 @@
ActivityManagerNative.getDefault().updateConfiguration(config);
} catch (RemoteException e) {
e.printStackTrace();
- return;
}
}
private void restoreLocale() {
Configuration config;
- log("LocaleChanger - restoring original locale for configuation change shim");
+ log("LocaleChanger - restoring original locale for configuration change shim...");
try {
unregister();
config = ActivityManagerNative.getDefault().getConfiguration();
@@ -1293,40 +1267,7 @@
@Override
public void onReceive(Context context, Intent intent) {
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- restoreLocale();
- }
- }, 500);
- }
- }
-
- private static class LocalIntentReceiver {
- private final SynchronousQueue<Intent> mResult = new SynchronousQueue<>();
-
- private IIntentSender.Stub mLocalSender = new IIntentSender.Stub() {
- @Override
- public void send(int code, Intent intent, String resolvedType,
- IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) {
- try {
- mResult.offer(intent, 5, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- };
-
- public IntentSender getIntentSender() {
- return new IntentSender((IIntentSender) mLocalSender);
- }
-
- public Intent getResult() {
- try {
- return mResult.take();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
+ mHandler.postDelayed(this::restoreLocale, 500);
}
}
}
diff --git a/app/src/main/java/masquerade/substratum/services/MasqDemo.java b/app/src/main/java/masquerade/substratum/services/MasqDemo.java
deleted file mode 100644
index b00d6e0..0000000
--- a/app/src/main/java/masquerade/substratum/services/MasqDemo.java
+++ /dev/null
@@ -1,137 +0,0 @@
-
-package masquerade.substratum.services;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.text.TextUtils;
-
-public class MasqDemo {
- public static final String MASQUERADE_TOKEN = "masquerade_token";
- public static final String PRIMARY_COMMAND_KEY = "primary_command_key";
- public static final String JOB_TIME_KEY = "job_time_key";
- public static final String INSTALL_LIST_KEY = "install_list";
- public static final String UNINSTALL_LIST_KEY = "uninstall_list";
- public static final String WITH_RESTART_UI_KEY = "with_restart_ui";
- public static final String BOOTANIMATION_PID_KEY = "bootanimation_pid";
- public static final String BOOTANIMATION_FILE_NAME = "bootanimation_file_name";
- public static final String FONTS_PID = "fonts_pid";
- public static final String FONTS_FILENAME = "fonts_filename";
- public static final String AUDIO_PID = "audio_pid";
- public static final String AUDIO_FILENAME = "audio_filename";
- public static final String COMMAND_VALUE_INSTALL = "install";
- public static final String COMMAND_VALUE_UNINSTALL = "uninstall";
- public static final String COMMAND_VALUE_RESTART_UI = "restart_ui";
- public static final String COMMAND_VALUE_CONFIGURATION_SHIM = "configuration_shim";
- public static final String COMMAND_VALUE_BOOTANIMATION = "bootanimation";
- public static final String COMMAND_VALUE_FONTS = "fonts";
- public static final String COMMAND_VALUE_AUDIO = "audio";
- public static final String INTENT_STATUS_CHANGED = "masquerade.substratum.STATUS_CHANGED";
- public static final String COMMAND_VALUE_JOB_COMPLETE = "job_complete";
-
- class MasqReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (TextUtils.equals(intent.getAction(), INTENT_STATUS_CHANGED)) {
- String command = intent.getStringExtra(PRIMARY_COMMAND_KEY);
- if (TextUtils.equals(command, COMMAND_VALUE_FONTS)) {
- // update ui, dismiss progress dialog, etc
- } else if (TextUtils.equals(command, COMMAND_VALUE_BOOTANIMATION)) {
-
- } else if (TextUtils.equals(command, COMMAND_VALUE_AUDIO)) {
-
- } else if (TextUtils.equals(command, COMMAND_VALUE_JOB_COMPLETE)) {
-
- }
- }
- }
- }
-
- // demo code for building a base intent for JobService commands
- public static Intent getMasqIntent(Context ctx) {
- Intent intent = new Intent();
- intent.setClassName("masquerade.substratum", "masquerade.substratum.services.JobService");
- // Credit StackOverflow http://stackoverflow.com/a/28132098
- // Use dummy PendingIntent for service to validate caller at onBind
- PendingIntent pending = PendingIntent.getActivity(ctx, 0, new Intent(), 0);
- intent.putExtra(MASQUERADE_TOKEN, pending);
- intent.putExtra(JOB_TIME_KEY, System.currentTimeMillis());
- return intent;
- }
-
- public static void install(Context context, ArrayList<String> overlay_apks) {
- // populate list however
- Intent masqIntent = getMasqIntent(context);
- masqIntent.putExtra(PRIMARY_COMMAND_KEY, COMMAND_VALUE_INSTALL);
- masqIntent.putExtra(INSTALL_LIST_KEY, overlay_apks);
- context.startService(masqIntent);
- }
-
- public static void uninstall(Context context, ArrayList<String> packages_to_remove) {
- Intent masqIntent = getMasqIntent(context);
- masqIntent.putExtra(PRIMARY_COMMAND_KEY, COMMAND_VALUE_UNINSTALL);
- masqIntent.putExtra(UNINSTALL_LIST_KEY, packages_to_remove);
- // only need to set if true, will restart SystemUI when done processing packages
- masqIntent.putExtra(WITH_RESTART_UI_KEY, true);
- context.startService(masqIntent);
- }
-
- public static void restartSystemUI(Context context) {
- Intent masqIntent = getMasqIntent(context);
- masqIntent.putExtra(PRIMARY_COMMAND_KEY, COMMAND_VALUE_RESTART_UI);
- context.startService(masqIntent);
- }
-
- public static void configurationChangeShim(Context context) {
- Intent masqIntent = getMasqIntent(context);
- masqIntent.putExtra(PRIMARY_COMMAND_KEY, COMMAND_VALUE_CONFIGURATION_SHIM);
- context.startService(masqIntent);
- }
-
- public static void clearThemedBootAnimation(Context context) {
- applyThemedBootAnimation(context, null);
- }
-
- public static void applyThemedBootAnimation(Context context, String fileName) {
- Intent masqIntent = getMasqIntent(context);
- masqIntent.putExtra(PRIMARY_COMMAND_KEY, COMMAND_VALUE_BOOTANIMATION);
- if (fileName != null) {
- masqIntent.putExtra(BOOTANIMATION_FILE_NAME, fileName);
- } else {
- // nothing. to reset to stock, just don't add PID and FILE
- }
- context.startService(masqIntent);
- }
-
- public static void clearThemedFont(Context context) {
- applyThemedFont(context, null, null);
- }
-
- public static void applyThemedFont(Context context, String pid, String fileName) {
- Intent masqIntent = getMasqIntent(context);
- masqIntent.putExtra(PRIMARY_COMMAND_KEY, COMMAND_VALUE_FONTS);
- if (pid != null) {
- masqIntent.putExtra(FONTS_PID, pid);
- masqIntent.putExtra(FONTS_FILENAME, fileName);
- }
- context.startService(masqIntent);
- }
-
- public static void clearThemedSounds(Context context) {
- applyThemedSounds(context, null, null);
- }
-
- public static void applyThemedSounds(Context context, String pid, String fileName) {
- Intent masqIntent = getMasqIntent(context);
- masqIntent.putExtra(PRIMARY_COMMAND_KEY, COMMAND_VALUE_AUDIO);
- if (pid != null) {
- masqIntent.putExtra(AUDIO_PID, pid);
- masqIntent.putExtra(AUDIO_FILENAME, fileName);
- }
- context.startService(masqIntent);
- }
-}
diff --git a/app/src/main/java/masquerade/substratum/utils/IOUtils.java b/app/src/main/java/masquerade/substratum/utils/IOUtils.java
index 06b5260..5c9d5c5 100644
--- a/app/src/main/java/masquerade/substratum/utils/IOUtils.java
+++ b/app/src/main/java/masquerade/substratum/utils/IOUtils.java
@@ -1,6 +1,28 @@
+/*
+ * Copyright (c) 2017 Project Substratum
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * Also add information on how to contact you by electronic and paper mail.
+ *
+ */
package masquerade.substratum.utils;
+import android.os.FileUtils;
+import android.util.Log;
+
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -12,8 +34,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-import android.os.FileUtils;
-
public class IOUtils {
public static final String SYSTEM_THEME_PATH = "/data/system/theme";
public static final String SYSTEM_THEME_FONT_PATH = SYSTEM_THEME_PATH + File.separator
@@ -31,12 +51,12 @@
public static final String SYSTEM_THEME_BOOTANIMATION_PATH = SYSTEM_THEME_PATH + File.separator
+ "bootanimation.zip";
- public static boolean dirExists(String dirPath) {
+ private static boolean dirExists(String dirPath) {
final File dir = new File(dirPath);
return dir.exists() && dir.isDirectory();
}
- public static void createDirIfNotExists(String dirPath) {
+ private static void createDirIfNotExists(String dirPath) {
if (!dirExists(dirPath)) {
File dir = new File(dirPath);
if (dir.mkdir()) {
@@ -80,17 +100,17 @@
public static void deleteThemedAudio() {
try {
- deleteRecursive(new File(SYSTEM_THEME_UI_SOUNDS_PATH));
- deleteRecursive(new File(SYSTEM_THEME_RINGTONE_PATH));
- deleteRecursive(new File(SYSTEM_THEME_NOTIFICATION_PATH));
- deleteRecursive(new File(SYSTEM_THEME_ALARM_PATH));
+ deleteRecursive(new File(SYSTEM_THEME_AUDIO_PATH));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void copyFolder(File source, File dest) {
- if (!dest.exists()) dest.mkdirs();
+ if (!dest.exists()) {
+ boolean created = dest.mkdirs();
+ if (!created) Log.e("CopyFolder", "Could not create destination folder...");
+ }
File[] files = source.listFiles();
for (File file : files) {
try {
@@ -172,7 +192,9 @@
for (File child : fileOrDirectory.listFiles())
deleteRecursive(child);
- fileOrDirectory.delete();
+ boolean deleted = fileOrDirectory.delete();
+ if (!deleted) Log.e("DeleteRecursive", "Could not delete file or directory - \'" +
+ fileOrDirectory.getName() + "\'");
}
public static void setPermissions(File path, int permissions) {
diff --git a/app/src/main/java/masquerade/substratum/utils/SoundUtils.java b/app/src/main/java/masquerade/substratum/utils/SoundUtils.java
index dda38eb..73999ce 100644
--- a/app/src/main/java/masquerade/substratum/utils/SoundUtils.java
+++ b/app/src/main/java/masquerade/substratum/utils/SoundUtils.java
@@ -1,9 +1,25 @@
+/*
+ * Copyright (c) 2017 Project Substratum
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * Also add information on how to contact you by electronic and paper mail.
+ *
+ */
package masquerade.substratum.utils;
-import java.io.File;
-import java.util.Arrays;
-
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -13,8 +29,11 @@
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.MediaStore;
-import android.util.Log;
import android.provider.Settings;
+import android.util.Log;
+
+import java.io.File;
+import java.util.Arrays;
public class SoundUtils {
private static final String SYSTEM_MEDIA_PATH = "/system/media/audio";
@@ -26,11 +45,12 @@
SYSTEM_MEDIA_PATH + File.separator + "notifications";
private static final String MEDIA_CONTENT_URI = "content://media/internal/audio/media";
- public static void updateGlobalSettings(ContentResolver resolver, String uri, String val) {
+ private static void updateGlobalSettings(ContentResolver resolver, String uri, String val) {
Settings.Global.putStringForUser(resolver, uri, val, UserHandle.USER_SYSTEM);
}
- public static boolean setUISounds(ContentResolver resolver, String sound_name, String location) {
+ public static boolean setUISounds(ContentResolver resolver, String sound_name, String
+ location) {
if (allowedUISound(sound_name)) {
updateGlobalSettings(resolver, sound_name, location);
return true;
@@ -39,12 +59,12 @@
}
public static void setDefaultUISounds(ContentResolver resolver, String sound_name,
- String sound_file) {
+ String sound_file) {
updateGlobalSettings(resolver, sound_name, "/system/media/audio/ui/" + sound_file);
}
// This string array contains all the SystemUI acceptable sound files
- public static Boolean allowedUISound(String targetValue) {
+ private static Boolean allowedUISound(String targetValue) {
String[] allowed_themable = {
"lock_sound",
"unlock_sound",
@@ -53,7 +73,7 @@
return Arrays.asList(allowed_themable).contains(targetValue);
}
- public static String getDefaultAudiblePath(int type) {
+ private static String getDefaultAudiblePath(int type) {
final String name;
final String path;
switch (type) {
@@ -76,25 +96,8 @@
return path;
}
- public static void clearAudibles(Context context, String audiblePath) {
- final File audibleDir = new File(audiblePath);
- if (audibleDir.exists() && audibleDir.isDirectory()) {
- String[] files = audibleDir.list();
- final ContentResolver resolver = context.getContentResolver();
- for (String s : files) {
- final String filePath = audiblePath + File.separator + s;
- Uri uri = MediaStore.Audio.Media.getContentUriForPath(filePath);
- resolver.delete(uri, MediaStore.MediaColumns.DATA + "=\""
- + filePath + "\"", null);
- boolean deleted = (new File(filePath)).delete();
- if (deleted)
- Log.e("SoundsHandler", "Database cleared");
- }
- }
- }
-
public static boolean setAudible(Context context, File ringtone, File ringtoneCache, int type,
- String name) {
+ String name) {
final String path = ringtone.getAbsolutePath();
final String mimeType = name.endsWith(".ogg") ? "application/ogg" : "application/mp3";
ContentValues values = new ContentValues();
@@ -111,8 +114,8 @@
Uri uri = MediaStore.Audio.Media.getContentUriForPath(path);
Uri newUri = null;
Cursor c = context.getContentResolver().query(uri,
- new String[] {
- MediaStore.MediaColumns._ID
+ new String[]{
+ MediaStore.MediaColumns._ID
},
MediaStore.MediaColumns.DATA + "='" + path + "'",
null, null);
@@ -135,7 +138,7 @@
}
public static boolean setUIAudible(Context context, File localized_ringtone,
- File ringtone_file, int type, String name) {
+ File ringtone_file, int type, String name) {
final String path = ringtone_file.getAbsolutePath();
final String path_clone = "/system/media/audio/ui/" + name + ".ogg";
@@ -153,8 +156,8 @@
Uri uri = MediaStore.Audio.Media.getContentUriForPath(path);
Uri newUri = null;
Cursor c = context.getContentResolver().query(uri,
- new String[] {
- MediaStore.MediaColumns._ID
+ new String[]{
+ MediaStore.MediaColumns._ID
},
MediaStore.MediaColumns.DATA + "='" + path_clone + "'",
null, null);
@@ -187,8 +190,8 @@
if (audiblePath != null) {
Uri uri = MediaStore.Audio.Media.getContentUriForPath(audiblePath);
Cursor c = context.getContentResolver().query(uri,
- new String[] {
- MediaStore.MediaColumns._ID
+ new String[]{
+ MediaStore.MediaColumns._ID
},
MediaStore.MediaColumns.DATA + "='" + audiblePath + "'",
null, null);
@@ -206,5 +209,4 @@
}
return true;
}
-
}
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..2588952
--- /dev/null
+++ b/app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-hdpi/substratum_masquerade.png b/app/src/main/res/mipmap-hdpi/substratum_masquerade.png
deleted file mode 100755
index aa94e2c..0000000
--- a/app/src/main/res/mipmap-hdpi/substratum_masquerade.png
+++ /dev/null
Binary files differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..bd2ae71
--- /dev/null
+++ b/app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-mdpi/substratum_masquerade.png b/app/src/main/res/mipmap-mdpi/substratum_masquerade.png
deleted file mode 100755
index bdc8a5d..0000000
--- a/app/src/main/res/mipmap-mdpi/substratum_masquerade.png
+++ /dev/null
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..c56d924
--- /dev/null
+++ b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xhdpi/substratum_masquerade.png b/app/src/main/res/mipmap-xhdpi/substratum_masquerade.png
deleted file mode 100755
index 0f2b92b..0000000
--- a/app/src/main/res/mipmap-xhdpi/substratum_masquerade.png
+++ /dev/null
Binary files differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..69011b7
--- /dev/null
+++ b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xxhdpi/substratum_masquerade.png b/app/src/main/res/mipmap-xxhdpi/substratum_masquerade.png
deleted file mode 100755
index 42ceea8..0000000
--- a/app/src/main/res/mipmap-xxhdpi/substratum_masquerade.png
+++ /dev/null
Binary files differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..4448e0b
--- /dev/null
+++ b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/substratum_masquerade.png b/app/src/main/res/mipmap-xxxhdpi/substratum_masquerade.png
deleted file mode 100755
index 5365867..0000000
--- a/app/src/main/res/mipmap-xxxhdpi/substratum_masquerade.png
+++ /dev/null
Binary files differ
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index b960a27..975087e 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -1,4 +1,3 @@
<resources>
-
<style name="AppTheme" parent="@android:style/Theme.NoDisplay"/>
</resources>
diff --git a/gradlew b/gradlew
old mode 100755
new mode 100644
diff --git a/gradlew.bat b/gradlew.bat
index aec9973..8a0b282 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -1,90 +1,90 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windowz variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega