forked from Blendman974/faceclaw
Add stats collection and first-run on-glasses onboarding app
This commit is contained in:
1 parent
84baee9c76
commit
406cefe0c5
73 files changed
+3906
-98
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import type { BuildKind } from './build-info'
|
||||
|
||||
declare const NSBundle: any
|
||||
declare const NSProcessInfo: any
|
||||
|
||||
let cached: BuildKind | null = null
|
||||
|
||||
/**
|
||||
* App Store (and TestFlight) builds carry no provisioning profile; anything
|
||||
* installed from Xcode or as an ad hoc build does. Simulator builds have none
|
||||
* either, so they're recognized by the simulator's environment.
|
||||
*/
|
||||
export function buildKind(): BuildKind {
|
||||
if (cached) return cached
|
||||
if (NSProcessInfo.processInfo.environment.objectForKey('SIMULATOR_DEVICE_NAME')) cached = 'debug'
|
||||
else if (NSBundle.mainBundle.pathForResourceOfType('embedded', 'mobileprovision')) cached = 'self-built'
|
||||
else cached = 'official'
|
||||
return cached
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Which kind of build this is, for analytics: an official release, or one
|
||||
* compiled by somebody else. Official releases are signed with the key
|
||||
* scripts/release.sh uses; anything else was built by whoever installed it.
|
||||
*/
|
||||
import { Utils } from "@nativescript/core";
|
||||
|
||||
declare const android: any;
|
||||
declare const java: any;
|
||||
|
||||
/**
|
||||
* `debug` is a debuggable build (build.sh / build_and_run.sh); `self-built`
|
||||
* is a release build signed with someone else's key.
|
||||
*/
|
||||
export type BuildKind = "official" | "self-built" | "debug" | "unknown";
|
||||
|
||||
/** SHA-256 of the release signing certificate (`apksigner verify --print-certs dist/Faceclaw-*.apk`). */
|
||||
const OFFICIAL_SIGNING_CERT_SHA256 = "c1efe42d74f3fc4e9a13bcfc8c99e018344a55525e5b300fa960c89431e382ad";
|
||||
|
||||
let cached: BuildKind | null = null;
|
||||
|
||||
export function buildKind(): BuildKind {
|
||||
cached ??= detectBuildKind();
|
||||
return cached;
|
||||
}
|
||||
|
||||
function detectBuildKind(): BuildKind {
|
||||
try {
|
||||
const context = Utils.android.getApplicationContext();
|
||||
const packageManager = context.getPackageManager();
|
||||
const PackageManager = android.content.pm.PackageManager;
|
||||
const signatures =
|
||||
android.os.Build.VERSION.SDK_INT >= 28
|
||||
? packageManager
|
||||
.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNING_CERTIFICATES)
|
||||
.signingInfo.getApkContentsSigners()
|
||||
: packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
|
||||
for (let index = 0; index < signatures.length; index++) {
|
||||
const digest = java.security.MessageDigest.getInstance("SHA-256").digest(signatures[index].toByteArray());
|
||||
if (hex(digest) === OFFICIAL_SIGNING_CERT_SHA256) return "official";
|
||||
}
|
||||
const debuggable = (context.getApplicationInfo().flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) !== 0;
|
||||
return debuggable ? "debug" : "self-built";
|
||||
} catch (error) {
|
||||
console.warn(`build-info: could not read the signing certificate: ${error}`);
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
function hex(bytes: any): string {
|
||||
let text = "";
|
||||
for (let index = 0; index < bytes.length; index++) text += ((bytes[index] & 0xff) + 0x100).toString(16).slice(1);
|
||||
return text;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
declare const FaceclawKitConnectionCounters: any
|
||||
|
||||
export function drainConnectionCounters(): Record<string, number> {
|
||||
const counts: Record<string, number> = {}
|
||||
const parsed = JSON.parse(String(FaceclawKitConnectionCounters.shared.drain())) as Record<string, unknown>
|
||||
for (const [name, count] of Object.entries(parsed)) {
|
||||
if (typeof count === 'number' && count > 0) counts[name] = count
|
||||
}
|
||||
return counts
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
declare const com: any;
|
||||
|
||||
/**
|
||||
* Connection-reliability event counts since the last call, from the shared
|
||||
* Kotlin session core (ConnectionCounters.kt), which keeps them process-wide.
|
||||
*/
|
||||
export function drainConnectionCounters(): Record<string, number> {
|
||||
const counts: Record<string, number> = {};
|
||||
const parsed = JSON.parse(String(com.faceclaw.app.ConnectionCounters.drain())) as Record<string, unknown>;
|
||||
for (const [name, count] of Object.entries(parsed)) {
|
||||
if (typeof count === "number" && count > 0) counts[name] = count;
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
Reference in new issue
Block a user