TangoInitializationHelper.java
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 Google Inc. All Rights Reserved.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  * 
00016  * 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
00017  */
00018 
00019 package com.introlab.rtabmap;
00020 
00021 import android.content.Context;
00022 import android.content.Intent;
00023 import android.content.ServiceConnection;
00024 import android.os.Build;
00025 import android.os.IBinder;
00026 import android.util.Log;
00027 
00028 import java.io.File;
00029 
00034 public class TangoInitializationHelper {
00035   public static final int ARCH_ERROR = -2;
00036   public static final int ARCH_FALLBACK = -1;
00037   public static final int ARCH_DEFAULT = 0;
00038   public static final int ARCH_ARM64 = 1;
00039   public static final int ARCH_ARM32 = 2;
00040   public static final int ARCH_X86_64 = 3;
00041   public static final int ARCH_X86 = 4;
00042 
00050   public static final boolean bindTangoService(final Context context,
00051                                                ServiceConnection connection) {
00052     Intent intent = new Intent();
00053     intent.setClassName("com.google.tango", "com.google.atap.tango.TangoService");
00054 
00055     boolean hasJavaService = (context.getPackageManager().resolveService(intent, 0) != null);
00056 
00057     // User doesn't have the latest packagename for TangoCore, fallback to the previous name.
00058     if (!hasJavaService) {
00059       intent = new Intent();
00060       intent.setClassName("com.projecttango.tango", "com.google.atap.tango.TangoService");
00061       hasJavaService = (context.getPackageManager().resolveService(intent, 0) != null);
00062     }
00063 
00064     // User doesn't have a Java-fied TangoCore at all; fallback to the deprecated approach
00065     // of doing nothing and letting the native side auto-init to the system-service version
00066     // of Tango.
00067     if (!hasJavaService) {
00068       return false;
00069     }
00070 
00071     return context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
00072   }
00073 
00074     
00080   public static final int loadTangoSharedLibrary() {
00081     int loadedSoId = ARCH_ERROR;
00082     String basePath = "/data/data/com.google.tango/libfiles/";
00083     if (!(new File(basePath).exists())) {
00084       basePath = "/data/data/com.projecttango.tango/libfiles/";
00085     }
00086     Log.i("TangoInitializationHelper", "basePath: " + basePath);
00087 
00088     try {
00089       System.load(basePath + "arm64-v8a/libtango_client_api.so");
00090       loadedSoId = ARCH_ARM64;
00091       Log.i("TangoInitializationHelper", "Success! Using arm64-v8a/libtango_client_api.");
00092     } catch (UnsatisfiedLinkError e) {
00093     }
00094     if (loadedSoId < ARCH_DEFAULT) {
00095       try {
00096         System.load(basePath + "armeabi-v7a/libtango_client_api.so");
00097         loadedSoId = ARCH_ARM32;
00098         Log.i("TangoInitializationHelper", "Success! Using armeabi-v7a/libtango_client_api.");
00099       } catch (UnsatisfiedLinkError e) {
00100       }
00101     }
00102     if (loadedSoId < ARCH_DEFAULT) {
00103       try {
00104         System.load(basePath + "x86_64/libtango_client_api.so");
00105         loadedSoId = ARCH_X86_64;
00106         Log.i("TangoInitializationHelper", "Success! Using x86_64/libtango_client_api.");
00107       } catch (UnsatisfiedLinkError e) {
00108       }
00109     }
00110     if (loadedSoId < ARCH_DEFAULT) {
00111       try {
00112         System.load(basePath + "x86/libtango_client_api.so");
00113         loadedSoId = ARCH_X86;
00114         Log.i("TangoInitializationHelper", "Success! Using x86/libtango_client_api.");
00115       } catch (UnsatisfiedLinkError e) {
00116       }
00117     }
00118     if (loadedSoId < ARCH_DEFAULT) {
00119       try {
00120         System.load(basePath + "default/libtango_client_api.so");
00121         loadedSoId = ARCH_DEFAULT;
00122         Log.i("TangoInitializationHelper", "Success! Using default/libtango_client_api.");
00123       } catch (UnsatisfiedLinkError e) {
00124       }
00125     }
00126     if (loadedSoId < ARCH_DEFAULT) {
00127       try {
00128         System.loadLibrary("tango_client_api");
00129         loadedSoId = ARCH_FALLBACK;
00130         Log.i("TangoInitializationHelper", "Falling back to libtango_client_api.so symlink.");
00131       } catch (UnsatisfiedLinkError e) {
00132       }
00133     }
00134     return loadedSoId;
00135   }
00136 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:27