diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..dea98f3 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Snapchat Dark Mode \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..958a5be --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6199cc2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..64b9390 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,55 @@ +plugins { + id 'com.android.application' + id 'kotlin-android' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "dev.tylerolson.snapchatdarkmode" + minSdkVersion 15 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +repositories { + maven { url 'https://jitpack.io' } +} + +dependencies { + + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.1' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + + //libsu + def libsuVersion = '3.1.2' + implementation "com.github.topjohnwu.libsu:core:${libsuVersion}" + implementation "com.github.topjohnwu.libsu:io:${libsuVersion}" + +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/dev/tylerolson/snapchatdarkmode/ExampleInstrumentedTest.kt b/app/src/androidTest/java/dev/tylerolson/snapchatdarkmode/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..18f0c2d --- /dev/null +++ b/app/src/androidTest/java/dev/tylerolson/snapchatdarkmode/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package dev.tylerolson.snapchatdarkmode + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("dev.tylerolson.snapchatdarkmodeenabler", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..55d482b --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..90675a0 Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/dev/tylerolson/snapchatdarkmode/MainActivity.kt b/app/src/main/java/dev/tylerolson/snapchatdarkmode/MainActivity.kt new file mode 100644 index 0000000..ae86676 --- /dev/null +++ b/app/src/main/java/dev/tylerolson/snapchatdarkmode/MainActivity.kt @@ -0,0 +1,114 @@ +package dev.tylerolson.snapchatdarkmode + +import android.app.AlertDialog +import android.content.DialogInterface +import android.os.Bundle +import android.util.Log +import android.widget.Button +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import com.topjohnwu.superuser.Shell + + +class MainActivity : AppCompatActivity() { + private val appTag: String = "SNAPCHAT DARK MODE" + private val xmlFile: String = "/data/data/com.snapchat.android/shared_prefs/APP_START_EXPERIMENT_PREFS.xml" + private var isDarkModeEnabled: Boolean = false + private var isRoot: Boolean = false + + init { + // Set settings before the main shell can be created + Shell.enableVerboseLogging = BuildConfig.DEBUG + Shell.setDefaultBuilder( + Shell.Builder.create() + .setFlags(Shell.FLAG_REDIRECT_STDERR) + .setTimeout(10) + ) + } + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + hasRootAccess() + + val darkModeStatus: TextView = findViewById(R.id.darkModeStatus) + checkDarkMode(darkModeStatus) + + val toggleButton: Button = findViewById(R.id.toggleButton) + toggleButton.setOnClickListener { + if (hasRootAccess()) { + if (isDarkModeEnabled) { + disableDarkMode(checkDarkMode(darkModeStatus)) + } else { + enableDarkMode(checkDarkMode(darkModeStatus)) + } + checkDarkMode(darkModeStatus) + } + } + } + + private fun hasRootAccess(): Boolean { + return if (!Shell.rootAccess()) { + showDialog( + "No Root Access", + "Root access could not be given on your device. This app will not work." + ) + false + } else { + if (!isRoot) { + showDialog("Root Access", "Root access has been given on your device. Enjoy!") + isRoot = true + } + true + } + } + + private fun showDialog(title: String, message: String) { + val builder = AlertDialog.Builder(this) + builder.setTitle(title) + .setMessage(message) + .setPositiveButton("Ok") { _: DialogInterface, _: Int -> } + builder.show() + } + + private fun checkDarkMode(darkModeStatus: TextView): MutableList { + val result: Shell.Result = Shell.su("cat $xmlFile").exec() + + Log.e(appTag, "Checking") + + isDarkModeEnabled = false + result.out.forEachIndexed { _, it -> + Log.e(appTag, it) + if (it.contains("ENABLED")) { + isDarkModeEnabled = true + } + } + + if (isDarkModeEnabled) { + darkModeStatus.text = "Dark mode is ON" + } else { + darkModeStatus.text = "Dark mode is OFF" + } + + return result.out + } + + private fun enableDarkMode(out: MutableList) { + Shell.su("sed -i '" + out.size + "d' " + xmlFile).exec() + Shell.sh("echo 'ENABLED' >> $xmlFile").exec() + Shell.sh("echo \"\" >> $xmlFile").exec() + + isDarkModeEnabled = true + showDialog("Dark Mode", "Enabled dark mode!") + } + + private fun disableDarkMode(out: MutableList) { + Shell.su("sed -i '" + (out.size - 1) + "d' " + xmlFile).exec() + + isDarkModeEnabled = false + showDialog("Dark Mode", "Disabled dark mode!") + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..4dc7b50 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,33 @@ + + + + + +