NativeConnectionHelper.java
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package io.grpc.binder.cpp;
16 
17 import android.content.Context;
18 import android.content.pm.PackageManager;
19 import android.os.Parcel;
20 import android.util.Log;
21 import java.util.HashMap;
22 import java.util.Map;
23 
29 final class NativeConnectionHelper {
30  // Maps connection id to GrpcBinderConnection instances
31  static Map<String, GrpcBinderConnection> s = new HashMap<>();
32 
33  static void tryEstablishConnection(Context context, String pkg, String cls, String action_name, String connId) {
34  // TODO(mingcl): Assert that connId is unique
35  s.put(connId, new GrpcBinderConnection(context, connId));
36  s.get(connId).tryConnect(pkg, cls, action_name);
37  }
38 
39  // Returns true if the packages signature of the 2 UIDs match.
40  // `context` is used to get PackageManager.
41  // Suppress unnecessary internal warnings related to checkSignatures compatibility issue.
42  // BinderTransport code is only used on newer Android platform versions so this is fine.
43  @SuppressWarnings("CheckSignatures")
44  static boolean isSignatureMatch(Context context, int uid1, int uid2) {
45  int result = context.getPackageManager().checkSignatures(uid1, uid2);
46  if (result == PackageManager.SIGNATURE_MATCH) {
47  return true;
48  }
49  Log.e(
50  "NativeConnectionHelper",
51  "Signatures does not match. checkSignature return value = " + result);
52  return false;
53  }
54 
55  static Parcel getEmptyParcel() {
56  return Parcel.obtain();
57  }
58 }
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
Map
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:451
testing::internal::Log
GTEST_API_ void Log(LogSeverity severity, const std::string &message, int stack_frames_to_skip)
Definition: bloaty/third_party/googletest/googlemock/src/gmock-internal-utils.cc:149
absl::FormatConversionChar::s
@ s
java
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:42