Consolidate the 2 app button prefernece controllers.
- move the fuelgauge app button controller and the button dialog fragment into app info package and change app detail fragment to use that controller instead. - remove the original appinfo/AppActionButtonPreferenceController Change-Id: I94ca072a8dfe6051853eb23efa1f96ac3e13d79d Fixes: 80312809 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -19,14 +19,12 @@ package com.android.settings.applications.appinfo;
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -35,7 +33,6 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -47,7 +44,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.DeviceAdminAdd;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
@@ -62,7 +58,6 @@ import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -77,7 +72,8 @@ import java.util.List;
|
||||
* uninstall the application.
|
||||
*/
|
||||
public class AppInfoDashboardFragment extends DashboardFragment
|
||||
implements ApplicationsState.Callbacks {
|
||||
implements ApplicationsState.Callbacks,
|
||||
ButtonActionDialogFragment.AppButtonsDialogListener {
|
||||
|
||||
private static final String TAG = "AppInfoDashboard";
|
||||
|
||||
@@ -101,10 +97,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
|
||||
// Dialog identifiers used in showDialog
|
||||
private static final int DLG_BASE = 0;
|
||||
private static final int DLG_FORCE_STOP = DLG_BASE + 1;
|
||||
private static final int DLG_DISABLE = DLG_BASE + 2;
|
||||
private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 3;
|
||||
static final int DLG_CLEAR_INSTANT_APP = DLG_BASE + 4;
|
||||
static final int DLG_CLEAR_INSTANT_APP = DLG_BASE + 1;
|
||||
|
||||
public static final String ARG_PACKAGE_NAME = "package";
|
||||
public static final String ARG_PACKAGE_UID = "uid";
|
||||
@@ -132,12 +125,11 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
private boolean mInitialized;
|
||||
private boolean mShowUninstalled;
|
||||
private boolean mUpdatedSysApp = false;
|
||||
private boolean mDisableAfterUninstall;
|
||||
|
||||
private List<Callback> mCallbacks = new ArrayList<>();
|
||||
|
||||
private InstantAppButtonsPreferenceController mInstantAppButtonPreferenceController;
|
||||
private AppActionButtonPreferenceController mAppActionButtonPreferenceController;
|
||||
private AppButtonsPreferenceController mAppButtonsPreferenceController;
|
||||
|
||||
/**
|
||||
* Callback to invoke when app info has been changed.
|
||||
@@ -146,11 +138,6 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
void refreshUi();
|
||||
}
|
||||
|
||||
private boolean isDisabledUntilUsed() {
|
||||
return mAppEntry.info.enabledSetting
|
||||
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -262,9 +249,6 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
// when app state changes.
|
||||
controllers.add(
|
||||
new AppHeaderViewPreferenceController(context, this, packageName, lifecycle));
|
||||
mAppActionButtonPreferenceController =
|
||||
new AppActionButtonPreferenceController(context, this, packageName);
|
||||
controllers.add(mAppActionButtonPreferenceController);
|
||||
|
||||
for (AbstractPreferenceController controller : controllers) {
|
||||
mCallbacks.add((Callback) controller);
|
||||
@@ -275,6 +259,10 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
mInstantAppButtonPreferenceController =
|
||||
new InstantAppButtonsPreferenceController(context, this, packageName, lifecycle);
|
||||
controllers.add(mInstantAppButtonPreferenceController);
|
||||
mAppButtonsPreferenceController = new AppButtonsPreferenceController(
|
||||
(SettingsActivity) getActivity(), this, lifecycle, packageName, mState,
|
||||
REQUEST_UNINSTALL, REQUEST_REMOVE_DEVICE_ADMIN);
|
||||
controllers.add(mAppButtonsPreferenceController);
|
||||
controllers.add(new AppBatteryPreferenceController(context, this, packageName, lifecycle));
|
||||
controllers.add(new AppMemoryPreferenceController(context, this, lifecycle));
|
||||
controllers.add(new DefaultHomeShortcutPreferenceController(context, packageName));
|
||||
@@ -374,30 +362,19 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch (requestCode) {
|
||||
case REQUEST_UNINSTALL:
|
||||
// Refresh option menu
|
||||
getActivity().invalidateOptionsMenu();
|
||||
if (requestCode == REQUEST_UNINSTALL) {
|
||||
// Refresh option menu
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
if (mAppButtonsPreferenceController != null) {
|
||||
mAppButtonsPreferenceController.handleActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
if (mDisableAfterUninstall) {
|
||||
mDisableAfterUninstall = false;
|
||||
new DisableChanger(this, mAppEntry.info,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
|
||||
.execute((Object) null);
|
||||
}
|
||||
if (!refreshUi()) {
|
||||
onPackageRemoved();
|
||||
} else {
|
||||
startListeningToPackageRemove();
|
||||
}
|
||||
break;
|
||||
case REQUEST_REMOVE_DEVICE_ADMIN:
|
||||
if (!refreshUi()) {
|
||||
setIntentAndFinish(true, true);
|
||||
} else {
|
||||
startListeningToPackageRemove();
|
||||
}
|
||||
break;
|
||||
@Override
|
||||
public void handleDialogClick(int id) {
|
||||
if (mAppButtonsPreferenceController != null) {
|
||||
mAppButtonsPreferenceController.handleDialogClick(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,6 +419,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
for (Callback callback : mCallbacks) {
|
||||
callback.refreshUi();
|
||||
}
|
||||
mAppButtonsPreferenceController.refreshUi();
|
||||
|
||||
if (!mInitialized) {
|
||||
// First time init: are we displaying an uninstalled app?
|
||||
@@ -471,53 +449,6 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
|
||||
@VisibleForTesting
|
||||
AlertDialog createDialog(int id, int errorCode) {
|
||||
switch (id) {
|
||||
case DLG_DISABLE:
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setMessage(getActivity().getText(R.string.app_disable_dlg_text))
|
||||
.setPositiveButton(R.string.app_disable_dlg_positive,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Disable the app
|
||||
mMetricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_DISABLE_APP);
|
||||
new DisableChanger(AppInfoDashboardFragment.this,
|
||||
mAppEntry.info,
|
||||
PackageManager
|
||||
.COMPONENT_ENABLED_STATE_DISABLED_USER)
|
||||
.execute((Object) null);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.dlg_cancel, null)
|
||||
.create();
|
||||
case DLG_SPECIAL_DISABLE:
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setMessage(getActivity().getText(R.string.app_disable_dlg_text))
|
||||
.setPositiveButton(R.string.app_disable_dlg_positive,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Disable the app and ask for uninstall
|
||||
mMetricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_DISABLE_APP);
|
||||
uninstallPkg(mAppEntry.info.packageName,
|
||||
false, true);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.dlg_cancel, null)
|
||||
.create();
|
||||
case DLG_FORCE_STOP:
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setTitle(getActivity().getText(R.string.force_stop_dlg_title))
|
||||
.setMessage(getActivity().getText(R.string.force_stop_dlg_text))
|
||||
.setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Force stop
|
||||
forceStopPackage(mAppEntry.info.packageName);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.dlg_cancel, null)
|
||||
.create();
|
||||
}
|
||||
return mInstantAppButtonPreferenceController.createDialog(id);
|
||||
}
|
||||
|
||||
@@ -530,22 +461,6 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
mMetricsFeatureProvider.action(
|
||||
getContext(), MetricsEvent.ACTION_SETTINGS_UNINSTALL_APP);
|
||||
startActivityForResult(uninstallIntent, REQUEST_UNINSTALL);
|
||||
mDisableAfterUninstall = andDisable;
|
||||
}
|
||||
|
||||
private void forceStopPackage(String pkgName) {
|
||||
mMetricsFeatureProvider.action(getContext(), MetricsEvent.ACTION_APP_FORCE_STOP, pkgName);
|
||||
final ActivityManager am = (ActivityManager) getActivity().getSystemService(
|
||||
Context.ACTIVITY_SERVICE);
|
||||
Log.d(TAG, "Stopping package " + pkgName);
|
||||
am.forceStopPackage(pkgName);
|
||||
final int userId = UserHandle.getUserId(mAppEntry.info.uid);
|
||||
mState.invalidatePackage(pkgName, userId);
|
||||
final AppEntry newEnt = mState.getEntry(pkgName, userId);
|
||||
if (newEnt != null) {
|
||||
mAppEntry = newEnt;
|
||||
}
|
||||
mAppActionButtonPreferenceController.checkForceStop(mAppEntry, mPackageInfo);
|
||||
}
|
||||
|
||||
public static void startAppInfoFragment(Class<?> fragment, int title, Bundle args,
|
||||
@@ -565,74 +480,6 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
.launch();
|
||||
}
|
||||
|
||||
void handleUninstallButtonClick() {
|
||||
if (mAppEntry == null) {
|
||||
setIntentAndFinish(true, true);
|
||||
return;
|
||||
}
|
||||
final String packageName = mAppEntry.info.packageName;
|
||||
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
||||
stopListeningToPackageRemove();
|
||||
final Activity activity = getActivity();
|
||||
final Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class);
|
||||
uninstallDAIntent.putExtra(DeviceAdminAdd.EXTRA_DEVICE_ADMIN_PACKAGE_NAME,
|
||||
mPackageName);
|
||||
mMetricsFeatureProvider.action(
|
||||
activity, MetricsEvent.ACTION_SETTINGS_UNINSTALL_DEVICE_ADMIN);
|
||||
activity.startActivityForResult(uninstallDAIntent, REQUEST_REMOVE_DEVICE_ADMIN);
|
||||
return;
|
||||
}
|
||||
final EnforcedAdmin admin = RestrictedLockUtils.checkIfUninstallBlocked(getActivity(),
|
||||
packageName, mUserId);
|
||||
final boolean uninstallBlockedBySystem = mAppsControlDisallowedBySystem ||
|
||||
RestrictedLockUtils.hasBaseUserRestriction(getActivity(), packageName, mUserId);
|
||||
if (admin != null && !uninstallBlockedBySystem) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), admin);
|
||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||
if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
||||
// If the system app has an update and this is the only user on the device,
|
||||
// then offer to downgrade the app, otherwise only offer to disable the
|
||||
// app for this user.
|
||||
if (mUpdatedSysApp && isSingleUser()) {
|
||||
showDialogInner(DLG_SPECIAL_DISABLE, 0);
|
||||
} else {
|
||||
showDialogInner(DLG_DISABLE, 0);
|
||||
}
|
||||
} else {
|
||||
mMetricsFeatureProvider.action(
|
||||
getActivity(),
|
||||
MetricsEvent.ACTION_SETTINGS_ENABLE_APP);
|
||||
new DisableChanger(this, mAppEntry.info,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
|
||||
.execute((Object) null);
|
||||
}
|
||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
||||
uninstallPkg(packageName, true, false);
|
||||
} else {
|
||||
uninstallPkg(packageName, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
void handleForceStopButtonClick() {
|
||||
if (mAppEntry == null) {
|
||||
setIntentAndFinish(true, true);
|
||||
return;
|
||||
}
|
||||
if (mAppsControlDisallowedAdmin != null && !mAppsControlDisallowedBySystem) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
||||
getActivity(), mAppsControlDisallowedAdmin);
|
||||
} else {
|
||||
showDialogInner(DLG_FORCE_STOP, 0);
|
||||
//forceStopPackage(mAppInfo.packageName);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns whether there is only one user on this device, not including the system-only user */
|
||||
private boolean isSingleUser() {
|
||||
final int userCount = mUserManager.getUserCount();
|
||||
return userCount == 1 || (mUserManager.isSplitSystemUser() && userCount == 2);
|
||||
}
|
||||
|
||||
private void onPackageRemoved() {
|
||||
getActivity().finishActivity(SUB_INFO_FRAGMENT);
|
||||
getActivity().finishAndRemoveTask();
|
||||
@@ -659,26 +506,6 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
return count;
|
||||
}
|
||||
|
||||
private static class DisableChanger extends AsyncTask<Object, Object, Object> {
|
||||
final PackageManager mPm;
|
||||
final WeakReference<AppInfoDashboardFragment> mActivity;
|
||||
final ApplicationInfo mInfo;
|
||||
final int mState;
|
||||
|
||||
DisableChanger(AppInfoDashboardFragment activity, ApplicationInfo info, int state) {
|
||||
mPm = activity.mPm;
|
||||
mActivity = new WeakReference<AppInfoDashboardFragment>(activity);
|
||||
mInfo = info;
|
||||
mState = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object... params) {
|
||||
mPm.setApplicationEnabledSetting(mInfo.packageName, mState, 0);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getPackageName() {
|
||||
if (mPackageName != null) {
|
||||
return mPackageName;
|
||||
|
Reference in New Issue
Block a user