Permalink
1 comment
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
with
153 additions
and 0 deletions.
@@ -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(); | ||
} | ||
} | ||
} | ||
} |
This comment has been minimized.
37f2ab5
Another Todo: close root stream