| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is an example of an Android Mojo app that is composed of native code and | 5 // This is an example of an Android Mojo app that is composed of native code and |
| 6 // Java code that the native code calls into. In particular, we call to Java | 6 // Java code that the native code calls into. In particular, we call to Java |
| 7 // upon entering MojoMain to retrieve the name of the device that the | 7 // upon entering MojoMain to retrieve the name of the device that the |
| 8 // application is running on and print it out to the log. | 8 // application is running on and print it out to the log. |
| 9 // | 9 // |
| 10 // To run the example: | 10 // To run the example: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 std::string GetApplicationClassName() { | 48 std::string GetApplicationClassName() { |
| 49 JNIEnv* env = base::android::AttachCurrentThread(); | 49 JNIEnv* env = base::android::AttachCurrentThread(); |
| 50 jobject context = base::android::GetApplicationContext(); | 50 jobject context = base::android::GetApplicationContext(); |
| 51 return base::android::ConvertJavaStringToUTF8( | 51 return base::android::ConvertJavaStringToUTF8( |
| 52 env, Java_DeviceName_getApplicationClassName(env, context).obj()); | 52 env, Java_DeviceName_getApplicationClassName(env, context).obj()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace examples | 55 } // namespace examples |
| 56 } // namespace mojo | 56 } // namespace mojo |
| 57 | 57 |
| 58 MojoResult MojoMain(MojoHandle shell_handle) { | 58 MojoResult MojoMain(MojoHandle application_request) { |
| 59 // Call a Java function to demonstrate that the JNI was correctly set up. | 59 // Call a Java function to demonstrate that the JNI was correctly set up. |
| 60 LOG(INFO) << "Device name: " << mojo::examples::GetDeviceName(); | 60 LOG(INFO) << "Device name: " << mojo::examples::GetDeviceName(); |
| 61 | 61 |
| 62 // Call a function that uses the application context to demonstrate that it | 62 // Call a function that uses the application context to demonstrate that it |
| 63 // was properly set. | 63 // was properly set. |
| 64 LOG(INFO) << "Application class: " | 64 LOG(INFO) << "Application class: " |
| 65 << mojo::examples::GetApplicationClassName(); | 65 << mojo::examples::GetApplicationClassName(); |
| 66 | 66 |
| 67 // Call a Mojo core function to demonstrate that the thunks were properly set. | 67 // Call a Mojo core function to demonstrate that the thunks were properly set. |
| 68 MojoTimeTicks ticks = MojoGetTimeTicksNow(); | 68 MojoTimeTicks ticks = MojoGetTimeTicksNow(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 // This is needed only if the application actually needs to access the | 84 // This is needed only if the application actually needs to access the |
| 85 // application context. For instance, GetDeviceName() itself doesn't need it, | 85 // application context. For instance, GetDeviceName() itself doesn't need it, |
| 86 // but we use it for demonstrative purposes in GetApplicationClassName(). | 86 // but we use it for demonstrative purposes in GetApplicationClassName(). |
| 87 extern "C" JNI_EXPORT void InitApplicationContext( | 87 extern "C" JNI_EXPORT void InitApplicationContext( |
| 88 const base::android::JavaRef<jobject>& context) { | 88 const base::android::JavaRef<jobject>& context) { |
| 89 JNIEnv* env = base::android::AttachCurrentThread(); | 89 JNIEnv* env = base::android::AttachCurrentThread(); |
| 90 base::android::InitApplicationContext(env, context); | 90 base::android::InitApplicationContext(env, context); |
| 91 } | 91 } |
| OLD | NEW |