Autoadd quick setting every time we create a work profile.

Before this CL, if we create a work profile for the second time, the
work profile quick setting will not be added, because AutoAddTracker
has already marked it as added. This CL fixes this by unmarking the
tile as added when the work profile is removed.

Test: Manual
Bug: 77515080
Change-Id: I72f292c599e8033df13484965f7ed65049f965ff
This commit is contained in:
arangelov
2018-08-17 18:43:31 +01:00
parent deee39507f
commit 5fe95989f9
5 changed files with 17 additions and 2 deletions

View File

@@ -72,6 +72,12 @@ public class AutoAddTracker {
}
}
public void setTileRemoved(String tile) {
if (mAutoAdded.remove(tile)) {
saveTiles();
}
}
public void destroy() {
mContext.getContentResolver().unregisterContentObserver(mObserver);
}

View File

@@ -32,6 +32,7 @@ public interface QSHost {
void removeCallback(Callback callback);
TileServices getTileServices();
void removeTile(String tileSpec);
void unmarkTileAsAutoAdded(String tileSpec);
int indexOf(String tileSpec);

View File

@@ -231,6 +231,11 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory> {
changeTileSpecs(tileSpecs-> tileSpecs.remove(spec));
}
@Override
public void unmarkTileAsAutoAdded(String spec) {
mAutoTiles.unmarkTileAsAutoAdded(spec);
}
public void addTile(String spec) {
changeTileSpecs(tileSpecs-> tileSpecs.add(spec));
}

View File

@@ -78,6 +78,7 @@ public class WorkModeTile extends QSTileImpl<BooleanState> implements
@Override
public void onManagedProfileRemoved() {
mHost.removeTile(getTileSpec());
mHost.unmarkTileAsAutoAdded(getTileSpec());
}
@Override

View File

@@ -96,6 +96,10 @@ public class AutoTileManager {
Dependency.get(ColorDisplayController.class).setListener(null);
}
public void unmarkTileAsAutoAdded(String tabSpec) {
mAutoTracker.setTileRemoved(tabSpec);
}
private final ManagedProfileController.Callback mProfileCallback =
new ManagedProfileController.Callback() {
@Override
@@ -104,8 +108,6 @@ public class AutoTileManager {
if (Dependency.get(ManagedProfileController.class).hasActiveProfile()) {
mHost.addTile(WORK);
mAutoTracker.setTileAdded(WORK);
mHandler.post(() -> Dependency.get(ManagedProfileController.class)
.removeCallback(mProfileCallback));
}
}