Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42f21d60 authored by Yuichiro Hanada's avatar Yuichiro Hanada
Browse files

Null check for the return value of getPackagesForOps()

AppOpsService.getPackagesForOps() may return null. The caller should
check it.

Bug: 324329757
Test: SystemUITests
Flag: NA
Change-Id: Ifc51678733caf412421c5ea1827668b3698e44e0
parent c12aae9d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -229,6 +229,9 @@ public class AppOpsControllerImpl extends BroadcastReceiver implements AppOpsCon

    private void fetchCurrentActiveOps() {
        List<AppOpsManager.PackageOps> packageOps = mAppOps.getPackagesForOps(OPS);
        if (packageOps == null) {
            return;
        }
        for (AppOpsManager.PackageOps op : packageOps) {
            for (AppOpsManager.OpEntry entry : op.getOps()) {
                for (Map.Entry<String, AppOpsManager.AttributedOpEntry> attributedOpEntry :
+11 −0
Original line number Diff line number Diff line
@@ -180,6 +180,17 @@ public class AppOpsControllerTest extends SysuiTestCase {
        assertThat(mController.getActiveAppOps()).isEmpty();
    }

    /** Regression test for b/324329757 */
    @Test
    public void startListening_fetchCurrentActive_nullPackageOps() {
        when(mAppOpsManager.getPackagesForOps(AppOpsControllerImpl.OPS)).thenReturn(null);

        mController.setListening(true);
        mBgExecutor.runAllReady();

        assertThat(mController.getActiveAppOps()).isEmpty();
    }

    /** Regression test for b/294104969. */
    @Test
    public void startListening_fetchesCurrentActive_oneActive() {