From f9f0d1178259507cd725360143619debb39a6594 Mon Sep 17 00:00:00 2001 From: markchien Date: Tue, 9 Apr 2019 19:51:33 +0800 Subject: [PATCH] Ignore the outdated entitlement check Don't run entitlement if the request is base on outdated subId. Bug: 129751453 Test: -build, flash, boot -atest TetherServiceTest -manual test with carrier SIM Change-Id: Id3157df1a5758f8c72acbc45c9fefd2215c87395 --- .../settings/network/TetherProvisioningActivity.java | 12 ++++++++++-- src/com/android/settings/wifi/tether/TetherService.java | 14 ++++++++++++++ .../android/settings/wifi/tether/TetherServiceTest.java | 17 ++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/network/TetherProvisioningActivity.java b/src/com/android/settings/network/TetherProvisioningActivity.java index b30950e5d1..48c570791b 100644 --- a/src/com/android/settings/network/TetherProvisioningActivity.java +++ b/src/com/android/settings/network/TetherProvisioningActivity.java @@ -39,6 +39,7 @@ public class TetherProvisioningActivity extends Activity { private static final int PROVISION_REQUEST = 0; private static final String TAG = "TetherProvisioningAct"; private static final String EXTRA_TETHER_TYPE = "TETHER_TYPE"; + private static final String EXTRA_SUBID = "subId"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private ResultReceiver mResultReceiver; @@ -49,14 +50,21 @@ public class TetherProvisioningActivity extends Activity { mResultReceiver = (ResultReceiver)getIntent().getParcelableExtra( ConnectivityManager.EXTRA_PROVISION_CALLBACK); - int tetherType = getIntent().getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, + final int tetherType = getIntent().getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, ConnectivityManager.TETHERING_INVALID); + + final int tetherSubId = getIntent().getIntExtra(EXTRA_SUBID, + SubscriptionManager.INVALID_SUBSCRIPTION_ID); final int subId = SubscriptionManager.getDefaultDataSubscriptionId(); + if (tetherSubId != subId) { + Log.e(TAG, "This Provisioning request is outdated, current subId: " + subId); + return; + } final Resources res = Utils.getResourcesForSubId(this, subId); final String[] provisionApp = res.getStringArray( com.android.internal.R.array.config_mobile_hotspot_provision_app); - Intent intent = new Intent(Intent.ACTION_MAIN); + final Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName(provisionApp[0], provisionApp[1]); intent.putExtra(EXTRA_TETHER_TYPE, tetherType); if (DEBUG) { diff --git a/src/com/android/settings/wifi/tether/TetherService.java b/src/com/android/settings/wifi/tether/TetherService.java index d1e8652348..3d58c99e63 100644 --- a/src/com/android/settings/wifi/tether/TetherService.java +++ b/src/com/android/settings/wifi/tether/TetherService.java @@ -55,6 +55,8 @@ public class TetherService extends Service { @VisibleForTesting public static final String EXTRA_RESULT = "EntitlementResult"; + @VisibleForTesting + public static final String EXTRA_SUBID = "subId"; // Activity results to match the activity provision protocol. // Default to something not ok. @@ -100,6 +102,18 @@ public class TetherService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + if (intent.hasExtra(EXTRA_SUBID)) { + final int tetherSubId = intent.getIntExtra(EXTRA_SUBID, + SubscriptionManager.INVALID_SUBSCRIPTION_ID); + final int subId = getTetherServiceWrapper().getDefaultDataSubscriptionId(); + if (tetherSubId != subId) { + Log.e(TAG, "This Provisioning request is outdated, current subId: " + subId); + if (!mInProvisionCheck) { + stopSelf(); + } + return START_NOT_STICKY; + } + } if (intent.hasExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE)) { int type = intent.getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, ConnectivityManager.TETHERING_INVALID); diff --git a/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java b/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java index dc96c02ab6..636d6ad914 100644 --- a/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java +++ b/tests/unit/src/com/android/settings/wifi/tether/TetherServiceTest.java @@ -264,11 +264,26 @@ public class TetherServiceTest extends ServiceTestCase { assertEquals(TetherService.class.getName(), pi.getIntent().getComponent().getClassName()); } + public void testIgnoreOutdatedRequest() { + Intent intent = new Intent(); + intent.putExtra(EXTRA_ADD_TETHER_TYPE, TETHERING_WIFI); + intent.putExtra(EXTRA_RUN_PROVISION, true); + intent.putExtra(EXTRA_PROVISION_CALLBACK, mResultReceiver); + intent.putExtra(TetherService.EXTRA_SUBID, 1 /* Tested subId number */); + startService(intent); + + SystemClock.sleep(PROVISION_TIMEOUT); + assertEquals(TETHERING_INVALID, mLastTetherRequestType); + assertTrue(mWrapper.isAppInactive(ENTITLEMENT_PACKAGE_NAME)); + assertTrue(mWrapper.isAppInactive(FAKE_PACKAGE_NAME)); + } + private void runProvisioningForType(int type) { Intent intent = new Intent(); intent.putExtra(EXTRA_ADD_TETHER_TYPE, type); intent.putExtra(EXTRA_RUN_PROVISION, true); intent.putExtra(EXTRA_PROVISION_CALLBACK, mResultReceiver); + intent.putExtra(TetherService.EXTRA_SUBID, INVALID_SUBSCRIPTION_ID); startService(intent); } @@ -289,7 +304,7 @@ public class TetherServiceTest extends ServiceTestCase { long startTime = SystemClock.uptimeMillis(); while (true) { if (mLastTetherRequestType == expectedType) { - mLastTetherRequestType = -1; + mLastTetherRequestType = TETHERING_INVALID; return true; } if ((SystemClock.uptimeMillis() - startTime) > PROVISION_TIMEOUT) { -- 2.11.0