Browse files

Bug 691054 - Back out bug 667980 (getNetworkLinkType) on Android beca…

…use of scary permissions [r=dougt, a=LegNeato]
  • Loading branch information...
1 parent 3447c25 commit a839fe14259950aef8b4aeeb19a530764bcdd3e8 @mbrubeck mbrubeck committed Oct 4, 2011
View
1 embedding/android/AndroidManifest.xml.in
@@ -16,7 +16,6 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-feature android:name="android.hardware.location" android:required="false"/>
View
15 embedding/android/GeckoApp.java
@@ -61,7 +61,6 @@
import android.net.*;
import android.database.*;
import android.provider.*;
-import android.telephony.*;
abstract public class GeckoApp
extends Activity
@@ -81,7 +80,6 @@
public Handler mMainHandler;
private IntentFilter mConnectivityFilter;
private BroadcastReceiver mConnectivityReceiver;
- private PhoneStateListener mPhoneStateListener;
enum LaunchState {PreLaunch, Launching, WaitButton,
Launched, GeckoRunning, GeckoExiting};
@@ -242,8 +240,6 @@ public void run() {
mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
mConnectivityReceiver = new GeckoConnectivityReceiver();
- mPhoneStateListener = new GeckoPhoneStateListener();
-
if (!checkAndSetLaunchState(LaunchState.PreLaunch,
LaunchState.Launching))
return;
@@ -354,10 +350,6 @@ public void onPause()
super.onPause();
unregisterReceiver(mConnectivityReceiver);
-
- TelephonyManager tm = (TelephonyManager)
- GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
- tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}
@Override
@@ -376,13 +368,6 @@ public void onResume()
onNewIntent(getIntent());
registerReceiver(mConnectivityReceiver, mConnectivityFilter);
-
- TelephonyManager tm = (TelephonyManager)
- GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
- tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
-
- // Notify if network state changed since we paused
- GeckoAppShell.onNetworkStateChange(true);
}
@Override
View
98 embedding/android/GeckoAppShell.java
@@ -58,7 +58,6 @@
import android.widget.*;
import android.hardware.*;
import android.location.*;
-import android.telephony.*;
import android.webkit.MimeTypeMap;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
@@ -96,10 +95,6 @@ private GeckoAppShell() { }
static private File sCacheFile = null;
static private int sFreeSpace = -1;
- static private String sNetworkState = "unknown";
- static private String sNetworkType = "unknown";
- static private int sNetworkTypeCode = 0;
-
/* The Android-side API: API methods that Android calls */
// Initialization methods
@@ -114,7 +109,7 @@ private GeckoAppShell() { }
public static native void callObserver(String observerKey, String topic, String data);
public static native void removeObserver(String observerKey);
public static native void loadLibs(String apkName, boolean shouldExtract);
- public static native void onChangeNetworkLinkStatus(String status, String type);
+ public static native void onChangeNetworkLinkStatus(String status);
public static native void reportJavaCrash(String stack);
// A looper thread, accessed by GeckoAppShell.getHandler
@@ -663,9 +658,6 @@ static void onAppShellReady()
// mLaunchState can only be Launched at this point
GeckoApp.setLaunchState(GeckoApp.LaunchState.GeckoRunning);
sendPendingEventsToGecko();
-
- // Refresh the network connectivity state
- onNetworkStateChange(false);
}
static void onXreExit() {
@@ -1028,92 +1020,20 @@ public void run() {
}
public static boolean isNetworkLinkUp() {
- if (sNetworkState == "up")
- return true;
- return false;
- }
-
- public static boolean isNetworkLinkKnown() {
- if (sNetworkState == "unknown")
+ ConnectivityManager cm = (ConnectivityManager)
+ GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo info = cm.getActiveNetworkInfo();
+ if (info == null || !info.isConnected())
return false;
return true;
}
- public static int getNetworkLinkType() {
- return sNetworkTypeCode;
- }
-
- public static void onNetworkStateChange(boolean notifyChanged) {
- String state;
- String type;
- int typeCode;
-
+ public static boolean isNetworkLinkKnown() {
ConnectivityManager cm = (ConnectivityManager)
GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo info = cm.getActiveNetworkInfo();
-
- // Note, these strings and codes correspond to those specified in
- // nsINetworkLinkService. Make sure to keep them in sync!
- type = "unknown";
- typeCode = 0;
- if (info == null) {
- state = "unknown";
- } else if (!info.isConnected()) {
- state = "down";
- } else {
- state = "up";
-
- int androidType = info.getType();
-
- if (androidType == ConnectivityManager.TYPE_WIFI) {
- type = "wifi";
- typeCode = 3;
- } else if (androidType == ConnectivityManager.TYPE_WIMAX) {
- type = "wimax";
- typeCode = 4;
- } else if (androidType == ConnectivityManager.TYPE_MOBILE) {
- TelephonyManager tm = (TelephonyManager)
- GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
- typeCode = tm.getNetworkType();
-
- // Note that the value of some of these constants are used due
- // to not all of these existing in API level 8.
- //
- // In particular, EVDO_B appears at level 9, and EHRPD and LTE
- // appear at level 11.
- if (androidType == TelephonyManager.NETWORK_TYPE_GPRS ||
- androidType == TelephonyManager.NETWORK_TYPE_EDGE ||
- androidType == TelephonyManager.NETWORK_TYPE_CDMA ||
- androidType == TelephonyManager.NETWORK_TYPE_IDEN ||
- androidType == TelephonyManager.NETWORK_TYPE_1xRTT) {
- type = "2g";
- typeCode = 5;
- } else if (androidType == TelephonyManager.NETWORK_TYPE_UMTS ||
- androidType == TelephonyManager.NETWORK_TYPE_HSDPA ||
- androidType == TelephonyManager.NETWORK_TYPE_HSUPA ||
- androidType == TelephonyManager.NETWORK_TYPE_HSPA ||
- androidType == TelephonyManager.NETWORK_TYPE_EVDO_0 ||
- androidType == TelephonyManager.NETWORK_TYPE_EVDO_A ||
- androidType == 12 || // TelephonyManager.NETWORK_TYPE_EVDO_B
- androidType == 14) { // TelephonyManager.NETWORK_TYPE_EHRPD
- type = "3g";
- typeCode = 6;
- } else if (androidType == 13) { // TelephonyManager.NETWORK_TYPE_LTE
- type = "4g";
- typeCode = 7;
- }
- }
- }
-
- // If the network state has changed, notify Gecko
- if (notifyChanged && (state != sNetworkState || typeCode != sNetworkTypeCode)) {
- Log.i("GeckoAppShell", "Network state changed: (" + state + ", " + type + ") ");
- sNetworkState = state;
- sNetworkType = type;
- sNetworkTypeCode = typeCode;
- if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning))
- onChangeNetworkLinkStatus(sNetworkState, sNetworkType);
- }
+ if (cm.getActiveNetworkInfo() == null)
+ return false;
+ return true;
}
public static void setSelectedLocale(String localeCode) {
View
15 embedding/android/GeckoConnectivityReceiver.java
@@ -38,12 +38,25 @@
package org.mozilla.gecko;
import android.content.*;
+import android.net.*;
public class GeckoConnectivityReceiver
extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
- GeckoAppShell.onNetworkStateChange(true);
+ String status;
+ ConnectivityManager cm = (ConnectivityManager)
+ context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo info = cm.getActiveNetworkInfo();
+ if (info == null)
+ status = "unknown";
+ else if (!info.isConnected())
+ status = "down";
+ else
+ status = "up";
+
+ if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning))
+ GeckoAppShell.onChangeNetworkLinkStatus(status);
}
}
View
50 embedding/android/GeckoPhoneStateListener.java
@@ -1,50 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Chris Lord <chrislord.net@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-package org.mozilla.gecko;
-
-import android.telephony.*;
-
-public class GeckoPhoneStateListener
- extends PhoneStateListener
-{
- @Override
- public void onDataConnectionStateChanged(int state, int networkType) {
- GeckoAppShell.onNetworkStateChange(true);
- }
-}
-
View
1 embedding/android/Makefile.in
@@ -52,7 +52,6 @@ JAVAFILES = \
GeckoEvent.java \
GeckoSurfaceView.java \
GeckoInputConnection.java \
- GeckoPhoneStateListener.java \
AlertNotification.java \
$(NULL)
View
4 netwerk/system/android/nsAndroidNetworkLinkService.cpp
@@ -80,8 +80,8 @@ NS_IMETHODIMP
nsAndroidNetworkLinkService::GetLinkType(PRUint32 *aLinkType)
{
NS_ENSURE_ARG_POINTER(aLinkType);
- NS_ENSURE_TRUE(mozilla::AndroidBridge::Bridge(), NS_ERROR_UNEXPECTED);
- *aLinkType = mozilla::AndroidBridge::Bridge()->GetNetworkLinkType();
+ // XXX This function has not yet been implemented for this platform
+ *aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN;
return NS_OK;
}
View
2 other-licenses/android/APKOpen.cpp
@@ -238,7 +238,7 @@ SHELL_WRAPPER0(onResume)
SHELL_WRAPPER0(onLowMemory)
SHELL_WRAPPER3(callObserver, jstring, jstring, jstring)
SHELL_WRAPPER1(removeObserver, jstring)
-SHELL_WRAPPER2(onChangeNetworkLinkStatus, jstring, jstring)
+SHELL_WRAPPER1(onChangeNetworkLinkStatus, jstring)
SHELL_WRAPPER1(reportJavaCrash, jstring)
static void * xul_handle = NULL;
View
9 widget/src/android/AndroidBridge.cpp
@@ -48,7 +48,6 @@
#include "nsOSHelperAppService.h"
#include "nsWindow.h"
#include "mozilla/Preferences.h"
-#include "nsINetworkLinkService.h"
#ifdef DEBUG
#define ALOG_BRIDGE(args...) ALOG(args)
@@ -142,7 +141,6 @@ AndroidBridge::Init(JNIEnv *jEnv,
jSetKeepScreenOn = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setKeepScreenOn", "(Z)V");
jIsNetworkLinkUp = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "isNetworkLinkUp", "()Z");
jIsNetworkLinkKnown = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "isNetworkLinkKnown", "()Z");
- jGetNetworkLinkType = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getNetworkLinkType", "()I");
jSetSelectedLocale = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setSelectedLocale", "(Ljava/lang/String;)V");
jScanMedia = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scanMedia", "(Ljava/lang/String;Ljava/lang/String;)V");
jGetSystemColors = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getSystemColors", "()[I");
@@ -673,13 +671,6 @@ AndroidBridge::IsNetworkLinkKnown()
return !!mJNIEnv->CallStaticBooleanMethod(mGeckoAppShellClass, jIsNetworkLinkKnown);
}
-int
-AndroidBridge::GetNetworkLinkType()
-{
- ALOG_BRIDGE("AndroidBridge::GetNetworkLinkType");
- return (int) mJNIEnv->CallStaticIntMethod(mGeckoAppShellClass, jGetNetworkLinkType);
-}
-
void
AndroidBridge::SetSelectedLocale(const nsAString& aLocale)
{
View
3 widget/src/android/AndroidBridge.h
@@ -204,8 +204,6 @@ class AndroidBridge
bool IsNetworkLinkKnown();
- int GetNetworkLinkType();
-
void SetSelectedLocale(const nsAString&);
void GetSystemColors(AndroidSystemColors *aColors);
@@ -318,7 +316,6 @@ class AndroidBridge
jmethodID jSetKeepScreenOn;
jmethodID jIsNetworkLinkUp;
jmethodID jIsNetworkLinkKnown;
- jmethodID jGetNetworkLinkType;
jmethodID jSetSelectedLocale;
jmethodID jScanMedia;
jmethodID jGetSystemColors;
View
10 widget/src/android/AndroidJNI.cpp
@@ -69,7 +69,7 @@ extern "C" {
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onLowMemory(JNIEnv *, jclass);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_callObserver(JNIEnv *, jclass, jstring observerKey, jstring topic, jstring data);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_removeObserver(JNIEnv *jenv, jclass, jstring jObserverKey);
- NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onChangeNetworkLinkStatus(JNIEnv *, jclass, jstring status, jstring type);
+ NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onChangeNetworkLinkStatus(JNIEnv *, jclass, jstring status);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_reportJavaCrash(JNIEnv *, jclass, jstring stack);
}
@@ -143,7 +143,7 @@ Java_org_mozilla_gecko_GeckoAppShell_removeObserver(JNIEnv *jenv, jclass, jstrin
}
NS_EXPORT void JNICALL
-Java_org_mozilla_gecko_GeckoAppShell_onChangeNetworkLinkStatus(JNIEnv *jenv, jclass, jstring jStatus, jstring jType)
+Java_org_mozilla_gecko_GeckoAppShell_onChangeNetworkLinkStatus(JNIEnv *jenv, jclass, jstring jStatus)
{
if (!nsAppShell::gAppShell)
return;
@@ -153,12 +153,6 @@ Java_org_mozilla_gecko_GeckoAppShell_onChangeNetworkLinkStatus(JNIEnv *jenv, jcl
nsAppShell::gAppShell->NotifyObservers(nsnull,
NS_NETWORK_LINK_TOPIC,
sStatus.get());
-
- nsJNIString sType(jType, jenv);
-
- nsAppShell::gAppShell->NotifyObservers(nsnull,
- NS_NETWORK_LINK_TYPE_TOPIC,
- sType.get());
}
NS_EXPORT void JNICALL

0 comments on commit a839fe1

Please sign in to comment.