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

Commit 79ef1e6b authored by Nishith  Khanna's avatar Nishith Khanna
Browse files

Merge remote-tracking branch 'origin/lineage-20.0' into v1-t

parents 67854d6a e7a28e77
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2334,7 +2334,6 @@ public class NotificationManagerService extends SystemService {
                mAppOps,
                new SysUiStatsEvent.BuilderFactory(),
                mShowReviewPermissionsNotification);
        mPreferencesHelper.updateFixedImportance(mUm.getUsers());
        mRankingHelper = new RankingHelper(getContext(),
                mRankingHandler,
                mPreferencesHelper,
@@ -2785,6 +2784,9 @@ public class NotificationManagerService extends SystemService {
            maybeShowInitialReviewPermissionsNotification();
        } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) {
            mSnoozeHelper.scheduleRepostsForPersistedNotifications(System.currentTimeMillis());
        } else if (phase == SystemService.PHASE_DEVICE_SPECIFIC_SERVICES_READY) {
            mPreferencesHelper.updateFixedImportance(mUm.getUsers());
            mPreferencesHelper.migrateNotificationPermissions(mUm.getUsers());
        }
    }
+27 −20
Original line number Diff line number Diff line
@@ -240,7 +240,6 @@ public class PreferencesHelper implements RankingConfig {
                    Settings.Global.REVIEW_PERMISSIONS_NOTIFICATION_STATE,
                    NotificationManagerService.REVIEW_NOTIF_STATE_SHOULD_SHOW);
        }
        ArrayList<PermissionHelper.PackagePermission> pkgPerms = new ArrayList<>();
        synchronized (mPackagePreferences) {
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
                tag = parser.getName();
@@ -258,27 +257,18 @@ public class PreferencesHelper implements RankingConfig {
                        String name = parser.getAttributeValue(null, ATT_NAME);
                        if (!TextUtils.isEmpty(name)) {
                            restorePackage(parser, forRestore, userId, name, upgradeForBubbles,
                                    migrateToPermission, pkgPerms);
                                    migrateToPermission);
                        }
                    }
                }
            }
        }
        if (migrateToPermission) {
            for (PackagePermission p : pkgPerms) {
                try {
                    mPermissionHelper.setNotificationPermission(p);
                } catch (Exception e) {
                    Slog.e(TAG, "could not migrate setting for " + p.packageName, e);
                }
            }
        }
    }

    @GuardedBy("mPackagePreferences")
    private void restorePackage(TypedXmlPullParser parser, boolean forRestore,
            @UserIdInt int userId, String name, boolean upgradeForBubbles,
            boolean migrateToPermission, ArrayList<PermissionHelper.PackagePermission> pkgPerms) {
            boolean migrateToPermission) {
        try {
            int uid = parser.getAttributeInt(null, ATT_UID, UNKNOWN_UID);
            if (forRestore) {
@@ -387,14 +377,6 @@ public class PreferencesHelper implements RankingConfig {
            if (migrateToPermission) {
                r.importance = appImportance;
                r.migrateToPm = true;
                if (r.uid != UNKNOWN_UID) {
                    // Don't call into permission system until we have a valid uid
                    PackagePermission pkgPerm = new PackagePermission(
                            r.pkg, UserHandle.getUserId(r.uid),
                            r.importance != IMPORTANCE_NONE,
                            hasUserConfiguredSettings(r));
                    pkgPerms.add(pkgPerm);
                }
            }
        } catch (Exception e) {
            Slog.w(TAG, "Failed to restore pkg", e);
@@ -2706,6 +2688,31 @@ public class PreferencesHelper implements RankingConfig {
        }
    }

    public void migrateNotificationPermissions(List<UserInfo> users) {
        for (UserInfo user : users) {
            List<PackageInfo> packages = mPm.getInstalledPackagesAsUser(
                    PackageManager.PackageInfoFlags.of(PackageManager.MATCH_ALL),
                    user.getUserHandle().getIdentifier());
            for (PackageInfo pi : packages) {
                synchronized (mPackagePreferences) {
                    PackagePreferences p = getOrCreatePackagePreferencesLocked(
                            pi.packageName, pi.applicationInfo.uid);
                    if (p.migrateToPm && p.uid != UNKNOWN_UID) {
                        try {
                            PackagePermission pkgPerm = new PackagePermission(
                                    p.pkg, UserHandle.getUserId(p.uid),
                                    p.importance != IMPORTANCE_NONE,
                                    hasUserConfiguredSettings(p));
                            mPermissionHelper.setNotificationPermission(pkgPerm);
                        } catch (Exception e) {
                            Slog.e(TAG, "could not migrate setting for " + p.pkg, e);
                        }
                    }
                }
            }
        }
    }

    private void updateConfig() {
        mRankingHandler.requestSort();
    }
+0 −4
Original line number Diff line number Diff line
@@ -676,10 +676,6 @@ public class PreferencesHelperTest extends UiServiceTestCase {
        compareChannels(ido, mHelper.getNotificationChannel(PKG_O, UID_O, ido.getId(), false));
        compareChannels(idp, mHelper.getNotificationChannel(PKG_P, UID_P, idp.getId(), false));

        verify(mPermissionHelper).setNotificationPermission(nMr1Expected);
        verify(mPermissionHelper).setNotificationPermission(oExpected);
        verify(mPermissionHelper).setNotificationPermission(pExpected);

        // verify that we also write a state for review_permissions_notification to eventually
        // show a notification
        assertEquals(NotificationManagerService.REVIEW_NOTIF_STATE_SHOULD_SHOW,