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