Fix crash when selecting AppInfo for uninstalled app from Recents.
am: 7574b64910
Change-Id: I9ade2a06180e6464ab105c1a12c5383aa480f77a
This commit is contained in:
@@ -515,7 +515,7 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
if (resultTo == null) {
|
||||
context.startActivity(intent);
|
||||
} 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.Fragment;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
@@ -74,6 +76,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
||||
protected static final int DLG_BASE = 0;
|
||||
|
||||
protected boolean mFinishing;
|
||||
protected boolean mListeningToPackageRemove;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -90,6 +93,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
||||
mUsbManager = IUsbManager.Stub.asInterface(b);
|
||||
|
||||
retrieveAppEntry();
|
||||
startListeningToPackageRemove();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,6 +118,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
stopListeningToPackageRemove();
|
||||
mSession.release();
|
||||
super.onDestroy();
|
||||
}
|
||||
@@ -246,4 +251,37 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -483,21 +483,22 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_UNINSTALL) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_UNINSTALL:
|
||||
if (mDisableAfterUninstall) {
|
||||
mDisableAfterUninstall = false;
|
||||
new DisableChanger(this, mAppEntry.info,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
|
||||
.execute((Object)null);
|
||||
}
|
||||
// continue with following operations
|
||||
case REQUEST_REMOVE_DEVICE_ADMIN:
|
||||
if (!refreshUi()) {
|
||||
setIntentAndFinish(true, true);
|
||||
} else {
|
||||
startListeningToPackageRemove();
|
||||
}
|
||||
}
|
||||
if (requestCode == REQUEST_REMOVE_DEVICE_ADMIN) {
|
||||
if (!refreshUi()) {
|
||||
setIntentAndFinish(true, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,6 +676,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
}
|
||||
|
||||
private void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) {
|
||||
stopListeningToPackageRemove();
|
||||
// Create new intent to launch Uninstaller activity
|
||||
Uri packageURI = Uri.parse("package:"+packageName);
|
||||
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
|
||||
@@ -730,7 +732,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
|
||||
intent.putExtra(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
|
||||
try {
|
||||
startActivity(intent);
|
||||
getActivity().startActivityForResult(intent, SUB_INFO_FRAGMENT);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(LOG_TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
|
||||
}
|
||||
@@ -764,6 +766,7 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
String packageName = mAppEntry.info.packageName;
|
||||
if (v == mUninstallButton) {
|
||||
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
||||
stopListeningToPackageRemove();
|
||||
Activity activity = getActivity();
|
||||
Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class);
|
||||
uninstallDAIntent.putExtra(DeviceAdminAdd.EXTRA_DEVICE_ADMIN_PACKAGE_NAME,
|
||||
@@ -1077,6 +1080,12 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
return summary.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPackageRemoved() {
|
||||
getActivity().finishActivity(SUB_INFO_FRAGMENT);
|
||||
super.onPackageRemoved();
|
||||
}
|
||||
|
||||
private class MemoryUpdater extends AsyncTask<Void, Void, ProcStatsPackageEntry> {
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user