Merge changes I5187d17c,I49a76582
* changes: ConnectivityService: regroup bool <-> int conversions ConnectivityService: move reportNetworkConnectivity to handler
This commit is contained in:
@@ -377,11 +377,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
private static final int EVENT_SET_ACCEPT_UNVALIDATED = 28;
|
private static final int EVENT_SET_ACCEPT_UNVALIDATED = 28;
|
||||||
|
|
||||||
/**
|
|
||||||
* used to specify whether a network should not be penalized when it becomes unvalidated.
|
|
||||||
*/
|
|
||||||
private static final int EVENT_SET_AVOID_UNVALIDATED = 35;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used to ask the user to confirm a connection to an unvalidated network.
|
* used to ask the user to confirm a connection to an unvalidated network.
|
||||||
* obj = network
|
* obj = network
|
||||||
@@ -399,6 +394,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
private static final int EVENT_REGISTER_NETWORK_LISTENER_WITH_INTENT = 31;
|
private static final int EVENT_REGISTER_NETWORK_LISTENER_WITH_INTENT = 31;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used to specify whether a network should not be penalized when it becomes unvalidated.
|
||||||
|
*/
|
||||||
|
private static final int EVENT_SET_AVOID_UNVALIDATED = 35;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used to trigger revalidation of a network.
|
||||||
|
*/
|
||||||
|
private static final int EVENT_REVALIDATE_NETWORK = 36;
|
||||||
|
|
||||||
private static String eventName(int what) {
|
private static String eventName(int what) {
|
||||||
return sMagicDecoderRing.get(what, Integer.toString(what));
|
return sMagicDecoderRing.get(what, Integer.toString(what));
|
||||||
}
|
}
|
||||||
@@ -871,8 +876,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleMobileDataAlwaysOn() {
|
private void handleMobileDataAlwaysOn() {
|
||||||
final boolean enable = (Settings.Global.getInt(
|
final boolean enable = toBool(Settings.Global.getInt(
|
||||||
mContext.getContentResolver(), Settings.Global.MOBILE_DATA_ALWAYS_ON, 1) == 1);
|
mContext.getContentResolver(), Settings.Global.MOBILE_DATA_ALWAYS_ON, 1));
|
||||||
final boolean isEnabled = (mNetworkRequests.get(mDefaultMobileDataRequest) != null);
|
final boolean isEnabled = (mNetworkRequests.get(mDefaultMobileDataRequest) != null);
|
||||||
if (enable == isEnabled) {
|
if (enable == isEnabled) {
|
||||||
return; // Nothing to do.
|
return; // Nothing to do.
|
||||||
@@ -2225,7 +2230,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
case NetworkMonitor.EVENT_PROVISIONING_NOTIFICATION: {
|
case NetworkMonitor.EVENT_PROVISIONING_NOTIFICATION: {
|
||||||
final int netId = msg.arg2;
|
final int netId = msg.arg2;
|
||||||
final boolean visible = (msg.arg1 != 0);
|
final boolean visible = toBool(msg.arg1);
|
||||||
final NetworkAgentInfo nai;
|
final NetworkAgentInfo nai;
|
||||||
synchronized (mNetworkForNetId) {
|
synchronized (mNetworkForNetId) {
|
||||||
nai = mNetworkForNetId.get(netId);
|
nai = mNetworkForNetId.get(netId);
|
||||||
@@ -2678,7 +2683,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
public void setAcceptUnvalidated(Network network, boolean accept, boolean always) {
|
public void setAcceptUnvalidated(Network network, boolean accept, boolean always) {
|
||||||
enforceConnectivityInternalPermission();
|
enforceConnectivityInternalPermission();
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_ACCEPT_UNVALIDATED,
|
mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_ACCEPT_UNVALIDATED,
|
||||||
accept ? 1 : 0, always ? 1: 0, network));
|
encodeBool(accept), encodeBool(always), network));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2715,7 +2720,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
if (always) {
|
if (always) {
|
||||||
nai.asyncChannel.sendMessage(
|
nai.asyncChannel.sendMessage(
|
||||||
NetworkAgent.CMD_SAVE_ACCEPT_UNVALIDATED, accept ? 1 : 0);
|
NetworkAgent.CMD_SAVE_ACCEPT_UNVALIDATED, encodeBool(accept));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!accept) {
|
if (!accept) {
|
||||||
@@ -2916,7 +2921,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EVENT_SET_ACCEPT_UNVALIDATED: {
|
case EVENT_SET_ACCEPT_UNVALIDATED: {
|
||||||
handleSetAcceptUnvalidated((Network) msg.obj, msg.arg1 != 0, msg.arg2 != 0);
|
Network network = (Network) msg.obj;
|
||||||
|
handleSetAcceptUnvalidated(network, toBool(msg.arg1), toBool(msg.arg2));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EVENT_SET_AVOID_UNVALIDATED: {
|
case EVENT_SET_AVOID_UNVALIDATED: {
|
||||||
@@ -2950,6 +2956,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case EVENT_REVALIDATE_NETWORK: {
|
||||||
|
handleReportNetworkConnectivity((Network) msg.obj, msg.arg1, toBool(msg.arg2));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3064,9 +3074,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public boolean isTetheringSupported() {
|
public boolean isTetheringSupported() {
|
||||||
enforceTetherAccessPermission();
|
enforceTetherAccessPermission();
|
||||||
int defaultVal = (mSystemProperties.get("ro.tether.denied").equals("true") ? 0 : 1);
|
int defaultVal = encodeBool(!mSystemProperties.get("ro.tether.denied").equals("true"));
|
||||||
boolean tetherEnabledInSettings = (Settings.Global.getInt(mContext.getContentResolver(),
|
boolean tetherSupported = toBool(Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
Settings.Global.TETHER_SUPPORTED, defaultVal) != 0)
|
Settings.Global.TETHER_SUPPORTED, defaultVal));
|
||||||
|
boolean tetherEnabledInSettings = tetherSupported
|
||||||
&& !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
|
&& !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
|
||||||
|
|
||||||
// Elevate to system UID to avoid caller requiring MANAGE_USERS permission.
|
// Elevate to system UID to avoid caller requiring MANAGE_USERS permission.
|
||||||
@@ -3078,8 +3089,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tetherEnabledInSettings && adminUser &&
|
return tetherEnabledInSettings && adminUser && mTethering.hasTetherableConfiguration();
|
||||||
mTethering.hasTetherableConfiguration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -3157,8 +3167,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
|
public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
enforceInternetPermission();
|
enforceInternetPermission();
|
||||||
|
final int uid = Binder.getCallingUid();
|
||||||
|
final int connectivityInfo = encodeBool(hasConnectivity);
|
||||||
|
mHandler.sendMessage(
|
||||||
|
mHandler.obtainMessage(EVENT_REVALIDATE_NETWORK, uid, connectivityInfo, network));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: execute this logic on ConnectivityService handler.
|
private void handleReportNetworkConnectivity(
|
||||||
|
Network network, int uid, boolean hasConnectivity) {
|
||||||
final NetworkAgentInfo nai;
|
final NetworkAgentInfo nai;
|
||||||
if (network == null) {
|
if (network == null) {
|
||||||
nai = getDefaultNetwork();
|
nai = getDefaultNetwork();
|
||||||
@@ -3173,10 +3189,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (hasConnectivity == nai.lastValidated) {
|
if (hasConnectivity == nai.lastValidated) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int uid = Binder.getCallingUid();
|
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
log("reportNetworkConnectivity(" + nai.network.netId + ", " + hasConnectivity +
|
int netid = nai.network.netId;
|
||||||
") by " + uid);
|
log("reportNetworkConnectivity(" + netid + ", " + hasConnectivity + ") by " + uid);
|
||||||
}
|
}
|
||||||
// Validating a network that has not yet connected could result in a call to
|
// Validating a network that has not yet connected could result in a call to
|
||||||
// rematchNetworkAndRequests() which is not meant to work on such networks.
|
// rematchNetworkAndRequests() which is not meant to work on such networks.
|
||||||
@@ -3879,7 +3894,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
final ContentResolver cr = mContext.getContentResolver();
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, enable ? 1 : 0);
|
Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, encodeBool(enable));
|
||||||
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||||
intent.putExtra("state", enable);
|
intent.putExtra("state", enable);
|
||||||
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
|
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
|
||||||
@@ -5555,4 +5570,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private void logNetworkEvent(NetworkAgentInfo nai, int evtype) {
|
private void logNetworkEvent(NetworkAgentInfo nai, int evtype) {
|
||||||
mMetricsLog.log(new NetworkEvent(nai.network.netId, evtype));
|
mMetricsLog.log(new NetworkEvent(nai.network.netId, evtype));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean toBool(int encodedBoolean) {
|
||||||
|
return encodedBoolean != 0; // Only 0 means false.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int encodeBool(boolean b) {
|
||||||
|
return b ? 1 : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user