Merge "Stop apps with Storage Managers from launching activity when disabled"

This commit is contained in:
TreeHugger Robot
2016-08-18 21:30:41 +00:00
committed by Android (Google) Code Review

View File

@@ -60,6 +60,9 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.TreeMap; import java.util.TreeMap;
import static android.content.pm.ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;
public class AppStorageSettings extends AppInfoWithHeader public class AppStorageSettings extends AppInfoWithHeader
implements OnClickListener, Callbacks, DialogInterface.OnClickListener { implements OnClickListener, Callbacks, DialogInterface.OnClickListener {
private static final String TAG = AppStorageSettings.class.getSimpleName(); private static final String TAG = AppStorageSettings.class.getSimpleName();
@@ -354,19 +357,27 @@ public class AppStorageSettings extends AppInfoWithHeader
} }
private void initDataButtons() { private void initDataButtons() {
// If the app doesn't have its own space management UI final boolean appHasSpaceManagementUI = mAppEntry.info.manageSpaceActivityName != null;
// And it's a system app that doesn't allow clearing user data or is an active admin final boolean appHasActiveAdmins = mDpm.packageHasActiveAdmins(mPackageName);
// Then disable the Clear Data button. // Check that SYSTEM_APP flag is set, and ALLOW_CLEAR_USER_DATA is not set.
if (mAppEntry.info.manageSpaceActivityName == null final boolean isNonClearableSystemApp =
&& ((mAppEntry.info.flags&(ApplicationInfo.FLAG_SYSTEM (mAppEntry.info.flags & (FLAG_SYSTEM | FLAG_ALLOW_CLEAR_USER_DATA)) == FLAG_SYSTEM;
| ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA)) final boolean appRestrictsClearingData = isNonClearableSystemApp || appHasActiveAdmins;
== ApplicationInfo.FLAG_SYSTEM
|| mDpm.packageHasActiveAdmins(mPackageName))) { final Intent intent = new Intent(Intent.ACTION_DEFAULT);
if (appHasSpaceManagementUI) {
intent.setClassName(mAppEntry.info.packageName, mAppEntry.info.manageSpaceActivityName);
}
final boolean isManageSpaceActivityAvailable =
getPackageManager().resolveActivity(intent, 0) != null;
if ((!appHasSpaceManagementUI && appRestrictsClearingData)
|| !isManageSpaceActivityAvailable) {
mClearDataButton.setText(R.string.clear_user_data_text); mClearDataButton.setText(R.string.clear_user_data_text);
mClearDataButton.setEnabled(false); mClearDataButton.setEnabled(false);
mCanClearData = false; mCanClearData = false;
} else { } else {
if (mAppEntry.info.manageSpaceActivityName != null) { if (appHasSpaceManagementUI) {
mClearDataButton.setText(R.string.manage_space_text); mClearDataButton.setText(R.string.manage_space_text);
} else { } else {
mClearDataButton.setText(R.string.clear_user_data_text); mClearDataButton.setText(R.string.clear_user_data_text);