Merge "Fix crash when an app with an active quicksettings tile is updated to no longer have that tile." into nyc-dev

This commit is contained in:
Jason Monk
2016-06-08 19:11:15 +00:00
committed by Android (Google) Code Review
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); if (DEBUG) Log.d(TAG, "Binding service " + mIntent + " " + mUser);
mBindTryCount++; mBindTryCount++;
try {
mIsBound = mContext.bindServiceAsUser(mIntent, this, mIsBound = mContext.bindServiceAsUser(mIntent, this,
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
mUser); mUser);
} catch (SecurityException e) {
Log.e(TAG, "Failed to bind to service", e);
mIsBound = false;
}
} else { } else {
if (DEBUG) Log.d(TAG, "Unbinding service " + mIntent + " " + mUser); if (DEBUG) Log.d(TAG, "Unbinding service " + mIntent + " " + mUser);
// Give it another chance next time it needs to be bound, out of kindness. // 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.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.UserHandle; import android.os.UserHandle;
import android.service.quicksettings.IQSTileService; import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.TileService;
import android.support.annotation.VisibleForTesting; import android.support.annotation.VisibleForTesting;
import android.util.Log; import android.util.Log;
import com.android.systemui.qs.external.TileLifecycleManager.TileChangeListener; import com.android.systemui.qs.external.TileLifecycleManager.TileChangeListener;
import java.util.List;
import libcore.util.Objects; import libcore.util.Objects;
/** /**
@@ -222,15 +229,29 @@ public class TileServiceManager {
if (!Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { if (!Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
return; return;
} }
if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
return;
}
Uri data = intent.getData(); Uri data = intent.getData();
String pkgName = data.getEncodedSchemeSpecificPart(); String pkgName = data.getEncodedSchemeSpecificPart();
final ComponentName component = mStateManager.getComponent(); final ComponentName component = mStateManager.getComponent();
if (!Objects.equal(pkgName, component.getPackageName())) { if (!Objects.equal(pkgName, component.getPackageName())) {
return; 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); mServices.getHost().removeTile(component);
} }
}; };