Skip to content

Commit

Permalink
Move android Telephony APIs from content/ to net/.
Browse files Browse the repository at this point in the history
This is needed for logging operator code in net/. See
https://codereview.chromium.org/246553003/

BUG=355604

Review URL: https://codereview.chromium.org/254823005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267437 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bolian@chromium.org committed May 1, 2014
1 parent dfb4832 commit 74d9c52
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 155 deletions.
3 changes: 0 additions & 3 deletions content/common/android/common_jni_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "content/common/android/device_telephony_info.h"
#include "content/common/android/hash_set.h"

namespace {
base::android::RegistrationMethod kContentRegisteredMethods[] = {
{ "DeviceTelephonyInfo",
content::DeviceTelephonyInfo::RegisterDeviceTelephonyInfo },
{ "HashSet", content::RegisterHashSet },
};

Expand Down
46 changes: 0 additions & 46 deletions content/common/android/device_telephony_info.cc

This file was deleted.

41 changes: 0 additions & 41 deletions content/common/android/device_telephony_info.h

This file was deleted.

2 changes: 0 additions & 2 deletions content/content_common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@
'common/android/address_parser_internal.h',
'common/android/common_jni_registrar.cc',
'common/android/common_jni_registrar.h',
'common/android/device_telephony_info.cc',
'common/android/device_telephony_info.h',
'common/android/gin_java_bridge_value.cc',
'common/android/gin_java_bridge_value.h',
'common/android/hash_set.cc',
Expand Down
1 change: 0 additions & 1 deletion content/content_jni.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
'public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java',
'public/android/java/src/org/chromium/content/browser/framehost/NavigationControllerImpl.java',
'public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java',
'public/android/java/src/org/chromium/content/common/DeviceTelephonyInfo.java',
],
'variables': {
'jni_gen_package': 'content',
Expand Down

This file was deleted.

6 changes: 2 additions & 4 deletions content/renderer/render_view_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
#if defined(OS_ANDROID)
#include <cpu-features.h>

#include "content/common/android/device_telephony_info.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "content/renderer/android/address_detector.h"
#include "content/renderer/android/content_detector.h"
Expand All @@ -214,6 +213,7 @@
#include "content/renderer/media/android/renderer_media_player_manager.h"
#include "content/renderer/media/android/stream_texture_factory_impl.h"
#include "content/renderer/media/android/webmediaplayer_android.h"
#include "net/android/network_library.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/WebFloatPoint.h"
#include "third_party/WebKit/public/platform/WebFloatRect.h"
Expand Down Expand Up @@ -726,12 +726,10 @@ void RenderViewImpl::Initialize(RenderViewImplParams* params) {
stats_collection_observer_.reset(new StatsCollectionObserver(this));

#if defined(OS_ANDROID)
content::DeviceTelephonyInfo device_info;

const std::string region_code =
command_line.HasSwitch(switches::kNetworkCountryIso)
? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
: device_info.GetNetworkCountryIso();
: net::android::GetTelephonyNetworkOperator();
content_detectors_.push_back(linked_ptr<ContentDetector>(
new AddressDetector()));
content_detectors_.push_back(linked_ptr<ContentDetector>(
Expand Down
29 changes: 29 additions & 0 deletions net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Context;
import android.content.Intent;
import android.security.KeyChain;
import android.telephony.TelephonyManager;
import android.util.Log;

import org.chromium.base.CalledByNative;
Expand Down Expand Up @@ -238,4 +239,32 @@ public static void clearTestRootCertificates() throws NoSuchAlgorithmException,
CertificateException, KeyStoreException {
X509Util.clearTestRootCertificates();
}

/**
* Returns the ISO country code equivalent of the current MCC.
*/
@CalledByNative
private static String getNetworkCountryIso(Context context) {
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
return telephonyManager.getNetworkCountryIso();
}
return "";
}

/**
* Returns the MCC+MNC (mobile country code + mobile network code) as
* the numeric name of the current registered operator.
*/
@CalledByNative
private static String getNetworkOperator(Context context) {
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
return telephonyManager.getNetworkOperator();
}
return "";
}

}
14 changes: 14 additions & 0 deletions net/android/network_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ bool GetMimeTypeFromExtension(const std::string& extension,
return true;
}

std::string GetTelephonyNetworkCountryIso() {
return base::android::ConvertJavaStringToUTF8(
Java_AndroidNetworkLibrary_getNetworkCountryIso(
base::android::AttachCurrentThread(),
base::android::GetApplicationContext()));
}

std::string GetTelephonyNetworkOperator() {
return base::android::ConvertJavaStringToUTF8(
Java_AndroidNetworkLibrary_getNetworkOperator(
base::android::AttachCurrentThread(),
base::android::GetApplicationContext()));
}

bool RegisterNetworkLibrary(JNIEnv* env) {
return RegisterNativesImpl(env);
}
Expand Down
8 changes: 8 additions & 0 deletions net/android/network_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ std::string GetNetworkList();
bool GetMimeTypeFromExtension(const std::string& extension,
std::string* result);

// Returns the ISO country code equivalent of the current MCC (mobile country
// code).
NET_EXPORT std::string GetTelephonyNetworkCountryIso();

// Returns MCC+MNC (mobile country code + mobile network code) as
// the numeric name of the current registered operator.
NET_EXPORT std::string GetTelephonyNetworkOperator();

// Register JNI methods
NET_EXPORT bool RegisterNetworkLibrary(JNIEnv* env);

Expand Down

0 comments on commit 74d9c52

Please sign in to comment.