[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / content / common / android / device_info.cc
blob2522cae160aa0b60925ba4c9e5cace2519502182
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/android/device_info.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/logging.h"
10 #include "jni/DeviceInfo_jni.h"
12 using base::android::AttachCurrentThread;
13 using base::android::ConvertJavaStringToUTF8;
14 using base::android::ScopedJavaLocalRef;
16 namespace content {
18 DeviceInfo::DeviceInfo() {
19 JNIEnv* env = AttachCurrentThread();
20 j_device_info_.Reset(Java_DeviceInfo_create(env,
21 base::android::GetApplicationContext()));
24 DeviceInfo::~DeviceInfo() {
27 int DeviceInfo::GetHeight() {
28 JNIEnv* env = AttachCurrentThread();
29 jint result =
30 Java_DeviceInfo_getHeight(env, j_device_info_.obj());
31 return static_cast<int>(result);
34 int DeviceInfo::GetWidth() {
35 JNIEnv* env = AttachCurrentThread();
36 jint result =
37 Java_DeviceInfo_getWidth(env, j_device_info_.obj());
38 return static_cast<int>(result);
41 int DeviceInfo::GetBitsPerPixel() {
42 JNIEnv* env = AttachCurrentThread();
43 jint result =
44 Java_DeviceInfo_getBitsPerPixel(env, j_device_info_.obj());
45 return static_cast<int>(result);
48 int DeviceInfo::GetBitsPerComponent() {
49 JNIEnv* env = AttachCurrentThread();
50 jint result =
51 Java_DeviceInfo_getBitsPerComponent(env, j_device_info_.obj());
52 return static_cast<int>(result);
55 double DeviceInfo::GetDPIScale() {
56 JNIEnv* env = AttachCurrentThread();
57 jdouble result =
58 Java_DeviceInfo_getDPIScale(env, j_device_info_.obj());
59 return static_cast<double>(result);
62 double DeviceInfo::GetRefreshRate() {
63 JNIEnv* env = AttachCurrentThread();
64 jdouble result =
65 Java_DeviceInfo_getRefreshRate(env, j_device_info_.obj());
66 return static_cast<double>(result);
69 std::string DeviceInfo::GetNetworkCountryIso() {
70 JNIEnv* env = AttachCurrentThread();
71 ScopedJavaLocalRef<jstring> result =
72 Java_DeviceInfo_getNetworkCountryIso(env, j_device_info_.obj());
73 return ConvertJavaStringToUTF8(result);
76 bool RegisterDeviceInfo(JNIEnv* env) {
77 return RegisterNativesImpl(env);
80 } // namespace content