Fix crash when an app with an active quicksettings tile is updated to no longer have that tile.

Fixes: 28721139
Change-Id: Ib53c7cc08e9378420a5fed3459c1e17864b28802
This commit is contained in:
Will Harmon
2016-06-06 12:54:59 -07:00
committed by Jason Monk
parent 79cb94b8d6
commit 604c2f9440
2 changed files with 32 additions and 6 deletions

View File

@@ -134,9 +134,14 @@ public class TileLifecycleManager extends BroadcastReceiver implements
}
if (DEBUG) Log.d(TAG, "Binding service " + mIntent + " " + mUser);
mBindTryCount++;
mIsBound = mContext.bindServiceAsUser(mIntent, this,
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
mUser);
try {
mIsBound = mContext.bindServiceAsUser(mIntent, this,
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
mUser);
} catch (SecurityException e) {
Log.e(TAG, "Failed to bind to service", e);
mIsBound = false;
}
} else {
if (DEBUG) Log.d(TAG, "Unbinding service " + mIntent + " " + mUser);
// Give it another chance next time it needs to be bound, out of kindness.

View File

@@ -21,13 +21,20 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Handler;
import android.os.UserHandle;
import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.TileService;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
import com.android.systemui.qs.external.TileLifecycleManager.TileChangeListener;
import java.util.List;
import libcore.util.Objects;
/**
@@ -222,15 +229,29 @@ public class TileServiceManager {
if (!Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
return;
}
if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
return;
}
Uri data = intent.getData();
String pkgName = data.getEncodedSchemeSpecificPart();
final ComponentName component = mStateManager.getComponent();
if (!Objects.equal(pkgName, component.getPackageName())) {
return;
}
// If the package is being updated, verify the component still exists.
if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
Intent queryIntent = new Intent(TileService.ACTION_QS_TILE);
queryIntent.setPackage(pkgName);
PackageManager pm = context.getPackageManager();
List<ResolveInfo> services = pm.queryIntentServicesAsUser(
queryIntent, 0, ActivityManager.getCurrentUser());
for (ResolveInfo info : services) {
if (Objects.equal(info.serviceInfo.packageName, component.getPackageName())
&& Objects.equal(info.serviceInfo.name, component.getClassName())) {
return;
}
}
}
mServices.getHost().removeTile(component);
}
};