Fix Settings getProfileIdsWithDisabled usage

In two places, Settings uses getProfileIdsWithDisabled intending to
restrict itself to *managed* profiles, but actually allows for any type
of profile.

Since the declared intent is to only deal with managed profiles, we
update the code to only consider managed profiles.

On devices that only have managed profiles (currently almost all
devices), this cl is a no-op.

Bug: 230495929
Bug: 230534572
Bug: 170249807
Test: com.android.settings.UtilsTest
Test: make RunSettingsRoboTests -j
Change-Id: Id04d45839ef61080b00ca2f91525718cb3a85120
This commit is contained in:
Adam Bookatz
2022-04-27 12:24:24 -07:00
parent de3a095e2c
commit 8311f68065
7 changed files with 57 additions and 37 deletions

View File

@@ -22,6 +22,7 @@ import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFIC
import android.app.KeyguardManager;
import android.content.Context;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.Looper;
@@ -42,6 +43,8 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import java.util.List;
/**
* The controller of the sensitive notifications.
*/
@@ -74,11 +77,13 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
mKm = context.getSystemService(KeyguardManager.class);
mProfileUserId = UserHandle.myUserId();
final int[] profileIds = mUm.getProfileIdsWithDisabled(UserHandle.myUserId());
for (int profileId : profileIds) {
if (profileId != UserHandle.myUserId()) {
mProfileUserId = profileId;
final List<UserInfo> profiles = mUm.getProfiles(UserHandle.myUserId());
final int count = profiles.size();
for (int i = 0; i < count; i++) {
final UserInfo profile = profiles.get(i);
if (profile.isManagedProfile()
&& profile.getUserHandle().getIdentifier() != UserHandle.myUserId()) {
mProfileUserId = profile.getUserHandle().getIdentifier();
}
}
}