Skip to content
Permalink
Browse files

Early WIP: DO NOT MERGE: Samsung stock theme support

Todo:
- My check for samsung devices will return SamsungOverlayService even on custom roms on samsung devices, move to last fallback
- Add my own copyright headers to files
- Factor out non theme-compatible Samsung devices
- Kill apps once their overlays are installed to apply
- Have root request earlier, and handle non-rooted failure gracefully
- Finish the stubs that SamsungOverlayService has
  • Loading branch information
USA-RedDragon committed Dec 11, 2017
1 parent 53f7637 commit 37f2ab501e19819ee6a982b7fd60729769ddeadd
@@ -25,6 +25,7 @@ import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.N
import android.os.Build.VERSION_CODES.N_MR1
import android.provider.Settings
import com.jereksel.libresubstratum.domain.overlayService.nougat.SamsungOverlayService
import com.jereksel.libresubstratum.domain.overlayService.nougat.WDUCommitsOverlayService
import com.jereksel.libresubstratum.domain.overlayService.nougat.WODUCommitsOverlayService
import com.jereksel.libresubstratum.extensions.getLogger
@@ -37,6 +38,10 @@ object OverlayServiceFactory {

val supportedAndroidVersions = listOf(N, N_MR1)

if (android.os.Build.MANUFACTURER.contentEquals("samsung")) {
return SamsungOverlayService(context)
}

if (!supportedAndroidVersions.contains(SDK_INT)) {
log.error("Not supported android version: {} {}", SDK_INT, RELEASE)
return InvalidOverlayService("This app works only on Android Nougat")
@@ -0,0 +1,62 @@
package com.jereksel.libresubstratum.domain.overlayService.nougat;

import android.content.Context;

import com.jereksel.libresubstratum.domain.OverlayInfo;
import com.jereksel.libresubstratum.domain.OverlayService;
import com.jereksel.libresubstratum.utils.Root;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SamsungOverlayService implements OverlayService {
private Context context;

public SamsungOverlayService(Context context) {
this.context = context;
}

public void enableOverlay(String id) {}
public void disableOverlay(String id) {}

public OverlayInfo getOverlayInfo(String id) {
return new OverlayInfo("test", true);
}

public List<OverlayInfo> getAllOverlaysForApk(String appId) {
return new ArrayList<OverlayInfo>();
}

public void restartSystemUI() {

}

public void installApk(File apk) {
Root.runCommand("pm install " + apk.getAbsolutePath());
//Root.runCommand("kill -9 `pidof " + pkg + "`");
}

public void uninstallApk(String appId) {
Root.runCommand("pm uninstall " + appId);
//Root.runCommand("kill -9 `pidof " + pkg + "`");
}

public List<String> requiredPermissions() {
ArrayList<String> permissions = new ArrayList<>();
//permissions.add("android.permission.WRITE_EXTERNAL_STORAGE");
return permissions;
}

public String additionalSteps() {
return null;
}

public List<OverlayInfo> getOverlaysPrioritiesForTarget(String targetAppId) {
return new ArrayList<>();
}

public void updatePriorities(List<String> overlayIds) {

}
}
@@ -0,0 +1,86 @@
package com.jereksel.libresubstratum.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Root {

private static Shell shell;

public static String runCommand(String command) {
return getShell().runCommand(command);
}

private static Shell getShell() {
if (shell == null) shell = new Shell();
return shell;
}

public static void closeShell() {
if (shell != null) shell.close();
}

private static class Shell {
private Process process;
private BufferedWriter bufferedWriter;
private BufferedReader bufferedReader;

private Shell() {
try {
process = Runtime.getRuntime().exec("su");
bufferedWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
} catch (IOException ex) {
ex.printStackTrace();
}
}

public String runCommand(String command) {
try {
StringBuilder sb = new StringBuilder();
String callback = "/shellCallback/";
bufferedWriter.write(command + "\necho " + callback + '\n');
bufferedWriter.flush();

char[] buffer = new char[256];
while (true) {
sb.append(buffer, 0, bufferedReader.read(buffer));
int i;
if ((i = sb.indexOf(callback)) > -1) {
sb.delete(i, i + callback.length());
break;
}
}
return sb.toString().trim();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}

public void close() {
try {
if (bufferedWriter != null) {
bufferedWriter.write("exit\n");
bufferedWriter.flush();

bufferedWriter.close();
}

if (bufferedReader != null)
bufferedReader.close();

if (process != null) {
process.waitFor();
process.destroy();
}

} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}

1 comment on commit 37f2ab5

@USA-RedDragon

This comment has been minimized.

Copy link
Owner Author

@USA-RedDragon USA-RedDragon commented on 37f2ab5 Dec 11, 2017

Another Todo: close root stream

Please sign in to comment.