Skip to content

Commit 1a9826a

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
fix: 32 bugs across server, CLI, generators, tests, and proto
Server bugs: - Fix race condition: register callback channel before stream.Send - Promote voidDetector JNI local ref to global ref - Enable SQLite WAL mode and set MaxOpenConns(1) - Add nil checks for systemMain/getSystemContext return values - Check NewStringUTF errors in launchPermissionDialog - Use errors.Is for io.EOF comparison in proxy_stream - Add all primitive types to NewPrimitiveArray (was byte-only) - Use INSERT OR REPLACE for client re-registration CLI bugs: - Fix --insecure flag description (TLS skip-verify, not plaintext) - Add default transport credentials when no flags given - Remove InsecureSkipVerify override when mTLS certs provided - Fix readFileViaJNI to loop reads instead of single truncating call Generator bugs: - Set ResultExpr for no-error object-returning methods - Add handle store logic for no-error object returns in template - Fix hardcoded jni import path to use JniModule variable - Fix collision rename: check for secondary collisions - Fix TrimRight→TrimSuffix for trailing underscore removal - Fix byte result type: uint32 cast to match proto field - Add int param/result type casts (int↔int32) - Remove unused cc field from generated client structs Test bugs: - Fix capture_test.go wrong CLI path (battery-manager→manager) - Fix 3 slice aliasing bugs (list_commands, setup_test, scenarios_test) - Fix TestMain os.Exit skipping defer cleanup - Fix %v→%w error wrapping in setup_test - Fix is-same test misleading failure message - Add test for uint16 client result expr - Add test for no-error object return server method Proto bugs: - Fix handlestore.proto go_package (jni→jni-proxy module) - Fix loop variable shadowing in protogen collision rename - Fix ReturnVoid handling in protoTypeFromReturn - Check scanner.Err() in protoscan after scanning
1 parent 7be21c8 commit 1a9826a

54 files changed

Lines changed: 199 additions & 120 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/jnicli/camera_record.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,23 @@ func readFileViaJNI(ctx context.Context, j *jniCaller, path string) ([]byte, err
691691
}
692692
buf := resp.GetArrayHandle()
693693

694-
// fis.read(buf)
695-
readMid, err := j.getMethodID(ctx, fisCls, "read", "([B)I")
694+
// fis.read(buf, offset, length) in a loop until all bytes are read.
695+
readMid, err := j.getMethodID(ctx, fisCls, "read", "([BII)I")
696696
if err != nil {
697697
return nil, fmt.Errorf("getting read method: %w", err)
698698
}
699-
if _, err := j.callIntMethod(ctx, fis, readMid, objVal(buf)); err != nil {
700-
return nil, fmt.Errorf("reading file: %w", err)
699+
var offset int32
700+
remaining := size
701+
for remaining > 0 {
702+
n, err := j.callIntMethod(ctx, fis, readMid, objVal(buf), intVal(offset), intVal(remaining))
703+
if err != nil {
704+
return nil, fmt.Errorf("reading file at offset %d: %w", offset, err)
705+
}
706+
if n == -1 {
707+
break // EOF
708+
}
709+
offset += n
710+
remaining -= n
701711
}
702712

703713
// fis.close()

cmd/jnicli/list_commands.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ var listCommandsCmd = &cobra.Command{
1717
}
1818

1919
func printLeafCommands(cmd *cobra.Command, path []string) {
20-
current := append(path, cmd.Use)
20+
current := make([]string, len(path)+1)
21+
copy(current, path)
22+
current[len(path)] = cmd.Use
2123

2224
if !cmd.HasSubCommands() && cmd.RunE != nil {
2325
fmt.Println(strings.Join(current, " "))

cmd/jnicli/root.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/spf13/cobra"
1212
"google.golang.org/grpc"
1313
"google.golang.org/grpc/credentials"
14+
"google.golang.org/grpc/credentials/insecure"
1415
)
1516

1617
const maxGRPCRecvMsgSize = 128 * 1024 * 1024
@@ -56,6 +57,9 @@ var rootCmd = &cobra.Command{
5657
// CA (jniservice generates its own CA). This is NOT plaintext.
5758
opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(
5859
&tls.Config{InsecureSkipVerify: true})))
60+
default:
61+
// No TLS configuration provided — use plaintext.
62+
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
5963
}
6064

