Skip to content
Snippets Groups Projects
Commit 5a685574 authored by Chalard Jean's avatar Chalard Jean
Browse files

Delete slots as the listeners are unregistered.

For the current code this is a no-op because the new
slots are always computed immediately in the same
critical section.

When the code uses callbacks for the carrier service UID
though, there will no longer be a time where the entire
array is reset. Instead, registering the callback will
immediately trigger the call that populates it again,
which means the value needs to be removed when a SIM
card is removed. Unregistering the callback is a good
time to do this.

Test: CarrierPrivilegeAuthenticatorTest
Change-Id: I6de4abdc57ffa455d7f8e4d35f5dd1e18937e94e
parent 1e4c90c7
No related branches found
No related tags found
No related merge requests found
......@@ -124,6 +124,11 @@ public class CarrierPrivilegeAuthenticator {
}
private class PrivilegeListener implements CarrierPrivilegesListenerShim {
public final int mLogicalSlot;
PrivilegeListener(final int logicalSlot) {
mLogicalSlot = logicalSlot;
}
@Override public void onCarrierPrivilegesChanged(
@NonNull List<String> privilegedPackageNames,
@NonNull int[] privilegedUids) {
......@@ -147,8 +152,8 @@ public class CarrierPrivilegeAuthenticator {
final HandlerExecutor executor = new HandlerExecutor(mHandler);
try {
for (int i = 0; i < modemCount; i++) {
PrivilegeListener carrierPrivilegesListener = new PrivilegeListener();
addCarrierPrivilegesListener(i, executor, carrierPrivilegesListener);
PrivilegeListener carrierPrivilegesListener = new PrivilegeListener(i);
addCarrierPrivilegesListener(executor, carrierPrivilegesListener);
mCarrierPrivilegesChangedListeners.add(carrierPrivilegesListener);
}
} catch (IllegalArgumentException e) {
......@@ -160,6 +165,7 @@ public class CarrierPrivilegeAuthenticator {
private void unregisterCarrierPrivilegesListeners() {
for (PrivilegeListener carrierPrivilegesListener : mCarrierPrivilegesChangedListeners) {
removeCarrierPrivilegesListener(carrierPrivilegesListener);
mCarrierServiceUid.delete(carrierPrivilegesListener.mLogicalSlot);
}
mCarrierPrivilegesChangedListeners.clear();
}
......@@ -260,11 +266,11 @@ public class CarrierPrivilegeAuthenticator {
// Helper methods to avoid having to deal with UnsupportedApiLevelException.
private void addCarrierPrivilegesListener(final int logicalSlotIndex,
@NonNull final Executor executor, @NonNull final PrivilegeListener listener) {
private void addCarrierPrivilegesListener(@NonNull final Executor executor,
@NonNull final PrivilegeListener listener) {
try {
mTelephonyManagerShim.addCarrierPrivilegesListener(
logicalSlotIndex, executor, listener);
mTelephonyManagerShim.addCarrierPrivilegesListener(listener.mLogicalSlot, executor,
listener);
} catch (UnsupportedApiLevelException unsupportedApiLevelException) {
// Should not happen since CarrierPrivilegeAuthenticator is only used on T+
Log.e(TAG, "addCarrierPrivilegesListener API is not available");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment