Skip to content

Commit

Permalink
Fixed distortion and disconnect issues
Browse files Browse the repository at this point in the history
Tested with LG Nexus Android 8.0, user build
Tested with a Android M 6.0, userdebug build

For use build, screen/input device probe will fail and
cause adb exec error to disconnect device.

Since Android 8.0 (at least), adb shell will not convert
\n to \n\r for binary stream, so no need to convert now.

Hope we don't break supporting for old Android version
  • Loading branch information
PenguinYang committed Jul 29, 2019
1 parent 9c994ce commit 1333e50
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 24 deletions.
76 changes: 56 additions & 20 deletions src/adbfb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int Commander::run(bool waitUntilFinished)
p = new QProcess();
}

//DT_TRACE("CMD" << cmd << args.join(" "));
DT_TRACE("CMD" << cmd << args.join(" "));
p->start(cmd, args);

if (waitUntilFinished) {
Expand Down Expand Up @@ -141,7 +141,8 @@ int ADBBase::increaseDelay()

ADBDevice::ADBDevice()
{
osType = ANDROID_JB;
buildType = "userdebug";
osType = ANDROID_JB; // Android 5.0 L
lcdBrightness = -1;
hasSysLCDBL = false;

Expand Down Expand Up @@ -282,9 +283,27 @@ void ADBDevice::probeDevice(void)
{
emit newPropmtMessae(tr("Probing device..."));

/* getprop based probe */
probeDeviceOSType();
probeInputDevices();
probeDeviceHasSysLCDBL();
probeDeviceBuildType();

/* No permission to probe on a user build */
if (! isUserBuild()) {
probeDeviceRoot();
probeInputDevices();
probeDeviceHasSysLCDBL();
}
}

int ADBDevice::probeDeviceRoot(void)
{
AdbExecutor adb;
int os = ANDROID_ICS;

adb.run("root");
adb.run("wait-for-device");

return 0;
}

int ADBDevice::probeDeviceOSType(void)
Expand All @@ -298,16 +317,29 @@ int ADBDevice::probeDeviceOSType(void)

adb.run();

if (adb.output.simplified().toInt() >= 16) {
os = ANDROID_JB;
}
//qDebug() << "OS type:" << os << adb.output;

osType = os;
osType = adb.output.simplified().toInt();
DT_TRACE("OS type: " << osType);

return os;
}

int ADBDevice::probeDeviceBuildType(void)
{
AdbExecutor adb;
int os = ANDROID_ICS;

adb.addArg("shell");
adb.addArg("getprop");
adb.addArg("ro.build.type");

adb.run();

buildType = adb.output.simplified();
DT_TRACE("Build type: " << buildType);

return 0;
}

void ADBDevice::probeDeviceHasSysLCDBL(void)
{
AdbExecutor adb;
Expand Down Expand Up @@ -500,19 +532,14 @@ void ADBDevice::sendVirtualClick(QPoint pos,
{
DT_TRACE("CLICK" << pos.x() << pos.y() << press << release);

switch(osType) {
case ANDROID_ICS:
if (osType <= ANDROID_JB) {
sendEvent(pos, press, release);
break;
case ANDROID_JB:
} else {
// Mouse move, ignored.
// Both true is impossible
if (press || release) {
sendTap(pos, press);
}
break;
default:
qDebug() << "Unknown OS type, click dropped.";
}
}

Expand Down Expand Up @@ -754,9 +781,17 @@ int ADBFrameBuffer::screenCap(QByteArray &bytes, int offset)
return adb.ret;
}

//DT_TRACE("BUF Original len: " << adb.output.length());
bytes = adb.outputFixNewLine();
//DT_TRACE("BUF fixed new line: " << bytes.length());
// Assume that Android < 7.0 has this issue
if (deviceOSType() < ANDROID_NO)
{
DT_TRACE("BUF Original len: " << adb.output.length());
bytes = adb.outputFixNewLine();
DT_TRACE("BUF fixed new line: " << bytes.length());
}
else
{
bytes = adb.output;
}

if (doCompress) {
minigzipDecompress(bytes);
Expand Down Expand Up @@ -920,6 +955,7 @@ void ADBFrameBuffer::probeFBInfo()
{
int ret;

probeDeviceOSType();
checkCompressSupport();
checkScreenCapOptions();

Expand Down
16 changes: 12 additions & 4 deletions src/adbfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
#define IMPOSSIBLE_FB_WIDTH 5120

enum {
ANDROID_ICS,
ANDROID_JB,
ANDROID_ICS = 14,
ANDROID_JB = 16,
ANDROID_LO = 21,
ANDROID_MA = 23,
ANDROID_NO = 24,
ANDROID_OR = 26,
ANDROID_UNKNOWN
};

Expand Down Expand Up @@ -209,11 +213,14 @@ class ADBDevice : public ADBBase
bool screenIsOn(void);
int screenBrightness(void) { return lcdBrightness; }
int deviceOSType(void) { return osType; }
bool isUserBuild(void) { return buildType == "user"; }
int probeDeviceOSType(void);

private:
void probeDeviceHasSysLCDBL(void);
void probeInputDevices(void);
int probeDeviceOSType(void);
int probeDeviceBuildType(void);
int probeDeviceRoot(void);

int getDeviceLCDBrightness();

Expand Down Expand Up @@ -257,6 +264,7 @@ public slots:
bool hasSysLCDBL;
int lcdBrightness;
int osType;
QString buildType;

// Used in jb to distinguish tap/swipe event
QPoint posOfPress;
Expand Down Expand Up @@ -290,7 +298,7 @@ public slots:
*/
#define INVALIDE_BUFFER_MAX 5

class ADBFrameBuffer: public ADBBase
class ADBFrameBuffer: public ADBDevice
{
Q_OBJECT

Expand Down

0 comments on commit 1333e50

Please sign in to comment.