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

Commit 05de9819 authored by Tsung-Mao Fang's avatar Tsung-Mao Fang
Browse files

Disable setting items in App details page

Prior to this cl, we allow user to tap on those
setting items which belong to another user profile app.
However, we already observed some functional broken cases now.
Such as, device can't get the storage data/screen time/mobile data
battery, notification for those apps from another user profile.
Therefore, we decide to grey out those setting items,
and we don't allow user to tap on unsupported setting items.

Test: Download apk in different user profile, and see setting items
is disabled/enabled correctly. and run robo test.
Fix: 230303570

Change-Id: I1bb6b1d8b52f6a00088b2f0e4279b896d568f8a6
parent 9d0da1b6
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.settings.fuelgauge.BatteryUsageStatsLoader;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
@@ -71,9 +72,10 @@ public class AppBatteryPreferenceController extends BasePreferenceController
    BatteryDiffEntry mBatteryDiffEntry;
    @VisibleForTesting
    boolean mIsChartGraphEnabled;
    @VisibleForTesting
    final AppInfoDashboardFragment mParent;

    private Preference mPreference;
    private final AppInfoDashboardFragment mParent;
    private String mBatteryPercent;
    private final String mPackageName;
    private final int mUid;
@@ -107,6 +109,11 @@ public class AppBatteryPreferenceController extends BasePreferenceController
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
        mPreference.setEnabled(false);
        if (!AppUtils.isAppInstalled(mParent.getAppEntry())) {
            mPreference.setSummary("");
            return;
        }

        loadBatteryDiffEntries();
    }

+2 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.settings.Utils;
import com.android.settings.datausage.AppDataUsage;
import com.android.settings.datausage.DataUsageUtils;
import com.android.settingslib.AppItem;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
@@ -61,6 +62,7 @@ public class AppDataUsagePreferenceController extends AppInfoPreferenceControlle
    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference.setEnabled(AppUtils.isAppInstalled(mAppEntry));
    }

    @Override
+1 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
        final TimeSpentInAppPreferenceController timeSpentInAppPreferenceController = use(
                TimeSpentInAppPreferenceController.class);
        timeSpentInAppPreferenceController.setPackageName(packageName);
        timeSpentInAppPreferenceController.setParentFragment(this);
        timeSpentInAppPreferenceController.initLifeCycleOwner(this);

        use(AppDataUsagePreferenceController.class).setParentFragment(this);
+5 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import androidx.preference.PreferenceScreen;

import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.applications.ApplicationsState;

/*
 * Abstract base controller for the app detail preferences that refresh the state when the app state
@@ -35,6 +36,7 @@ public abstract class AppInfoPreferenceControllerBase extends BasePreferenceCont

    protected AppInfoDashboardFragment mParent;
    protected Preference mPreference;
    protected ApplicationsState.AppEntry mAppEntry;

    private final Class<? extends SettingsPreferenceFragment> mDetailFragmentClass;

@@ -72,10 +74,12 @@ public abstract class AppInfoPreferenceControllerBase extends BasePreferenceCont
    public void setParentFragment(AppInfoDashboardFragment parent) {
        mParent = parent;
        parent.addToCallbackList(this);
        mAppEntry = mParent.getAppEntry();
    }

    /**
     * Gets the fragment class to be launched when the preference is clicked.
     *
     * @return the fragment to launch
     */
    protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
@@ -84,10 +88,10 @@ public abstract class AppInfoPreferenceControllerBase extends BasePreferenceCont

    /**
     * Gets any extras that should be passed to the fragment class when the preference is clicked.
     *
     * @return a bundle of extras to include in the launch intent
     */
    protected Bundle getArguments() {
        return null;
    }

}
+9 −1
Original line number Diff line number Diff line
@@ -22,11 +22,13 @@ import android.content.Context;
import android.os.Bundle;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.app.AppNotificationSettings;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.AppNotificationSettings;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;

public class AppNotificationPreferenceController extends AppInfoPreferenceControllerBase {
@@ -49,6 +51,12 @@ public class AppNotificationPreferenceController extends AppInfoPreferenceContro
        }
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference.setEnabled(AppUtils.isAppInstalled(mAppEntry));
    }

    @Override
    public void updateState(Preference preference) {
        preference.setSummary(getNotificationSummary(mParent.getAppEntry(), mContext, mBackend));
Loading