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

Commit 6d041cbe authored by Danny Epstein's avatar Danny Epstein Committed by Android (Google) Code Review
Browse files

Merge "Only update privacy chip when privacy items change"

parents fdc7249d ece19c55
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import java.util.stream.Collectors;
public class OngoingPrivacyChip extends LinearLayout implements View.OnClickListener {

    private Context mContext;
    private Handler mHandler;

    private LinearLayout mIconsContainer;
    private List<PrivacyItem> mPrivacyItems;
@@ -88,6 +89,7 @@ public class OngoingPrivacyChip extends LinearLayout implements View.OnClickList

    private void init(Context context) {
        mContext = context;
        mHandler = new Handler(Looper.getMainLooper());
        mPrivacyItems = new ArrayList<>();
        sAppOpsController = Dependency.get(AppOpsController.class);
        mUserManager = mContext.getSystemService(UserManager.class);
@@ -131,8 +133,7 @@ public class OngoingPrivacyChip extends LinearLayout implements View.OnClickList
    @Override
    public void onClick(View v) {
        updatePrivacyList();
        Handler mUiHandler = new Handler(Looper.getMainLooper());
        mUiHandler.post(() -> {
        mHandler.post(() -> {
            mActivityStarter.postStartActivityDismissingKeyguard(
                    new Intent(Intent.ACTION_REVIEW_ONGOING_PERMISSION_USAGE), 0);
        });
@@ -152,21 +153,17 @@ public class OngoingPrivacyChip extends LinearLayout implements View.OnClickList
    }

    private void updatePrivacyList() {
        mPrivacyItems = mCurrentUserIds.stream()
        List<PrivacyItem> privacyItems = mCurrentUserIds.stream()
                .flatMap(item -> sAppOpsController.getActiveAppOpsForUser(item).stream())
                .filter(Objects::nonNull)
                .map(item -> toPrivacyItem(item))
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        if (!privacyItems.equals(mPrivacyItems)) {
            mPrivacyItems = privacyItems;
            mPrivacyDialogBuilder = new PrivacyDialogBuilder(mContext, mPrivacyItems);

        Handler refresh = new Handler(Looper.getMainLooper());
        refresh.post(new Runnable() {
            @Override
            public void run() {
                updateView();
            mHandler.post(this::updateView);
        }
        });
    }

    private PrivacyItem toPrivacyItem(AppOpItem appOpItem) {
+17 −0
Original line number Diff line number Diff line
@@ -23,16 +23,20 @@ import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.util.Log;

import java.util.Objects;

/**
 * Class to hold the data for the applications that are using the AppOps permissions.
 */
public class PrivacyApplication {
    private static final String TAG = "PrivacyApplication";

    private String mPackageName;
    private Drawable mIcon;
    private String mApplicationName;

    public PrivacyApplication(String packageName, Context context) {
        mPackageName = packageName;
        try {
            CarUserManagerHelper carUserManagerHelper = new CarUserManagerHelper(context);
            ApplicationInfo app = context.getPackageManager()
@@ -59,4 +63,17 @@ public class PrivacyApplication {
    public String getApplicationName() {
        return mApplicationName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PrivacyApplication that = (PrivacyApplication) o;
        return mPackageName.equals(that.mPackageName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mPackageName);
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar.car.privacy;

import java.util.Objects;

/**
 * Class for holding the data of each privacy item displayed in {@link OngoingPrivacyDialog}
 */
@@ -43,4 +45,18 @@ public class PrivacyItem {
    public PrivacyType getPrivacyType() {
        return mPrivacyType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PrivacyItem that = (PrivacyItem) o;
        return mPrivacyType == that.mPrivacyType
                && mPrivacyApplication.equals(that.mPrivacyApplication);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mPrivacyType, mPrivacyApplication);
    }
}