Fix crash in Storage app info when the corresponding app is uninstalled
in the background. 1. Move the handling for package removal from InstalledAppDetails to AppInfoBase so that all app info subclass will now finish correspondingly if the package is uninstalled. 2. In InstalledAppDetails, when handling package removal, will also finish the app info fragment that it starts earlier. Change-Id: Id741e7475414045040dd0797ff3bc63ac214f400 Fixes: 27774473
This commit is contained in:
@@ -515,7 +515,7 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
if (resultTo == null) {
|
if (resultTo == null) {
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
resultTo.startActivityForResult(intent, resultRequestCode);
|
resultTo.getActivity().startActivityForResult(intent, resultRequestCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,8 +22,10 @@ import android.app.Dialog;
|
|||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
@@ -74,6 +76,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
protected static final int DLG_BASE = 0;
|
protected static final int DLG_BASE = 0;
|
||||||
|
|
||||||
protected boolean mFinishing;
|
protected boolean mFinishing;
|
||||||
|
protected boolean mListeningToPackageRemove;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -90,6 +93,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
mUsbManager = IUsbManager.Stub.asInterface(b);
|
mUsbManager = IUsbManager.Stub.asInterface(b);
|
||||||
|
|
||||||
retrieveAppEntry();
|
retrieveAppEntry();
|
||||||
|
startListeningToPackageRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,6 +118,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
stopListeningToPackageRemove();
|
||||||
mSession.release();
|
mSession.release();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
@@ -246,4 +251,37 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
return dialogFragment;
|
return dialogFragment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void startListeningToPackageRemove() {
|
||||||
|
if (mListeningToPackageRemove) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mListeningToPackageRemove = true;
|
||||||
|
final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED);
|
||||||
|
filter.addDataScheme("package");
|
||||||
|
getContext().registerReceiver(mPackageRemovedReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void stopListeningToPackageRemove() {
|
||||||
|
if (!mListeningToPackageRemove) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mListeningToPackageRemove = false;
|
||||||
|
getContext().unregisterReceiver(mPackageRemovedReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPackageRemoved() {
|
||||||
|
getActivity().finishAndRemoveTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final BroadcastReceiver mPackageRemovedReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String packageName = intent.getData().getSchemeSpecificPart();
|
||||||
|
if (!mFinishing && mAppEntry.info.packageName.equals(packageName)) {
|
||||||
|
onPackageRemoved();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,6 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.Loader;
|
import android.content.Loader;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
@@ -165,8 +164,6 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
private Preference mMemoryPreference;
|
private Preference mMemoryPreference;
|
||||||
|
|
||||||
private boolean mDisableAfterUninstall;
|
private boolean mDisableAfterUninstall;
|
||||||
private boolean mListeningToPackageRemove;
|
|
||||||
|
|
||||||
// Used for updating notification preference.
|
// Used for updating notification preference.
|
||||||
private final NotificationBackend mBackend = new NotificationBackend();
|
private final NotificationBackend mBackend = new NotificationBackend();
|
||||||
|
|
||||||
@@ -326,7 +323,6 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
removePreference(KEY_DATA);
|
removePreference(KEY_DATA);
|
||||||
}
|
}
|
||||||
mBatteryHelper = new BatteryStatsHelper(getActivity(), true);
|
mBatteryHelper = new BatteryStatsHelper(getActivity(), true);
|
||||||
startListeningToPackageRemove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -362,7 +358,6 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
TrafficStats.closeQuietly(mStatsSession);
|
TrafficStats.closeQuietly(mStatsSession);
|
||||||
stopListeningToPackageRemove();
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,7 +737,7 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
|
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
|
||||||
intent.putExtra(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
intent.putExtra(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
||||||
try {
|
try {
|
||||||
startActivity(intent);
|
getActivity().startActivityForResult(intent, SUB_INFO_FRAGMENT);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
Log.w(LOG_TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
|
Log.w(LOG_TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
|
||||||
}
|
}
|
||||||
@@ -1090,6 +1085,12 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
return summary.toString();
|
return summary.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPackageRemoved() {
|
||||||
|
getActivity().finishActivity(SUB_INFO_FRAGMENT);
|
||||||
|
super.onPackageRemoved();
|
||||||
|
}
|
||||||
|
|
||||||
private class MemoryUpdater extends AsyncTask<Void, Void, ProcStatsPackageEntry> {
|
private class MemoryUpdater extends AsyncTask<Void, Void, ProcStatsPackageEntry> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1246,33 +1247,4 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
mPermissionsPreference.setSummary(summary);
|
mPermissionsPreference.setSummary(summary);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void startListeningToPackageRemove() {
|
|
||||||
if (mListeningToPackageRemove) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mListeningToPackageRemove = true;
|
|
||||||
final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED);
|
|
||||||
filter.addDataScheme("package");
|
|
||||||
getContext().registerReceiver(mPackageRemovedReceiver, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopListeningToPackageRemove() {
|
|
||||||
if (!mListeningToPackageRemove) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mListeningToPackageRemove = false;
|
|
||||||
getContext().unregisterReceiver(mPackageRemovedReceiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final BroadcastReceiver mPackageRemovedReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
String packageName = intent.getData().getSchemeSpecificPart();
|
|
||||||
if (!mFinishing && mAppEntry.info.packageName.equals(packageName)) {
|
|
||||||
getActivity().finishAndRemoveTask();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user