Merge "Internal API for system apps to determine default network for other apps" into nyc-dev am: 80f2000
am: a948f88 * commit 'a948f8872aa045ab22f42285f195fdb413c5ff66': Internal API for system apps to determine default network for other apps Change-Id: Ib719f0cebb41afe4aa52241f3797598a7e468d2d
This commit is contained in:
@@ -766,6 +766,28 @@ public class ConnectivityManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Network} object corresponding to the currently active
|
||||
* default data network for a specific UID. In the event that the default data
|
||||
* network disconnects, the returned {@code Network} object will no longer
|
||||
* be usable. This will return {@code null} when there is no default
|
||||
* network for the UID.
|
||||
* <p>This method requires the caller to hold the permission
|
||||
* {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
|
||||
*
|
||||
* @return a {@link Network} object for the current default network for the
|
||||
* given UID or {@code null} if no default network is currently active
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public Network getActiveNetworkForUid(int uid) {
|
||||
try {
|
||||
return mService.getActiveNetworkForUid(uid);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures an always-on VPN connection through a specific application.
|
||||
* This connection is automatically granted and persisted after a reboot.
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.android.internal.net.VpnProfile;
|
||||
interface IConnectivityManager
|
||||
{
|
||||
Network getActiveNetwork();
|
||||
Network getActiveNetworkForUid(int uid);
|
||||
NetworkInfo getActiveNetworkInfo();
|
||||
NetworkInfo getActiveNetworkInfoForUid(int uid);
|
||||
NetworkInfo getNetworkInfo(int networkType);
|
||||
|
||||
@@ -991,7 +991,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
@Override
|
||||
public Network getActiveNetwork() {
|
||||
enforceAccessPermission();
|
||||
final int uid = Binder.getCallingUid();
|
||||
return getActiveNetworkForUidInternal(Binder.getCallingUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Network getActiveNetworkForUid(int uid) {
|
||||
enforceConnectivityInternalPermission();
|
||||
return getActiveNetworkForUidInternal(uid);
|
||||
}
|
||||
|
||||
private Network getActiveNetworkForUidInternal(final int uid) {
|
||||
final int user = UserHandle.getUserId(uid);
|
||||
int vpnNetId = NETID_UNSET;
|
||||
synchronized (mVpns) {
|
||||
|
||||
@@ -59,6 +59,7 @@ import android.os.Message;
|
||||
import android.os.MessageQueue;
|
||||
import android.os.Messenger;
|
||||
import android.os.MessageQueue.IdleHandler;
|
||||
import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
@@ -690,6 +691,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertEquals(transportToLegacyType(transport), mCm.getActiveNetworkInfo().getType());
|
||||
// Test getActiveNetwork()
|
||||
assertNotNull(mCm.getActiveNetwork());
|
||||
assertEquals(mCm.getActiveNetwork(), mCm.getActiveNetworkForUid(Process.myUid()));
|
||||
switch (transport) {
|
||||
case TRANSPORT_WIFI:
|
||||
assertEquals(mCm.getActiveNetwork(), mWiFiNetworkAgent.getNetwork());
|
||||
@@ -713,6 +715,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertNull(mCm.getActiveNetworkInfo());
|
||||
// Test getActiveNetwork()
|
||||
assertNull(mCm.getActiveNetwork());
|
||||
assertNull(mCm.getActiveNetworkForUid(Process.myUid()));
|
||||
// Test getAllNetworks()
|
||||
assertEquals(0, mCm.getAllNetworks().length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user