Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Kitkat #3341

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Its features include:

## Requirements

The Android device requires at least API 21 (Android 5.0).
The Android device requires at least API 19 (Android 4.4).

Make sure you [enable adb debugging][enable-adb] on your device(s).

Expand Down
4 changes: 4 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME
#define SC_DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
#define SC_DEVICE_ANDROID_DATA_PATH "/data/local/tmp"

static char *
get_server_path(void) {
Expand Down Expand Up @@ -166,6 +167,9 @@ execute_server(struct sc_server *server,
cmd[count++] = "-s";
cmd[count++] = serial;
cmd[count++] = "shell";
cmd[count++] = "mkdir -p " SC_DEVICE_ANDROID_DATA_PATH "/dalvik-cache";
cmd[count++] = "&&";
cmd[count++] = "ANDROID_DATA=" SC_DEVICE_ANDROID_DATA_PATH;
cmd[count++] = "CLASSPATH=" SC_DEVICE_SERVER_PATH;
cmd[count++] = "app_process";

Expand Down
1 change: 0 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ page at http://checkstyle.sourceforge.net/config.html -->
<property name="severity" value="info" />
</module>
<module name="UpperEll" />

</module>

</module>
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

android.useAndroidX=true
1 change: 1 addition & 0 deletions libcore/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apply plugin: 'java-library'
30 changes: 30 additions & 0 deletions libcore/src/main/java/libcore/io/ErrnoException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package libcore.io;

/**
* A checked exception thrown when {@link Os} methods fail. This exception contains the native
* errno value, for comparison against the constants in {@link OsConstants}, should sophisticated
* callers need to adjust their behavior based on the exact failure.
*/
public final class ErrnoException extends Exception {
private final String functionName;
public final int errno;

public ErrnoException(String functionName, int errno) {
throw new AssertionError();
}
}
23 changes: 23 additions & 0 deletions libcore/src/main/java/libcore/io/Libcore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package libcore.io;

public final class Libcore {
private Libcore() {
}

public static Os os = null;
}
24 changes: 24 additions & 0 deletions libcore/src/main/java/libcore/io/Os.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package libcore.io;

import java.io.FileDescriptor;
import java.nio.ByteBuffer;

public interface Os {
String strerror(int errno);
int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException;
}
30 changes: 30 additions & 0 deletions libcore/src/main/java/libcore/io/OsConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package libcore.io;

public final class OsConstants {
private OsConstants() {
}

public static final int EINTR = placeholder();

public static String errnoName(int errno) {
return null;
}

// A hack to avoid these constants being inlined by javac...
private static int placeholder() { return 0; }
}
24 changes: 24 additions & 0 deletions os-compat/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 31
defaultConfig {
minSdkVersion 19
targetSdkVersion 31
}
androidResources {
namespace = "androidx.system"
}
buildFeatures {
aidl = false
androidResources = false
buildConfig = false
}
}

dependencies {
compileOnly rootProject.fileTree("thirdparty/androidx/annotation/1.3.0/annotation-1.3.0.jar")
compileOnly project(':libcore')
}

apply from: "$project.rootDir/config/android-checkstyle.gradle"
91 changes: 91 additions & 0 deletions os-compat/src/main/java/androidx/system/ErrnoException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.system;

import java.io.IOException;
import java.net.SocketException;

/**
* A checked exception thrown when {@link OsCompat} methods fail. This exception contains the native
* errno value, for comparison against the constants in {@link OsConstantsCompat}, should sophisticated
* callers need to adjust their behavior based on the exact failure.
*/
public final class ErrnoException extends Exception {
private final String functionName;
private final int errno;

/**
* Constructs an instance with the given function name and errno value.
*/
public ErrnoException(String functionName, int errno) {
this.functionName = functionName;
this.errno = errno;
}

/**
* Constructs an instance with the given function name, errno value, and cause.
*/
public ErrnoException(String functionName, int errno, Throwable cause) {
super(cause);
this.functionName = functionName;
this.errno = errno;
}

/**
* The errno value, for comparison with the {@code E} constants in {@link OsConstantsCompat}.
*/
public int getErrno() {
return errno;
}

/**
* Converts the stashed function name and errno value to a human-readable string.
* We do this here rather than in the constructor so that callers only pay for
* this if they need it.
*/
@Override public String getMessage() {
String errnoName = OsConstantsCompat.errnoName(errno);
if (errnoName == null) {
errnoName = "errno " + errno;
}
String description = OsCompat.strerror(errno);
return functionName + " failed: " + errnoName + " (" + description + ")";
}

/**
* Throws an {@link IOException} with a message based on {@link #getMessage()} and with this
* instance as the cause.
*
* <p>This method always terminates by throwing the exception. Callers can write
* {@code throw e.rethrowAsIOException()} to make that clear to the compiler.
*/
public IOException rethrowAsIOException() throws IOException {
throw new IOException(getMessage(), this);
}

/**
* Throws a {@link SocketException} with a message based on {@link #getMessage()} and with this
* instance as the cause.
*
* <p>This method always terminates by throwing the exception. Callers can write
* {@code throw e.rethrowAsIOException()} to make that clear to the compiler.
*/
public SocketException rethrowAsSocketException() throws SocketException {
final SocketException newException = new SocketException(getMessage());
newException.initCause(this);
throw newException;
}
}
33 changes: 33 additions & 0 deletions os-compat/src/main/java/androidx/system/Os.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.system;

import java.io.FileDescriptor;
import java.io.InterruptedIOException;
import java.nio.ByteBuffer;

interface Os {
String strerror(int errno);

int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException;

// https://android.googlesource.com/platform/libcore/+/lollipop-mr1-release/luni/src/main/java/libcore/io/Posix.java#253
static void maybeUpdateBufferPosition(ByteBuffer buffer, int originalPosition, int bytesReadOrWritten) {
if (bytesReadOrWritten > 0) {
buffer.position(bytesReadOrWritten + originalPosition);
}
}
}
47 changes: 47 additions & 0 deletions os-compat/src/main/java/androidx/system/OsApi21.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.system;

import androidx.annotation.RequiresApi;

import java.io.FileDescriptor;
import java.io.InterruptedIOException;
import java.nio.ByteBuffer;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.system.Os.maybeUpdateBufferPosition;

@RequiresApi(21)
final class OsApi21 implements Os {
@Override
public String strerror(int errno) {
return android.system.Os.strerror(errno);
}

@Override
public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException {
try {
final int position = buffer.position();
final int bytesWritten = android.system.Os.write(fd, buffer);
if (SDK_INT < 22) {
maybeUpdateBufferPosition(buffer, position, bytesWritten);
}
return bytesWritten;
} catch (android.system.ErrnoException e) {
throw new ErrnoException("write", e.errno);
}
}
}
Loading