Bug 691054 - Back out bug 667980 (getNetworkLinkType) on Android because of scary permissions [r=dougt]

This commit is contained in:
Matt Brubeck 2011-10-03 16:34:43 -07:00
Родитель e5f6505935
Коммит 022b0c3f9e
11 изменённых файлов: 28 добавлений и 180 удалений

Просмотреть файл

@ -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-permission android:name="android.permission.READ_LOGS"/>

Просмотреть файл

@ -62,7 +62,6 @@ import android.util.*;
import android.net.*;
import android.database.*;
import android.provider.*;
import android.telephony.*;
import android.content.pm.*;
import android.content.pm.PackageManager.*;
import dalvik.system.*;
@ -87,7 +86,6 @@ abstract public class GeckoApp
public Handler mMainHandler;
private IntentFilter mConnectivityFilter;
private BroadcastReceiver mConnectivityReceiver;
private PhoneStateListener mPhoneStateListener;
enum LaunchState {PreLaunch, Launching, WaitButton,
Launched, GeckoRunning, GeckoExiting};
@ -398,8 +396,6 @@ abstract public class GeckoApp
mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
mConnectivityReceiver = new GeckoConnectivityReceiver();
mPhoneStateListener = new GeckoPhoneStateListener();
if (!checkAndSetLaunchState(LaunchState.PreLaunch,
LaunchState.Launching))
return;
@ -485,10 +481,6 @@ abstract public class GeckoApp
super.onPause();
unregisterReceiver(mConnectivityReceiver);
TelephonyManager tm = (TelephonyManager)
GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}
@Override
@ -507,13 +499,6 @@ abstract public class GeckoApp
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

Просмотреть файл

@ -58,7 +58,6 @@ import android.graphics.*;
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 @@ public class 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 @@ public class 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);
public static native void processNextNativeEvent();
@ -681,9 +676,6 @@ public class GeckoAppShell
// mLaunchState can only be Launched at this point
GeckoApp.setLaunchState(GeckoApp.LaunchState.GeckoRunning);
sendPendingEventsToGecko();
// Refresh the network connectivity state
onNetworkStateChange(false);
}
static void onXreExit() {
@ -1067,92 +1059,20 @@ public class GeckoAppShell
}
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(LOG_FILE_NAME, "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) {

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -52,7 +52,6 @@ JAVAFILES = \
GeckoEvent.java \
GeckoSurfaceView.java \
GeckoInputConnection.java \
GeckoPhoneStateListener.java \
AlertNotification.java \
SurfaceLockInfo.java \
$(NULL)

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -237,7 +237,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)
SHELL_WRAPPER0(executeNextRunnable)
SHELL_WRAPPER1(cameraCallbackBridge, jbyteArray)

Просмотреть файл

@ -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)
@ -143,7 +142,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");
@ -685,13 +683,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)
{

Просмотреть файл

@ -205,8 +205,6 @@ public:
bool IsNetworkLinkKnown();
int GetNetworkLinkType();
void SetSelectedLocale(const nsAString&);
void GetSystemColors(AndroidSystemColors *aColors);
@ -348,7 +346,6 @@ protected:
jmethodID jSetKeepScreenOn;
jmethodID jIsNetworkLinkUp;
jmethodID jIsNetworkLinkKnown;
jmethodID jGetNetworkLinkType;
jmethodID jSetSelectedLocale;
jmethodID jScanMedia;
jmethodID jGetSystemColors;

Просмотреть файл

@ -70,7 +70,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);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_executeNextRunnable(JNIEnv *, jclass);
}
@ -153,7 +153,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;
@ -163,12 +163,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