[TNU02] Update tethering notification by active data subid
Tethering notification can be customized by different subid. Thus update notification when active data subid changed. Bug: 122085773 Bug: 130596698 Test: atest TetheringTests Change-Id: I799d713326cfbf4dc96c712c6b15ed5a4ac18dd2 Merged-In: I799d713326cfbf4dc96c712c6b15ed5a4ac18dd2 (cherry picked from aosp/1209984)
This commit is contained in:
@@ -369,9 +369,10 @@ public class Tethering {
|
|||||||
|
|
||||||
mActiveDataSubId = subId;
|
mActiveDataSubId = subId;
|
||||||
updateConfiguration();
|
updateConfiguration();
|
||||||
|
mNotificationUpdater.onActiveDataSubscriptionIdChanged(subId);
|
||||||
// To avoid launching unexpected provisioning checks, ignore re-provisioning
|
// To avoid launching unexpected provisioning checks, ignore re-provisioning
|
||||||
// when no CarrierConfig loaded yet. Assume reevaluateSimCardProvisioning()
|
// when no CarrierConfig loaded yet. Assume reevaluateSimCardProvisioning()
|
||||||
// ill be triggered again when CarrierConfig is loaded.
|
// will be triggered again when CarrierConfig is loaded.
|
||||||
if (mEntitlementMgr.getCarrierConfig(mConfig) != null) {
|
if (mEntitlementMgr.getCarrierConfig(mConfig) != null) {
|
||||||
mEntitlementMgr.reevaluateSimCardProvisioning(mConfig);
|
mEntitlementMgr.reevaluateSimCardProvisioning(mConfig);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.content.Intent;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.telephony.SubscriptionManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
@@ -54,6 +55,9 @@ import com.android.networkstack.tethering.R;
|
|||||||
public class TetheringNotificationUpdater {
|
public class TetheringNotificationUpdater {
|
||||||
private static final String TAG = TetheringNotificationUpdater.class.getSimpleName();
|
private static final String TAG = TetheringNotificationUpdater.class.getSimpleName();
|
||||||
private static final String CHANNEL_ID = "TETHERING_STATUS";
|
private static final String CHANNEL_ID = "TETHERING_STATUS";
|
||||||
|
private static final String WIFI_DOWNSTREAM = "WIFI";
|
||||||
|
private static final String USB_DOWNSTREAM = "USB";
|
||||||
|
private static final String BLUETOOTH_DOWNSTREAM = "BT";
|
||||||
private static final boolean NOTIFY_DONE = true;
|
private static final boolean NOTIFY_DONE = true;
|
||||||
private static final boolean NO_NOTIFY = false;
|
private static final boolean NO_NOTIFY = false;
|
||||||
// Id to update and cancel tethering notification. Must be unique within the tethering app.
|
// Id to update and cancel tethering notification. Must be unique within the tethering app.
|
||||||
@@ -65,14 +69,22 @@ public class TetheringNotificationUpdater {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final NotificationManager mNotificationManager;
|
private final NotificationManager mNotificationManager;
|
||||||
private final NotificationChannel mChannel;
|
private final NotificationChannel mChannel;
|
||||||
// Downstream type is one of ConnectivityManager.TETHERING_* constants, 0 1 or 2.
|
|
||||||
// This value has to be made 1 2 and 4, and OR'd with the others.
|
|
||||||
// WARNING : the constructor is called on a different thread. Thread safety therefore
|
// WARNING : the constructor is called on a different thread. Thread safety therefore
|
||||||
// relies on this value being initialized to 0, and not any other value. If you need
|
// relies on this value being initialized to 0, and not any other value. If you need
|
||||||
// to change this, you will need to change the thread where the constructor is invoked,
|
// to change this, you will need to change the thread where the constructor is invoked,
|
||||||
// or to introduce synchronization.
|
// or to introduce synchronization.
|
||||||
|
// Downstream type is one of ConnectivityManager.TETHERING_* constants, 0 1 or 2.
|
||||||
|
// This value has to be made 1 2 and 4, and OR'd with the others.
|
||||||
private int mDownstreamTypesMask = DOWNSTREAM_NONE;
|
private int mDownstreamTypesMask = DOWNSTREAM_NONE;
|
||||||
|
|
||||||
|
// WARNING : this value is not able to being initialized to 0 and must have volatile because
|
||||||
|
// telephony service is not guaranteed that is up before tethering service starts. If telephony
|
||||||
|
// is up later than tethering, TetheringNotificationUpdater will use incorrect and valid
|
||||||
|
// subscription id(0) to query resources. Therefore, initialized subscription id must be
|
||||||
|
// INVALID_SUBSCRIPTION_ID.
|
||||||
|
private volatile int mActiveDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
public TetheringNotificationUpdater(@NonNull final Context context) {
|
public TetheringNotificationUpdater(@NonNull final Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mNotificationManager = (NotificationManager) context.createContextAsUser(UserHandle.ALL, 0)
|
mNotificationManager = (NotificationManager) context.createContextAsUser(UserHandle.ALL, 0)
|
||||||
@@ -91,6 +103,18 @@ public class TetheringNotificationUpdater {
|
|||||||
updateNotification();
|
updateNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called when active data subscription id changed */
|
||||||
|
public void onActiveDataSubscriptionIdChanged(final int subId) {
|
||||||
|
if (mActiveDataSubId == subId) return;
|
||||||
|
mActiveDataSubId = subId;
|
||||||
|
updateNotification();
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
Resources getResourcesForSubId(@NonNull final Context c, final int subId) {
|
||||||
|
return SubscriptionManager.getResourcesForSubId(c, subId);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateNotification() {
|
private void updateNotification() {
|
||||||
final boolean tetheringInactive = mDownstreamTypesMask <= DOWNSTREAM_NONE;
|
final boolean tetheringInactive = mDownstreamTypesMask <= DOWNSTREAM_NONE;
|
||||||
|
|
||||||
@@ -115,11 +139,11 @@ public class TetheringNotificationUpdater {
|
|||||||
int downstreamTypesMask = DOWNSTREAM_NONE;
|
int downstreamTypesMask = DOWNSTREAM_NONE;
|
||||||
final String[] downstreams = types.split("\\|");
|
final String[] downstreams = types.split("\\|");
|
||||||
for (String downstream : downstreams) {
|
for (String downstream : downstreams) {
|
||||||
if ("USB".equals(downstream.trim())) {
|
if (USB_DOWNSTREAM.equals(downstream.trim())) {
|
||||||
downstreamTypesMask |= (1 << TETHERING_USB);
|
downstreamTypesMask |= (1 << TETHERING_USB);
|
||||||
} else if ("WIFI".equals(downstream.trim())) {
|
} else if (WIFI_DOWNSTREAM.equals(downstream.trim())) {
|
||||||
downstreamTypesMask |= (1 << TETHERING_WIFI);
|
downstreamTypesMask |= (1 << TETHERING_WIFI);
|
||||||
} else if ("BT".equals(downstream.trim())) {
|
} else if (BLUETOOTH_DOWNSTREAM.equals(downstream.trim())) {
|
||||||
downstreamTypesMask |= (1 << TETHERING_BLUETOOTH);
|
downstreamTypesMask |= (1 << TETHERING_BLUETOOTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,8 +159,7 @@ public class TetheringNotificationUpdater {
|
|||||||
* @return {@link android.util.SparseArray} with downstream types and icon id info.
|
* @return {@link android.util.SparseArray} with downstream types and icon id info.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private SparseArray<Integer> getIcons(@ArrayRes int id) {
|
private SparseArray<Integer> getIcons(@ArrayRes int id, @NonNull Resources res) {
|
||||||
final Resources res = mContext.getResources();
|
|
||||||
final String[] array = res.getStringArray(id);
|
final String[] array = res.getStringArray(id);
|
||||||
final SparseArray<Integer> icons = new SparseArray<>();
|
final SparseArray<Integer> icons = new SparseArray<>();
|
||||||
for (String config : array) {
|
for (String config : array) {
|
||||||
@@ -161,8 +184,9 @@ public class TetheringNotificationUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupNotification() {
|
private boolean setupNotification() {
|
||||||
final Resources res = mContext.getResources();
|
final Resources res = getResourcesForSubId(mContext, mActiveDataSubId);
|
||||||
final SparseArray<Integer> downstreamIcons = getIcons(R.array.tethering_notification_icons);
|
final SparseArray<Integer> downstreamIcons =
|
||||||
|
getIcons(R.array.tethering_notification_icons, res);
|
||||||
|
|
||||||
final int iconId = downstreamIcons.get(mDownstreamTypesMask, NO_ICON_ID);
|
final int iconId = downstreamIcons.get(mDownstreamTypesMask, NO_ICON_ID);
|
||||||
if (iconId == NO_ICON_ID) return NO_NOTIFY;
|
if (iconId == NO_ICON_ID) return NO_NOTIFY;
|
||||||
|
|||||||
@@ -210,7 +210,6 @@ public class TetheringTest {
|
|||||||
private PhoneStateListener mPhoneStateListener;
|
private PhoneStateListener mPhoneStateListener;
|
||||||
private InterfaceConfigurationParcel mInterfaceConfiguration;
|
private InterfaceConfigurationParcel mInterfaceConfiguration;
|
||||||
|
|
||||||
|
|
||||||
private class TestContext extends BroadcastInterceptingContext {
|
private class TestContext extends BroadcastInterceptingContext {
|
||||||
TestContext(Context base) {
|
TestContext(Context base) {
|
||||||
super(base);
|
super(base);
|
||||||
@@ -1399,6 +1398,7 @@ public class TetheringTest {
|
|||||||
mPhoneStateListener.onActiveDataSubscriptionIdChanged(fakeSubId);
|
mPhoneStateListener.onActiveDataSubscriptionIdChanged(fakeSubId);
|
||||||
final TetheringConfiguration newConfig = mTethering.getTetheringConfiguration();
|
final TetheringConfiguration newConfig = mTethering.getTetheringConfiguration();
|
||||||
assertEquals(fakeSubId, newConfig.activeDataSubId);
|
assertEquals(fakeSubId, newConfig.activeDataSubId);
|
||||||
|
verify(mNotificationUpdater, times(1)).onActiveDataSubscriptionIdChanged(eq(fakeSubId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user