6165
conn, err := grpc.NewClient(flagAddr, opts...)
@@ -75,7 +79,7 @@ var rootCmd = &cobra.Command{
7579

7680
func init() {
7781
rootCmd.PersistentFlags().StringVarP(&flagAddr, "addr", "a", "localhost:50051", "gRPC server address")
78-
rootCmd.PersistentFlags().BoolVar(&flagInsecure, "insecure", false, "use insecure connection (no TLS)")
82+
rootCmd.PersistentFlags().BoolVar(&flagInsecure, "insecure", false, "skip TLS server certificate verification")
7983
rootCmd.PersistentFlags().DurationVar(&flagTimeout, "timeout", 10*time.Second, "request timeout")
8084
rootCmd.PersistentFlags().StringVarP(&flagFormat, "format", "f", "json", "output format (json|text)")
8185
rootCmd.PersistentFlags().StringVar(&flagCert, "cert", "", "path to client certificate PEM file (for mTLS)")
@@ -110,9 +114,5 @@ func buildMTLSCredentials() (credentials.TransportCredentials, error) {
110114
tlsCfg.RootCAs = caPool
111115
}
112116

113-
if flagInsecure {
114-
tlsCfg.InsecureSkipVerify = true
115-
}
116-
117117
return credentials.NewTLS(tlsCfg), nil
118118
}

cmd/jniservice/server.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ func initAndroidContext(vm *jni.VM, handles *handlestore.HandleStore) int64 {
427427
if err != nil {
428428
return fmt.Errorf("systemMain: %w", err)
429429
}
430+
if atObj == nil || atObj.Ref() == 0 {
431+
return fmt.Errorf("systemMain returned null")
432+
}
430433

431434
getCtxMID, err := env.GetMethodID(atCls, "getSystemContext", "()Landroid/app/ContextImpl;")
432435
if err != nil {
@@ -436,6 +439,9 @@ func initAndroidContext(vm *jni.VM, handles *handlestore.HandleStore) int64 {
436439
if err != nil {
437440
return fmt.Errorf("getSystemContext: %w", err)
438441
}
442+
if ctxObj == nil || ctxObj.Ref() == 0 {
443+
return fmt.Errorf("getSystemContext returned null")
444+
}
439445
contextHandle = handles.Put(env, ctxObj)
440446
}
441447

@@ -529,7 +535,10 @@ func launchPermissionDialog(
529535
if err != nil {
530536
return err
531537
}
532-
reqIDKey, _ := env.NewStringUTF("request_id")
538+
reqIDKey, err := env.NewStringUTF("request_id")
539+
if err != nil {
540+
return fmt.Errorf("creating request_id key string: %w", err)
541+
}
533542
// Intentionally ignoring error: putExtra is an Intent builder method
534543
// where failure is non-recoverable in the dialog launch flow.
535544
_, _ = env.CallObjectMethod(intent, putLongMID, jni.ObjectValue(&reqIDKey.Object), jni.LongValue(requestID))
@@ -540,23 +549,35 @@ func launchPermissionDialog(
540549
if err != nil {
541550
return err
542551
}
543-
clientIDKey, _ := env.NewStringUTF("client_id")
544-
clientIDVal, _ := env.NewStringUTF(clientID)
552+
clientIDKey, err := env.NewStringUTF("client_id")
553+
if err != nil {
554+
return fmt.Errorf("creating client_id key string: %w", err)
555+
}
556+
clientIDVal, err := env.NewStringUTF(clientID)
557+
if err != nil {
558+
return fmt.Errorf("creating client_id value string: %w", err)
559+
}
545560
// Intentionally ignoring error: putExtra is an Intent builder method
546561
// where failure is non-recoverable in the dialog launch flow.
547562
_, _ = env.CallObjectMethod(intent, putStringMID,
548563
jni.ObjectValue(&clientIDKey.Object), jni.ObjectValue(&clientIDVal.Object))
549564

550565
// intent.putExtra("methods", joinedMethods)
551-
methodsKey, _ := env.NewStringUTF("methods")
566+
methodsKey, err := env.NewStringUTF("methods")
567+
if err != nil {
568+
return fmt.Errorf("creating methods key string: %w", err)
569+
}
552570
joinedMethods := ""
553571
for i, m := range methods {
554572
if i > 0 {
555573
joinedMethods += ","
556574
}
557575
joinedMethods += m
558576
}
559-
methodsVal, _ := env.NewStringUTF(joinedMethods)
577+
methodsVal, err := env.NewStringUTF(joinedMethods)
578+
if err != nil {
579+
return fmt.Errorf("creating methods value string: %w", err)
580+
}
560581
// Intentionally ignoring error: putExtra is an Intent builder method
561582
// where failure is non-recoverable in the dialog launch flow.
562583
_, _ = env.CallObjectMethod(intent, putStringMID,

grpc/client/accounts/client.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grpc/client/admin/client.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grpc/client/alarm/client.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grpc/client/audiomanager/client.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grpc/client/battery/client.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grpc/client/biometric/client.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)