1 /* 2 * Copyright (C) 2008 The Android Open Source Project 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 17 package com.example.android.platform_library; 18 19 import android.util.Config; 20 import android.util.Log; 21 22 public final class PlatformLibrary { 23 static { 24 /* 25 * Load the library. If it's already loaded, this does nothing. 26 */ 27 System.loadLibrary("platform_library_jni"); 28 } 29 30 private int mJniInt = -1; 31 32 public PlatformLibrary() {} 33 34 /* 35 * Test native methods. 36 */ 37 public int getInt(boolean bad) { 38 /* this alters mJniInt */ 39 int result = getJniInt(bad); 40 41 /* reverse a string, for no very good reason */ 42 String reverse = reverseString("Android!"); 43 44 Log.i("PlatformLibrary", "getInt: " + result + ", '" + reverse + "'"); 45 46 return mJniInt; 47 } 48 49 /* 50 * Simple method, called from native code. 51 */ 52 private static void yodel(String msg) { 53 Log.d("PlatformLibrary", "yodel: " + msg); 54 } 55 56 /* 57 * Trivial native method call. If "bad" is true, this will throw an 58 * exception. 59 */ 60 native private int getJniInt(boolean bad); 61 62 /* 63 * Native method that returns a new string that is the reverse of 64 * the original. This also calls yodel(). 65 */ 66 native private static String reverseString(String str); 67 } 68