Merge "Some cleanups for Tethering"

This commit is contained in:
Mark Chien
2019-04-03 10:16:25 +00:00
committed by Gerrit Code Review
3 changed files with 22 additions and 25 deletions

View File

@@ -2617,7 +2617,7 @@ public class ConnectivityManager {
/** /**
* Start listening to tethering change events. Any new added callback will receive the last * Start listening to tethering change events. Any new added callback will receive the last
* tethering status right away. If callback is registered when tethering loses its upstream or * tethering status right away. If callback is registered when tethering has no upstream or
* disabled, {@link OnTetheringEventCallback#onUpstreamChanged} will immediately be called * disabled, {@link OnTetheringEventCallback#onUpstreamChanged} will immediately be called
* with a null argument. The same callback object cannot be registered twice. * with a null argument. The same callback object cannot be registered twice.
* *

View File

@@ -52,7 +52,6 @@ import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.Log;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
@@ -231,7 +230,7 @@ public class EntitlementManager {
private void handleNotifyUpstream(boolean isCellular) { private void handleNotifyUpstream(boolean isCellular) {
if (DBG) { if (DBG) {
Log.d(TAG, "notifyUpstream: " + isCellular mLog.i("notifyUpstream: " + isCellular
+ ", mCellularUpstreamPermitted: " + mCellularUpstreamPermitted + ", mCellularUpstreamPermitted: " + mCellularUpstreamPermitted
+ ", mNeedReRunProvisioningUi: " + mNeedReRunProvisioningUi); + ", mNeedReRunProvisioningUi: " + mNeedReRunProvisioningUi);
} }
@@ -294,7 +293,7 @@ public class EntitlementManager {
* masterHandler to avoid race conditions. * masterHandler to avoid race conditions.
*/ */
public void reevaluateSimCardProvisioning() { public void reevaluateSimCardProvisioning() {
if (DBG) Log.d(TAG, "reevaluateSimCardProvisioning"); if (DBG) mLog.i("reevaluateSimCardProvisioning");
if (!mHandler.getLooper().isCurrentThread()) { if (!mHandler.getLooper().isCurrentThread()) {
// Except for test, this log should not appear in normal flow. // Except for test, this log should not appear in normal flow.
@@ -351,7 +350,7 @@ public class EntitlementManager {
* @param type tethering type from ConnectivityManager.TETHERING_{@code *} * @param type tethering type from ConnectivityManager.TETHERING_{@code *}
*/ */
protected void runSilentTetherProvisioning(int type) { protected void runSilentTetherProvisioning(int type) {
if (DBG) Log.d(TAG, "runSilentTetherProvisioning: " + type); if (DBG) mLog.i("runSilentTetherProvisioning: " + type);
// For silent provisioning, settings would stop tethering when entitlement fail. // For silent provisioning, settings would stop tethering when entitlement fail.
ResultReceiver receiver = buildProxyReceiver(type, ResultReceiver receiver = buildProxyReceiver(type,
false/* notifyFail */, null); false/* notifyFail */, null);
@@ -382,7 +381,7 @@ public class EntitlementManager {
@VisibleForTesting @VisibleForTesting
protected void runUiTetherProvisioning(int type, ResultReceiver receiver) { protected void runUiTetherProvisioning(int type, ResultReceiver receiver) {
if (DBG) Log.d(TAG, "runUiTetherProvisioning: " + type); if (DBG) mLog.i("runUiTetherProvisioning: " + type);
Intent intent = new Intent(Settings.ACTION_TETHER_PROVISIONING); Intent intent = new Intent(Settings.ACTION_TETHER_PROVISIONING);
intent.putExtra(EXTRA_ADD_TETHER_TYPE, type); intent.putExtra(EXTRA_ADD_TETHER_TYPE, type);
@@ -428,7 +427,7 @@ public class EntitlementManager {
|| mCellularPermitted.indexOfValue(TETHER_ERROR_NO_ERROR) > -1); || mCellularPermitted.indexOfValue(TETHER_ERROR_NO_ERROR) > -1);
if (DBG) { if (DBG) {
Log.d(TAG, "Cellular permission change from " + oldPermitted mLog.i("Cellular permission change from " + oldPermitted
+ " to " + mCellularUpstreamPermitted); + " to " + mCellularUpstreamPermitted);
} }
@@ -453,10 +452,8 @@ public class EntitlementManager {
* @param resultCode Provisioning result * @param resultCode Provisioning result
*/ */
protected void addDownstreamMapping(int type, int resultCode) { protected void addDownstreamMapping(int type, int resultCode) {
if (DBG) { mLog.i("addDownstreamMapping: " + type + ", result: " + resultCode
Log.d(TAG, "addDownstreamMapping: " + type + ", result: " + resultCode
+ " ,TetherTypeRequested: " + mCurrentTethers.contains(type)); + " ,TetherTypeRequested: " + mCurrentTethers.contains(type));
}
if (!mCurrentTethers.contains(type)) return; if (!mCurrentTethers.contains(type)) return;
mCellularPermitted.put(type, resultCode); mCellularPermitted.put(type, resultCode);
@@ -468,7 +465,7 @@ public class EntitlementManager {
* @param type tethering type from ConnectivityManager.TETHERING_{@code *} * @param type tethering type from ConnectivityManager.TETHERING_{@code *}
*/ */
protected void removeDownstreamMapping(int type) { protected void removeDownstreamMapping(int type) {
if (DBG) Log.d(TAG, "removeDownstreamMapping: " + type); mLog.i("removeDownstreamMapping: " + type);
mCellularPermitted.delete(type); mCellularPermitted.delete(type);
evaluateCellularPermission(); evaluateCellularPermission();
} }
@@ -617,7 +614,7 @@ public class EntitlementManager {
*/ */
private int updateEntitlementCacheValue(int type, int resultCode) { private int updateEntitlementCacheValue(int type, int resultCode) {
if (DBG) { if (DBG) {
Log.d(TAG, "updateEntitlementCacheValue: " + type + ", result: " + resultCode); mLog.i("updateEntitlementCacheValue: " + type + ", result: " + resultCode);
} }
if (resultCode == TETHER_ERROR_NO_ERROR) { if (resultCode == TETHER_ERROR_NO_ERROR) {
mEntitlementCacheValue.put(type, resultCode); mEntitlementCacheValue.put(type, resultCode);

View File

@@ -122,7 +122,7 @@ public class TetheringConfigurationTest {
mMockContext = new MockContext(mContext); mMockContext = new MockContext(mContext);
} }
private TetheringConfiguration getTetheringConfiguration(int[] legacyTetherUpstreamTypes) { private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
when(mResources.getIntArray(config_tether_upstream_types)).thenReturn( when(mResources.getIntArray(config_tether_upstream_types)).thenReturn(
legacyTetherUpstreamTypes); legacyTetherUpstreamTypes);
return new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID); return new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
@@ -143,13 +143,13 @@ public class TetheringConfigurationTest {
public void testDunFromTelephonyManagerMeansDun() { public void testDunFromTelephonyManagerMeansDun() {
when(mTelephonyManager.getTetherApnRequired()).thenReturn(true); when(mTelephonyManager.getTetherApnRequired()).thenReturn(true);
final TetheringConfiguration cfgWifi = getTetheringConfiguration(new int[]{TYPE_WIFI}); final TetheringConfiguration cfgWifi = getTetheringConfiguration(TYPE_WIFI);
final TetheringConfiguration cfgMobileWifiHipri = getTetheringConfiguration( final TetheringConfiguration cfgMobileWifiHipri = getTetheringConfiguration(
new int[]{TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI}); TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI);
final TetheringConfiguration cfgWifiDun = getTetheringConfiguration( final TetheringConfiguration cfgWifiDun = getTetheringConfiguration(
new int[]{TYPE_WIFI, TYPE_MOBILE_DUN}); TYPE_WIFI, TYPE_MOBILE_DUN);
final TetheringConfiguration cfgMobileWifiHipriDun = getTetheringConfiguration( final TetheringConfiguration cfgMobileWifiHipriDun = getTetheringConfiguration(
new int[]{TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI, TYPE_MOBILE_DUN}); TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI, TYPE_MOBILE_DUN);
for (TetheringConfiguration cfg : Arrays.asList(cfgWifi, cfgMobileWifiHipri, for (TetheringConfiguration cfg : Arrays.asList(cfgWifi, cfgMobileWifiHipri,
cfgWifiDun, cfgMobileWifiHipriDun)) { cfgWifiDun, cfgMobileWifiHipriDun)) {
@@ -167,20 +167,20 @@ public class TetheringConfigurationTest {
public void testDunNotRequiredFromTelephonyManagerMeansNoDun() { public void testDunNotRequiredFromTelephonyManagerMeansNoDun() {
when(mTelephonyManager.getTetherApnRequired()).thenReturn(false); when(mTelephonyManager.getTetherApnRequired()).thenReturn(false);
final TetheringConfiguration cfgWifi = getTetheringConfiguration(new int[]{TYPE_WIFI}); final TetheringConfiguration cfgWifi = getTetheringConfiguration(TYPE_WIFI);
final TetheringConfiguration cfgMobileWifiHipri = getTetheringConfiguration( final TetheringConfiguration cfgMobileWifiHipri = getTetheringConfiguration(
new int[]{TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI}); TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI);
final TetheringConfiguration cfgWifiDun = getTetheringConfiguration( final TetheringConfiguration cfgWifiDun = getTetheringConfiguration(
new int[]{TYPE_WIFI, TYPE_MOBILE_DUN}); TYPE_WIFI, TYPE_MOBILE_DUN);
final TetheringConfiguration cfgWifiMobile = getTetheringConfiguration( final TetheringConfiguration cfgWifiMobile = getTetheringConfiguration(
new int[]{TYPE_WIFI, TYPE_MOBILE}); TYPE_WIFI, TYPE_MOBILE);
final TetheringConfiguration cfgWifiHipri = getTetheringConfiguration( final TetheringConfiguration cfgWifiHipri = getTetheringConfiguration(
new int[]{TYPE_WIFI, TYPE_MOBILE_HIPRI}); TYPE_WIFI, TYPE_MOBILE_HIPRI);
final TetheringConfiguration cfgMobileWifiHipriDun = getTetheringConfiguration( final TetheringConfiguration cfgMobileWifiHipriDun = getTetheringConfiguration(
new int[]{TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI, TYPE_MOBILE_DUN}); TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI, TYPE_MOBILE_DUN);
String msg; String msg;
// TYPE_MOBILE_DUN should not be present in all of the combinations. // TYPE_MOBILE_DUN should be present in none of the combinations.
// TYPE_WIFI should not be affected. // TYPE_WIFI should not be affected.
for (TetheringConfiguration cfg : Arrays.asList(cfgWifi, cfgMobileWifiHipri, cfgWifiDun, for (TetheringConfiguration cfg : Arrays.asList(cfgWifi, cfgMobileWifiHipri, cfgWifiDun,
cfgWifiMobile, cfgWifiHipri, cfgMobileWifiHipriDun)) { cfgWifiMobile, cfgWifiHipri, cfgMobileWifiHipriDun)) {