Fix telemetry version for debug build (#1566)

This commit is contained in:
LoveSy 2022-01-28 14:47:07 +08:00 committed by GitHub
parent 05d93b85ec
commit f02712ce5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 25 deletions

View File

@ -113,13 +113,6 @@ android {
}
}
}
sourceSets {
named("release") {
java {
srcDirs("src/release/java")
}
}
}
}
val optimizeReleaseRes = task("optimizeReleaseRes").doLast {

View File

@ -1,28 +1,53 @@
package org.lsposed.manager.util;
import android.app.Application;
import android.os.Handler;
import android.util.Log;
import androidx.annotation.NonNull;
import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.crashes.AbstractCrashesListener;
import com.microsoft.appcenter.channel.AbstractChannelListener;
import com.microsoft.appcenter.channel.Channel;
import com.microsoft.appcenter.crashes.Crashes;
import com.microsoft.appcenter.crashes.model.ErrorReport;
import org.lsposed.manager.App;
import org.lsposed.manager.BuildConfig;
import java.util.Locale;
public class Telemetry {
public static void start(Application app) {
Crashes.setListener(new AbstractCrashesListener() {
static Channel.Listener patchDeviceListener = new AbstractChannelListener() {
@Override
public void onBeforeSending(ErrorReport report) {
var d = report.getDevice();
public void onPreparedLog(@NonNull com.microsoft.appcenter.ingestion.models.Log log, @NonNull String groupName, int flags) {
var d = log.getDevice();
d.setAppVersion(BuildConfig.VERSION_NAME);
d.setAppBuild(String.valueOf(BuildConfig.VERSION_CODE));
d.setAppNamespace(BuildConfig.APPLICATION_ID);
report.setDevice(d);
log.setDevice(d);
}
});
};
static void addPatchDeviceListener() {
try {
var channel = AppCenter.class.getDeclaredField("mChannel");
channel.setAccessible(true);
((Channel) channel.get(AppCenter.getInstance())).addListener(patchDeviceListener);
} catch (Throwable e) {
Log.e(App.TAG, "add listener", e);
}
}
static void patchDevice() throws Throwable {
var handle = AppCenter.class.getDeclaredField("mHandler");
handle.setAccessible(true);
((Handler) handle.get(AppCenter.getInstance())).post(Telemetry::addPatchDeviceListener);
}
public static void start(Application app) {
AppCenter.start(app, "eb3c4175-e879-4312-a72e-b0e64bca142c", Crashes.class);
try {
patchDevice();
} catch (Throwable e) {
Log.w(App.TAG, "patch device", e);
}
}
}

View File

@ -174,6 +174,9 @@ val zipAll = task("zipAll") {
}
val apkDir: String
get() = if (rootProject.extra.properties["android.injected.invoked.from.ide"] == "true") "intermediates" else "outputs"
fun afterEval() = android.applicationVariants.forEach { variant ->
val variantCapped = variant.name.capitalize(Locale.ROOT)
val variantLowered = variant.name.toLowerCase(Locale.ROOT)
@ -235,11 +238,11 @@ fun afterEval() = android.applicationVariants.forEach { variant ->
filter<FixCrLfFilter>("eol" to FixCrLfFilter.CrLf.newInstance("lf"))
}
}
from("${project(":app").buildDir}/outputs/apk/${buildTypeLowered}") {
from("${project(":app").buildDir}/$apkDir/apk/${buildTypeLowered}") {
include("*.apk")
rename(".*\\.apk", "manager.apk")
}
from("${project(":daemon").buildDir}/outputs/apk/${buildTypeLowered}") {
from("${project(":daemon").buildDir}/$apkDir/apk/${buildTypeLowered}") {
include("*.apk")
rename(".*\\.apk", "daemon.apk")
}
@ -305,7 +308,7 @@ val killLspd = task<Exec>("killLspd") {
}
val pushDaemon = task<Exec>("pushDaemon") {
dependsOn(":daemon:assembleDebug")
workingDir("${project(":daemon").buildDir}/outputs/apk/debug")
workingDir("${project(":daemon").buildDir}/$apkDir/apk/debug")
commandLine(adb, "push", "daemon-debug.apk", "/data/local/tmp/daemon.apk")
}
val pushDaemonNative = task<Exec>("pushDaemonNative") {
@ -330,7 +333,7 @@ val reRunDaemon = task<Exec>("reRunDaemon") {
val tmpApk = "/data/local/tmp/lsp.apk"
val pushApk = task<Exec>("pushApk") {
dependsOn(":app:assembleDebug")
workingDir("${project(":app").buildDir}/outputs/apk/debug")
workingDir("${project(":app").buildDir}/$apkDir/apk/debug")
commandLine(adb, "push", "app-debug.apk", tmpApk)
}
val openApp = task<Exec>("openApp") {