Merge "Disable setting items in App details page" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ca72e5c333
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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));
|
||||
|
@@ -26,12 +26,13 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.loader.content.Loader;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.AppStorageSettings;
|
||||
import com.android.settings.applications.FetchPackageStorageAsyncLoader;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
@@ -47,14 +48,22 @@ public class AppStoragePreferenceController extends AppInfoPreferenceControllerB
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference.setEnabled(AppUtils.isAppInstalled(mAppEntry));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final ApplicationsState.AppEntry entry = mParent.getAppEntry();
|
||||
if (entry != null && entry.info != null) {
|
||||
final boolean isExternal =
|
||||
(entry.info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
|
||||
preference.setSummary(getStorageSummary(mLastResult, isExternal));
|
||||
if (!AppUtils.isAppInstalled(mAppEntry)) {
|
||||
preference.setSummary("");
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean isExternal =
|
||||
(mAppEntry.info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
|
||||
preference.setSummary(getStorageSummary(mLastResult, isExternal));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,5 +111,4 @@ public class AppStoragePreferenceController extends AppInfoPreferenceControllerB
|
||||
@Override
|
||||
public void onLoaderReset(Loader<StorageStatsSource.AppStorageStats> loader) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,6 +31,8 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.core.LiveDataController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,6 +47,8 @@ public class TimeSpentInAppPreferenceController extends LiveDataController {
|
||||
private final ApplicationFeatureProvider mAppFeatureProvider;
|
||||
private Intent mIntent;
|
||||
private String mPackageName;
|
||||
protected AppInfoDashboardFragment mParent;
|
||||
protected ApplicationsState.AppEntry mAppEntry;
|
||||
|
||||
public TimeSpentInAppPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
@@ -59,6 +63,14 @@ public class TimeSpentInAppPreferenceController extends LiveDataController {
|
||||
.putExtra(Intent.EXTRA_PACKAGE_NAME, mPackageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parent fragment for this controller.
|
||||
*/
|
||||
public void setParentFragment(AppInfoDashboardFragment parent) {
|
||||
mParent = parent;
|
||||
mAppEntry = mParent.getAppEntry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (TextUtils.isEmpty(mPackageName)) {
|
||||
@@ -84,6 +96,7 @@ public class TimeSpentInAppPreferenceController extends LiveDataController {
|
||||
if (pref != null) {
|
||||
pref.setIntent(mIntent);
|
||||
}
|
||||
pref.setEnabled(AppUtils.isAppInstalled(mAppEntry));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user