Skip to content

Commit

Permalink
Move I/O to separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Jan 3, 2019
1 parent ada088e commit d0a75d1
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 90 deletions.
20 changes: 15 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ buildscript {
}
}

ext {
compileSdkVersion = 28
buildToolsVersion = "28.0.3"
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Expand All @@ -38,6 +33,21 @@ subprojects {
}

afterEvaluate {
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 9
targetSdkVersion 28
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

if (getPlugins().hasPlugin('com.android.library')) {
task javadoc(type: Javadoc) {
failOnError false
Expand Down
17 changes: 1 addition & 16 deletions busybox/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.topjohnwu'
group='com.github.topjohnwu.libsu'

buildscript {
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion 9
targetSdkVersion rootProject.ext.compileSdkVersion
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(':core')
Expand Down
12 changes: 1 addition & 11 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.topjohnwu'
group='com.github.topjohnwu.libsu'

buildscript {
dependencies {
Expand All @@ -10,19 +10,9 @@ buildscript {
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion 9
targetSdkVersion rootProject.ext.compileSdkVersion
consumerProguardFiles 'proguard-rules.pro'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
35 changes: 0 additions & 35 deletions core/src/main/java/com/topjohnwu/superuser/internal/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,6 @@ public static ShellImpl createShell(long timeout, String... cmd) throws IOExcept
return new ShellImpl(timeout, cmd);
}

public static ShellFileIO createShellFileIO(ShellFile file, String mode) throws FileNotFoundException {
String internalMode;
switch (mode) {
case "r":
internalMode = "r";
break;
case "rw":
case "rws":
case "rwd":
internalMode = "rw";
break;
default:
throw new IllegalArgumentException("Unknown mode: " + mode);
}
return new ShellFileIO(file, internalMode);
}

public static RandomAccessFileWrapper createRandomAccessFileWrapper(File file, String mode)
throws FileNotFoundException {
return new RandomAccessFileWrapper(file, mode);
}

public static ShellInputStream createShellInputStream(ShellFile file) throws FileNotFoundException {
return new ShellInputStream(file);
}

public static ShellOutputStream createShellOutputStream(ShellFile file, boolean append)
throws FileNotFoundException {
return new ShellOutputStream(file, append);
}

public static ShellFile createShellFile(File file) {
return new ShellFile(file);
}

public static Shell.Job createJob(boolean su, InputStream in) {
return new PendingJob(su).add(in);
}
Expand Down
10 changes: 0 additions & 10 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId "com.topjohnwu.libsuexample"
minSdkVersion 16
targetSdkVersion rootProject.ext.compileSdkVersion
versionCode 1
versionName "1.0"
}
Expand All @@ -18,13 +15,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions io/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
15 changes: 15 additions & 0 deletions io/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.topjohnwu.libsu'

buildscript {
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(':core')
}
21 changes: 21 additions & 0 deletions io/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions io/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.topjohnwu.superuser" />
43 changes: 43 additions & 0 deletions io/src/main/java/com/topjohnwu/superuser/internal/IOFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.topjohnwu.superuser.internal;

import java.io.File;
import java.io.FileNotFoundException;

public final class IOFactory {
private IOFactory() {}

public static ShellFileIO createShellFileIO(ShellFile file, String mode) throws FileNotFoundException {
String internalMode;
switch (mode) {
case "r":
internalMode = "r";
break;
case "rw":
case "rws":
case "rwd":
internalMode = "rw";
break;
default:
throw new IllegalArgumentException("Unknown mode: " + mode);
}
return new ShellFileIO(file, internalMode);
}

public static RandomAccessFileWrapper createRandomAccessFileWrapper(File file, String mode)
throws FileNotFoundException {
return new RandomAccessFileWrapper(file, mode);
}

public static ShellInputStream createShellInputStream(ShellFile file) throws FileNotFoundException {
return new ShellInputStream(file);
}

public static ShellOutputStream createShellOutputStream(ShellFile file, boolean append)
throws FileNotFoundException {
return new ShellOutputStream(file, append);
}

public static ShellFile createShellFile(File file) {
return new ShellFile(file);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.os.Build;

import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.internal.Factory;
import com.topjohnwu.superuser.internal.IOFactory;
import com.topjohnwu.superuser.internal.ShellFile;

import java.io.File;
Expand Down Expand Up @@ -67,7 +67,7 @@ public SuFile(@NonNull File file) {
} else if (file instanceof ShellFile || !Shell.rootAccess()) {
f = file;
} else {
f = Factory.createShellFile(file);
f = IOFactory.createShellFile(file);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.topjohnwu.superuser.io;

import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.internal.Factory;
import com.topjohnwu.superuser.internal.IOFactory;

import java.io.BufferedInputStream;
import java.io.File;
Expand Down Expand Up @@ -49,15 +49,15 @@ public SuFileInputStream(String path) throws FileNotFoundException {
public SuFileInputStream(File file) throws FileNotFoundException {
super(null);
if (file instanceof SuFile && ((SuFile) file).isSU()) {
in = Factory.createShellInputStream(((SuFile) file).getShellFile());
in = IOFactory.createShellInputStream(((SuFile) file).getShellFile());
} else {
try {
// Try normal FileInputStream
in = new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
if (!Shell.rootAccess())
throw e;
in = Factory.createShellInputStream(Factory.createShellFile(file));
in = IOFactory.createShellInputStream(IOFactory.createShellFile(file));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.topjohnwu.superuser.io;

import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.internal.Factory;
import com.topjohnwu.superuser.internal.IOFactory;

import java.io.BufferedOutputStream;
import java.io.File;
Expand Down Expand Up @@ -67,7 +67,7 @@ public SuFileOutputStream(File file, boolean append) throws FileNotFoundExceptio
super(null);
if (file instanceof SuFile && ((SuFile) file).isSU()) {
out = new BufferedOutputStream(
Factory.createShellOutputStream(((SuFile) file).getShellFile(), append),
IOFactory.createShellOutputStream(((SuFile) file).getShellFile(), append),
4 * 1024 * 1024);
} else {
try {
Expand All @@ -77,7 +77,7 @@ public SuFileOutputStream(File file, boolean append) throws FileNotFoundExceptio
if (!Shell.rootAccess())
throw e;
out = new BufferedOutputStream(
Factory.createShellOutputStream(Factory.createShellFile(file), append),
IOFactory.createShellOutputStream(IOFactory.createShellFile(file), append),
4 * 1024 * 1024);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.topjohnwu.superuser.io;

import com.topjohnwu.superuser.internal.Factory;
import com.topjohnwu.superuser.internal.IOFactory;

import java.io.Closeable;
import java.io.DataInput;
Expand Down Expand Up @@ -73,12 +73,12 @@ public static SuRandomAccessFile open(File file) throws FileNotFoundException {
*/
public static SuRandomAccessFile open(File file, String mode) throws FileNotFoundException {
if (file instanceof SuFile && ((SuFile) file).isSU()) {
return Factory.createShellFileIO(((SuFile) file).getShellFile(), mode);
return IOFactory.createShellFileIO(((SuFile) file).getShellFile(), mode);
} else {
try {
return Factory.createRandomAccessFileWrapper(file, mode);
return IOFactory.createRandomAccessFileWrapper(file, mode);
} catch (FileNotFoundException e) {
return Factory.createShellFileIO(Factory.createShellFile(file), mode);
return IOFactory.createShellFileIO(IOFactory.createShellFile(file), mode);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':core', ':example', ':busybox'
include ':core', ':example', ':busybox', ':io'

0 comments on commit d0a75d1

Please sign in to comment.