Merge "Set attributionTag for noteOp(WRITE_SETTINGS) calls"
diff --git a/Tethering/common/TetheringLib/Android.bp b/Tethering/common/TetheringLib/Android.bp
index 31c40d2..ee6b9f1 100644
--- a/Tethering/common/TetheringLib/Android.bp
+++ b/Tethering/common/TetheringLib/Android.bp
@@ -16,6 +16,7 @@
// AIDL interfaces between the core system and the tethering mainline module.
aidl_interface {
name: "tethering-aidl-interfaces",
+ unstable: true,
local_include_dir: "src",
include_dirs: ["frameworks/base/core/java"], // For framework parcelables.
srcs: [
diff --git a/Tethering/res/values-mcc310-mnc004/strings.xml b/Tethering/res/values-mcc310-mnc004/strings.xml
index 9dadd49..ce9ff60 100644
--- a/Tethering/res/values-mcc310-mnc004/strings.xml
+++ b/Tethering/res/values-mcc310-mnc004/strings.xml
@@ -25,6 +25,4 @@
<string name="upstream_roaming_notification_title">Hotspot or tethering is on</string>
<!-- String for cellular roaming notification message [CHAR LIMIT=500] -->
<string name="upstream_roaming_notification_message">Additional charges may apply while roaming</string>
- <!-- String for cellular roaming notification continue button [CHAR LIMIT=200] -->
- <string name="upstream_roaming_notification_continue_button">Continue</string>
</resources>
diff --git a/Tethering/res/values-mcc310-mnc120/strings.xml b/Tethering/res/values-mcc310-mnc120/strings.xml
deleted file mode 100644
index 618df90..0000000
--- a/Tethering/res/values-mcc310-mnc120/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2020 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
- <!-- String for tethered notification title with client number info. -->
- <plurals name="tethered_notification_title_with_client_number">
- <item quantity="one"><xliff:g>%1$d</xliff:g> device connected.</item>
- <item quantity="other"><xliff:g>%1$d</xliff:g> devices connected.</item>
- </plurals>
-</resources>
\ No newline at end of file
diff --git a/Tethering/res/values-mcc311-mnc480/strings.xml b/Tethering/res/values-mcc311-mnc480/strings.xml
index 9dadd49..ce9ff60 100644
--- a/Tethering/res/values-mcc311-mnc480/strings.xml
+++ b/Tethering/res/values-mcc311-mnc480/strings.xml
@@ -25,6 +25,4 @@
<string name="upstream_roaming_notification_title">Hotspot or tethering is on</string>
<!-- String for cellular roaming notification message [CHAR LIMIT=500] -->
<string name="upstream_roaming_notification_message">Additional charges may apply while roaming</string>
- <!-- String for cellular roaming notification continue button [CHAR LIMIT=200] -->
- <string name="upstream_roaming_notification_continue_button">Continue</string>
</resources>
diff --git a/Tethering/res/values-mcc311-mnc490/strings.xml b/Tethering/res/values-mcc311-mnc490/strings.xml
deleted file mode 100644
index 618df90..0000000
--- a/Tethering/res/values-mcc311-mnc490/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2020 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
- <!-- String for tethered notification title with client number info. -->
- <plurals name="tethered_notification_title_with_client_number">
- <item quantity="one"><xliff:g>%1$d</xliff:g> device connected.</item>
- <item quantity="other"><xliff:g>%1$d</xliff:g> devices connected.</item>
- </plurals>
-</resources>
\ No newline at end of file
diff --git a/Tethering/res/values-mcc312-mnc530/strings.xml b/Tethering/res/values-mcc312-mnc530/strings.xml
deleted file mode 100644
index 618df90..0000000
--- a/Tethering/res/values-mcc312-mnc530/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2020 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
- <!-- String for tethered notification title with client number info. -->
- <plurals name="tethered_notification_title_with_client_number">
- <item quantity="one"><xliff:g>%1$d</xliff:g> device connected.</item>
- <item quantity="other"><xliff:g>%1$d</xliff:g> devices connected.</item>
- </plurals>
-</resources>
\ No newline at end of file
diff --git a/Tethering/res/values/config.xml b/Tethering/res/values/config.xml
index 66fbefc..83c99d2 100644
--- a/Tethering/res/values/config.xml
+++ b/Tethering/res/values/config.xml
@@ -158,51 +158,6 @@
<!-- ComponentName of the service used to run no ui tether provisioning. -->
<string translatable="false" name="config_wifi_tether_enable">com.android.settings/.wifi.tether.TetherService</string>
- <!-- Enable tethering notification -->
- <!-- Icons for showing tether enable notification.
- Each item should have two elements and be separated with ";".
-
- The first element is downstream types which is one of tethering. This element has to be
- made by WIFI, USB, BT, and OR'd with the others. Use "|" to combine multiple downstream
- types and use "," to separate each combinations. Such as
-
- USB|BT,WIFI|USB|BT
-
- The second element is icon for the item. This element has to be composed by
- <package name>:drawable/<resource name>. Such as
-
- 1. com.android.networkstack.tethering:drawable/stat_sys_tether_general
- 2. android:drawable/xxx
-
- So the entire string of each item would be
-
- USB|BT,WIFI|USB|BT;com.android.networkstack.tethering:drawable/stat_sys_tether_general
-
- NOTE: One config can be separated into two or more for readability. Such as
-
- WIFI|USB,WIFI|BT,USB|BT,WIFI|USB|BT;android:drawable/xxx
-
- can be separated into
-
- WIFI|USB;android:drawable/xxx
- WIFI|BT;android:drawable/xxx
- USB|BT;android:drawable/xxx
- WIFI|USB|BT;android:drawable/xxx
-
- Notification will not show if the downstream type isn't listed in array.
- Empty array means disable notifications. -->
- <!-- In AOSP, hotspot is configured to no notification by default. Because status bar has showed
- an icon on the right side already -->
- <string-array translatable="false" name="tethering_notification_icons">
- <item>USB;com.android.networkstack.tethering:drawable/stat_sys_tether_usb</item>
- <item>BT;com.android.networkstack.tethering:drawable/stat_sys_tether_bluetooth</item>
- <item>WIFI|USB,WIFI|BT,USB|BT,WIFI|USB|BT;com.android.networkstack.tethering:drawable/stat_sys_tether_general</item>
- </string-array>
- <!-- String for tether enable notification title. -->
- <string name="tethering_notification_title">@string/tethered_notification_title</string>
- <!-- String for tether enable notification message. -->
- <string name="tethering_notification_message">@string/tethered_notification_message</string>
-
<!-- No upstream notification is shown when there is a downstream but no upstream that is able
to do the tethering. -->
<!-- Delay(millisecond) to show no upstream notification after there's no Backhaul. Set delay to
diff --git a/Tethering/res/values/overlayable.xml b/Tethering/res/values/overlayable.xml
index bbba3f3..16ae8ad 100644
--- a/Tethering/res/values/overlayable.xml
+++ b/Tethering/res/values/overlayable.xml
@@ -32,44 +32,6 @@
<item type="string" name="config_mobile_hotspot_provision_response"/>
<item type="integer" name="config_mobile_hotspot_provision_check_period"/>
<item type="string" name="config_wifi_tether_enable"/>
- <!-- Configuration values for TetheringNotificationUpdater -->
- <!-- Icons for showing tether enable notification.
- Each item should have two elements and be separated with ";".
-
- The first element is downstream types which is one of tethering. This element has to be
- made by WIFI, USB, BT, and OR'd with the others. Use "|" to combine multiple downstream
- types and use "," to separate each combinations. Such as
-
- USB|BT,WIFI|USB|BT
-
- The second element is icon for the item. This element has to be composed by
- <package name>:drawable/<resource name>. Such as
-
- 1. com.android.networkstack.tethering:drawable/stat_sys_tether_general
- 2. android:drawable/xxx
-
- So the entire string of each item would be
-
- USB|BT,WIFI|USB|BT;com.android.networkstack.tethering:drawable/stat_sys_tether_general
-
- NOTE: One config can be separated into two or more for readability. Such as
-
- WIFI|USB,WIFI|BT,USB|BT,WIFI|USB|BT;android:drawable/xxx
-
- can be separated into
-
- WIFI|USB;android:drawable/xxx
- WIFI|BT;android:drawable/xxx
- USB|BT;android:drawable/xxx
- WIFI|USB|BT;android:drawable/xxx
-
- Notification will not show if the downstream type isn't listed in array.
- Empty array means disable notifications. -->
- <item type="array" name="tethering_notification_icons"/>
- <!-- String for tether enable notification title. -->
- <item type="string" name="tethering_notification_title"/>
- <!-- String for tether enable notification message. -->
- <item type="string" name="tethering_notification_message"/>
<!-- Params from config.xml that can be overlaid -->
</policy>
</overlayable>
diff --git a/Tethering/res/values/strings.xml b/Tethering/res/values/strings.xml
index 4fa60d4..d63c7c5 100644
--- a/Tethering/res/values/strings.xml
+++ b/Tethering/res/values/strings.xml
@@ -19,9 +19,6 @@
<string name="tethered_notification_title">Tethering or hotspot active</string>
<!-- String for tethered notification message [CHAR LIMIT=200] -->
<string name="tethered_notification_message">Tap to set up.</string>
- <!-- String for tethered notification title with client number info. -->
- <plurals name="tethered_notification_title_with_client_number">
- </plurals>
<!-- This notification is shown when tethering has been disabled on a user's device.
The device is managed by the user's employer. Tethering can't be turned on unless the
@@ -47,6 +44,4 @@
<string name="upstream_roaming_notification_title"></string>
<!-- String for cellular roaming notification message [CHAR LIMIT=500] -->
<string name="upstream_roaming_notification_message"></string>
- <!-- String for cellular roaming notification continue button [CHAR LIMIT=200] -->
- <string name="upstream_roaming_notification_continue_button"></string>
</resources>
diff --git a/Tethering/src/com/android/networkstack/tethering/OffloadHardwareInterface.java b/Tethering/src/com/android/networkstack/tethering/OffloadHardwareInterface.java
index 85a23fb..55344fc 100644
--- a/Tethering/src/com/android/networkstack/tethering/OffloadHardwareInterface.java
+++ b/Tethering/src/com/android/networkstack/tethering/OffloadHardwareInterface.java
@@ -142,7 +142,7 @@
public boolean initOffloadConfig() {
IOffloadConfig offloadConfig;
try {
- offloadConfig = IOffloadConfig.getService();
+ offloadConfig = IOffloadConfig.getService(true /*retry*/);
} catch (RemoteException e) {
mLog.e("getIOffloadConfig error " + e);
return false;
diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringNotificationUpdater.java b/Tethering/src/com/android/networkstack/tethering/TetheringNotificationUpdater.java
index f490cc4..7fd6b61 100644
--- a/Tethering/src/com/android/networkstack/tethering/TetheringNotificationUpdater.java
+++ b/Tethering/src/com/android/networkstack/tethering/TetheringNotificationUpdater.java
@@ -17,9 +17,6 @@
package com.android.networkstack.tethering;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING;
-import static android.net.TetheringManager.TETHERING_BLUETOOTH;
-import static android.net.TetheringManager.TETHERING_USB;
-import static android.net.TetheringManager.TETHERING_WIFI;
import static android.text.TextUtils.isEmpty;
import android.app.Notification;
@@ -39,10 +36,8 @@
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
-import android.util.Log;
import android.util.SparseArray;
-import androidx.annotation.ArrayRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.IntRange;
@@ -77,9 +72,6 @@
private static final boolean NO_NOTIFY = false;
@VisibleForTesting
static final int EVENT_SHOW_NO_UPSTREAM = 1;
- // Id to update and cancel enable notification. Must be unique within the tethering app.
- @VisibleForTesting
- static final int ENABLE_NOTIFICATION_ID = 1000;
// Id to update and cancel restricted notification. Must be unique within the tethering app.
@VisibleForTesting
static final int RESTRICTED_NOTIFICATION_ID = 1001;
@@ -120,7 +112,6 @@
@Retention(RetentionPolicy.SOURCE)
@IntDef(value = {
- ENABLE_NOTIFICATION_ID,
RESTRICTED_NOTIFICATION_ID,
NO_UPSTREAM_NOTIFICATION_ID,
ROAMING_NOTIFICATION_ID
@@ -223,7 +214,6 @@
final boolean tetheringActiveChanged =
(downstreamTypes == DOWNSTREAM_NONE) != (mDownstreamTypesMask == DOWNSTREAM_NONE);
final boolean subIdChanged = subId != mActiveDataSubId;
- final boolean downstreamChanged = downstreamTypes != mDownstreamTypesMask;
final boolean upstreamChanged = noUpstream != mNoUpstream;
final boolean roamingChanged = isRoaming != mRoaming;
final boolean updateAll = tetheringActiveChanged || subIdChanged;
@@ -232,19 +222,10 @@
mNoUpstream = noUpstream;
mRoaming = isRoaming;
- if (updateAll || downstreamChanged) updateEnableNotification();
if (updateAll || upstreamChanged) updateNoUpstreamNotification();
if (updateAll || roamingChanged) updateRoamingNotification();
}
- private void updateEnableNotification() {
- final boolean tetheringInactive = mDownstreamTypesMask == DOWNSTREAM_NONE;
-
- if (tetheringInactive || setupNotification() == NO_NOTIFY) {
- clearNotification(ENABLE_NOTIFICATION_ID);
- }
- }
-
private void updateNoUpstreamNotification() {
final boolean tetheringInactive = mDownstreamTypesMask == DOWNSTREAM_NONE;
@@ -310,64 +291,6 @@
NO_UPSTREAM_NOTIFICATION_ID, null /* pendingIntent */, action);
}
- /**
- * Returns the downstream types mask which convert from given string.
- *
- * @param types This string has to be made by "WIFI", "USB", "BT", and OR'd with the others.
- *
- * @return downstream types mask value.
- */
- @VisibleForTesting
- @IntRange(from = 0, to = 7)
- int getDownstreamTypesMask(@NonNull final String types) {
- int downstreamTypesMask = DOWNSTREAM_NONE;
- final String[] downstreams = types.split("\\|");
- for (String downstream : downstreams) {
- if (USB_DOWNSTREAM.equals(downstream.trim())) {
- downstreamTypesMask |= (1 << TETHERING_USB);
- } else if (WIFI_DOWNSTREAM.equals(downstream.trim())) {
- downstreamTypesMask |= (1 << TETHERING_WIFI);
- } else if (BLUETOOTH_DOWNSTREAM.equals(downstream.trim())) {
- downstreamTypesMask |= (1 << TETHERING_BLUETOOTH);
- }
- }
- return downstreamTypesMask;
- }
-
- /**
- * Returns the icons {@link android.util.SparseArray} which get from given string-array resource
- * id.
- *
- * @param id String-array resource id
- *
- * @return {@link android.util.SparseArray} with downstream types and icon id info.
- */
- @NonNull
- @VisibleForTesting
- SparseArray<Integer> getIcons(@ArrayRes int id, @NonNull Resources res) {
- final String[] array = res.getStringArray(id);
- final SparseArray<Integer> icons = new SparseArray<>();
- for (String config : array) {
- if (isEmpty(config)) continue;
-
- final String[] elements = config.split(";");
- if (elements.length != 2) {
- Log.wtf(TAG,
- "Unexpected format in Tethering notification configuration : " + config);
- continue;
- }
-
- final String[] types = elements[0].split(",");
- for (String type : types) {
- int mask = getDownstreamTypesMask(type);
- if (mask == DOWNSTREAM_NONE) continue;
- icons.put(mask, res.getIdentifier(
- elements[1].trim(), null /* defType */, null /* defPackage */));
- }
- }
- return icons;
- }
-
private boolean setupRoamingNotification() {
final Resources res = getResourcesForSubId(mContext, mActiveDataSubId);
final boolean upstreamRoamingNotification =
@@ -403,29 +326,6 @@
return NOTIFY_DONE;
}
- private boolean setupNotification() {
- final Resources res = getResourcesForSubId(mContext, mActiveDataSubId);
- final SparseArray<Integer> downstreamIcons =
- getIcons(R.array.tethering_notification_icons, res);
-
- final int iconId = downstreamIcons.get(mDownstreamTypesMask, NO_ICON_ID);
- if (iconId == NO_ICON_ID) return NO_NOTIFY;
-
- final String title = res.getString(R.string.tethering_notification_title);
- final String message = res.getString(R.string.tethering_notification_message);
- if (isEmpty(title) || isEmpty(message)) return NO_NOTIFY;
-
- final PendingIntent pi = PendingIntent.getActivity(
- mContext.createContextAsUser(UserHandle.CURRENT, 0 /* flags */),
- 0 /* requestCode */,
- new Intent(Settings.ACTION_TETHER_SETTINGS),
- Intent.FLAG_ACTIVITY_NEW_TASK,
- null /* options */);
-
- showNotification(iconId, title, message, ENABLE_NOTIFICATION_ID, pi, new Action[0]);
- return NOTIFY_DONE;
- }
-
private void showNotification(@DrawableRes final int iconId, @NonNull final String title,
@NonNull final String message, @NotificationId final int id, @Nullable PendingIntent pi,
@NonNull final Action... actions) {
diff --git a/Tethering/tests/integration/Android.bp b/Tethering/tests/integration/Android.bp
index 6b751af..3305ed0 100644
--- a/Tethering/tests/integration/Android.bp
+++ b/Tethering/tests/integration/Android.bp
@@ -69,6 +69,7 @@
test_config: "AndroidTest_Coverage.xml",
defaults: ["libnetworkstackutilsjni_deps"],
static_libs: [
+ "NetworkStaticLibTestsLib",
"NetworkStackTestsLib",
"TetheringTestsLib",
"TetheringIntegrationTestsLib",
diff --git a/Tethering/tests/unit/Android.bp b/Tethering/tests/unit/Android.bp
index 4849fd5..056a94e 100644
--- a/Tethering/tests/unit/Android.bp
+++ b/Tethering/tests/unit/Android.bp
@@ -14,6 +14,26 @@
// limitations under the License.
//
+// Tests in this folder are included both in unit tests and CTS.
+java_library {
+ name: "TetheringCommonTests",
+ srcs: [
+ "common/**/*.java",
+ "common/**/*.kt"
+ ],
+ static_libs: [
+ "androidx.test.rules",
+ "net-tests-utils",
+ ],
+ // TODO(b/147200698) change sdk_version to module-current and remove framework-minus-apex
+ sdk_version: "core_platform",
+ libs: [
+ "framework-minus-apex",
+ "framework-tethering",
+ ],
+ visibility: ["//cts/tests/tests/tethering"],
+}
+
java_defaults {
name: "TetheringTestsDefaults",
srcs: [
@@ -22,6 +42,7 @@
],
static_libs: [
"TetheringApiCurrentLib",
+ "TetheringCommonTests",
"androidx.test.rules",
"frameworks-base-testutils",
"mockito-target-extended-minus-junit4",
diff --git a/Tethering/tests/unit/src/android/net/TetheredClientTest.kt b/Tethering/tests/unit/common/android/net/TetheredClientTest.kt
similarity index 100%
rename from Tethering/tests/unit/src/android/net/TetheredClientTest.kt
rename to Tethering/tests/unit/common/android/net/TetheredClientTest.kt
diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringNotificationUpdaterTest.kt b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringNotificationUpdaterTest.kt
index 04f31a7..745468f 100644
--- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringNotificationUpdaterTest.kt
+++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringNotificationUpdaterTest.kt
@@ -20,8 +20,6 @@
import android.app.NotificationManager
import android.content.Context
import android.content.res.Resources
-import android.net.ConnectivityManager.TETHERING_BLUETOOTH
-import android.net.ConnectivityManager.TETHERING_USB
import android.net.ConnectivityManager.TETHERING_WIFI
import android.os.Handler
import android.os.HandlerThread
@@ -29,14 +27,12 @@
import android.net.NetworkCapabilities
import android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING
import android.os.UserHandle
-import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
import android.telephony.TelephonyManager
import androidx.test.filters.SmallTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import com.android.internal.util.test.BroadcastInterceptingContext
import com.android.networkstack.tethering.TetheringNotificationUpdater.DOWNSTREAM_NONE
-import com.android.networkstack.tethering.TetheringNotificationUpdater.ENABLE_NOTIFICATION_ID
import com.android.networkstack.tethering.TetheringNotificationUpdater.EVENT_SHOW_NO_UPSTREAM
import com.android.networkstack.tethering.TetheringNotificationUpdater.NO_UPSTREAM_NOTIFICATION_ID
import com.android.networkstack.tethering.TetheringNotificationUpdater.RESTRICTED_NOTIFICATION_ID
@@ -63,17 +59,9 @@
import org.mockito.MockitoAnnotations
const val TEST_SUBID = 1
-const val WIFI_ICON_ID = 1
-const val USB_ICON_ID = 2
-const val BT_ICON_ID = 3
-const val GENERAL_ICON_ID = 4
const val WIFI_MASK = 1 shl TETHERING_WIFI
-const val USB_MASK = 1 shl TETHERING_USB
-const val BT_MASK = 1 shl TETHERING_BLUETOOTH
-const val TITLE = "Tethering active"
-const val MESSAGE = "Tap here to set up."
-const val TEST_TITLE = "Hotspot active"
-const val TEST_MESSAGE = "Tap to set up hotspot."
+const val TEST_DISALLOW_TITLE = "Tether function is disallowed"
+const val TEST_DISALLOW_MESSAGE = "Please contact your admin"
const val TEST_NO_UPSTREAM_TITLE = "Hotspot has no internet access"
const val TEST_NO_UPSTREAM_MESSAGE = "Device cannot connect to internet."
const val TEST_NO_UPSTREAM_BUTTON = "Turn off hotspot"
@@ -88,7 +76,6 @@
@Mock private lateinit var mockContext: Context
@Mock private lateinit var notificationManager: NotificationManager
@Mock private lateinit var telephonyManager: TelephonyManager
- @Mock private lateinit var defaultResources: Resources
@Mock private lateinit var testResources: Resources
// lateinit for these classes under test, as they should be reset to a different instance for
@@ -97,11 +84,6 @@
private lateinit var notificationUpdater: TetheringNotificationUpdater
private lateinit var fakeTetheringThread: HandlerThread
- private val ENABLE_ICON_CONFIGS = arrayOf(
- "USB;android.test:drawable/usb", "BT;android.test:drawable/bluetooth",
- "WIFI|BT;android.test:drawable/general", "WIFI|USB;android.test:drawable/general",
- "USB|BT;android.test:drawable/general", "WIFI|USB|BT;android.test:drawable/general")
-
private val ROAMING_CAPABILITIES = NetworkCapabilities()
private val HOME_CAPABILITIES = NetworkCapabilities().addCapability(NET_CAPABILITY_NOT_ROAMING)
private val NOTIFICATION_ICON_ID = R.drawable.stat_sys_tether_general
@@ -117,29 +99,19 @@
private inner class WrappedNotificationUpdater(c: Context, looper: Looper)
: TetheringNotificationUpdater(c, looper) {
- override fun getResourcesForSubId(context: Context, subId: Int) =
- when (subId) {
- TEST_SUBID -> testResources
- INVALID_SUBSCRIPTION_ID -> defaultResources
- else -> super.getResourcesForSubId(context, subId)
- }
+ override fun getResourcesForSubId(c: Context, subId: Int) =
+ if (subId == TEST_SUBID) testResources else super.getResourcesForSubId(c, subId)
}
private fun setupResources() {
- doReturn(ENABLE_ICON_CONFIGS).`when`(defaultResources)
- .getStringArray(R.array.tethering_notification_icons)
- doReturn(arrayOf("WIFI;android.test:drawable/wifi")).`when`(testResources)
- .getStringArray(R.array.tethering_notification_icons)
doReturn(5).`when`(testResources)
.getInteger(R.integer.delay_to_show_no_upstream_after_no_backhaul)
doReturn(true).`when`(testResources)
.getBoolean(R.bool.config_upstream_roaming_notification)
- doReturn(TITLE).`when`(defaultResources).getString(R.string.tethering_notification_title)
- doReturn(MESSAGE).`when`(defaultResources)
- .getString(R.string.tethering_notification_message)
- doReturn(TEST_TITLE).`when`(testResources).getString(R.string.tethering_notification_title)
- doReturn(TEST_MESSAGE).`when`(testResources)
- .getString(R.string.tethering_notification_message)
+ doReturn(TEST_DISALLOW_TITLE).`when`(testResources)
+ .getString(R.string.disable_tether_notification_title)
+ doReturn(TEST_DISALLOW_MESSAGE).`when`(testResources)
+ .getString(R.string.disable_tether_notification_message)
doReturn(TEST_NO_UPSTREAM_TITLE).`when`(testResources)
.getString(R.string.no_upstream_notification_title)
doReturn(TEST_NO_UPSTREAM_MESSAGE).`when`(testResources)
@@ -150,14 +122,6 @@
.getString(R.string.upstream_roaming_notification_title)
doReturn(TEST_ROAMING_MESSAGE).`when`(testResources)
.getString(R.string.upstream_roaming_notification_message)
- doReturn(USB_ICON_ID).`when`(defaultResources)
- .getIdentifier(eq("android.test:drawable/usb"), any(), any())
- doReturn(BT_ICON_ID).`when`(defaultResources)
- .getIdentifier(eq("android.test:drawable/bluetooth"), any(), any())
- doReturn(GENERAL_ICON_ID).`when`(defaultResources)
- .getIdentifier(eq("android.test:drawable/general"), any(), any())
- doReturn(WIFI_ICON_ID).`when`(testResources)
- .getIdentifier(eq("android.test:drawable/wifi"), any(), any())
}
@Before
@@ -206,119 +170,27 @@
}
@Test
- fun testNotificationWithDownstreamChanged() {
- // Wifi downstream. No notification.
- notificationUpdater.onDownstreamChanged(WIFI_MASK)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID))
-
- // Same downstream changed. Nothing happened.
- notificationUpdater.onDownstreamChanged(WIFI_MASK)
- verifyZeroInteractions(notificationManager)
-
- // Wifi and usb downstreams. Show enable notification
- notificationUpdater.onDownstreamChanged(WIFI_MASK or USB_MASK)
- verifyNotification(GENERAL_ICON_ID, TITLE, MESSAGE, ENABLE_NOTIFICATION_ID)
-
- // Usb downstream. Still show enable notification.
- notificationUpdater.onDownstreamChanged(USB_MASK)
- verifyNotification(USB_ICON_ID, TITLE, MESSAGE, ENABLE_NOTIFICATION_ID)
-
- // No downstream. No notification.
- notificationUpdater.onDownstreamChanged(DOWNSTREAM_NONE)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID, NO_UPSTREAM_NOTIFICATION_ID,
- ROAMING_NOTIFICATION_ID))
- }
-
- @Test
- fun testNotificationWithActiveDataSubscriptionIdChanged() {
- // Usb downstream. Showed enable notification with default resource.
- notificationUpdater.onDownstreamChanged(USB_MASK)
- verifyNotification(USB_ICON_ID, TITLE, MESSAGE, ENABLE_NOTIFICATION_ID)
-
- // Same subId changed. Nothing happened.
- notificationUpdater.onActiveDataSubscriptionIdChanged(INVALID_SUBSCRIPTION_ID)
- verifyZeroInteractions(notificationManager)
-
- // Set test sub id. Clear notification with test resource.
+ fun testRestrictedNotification() {
+ // Set test sub id.
notificationUpdater.onActiveDataSubscriptionIdChanged(TEST_SUBID)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID, NO_UPSTREAM_NOTIFICATION_ID,
- ROAMING_NOTIFICATION_ID))
-
- // Wifi downstream. Show enable notification with test resource.
- notificationUpdater.onDownstreamChanged(WIFI_MASK)
- verifyNotification(WIFI_ICON_ID, TEST_TITLE, TEST_MESSAGE, ENABLE_NOTIFICATION_ID)
-
- // No downstream. No notification.
- notificationUpdater.onDownstreamChanged(DOWNSTREAM_NONE)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID, NO_UPSTREAM_NOTIFICATION_ID,
- ROAMING_NOTIFICATION_ID))
- }
-
- private fun assertIconNumbers(number: Int, configs: Array<String?>) {
- doReturn(configs).`when`(defaultResources)
- .getStringArray(R.array.tethering_notification_icons)
- assertEquals(number, notificationUpdater.getIcons(
- R.array.tethering_notification_icons, defaultResources).size())
- }
-
- @Test
- fun testGetIcons() {
- assertIconNumbers(0, arrayOfNulls<String>(0))
- assertIconNumbers(0, arrayOf(null, ""))
- assertIconNumbers(3, arrayOf(
- // These configurations are invalid with wrong strings or symbols.
- ";", ",", "|", "|,;", "WIFI", "1;2", " U SB; ", "bt;", "WIFI;USB;BT", "WIFI|USB|BT",
- "WIFI,BT,USB", " WIFI| | | USB, test:drawable/test",
- // This configuration is valid with two downstream types (USB, BT).
- "USB|,,,,,|BT;drawable/test ",
- // This configuration is valid with one downstream types (WIFI).
- " WIFI ; android.test:drawable/xxx "))
- }
-
- @Test
- fun testGetDownstreamTypesMask() {
- assertEquals(DOWNSTREAM_NONE, notificationUpdater.getDownstreamTypesMask(""))
- assertEquals(DOWNSTREAM_NONE, notificationUpdater.getDownstreamTypesMask("1"))
- assertEquals(DOWNSTREAM_NONE, notificationUpdater.getDownstreamTypesMask("WIFI_P2P"))
- assertEquals(DOWNSTREAM_NONE, notificationUpdater.getDownstreamTypesMask("usb"))
- assertEquals(WIFI_MASK, notificationUpdater.getDownstreamTypesMask(" WIFI "))
- assertEquals(USB_MASK, notificationUpdater.getDownstreamTypesMask("USB | B T"))
- assertEquals(BT_MASK, notificationUpdater.getDownstreamTypesMask(" WIFI: | BT"))
- assertEquals(WIFI_MASK or USB_MASK,
- notificationUpdater.getDownstreamTypesMask("1|2|USB|WIFI|BLUETOOTH||"))
- }
-
- @Test
- fun testSetupRestrictedNotification() {
- val title = context.resources.getString(R.string.disable_tether_notification_title)
- val message = context.resources.getString(R.string.disable_tether_notification_message)
- val disallowTitle = "Tether function is disallowed"
- val disallowMessage = "Please contact your admin"
- doReturn(title).`when`(defaultResources)
- .getString(R.string.disable_tether_notification_title)
- doReturn(message).`when`(defaultResources)
- .getString(R.string.disable_tether_notification_message)
- doReturn(disallowTitle).`when`(testResources)
- .getString(R.string.disable_tether_notification_title)
- doReturn(disallowMessage).`when`(testResources)
- .getString(R.string.disable_tether_notification_message)
+ verifyNotificationCancelled(listOf(NO_UPSTREAM_NOTIFICATION_ID, ROAMING_NOTIFICATION_ID))
// User restrictions on. Show restricted notification.
notificationUpdater.notifyTetheringDisabledByRestriction()
- verifyNotification(NOTIFICATION_ICON_ID, title, message, RESTRICTED_NOTIFICATION_ID)
+ verifyNotification(NOTIFICATION_ICON_ID, TEST_DISALLOW_TITLE, TEST_DISALLOW_MESSAGE,
+ RESTRICTED_NOTIFICATION_ID)
// User restrictions off. Clear notification.
notificationUpdater.tetheringRestrictionLifted()
verifyNotificationCancelled(listOf(RESTRICTED_NOTIFICATION_ID))
- // Set test sub id. No notification.
- notificationUpdater.onActiveDataSubscriptionIdChanged(TEST_SUBID)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID, NO_UPSTREAM_NOTIFICATION_ID,
- ROAMING_NOTIFICATION_ID))
+ // No downstream.
+ notificationUpdater.onDownstreamChanged(DOWNSTREAM_NONE)
+ verifyZeroInteractions(notificationManager)
- // User restrictions on again. Show restricted notification with test resource.
+ // User restrictions on again. Show restricted notification.
notificationUpdater.notifyTetheringDisabledByRestriction()
- verifyNotification(NOTIFICATION_ICON_ID, disallowTitle, disallowMessage,
+ verifyNotification(NOTIFICATION_ICON_ID, TEST_DISALLOW_TITLE, TEST_DISALLOW_MESSAGE,
RESTRICTED_NOTIFICATION_ID)
}
@@ -356,15 +228,14 @@
}
@Test
- fun testNotificationWithUpstreamCapabilitiesChanged_NoUpstream() {
- // Set test sub id. No notification.
+ fun testNoUpstreamNotification() {
+ // Set test sub id.
notificationUpdater.onActiveDataSubscriptionIdChanged(TEST_SUBID)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID, NO_UPSTREAM_NOTIFICATION_ID,
- ROAMING_NOTIFICATION_ID))
+ verifyNotificationCancelled(listOf(NO_UPSTREAM_NOTIFICATION_ID, ROAMING_NOTIFICATION_ID))
- // Wifi downstream. Show enable notification with test resource.
+ // Wifi downstream.
notificationUpdater.onDownstreamChanged(WIFI_MASK)
- verifyNotification(WIFI_ICON_ID, TEST_TITLE, TEST_MESSAGE, ENABLE_NOTIFICATION_ID)
+ verifyNotificationCancelled(listOf(NO_UPSTREAM_NOTIFICATION_ID, ROAMING_NOTIFICATION_ID))
// There is no upstream. Show no upstream notification.
notificationUpdater.onUpstreamCapabilitiesChanged(null)
@@ -386,15 +257,14 @@
verifyNotification(NOTIFICATION_ICON_ID, TEST_NO_UPSTREAM_TITLE, TEST_NO_UPSTREAM_MESSAGE,
NO_UPSTREAM_NOTIFICATION_ID)
- // No downstream. No notification.
+ // No downstream.
notificationUpdater.onDownstreamChanged(DOWNSTREAM_NONE)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID, NO_UPSTREAM_NOTIFICATION_ID,
- ROAMING_NOTIFICATION_ID))
+ verifyNotificationCancelled(listOf(NO_UPSTREAM_NOTIFICATION_ID, ROAMING_NOTIFICATION_ID))
- // Put up enable notification with wifi downstream and home capabilities.
+ // Wifi downstream and home capabilities.
notificationUpdater.onDownstreamChanged(WIFI_MASK)
notificationUpdater.onUpstreamCapabilitiesChanged(HOME_CAPABILITIES)
- verifyNotification(WIFI_ICON_ID, TEST_TITLE, TEST_MESSAGE, ENABLE_NOTIFICATION_ID)
+ verifyNotificationCancelled(listOf(NO_UPSTREAM_NOTIFICATION_ID, ROAMING_NOTIFICATION_ID))
// Set R.integer.delay_to_show_no_upstream_after_no_backhaul to -1 and change to no upstream
// again. Don't put up no upstream notification.
@@ -429,15 +299,14 @@
}
@Test
- fun testNotificationWithUpstreamCapabilitiesChanged_Roaming() {
- // Set test sub id. Clear notification.
+ fun testRoamingNotification() {
+ // Set test sub id.
notificationUpdater.onActiveDataSubscriptionIdChanged(TEST_SUBID)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID, NO_UPSTREAM_NOTIFICATION_ID,
- ROAMING_NOTIFICATION_ID))
+ verifyNotificationCancelled(listOf(NO_UPSTREAM_NOTIFICATION_ID, ROAMING_NOTIFICATION_ID))
- // Wifi downstream. Show enable notification with test resource.
+ // Wifi downstream.
notificationUpdater.onDownstreamChanged(WIFI_MASK)
- verifyNotification(WIFI_ICON_ID, TEST_TITLE, TEST_MESSAGE, ENABLE_NOTIFICATION_ID)
+ verifyNotificationCancelled(listOf(NO_UPSTREAM_NOTIFICATION_ID, ROAMING_NOTIFICATION_ID))
// Upstream capabilities changed to roaming state. Show roaming notification.
notificationUpdater.onUpstreamCapabilitiesChanged(ROAMING_CAPABILITIES)
@@ -464,14 +333,16 @@
verifyNotification(NOTIFICATION_ICON_ID, TEST_NO_UPSTREAM_TITLE, TEST_NO_UPSTREAM_MESSAGE,
NO_UPSTREAM_NOTIFICATION_ID)
- // No downstream. No notification.
+ // No downstream.
notificationUpdater.onDownstreamChanged(DOWNSTREAM_NONE)
- verifyNotificationCancelled(listOf(ENABLE_NOTIFICATION_ID, NO_UPSTREAM_NOTIFICATION_ID,
- ROAMING_NOTIFICATION_ID))
+ verifyNotificationCancelled(listOf(NO_UPSTREAM_NOTIFICATION_ID, ROAMING_NOTIFICATION_ID))
- // Wifi downstream again. Show enable notification with test resource.
+ // Wifi downstream again.
notificationUpdater.onDownstreamChanged(WIFI_MASK)
- verifyNotification(WIFI_ICON_ID, TEST_TITLE, TEST_MESSAGE, ENABLE_NOTIFICATION_ID)
+ notificationUpdater.handler.waitForDelayedMessage(EVENT_SHOW_NO_UPSTREAM, TIMEOUT_MS)
+ verifyNotificationCancelled(listOf(ROAMING_NOTIFICATION_ID), false)
+ verifyNotification(NOTIFICATION_ICON_ID, TEST_NO_UPSTREAM_TITLE, TEST_NO_UPSTREAM_MESSAGE,
+ NO_UPSTREAM_NOTIFICATION_ID)
// Set R.bool.config_upstream_roaming_notification to false and change upstream
// network to roaming state again. No roaming notification.