TangoInitializationHelper.java
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * Copied for convenience from https://github.com/googlesamples/tango-examples-c/blob/master/cpp_example_util/app/src/main/java/com/projecttango/examples/cpp/util/TangoInitializationHelper.java
17  */
18 
19 package com.introlab.rtabmap;
20 
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.ServiceConnection;
24 import android.os.Build;
25 import android.os.IBinder;
26 import android.util.Log;
27 
28 import java.io.File;
29 
35  public static final int ARCH_ERROR = -2;
36  public static final int ARCH_FALLBACK = -1;
37  public static final int ARCH_DEFAULT = 0;
38  public static final int ARCH_ARM64 = 1;
39  public static final int ARCH_ARM32 = 2;
40  public static final int ARCH_X86_64 = 3;
41  public static final int ARCH_X86 = 4;
42 
50  public static final boolean bindTangoService(final Context context,
51  ServiceConnection connection) {
52  Intent intent = new Intent();
53  intent.setClassName("com.google.tango", "com.google.atap.tango.TangoService");
54 
55  boolean hasJavaService = (context.getPackageManager().resolveService(intent, 0) != null);
56 
57  // User doesn't have the latest packagename for TangoCore, fallback to the previous name.
58  if (!hasJavaService) {
59  intent = new Intent();
60  intent.setClassName("com.projecttango.tango", "com.google.atap.tango.TangoService");
61  hasJavaService = (context.getPackageManager().resolveService(intent, 0) != null);
62  }
63 
64  // User doesn't have a Java-fied TangoCore at all; fallback to the deprecated approach
65  // of doing nothing and letting the native side auto-init to the system-service version
66  // of Tango.
67  if (!hasJavaService) {
68  return false;
69  }
70 
71  return context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
72  }
73 
74 
80  public static final int loadTangoSharedLibrary() {
81  int loadedSoId = ARCH_ERROR;
82  String basePath = "/data/data/com.google.tango/libfiles/";
83  if (!(new File(basePath).exists())) {
84  basePath = "/data/data/com.projecttango.tango/libfiles/";
85  }
86  Log.i("TangoInitializationHelper", "basePath: " + basePath);
87 
88  try {
89  System.load(basePath + "arm64-v8a/libtango_client_api.so");
90  loadedSoId = ARCH_ARM64;
91  Log.i("TangoInitializationHelper", "Success! Using arm64-v8a/libtango_client_api.");
92  } catch (UnsatisfiedLinkError e) {
93  }
94  if (loadedSoId < ARCH_DEFAULT) {
95  try {
96  System.load(basePath + "armeabi-v7a/libtango_client_api.so");
97  loadedSoId = ARCH_ARM32;
98  Log.i("TangoInitializationHelper", "Success! Using armeabi-v7a/libtango_client_api.");
99  } catch (UnsatisfiedLinkError e) {
100  }
101  }
102  if (loadedSoId < ARCH_DEFAULT) {
103  try {
104  System.load(basePath + "x86_64/libtango_client_api.so");
105  loadedSoId = ARCH_X86_64;
106  Log.i("TangoInitializationHelper", "Success! Using x86_64/libtango_client_api.");
107  } catch (UnsatisfiedLinkError e) {
108  }
109  }
110  if (loadedSoId < ARCH_DEFAULT) {
111  try {
112  System.load(basePath + "x86/libtango_client_api.so");
113  loadedSoId = ARCH_X86;
114  Log.i("TangoInitializationHelper", "Success! Using x86/libtango_client_api.");
115  } catch (UnsatisfiedLinkError e) {
116  }
117  }
118  if (loadedSoId < ARCH_DEFAULT) {
119  try {
120  System.load(basePath + "default/libtango_client_api.so");
121  loadedSoId = ARCH_DEFAULT;
122  Log.i("TangoInitializationHelper", "Success! Using default/libtango_client_api.");
123  } catch (UnsatisfiedLinkError e) {
124  }
125  }
126  if (loadedSoId < ARCH_DEFAULT) {
127  try {
128  System.loadLibrary("tango_client_api");
129  loadedSoId = ARCH_FALLBACK;
130  Log.i("TangoInitializationHelper", "Falling back to libtango_client_api.so symlink.");
131  } catch (UnsatisfiedLinkError e) {
132  }
133  }
134  return loadedSoId;
135  }
136 }
com.introlab.rtabmap.TangoInitializationHelper
Definition: TangoInitializationHelper.java:34
com.introlab.rtabmap.TangoInitializationHelper.ARCH_X86_64
static final int ARCH_X86_64
Definition: TangoInitializationHelper.java:40
com.introlab.rtabmap.TangoInitializationHelper.bindTangoService
static final boolean bindTangoService(final Context context, ServiceConnection connection)
Definition: TangoInitializationHelper.java:50
com.introlab.rtabmap.TangoInitializationHelper.ARCH_ARM32
static final int ARCH_ARM32
Definition: TangoInitializationHelper.java:39
com.introlab.rtabmap.TangoInitializationHelper.ARCH_FALLBACK
static final int ARCH_FALLBACK
Definition: TangoInitializationHelper.java:36
com.introlab.rtabmap.TangoInitializationHelper.ARCH_ARM64
static final int ARCH_ARM64
Definition: TangoInitializationHelper.java:38
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
com.introlab.rtabmap.TangoInitializationHelper.loadTangoSharedLibrary
static final int loadTangoSharedLibrary()
Definition: TangoInitializationHelper.java:80
com.introlab.rtabmap.TangoInitializationHelper.ARCH_ERROR
static final int ARCH_ERROR
Definition: TangoInitializationHelper.java:35
com.introlab.rtabmap.TangoInitializationHelper.ARCH_DEFAULT
static final int ARCH_DEFAULT
Definition: TangoInitializationHelper.java:37
com.introlab.rtabmap.TangoInitializationHelper.ARCH_X86
static final int ARCH_X86
Definition: TangoInitializationHelper.java:41


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:22