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

Commit a037ad40 authored by Adnan Begovic's avatar Adnan Begovic
Browse files

SystemUi: Handle custom and dynamic tiles the same way.

Change-Id: I885a75444f88a8a0e521af55b413770681c55df6
parent de980ffe
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -513,11 +513,6 @@ public class PhoneStatusBarPolicy implements Callback {
        final int userId = UserHandle.myUserId();
        long token = Binder.clearCallingIdentity();
        try {
            if (!QSUtils.isQSTileEnabledForUser(
                    mContext, QSConstants.DYNAMIC_TILE_SU, userId)) {
                return;
            }

            final UserHandle user = new UserHandle(userId);
            final int icon = QSUtils.getDynamicQSTileResIconId(mContext, userId,
                    QSConstants.DYNAMIC_TILE_SU);
@@ -608,9 +603,7 @@ public class PhoneStatusBarPolicy implements Callback {

    private boolean isSuEnabledForUser(int userId) {
        final boolean hasSuAccess = mSuController.hasActiveSessions();
        final boolean isEnabledForUser = QSUtils.isQSTileEnabledForUser(mContext,
                QSConstants.DYNAMIC_TILE_SU, userId);
        return  (userId == UserHandle.USER_OWNER) && isEnabledForUser && hasSuAccess;
        return  (userId == UserHandle.USER_OWNER) && hasSuAccess;
    }

    private void processQSChangedLocked() {
+8 −19
Original line number Diff line number Diff line
@@ -289,7 +289,6 @@ public class QSTileHost implements QSTile.Host, Tunable {
        }
        if (DEBUG) Log.d(TAG, "Recreating tiles");
        final List<String> tileSpecs = loadTileSpecs(newValue);
        removeUnusedDynamicTiles(tileSpecs);
        if (tileSpecs.equals(mTileSpecs)) return;
        for (Map.Entry<String, QSTile<?>> tile : mTiles.entrySet()) {
            if (!tileSpecs.contains(tile.getKey())) {
@@ -304,7 +303,12 @@ public class QSTileHost implements QSTile.Host, Tunable {
            } else {
                if (DEBUG) Log.d(TAG, "Creating tile: " + tileSpec);
                try {
                    if (mCustomTileData.get(tileSpec) != null) {
                        newTiles.put(tileSpec, new CustomQSTile(this,
                                mCustomTileData.get(tileSpec).sbc));
                    } else {
                        newTiles.put(tileSpec, createTile(tileSpec));
                    }
                } catch (Throwable t) {
                    Log.w(TAG, "Error creating tile for spec: " + tileSpec, t);
                }
@@ -319,23 +323,6 @@ public class QSTileHost implements QSTile.Host, Tunable {
        }
    }

    private void removeUnusedDynamicTiles(List<String> tileSpecs) {
        List<CustomTileData.Entry> tilesToRemove = new ArrayList<>();
        for (CustomTileData.Entry entry : mCustomTileData.getEntries().values()) {
            if (entry.sbc.getPackage().equals(mContext.getPackageName())
                    || entry.sbc.getUid() == Process.SYSTEM_UID) {
                if (!tileSpecs.contains(entry.sbc.getTag())) {
                    tilesToRemove.add(entry);
                }
            }
        }

        for (CustomTileData.Entry entry : tilesToRemove) {
            mCustomTileData.remove(entry.key);
            removeCustomTile(entry.sbc);
        }
    }

    @Override
    public void goToSettingsPage() {
        if (mCallback != null) {
@@ -461,6 +448,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
    void addCustomTile(StatusBarPanelCustomTile sbc) {
        synchronized (mTiles) {
            mCustomTileData.add(new CustomTileData.Entry(sbc));
            mTileSpecs.add(sbc.getKey());
            mTiles.put(sbc.getKey(), new CustomQSTile(this, sbc));
            if (mCallback != null) {
                mCallback.onTilesChanged();
@@ -471,6 +459,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
    void removeCustomTileSysUi(String key) {
        synchronized (mTiles) {
            if (mTiles.containsKey(key)) {
                mTileSpecs.remove(key);
                mTiles.remove(key);
                mCustomTileData.remove(key);
                if (mCallback != null) {
+8 −14
Original line number Diff line number Diff line
@@ -1080,7 +1080,7 @@ class AlarmManagerService extends SystemService {
        if (a.alarmClock != null) {
            mNextAlarmClockMayChange = true;
            //Publish as system user
            publishNextAlarmCustomTile(Process.SYSTEM_UID);
            publishNextAlarmCustomTile(UserHandle.myUserId());
        }

        boolean needRebatch = false;
@@ -2691,11 +2691,6 @@ class AlarmManagerService extends SystemService {
        long token = Binder.clearCallingIdentity();
        try {
            final UserHandle user = new UserHandle(userId);
            if (!QSUtils.isQSTileEnabledForUser(
                    getContext(), QSConstants.DYNAMIC_TILE_NEXT_ALARM, user.getUserId(userId))) {
                return;
            }

            final int icon = QSUtils.getDynamicQSTileResIconId(getContext(), userId,
                    QSConstants.DYNAMIC_TILE_NEXT_ALARM);
            final String contentDesc = QSUtils.getDynamicQSTileLabel(getContext(), userId,
@@ -2714,13 +2709,18 @@ class AlarmManagerService extends SystemService {
                final String pkg = alarm.operation.getCreatorPackage();
                CustomTile.ExpandedListItem item = new CustomTile.ExpandedListItem();
                item.setExpandedListItemDrawable(icon);
                item.setExpandedListItemTitle(formatNextAlarm(getContext(), alarm.alarmClock, userId));
                item.setExpandedListItemTitle(formatNextAlarm(getContext(), alarm.alarmClock,
                        userId));
                item.setExpandedListItemSummary(getAlarmApkLabel(pkg));
                item.setExpandedListItemOnClickIntent(getCustomTilePendingIntent(user, pkg));
                items.add(item);
            }
            style.setListItems(items);

            // Don't bother posting a tile if no "next alarms" are available.
            if (nextAlarm == null) {
                return;
            }
            // Build the custom tile
            CMStatusBarManager statusBarManager = CMStatusBarManager.getInstance(getContext());
            CustomTile tile = new CustomTile.Builder(resourceContext)
@@ -2790,13 +2790,7 @@ class AlarmManagerService extends SystemService {
            int count = mNextAlarmClockForUser.size();
            for (int i = 0; i < count; i++) {
                int userId = mNextAlarmClockForUser.keyAt(i);
                boolean enabled = QSUtils.isQSTileEnabledForUser(
                        getContext(), QSConstants.DYNAMIC_TILE_NEXT_ALARM, userId);
                if (enabled) {
                publishNextAlarmCustomTile(userId);
                } else {
                    unpublishNextAlarmCustomTile(userId);
                }
            }
        }
    }
+1 −8
Original line number Diff line number Diff line
@@ -3582,11 +3582,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        final int userId = UserHandle.myUserId();
        long token = Binder.clearCallingIdentity();
        try {
            if (!QSUtils.isQSTileEnabledForUser(
                    mContext, QSConstants.DYNAMIC_TILE_IME_SELECTOR, userId)) {
                return;
            }

            final UserHandle user = new UserHandle(userId);
            final int icon = QSUtils.getDynamicQSTileResIconId(mContext, userId,
                    QSConstants.DYNAMIC_TILE_IME_SELECTOR);
@@ -3639,9 +3634,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            }
        }
        final boolean hasInputMethod = isIMEVisible && imi != null && mCurrentSubtype != null;
        final boolean isEnabledForUser = QSUtils.isQSTileEnabledForUser(mContext,
                QSConstants.DYNAMIC_TILE_NEXT_ALARM, userId);
        boolean enabled = isEnabledForUser && hasInputMethod;
        boolean enabled = hasInputMethod;
        if (enabled) {
            publishImeSelectorCustomTile(imi);
        } else {
+1 −8
Original line number Diff line number Diff line
@@ -923,11 +923,6 @@ public class UsbDeviceManager {
            final int userId = UserHandle.myUserId();
            long token = Binder.clearCallingIdentity();
            try {
                if (!QSUtils.isQSTileEnabledForUser(
                        mContext, QSConstants.DYNAMIC_TILE_ADB, userId)) {
                    return;
                }

                final UserHandle user = new UserHandle(userId);
                final int icon = QSUtils.getDynamicQSTileResIconId(mContext, userId,
                        QSConstants.DYNAMIC_TILE_ADB);
@@ -997,9 +992,7 @@ public class UsbDeviceManager {
                    || CMSettings.Secure.getInt(mContext.getContentResolver(),
                            CMSettings.Secure.ADB_NOTIFY, 1) == 1;
            boolean isActive = notifEnabled && (usbAdbActive || netAdbActive);
            final boolean isEnabledForUser = QSUtils.isQSTileEnabledForUser(mContext,
                    QSConstants.DYNAMIC_TILE_ADB, userId);
            boolean enabled = (userId == UserHandle.USER_OWNER) && isEnabledForUser && isActive;
            boolean enabled = (userId == UserHandle.USER_OWNER) && isActive;
            if (enabled) {
                publishAdbCustomTile();
            } else {