Permalink
Browse files

OMS7-N: Implement multi-target enable/disable and disable-all [11/11]

Just use the enable option like normal, but you can add more arguments
for more packages. Also add a feature that allows the client to disable
all of the current user's overlays.

Multiple targets example:
    om enable android.AkZent com.android.systemui.AkZent

Works the same as:
    om enable android.AkZent && om enable com.android.systemui.AkZent

Original implementation for M by @USA-RedDragon
Current and further development by @nicholaschum

Change-Id: I04a595084a87b8260b5c534c4f5f111adbe154d7
  • Loading branch information...
USA-RedDragon authored and nathanchance committed Jun 26, 2016
1 parent 309379b commit 5555a17641c7ccbb5ceb5462317ca4f9046b1ff3
@@ -83,10 +83,12 @@ interface IOverlayManager {
* @param packageName The name of the overlay package.
* @param enable true to enable the overlay, false to disable it.
* @param userId The user for which to change the overlay.
* @param shouldWait true to wait to reload resources until refresh is called
* @return true if the system successfully registered the request, false
* otherwise.
*/
boolean setEnabled(in String packageName, in boolean enable, in int userId);
boolean setEnabled(in String packageName, in boolean enable, in int userId,
in boolean shouldWait);
/**
* Change the priority of the given overlay to be just higher than the
@@ -126,4 +128,10 @@ interface IOverlayManager {
* @param userId The user for which to change the overlay.
*/
boolean setLowestPriority(in String packageName, in int userId);
/**
* Refresh assets
* @param uid the user to refresh assets for
*/
void refresh(in int uid);
}
@@ -255,7 +255,7 @@ public void onSwitchUser(final int newUserId) {
synchronized (mLock) {
targets = mImpl.onSwitchUser(newUserId);
}
updateAssets(newUserId, targets);
updateSelectedAssets(newUserId, targets);
}
public List<String> getEnabledOverlayPaths(@NonNull final String packageName,
@@ -451,7 +451,7 @@ public OverlayInfo getOverlayInfo(@Nullable final String packageName,
@Override
public boolean setEnabled(@Nullable final String packageName, final boolean enable,
int userId) throws RemoteException {
int userId, final boolean shouldWait) throws RemoteException {
enforceChangeConfigurationPermission("setEnabled");
userId = handleIncomingUser(userId, "setEnabled");
if (packageName == null) {
@@ -461,7 +461,7 @@ public boolean setEnabled(@Nullable final String packageName, final boolean enab
final long ident = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
return mImpl.onSetEnabled(packageName, enable, userId);
return mImpl.onSetEnabled(packageName, enable, userId, shouldWait);
}
} finally {
Binder.restoreCallingIdentity(ident);
@@ -590,6 +590,15 @@ private void enforceDumpPermission(@NonNull final String message) {
message);
}
}
public void refresh(int uid) {
Collection<String> targets;
synchronized (mLock) {
targets = mImpl.onSwitchUser(uid);
}
List targeted = new ArrayList(targets);
updateSelectedAssets(uid, targeted);
}
};
private boolean isOverlayPackage(@NonNull final PackageInfo pi) {
@@ -603,45 +612,48 @@ public void onSettingsChanged() {
}
@Override
public void onOverlayAdded(@NonNull final OverlayInfo oi) {
scheduleBroadcast(Intent.ACTION_OVERLAY_ADDED, oi, oi.isEnabled());
public void onOverlayAdded(@NonNull final OverlayInfo oi, final boolean shouldWait) {
scheduleBroadcast(Intent.ACTION_OVERLAY_ADDED, oi, oi.isEnabled(), shouldWait);
}
@Override
public void onOverlayRemoved(@NonNull final OverlayInfo oi) {
scheduleBroadcast(Intent.ACTION_OVERLAY_REMOVED, oi, oi.isEnabled());
public void onOverlayRemoved(@NonNull final OverlayInfo oi, final boolean shouldWait) {
scheduleBroadcast(Intent.ACTION_OVERLAY_REMOVED, oi, oi.isEnabled(), shouldWait);
}
@Override
public void onOverlayChanged(@NonNull final OverlayInfo oi,
@NonNull final OverlayInfo oldOi) {
scheduleBroadcast(Intent.ACTION_OVERLAY_CHANGED, oi, oi.isEnabled() != oldOi.isEnabled());
public void onOverlayChanged(@NonNull final OverlayInfo oi, @NonNull OverlayInfo oldOi,
final boolean shouldWait) {
scheduleBroadcast(Intent.ACTION_OVERLAY_CHANGED, oi,
oi.isEnabled() != oldOi.isEnabled(), shouldWait);
}
@Override
public void onOverlayPriorityChanged(@NonNull final OverlayInfo oi) {
scheduleBroadcast(Intent.ACTION_OVERLAY_PRIORITY_CHANGED, oi, oi.isEnabled());
scheduleBroadcast(Intent.ACTION_OVERLAY_PRIORITY_CHANGED, oi, oi.isEnabled(), false);
}
private void scheduleBroadcast(@NonNull final String action, @NonNull final OverlayInfo oi,
final boolean doUpdate) {
FgThread.getHandler().post(new BroadcastRunnable(action, oi, doUpdate));
final boolean doUpdate, final boolean shouldWait) {
FgThread.getHandler().post(new BroadcastRunnable(action, oi, doUpdate, shouldWait));
}
private final class BroadcastRunnable extends Thread {
private final String mAction;
private final OverlayInfo mOverlayInfo;
private final boolean mDoUpdate;
private final boolean shouldWait;
public BroadcastRunnable(@NonNull final String action, @NonNull final OverlayInfo oi,
final boolean doUpdate) {
public BroadcastRunnable(@NonNull final String action, @NonNull final OverlayInfo oi,
final boolean doUpdate, final boolean shouldWait) {
mAction = action;
mOverlayInfo = oi;
mDoUpdate = doUpdate;
this.shouldWait = shouldWait;
}
public void run() {
if (mDoUpdate) {
if (mDoUpdate && !shouldWait) {
updateAssets(mOverlayInfo.userId, mOverlayInfo.targetPackageName);
}
sendBroadcast(mAction, mOverlayInfo.targetPackageName, mOverlayInfo.packageName,
@@ -672,10 +684,10 @@ private void sendBroadcast(@NonNull final String action,
private void updateAssets(final int userId, final String targetPackageName) {
final List<String> list = new ArrayList<>();
list.add(targetPackageName);
updateAssets(userId, list);
updateSelectedAssets(userId, list);
}
private void updateAssets(final int userId, List<String> targetPackageNames) {
private void updateSelectedAssets(final int userId, List<String> targetPackageNames) {
final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
final boolean updateFrameworkRes = targetPackageNames.contains("android");
if (updateFrameworkRes) {
@@ -324,7 +324,7 @@ OverlayInfo onGetOverlayInfo(@NonNull final String packageName, final int userId
}
boolean onSetEnabled(@NonNull final String packageName, final boolean enable,
final int userId) {
final int userId, final boolean shouldWait) {
if (DEBUG) {
Slog.d(TAG, String.format("onSetEnabled packageName=%s enable=%s userId=%d",
packageName, enable, userId));
@@ -340,7 +340,7 @@ boolean onSetEnabled(@NonNull final String packageName, final boolean enable,
final PackageInfo targetPackage =
mPackageManager.getPackageInfo(oi.targetPackageName, userId);
mSettings.setEnabled(packageName, userId, enable);
updateState(targetPackage, overlayPackage, userId);
updateState(targetPackage, overlayPackage, userId, shouldWait);
return true;
} catch (OverlayManagerSettings.BadKeyException e) {
return false;
@@ -379,6 +379,12 @@ void onDump(@NonNull final PrintWriter pw) {
private void updateState(@Nullable final PackageInfo targetPackage,
@NonNull final PackageInfo overlayPackage, final int userId)
throws OverlayManagerSettings.BadKeyException {
updateState(targetPackage, overlayPackage, userId, false);
}
private void updateState(@Nullable final PackageInfo targetPackage,
@NonNull final PackageInfo overlayPackage, final int userId,
final boolean shouldWait) throws OverlayManagerSettings.BadKeyException {
if (targetPackage != null) {
mIdmapManager.createIdmap(targetPackage, overlayPackage, userId);
}
@@ -395,7 +401,7 @@ private void updateState(@Nullable final PackageInfo targetPackage,
OverlayInfo.stateToString(currentState),
OverlayInfo.stateToString(newState)));
}
mSettings.setState(overlayPackage.packageName, userId, newState);
mSettings.setState(overlayPackage.packageName, userId, newState, shouldWait);
}
}
@@ -76,7 +76,7 @@ void remove(@NonNull final String packageName, final int userId) {
final OverlayInfo oi = item.getOverlayInfo();
mItems.remove(item);
if (oi != null) {
notifyOverlayRemoved(oi);
notifyOverlayRemoved(oi, false);
}
}
@@ -135,7 +135,7 @@ void setUpgrading(@NonNull final String packageName, final int userId, final boo
final OverlayInfo oi = item.getOverlayInfo();
item.setUpgrading(true);
item.setState(STATE_NOT_APPROVED_UNKNOWN);
notifyOverlayRemoved(oi);
notifyOverlayRemoved(oi, false);
} else {
item.setUpgrading(false);
}
@@ -172,8 +172,8 @@ int getState(@NonNull final String packageName, final int userId) throws BadKeyE
return item.getState();
}
void setState(@NonNull final String packageName, final int userId, final int state)
throws BadKeyException {
void setState(@NonNull final String packageName, final int userId, final int state,
final boolean shouldWait) throws BadKeyException {
final SettingsItem item = select(packageName, userId);
if (item == null) {
throw new BadKeyException(packageName, userId);
@@ -182,10 +182,10 @@ void setState(@NonNull final String packageName, final int userId, final int sta
item.setState(state);
final OverlayInfo current = item.getOverlayInfo();
if (previous.state == STATE_NOT_APPROVED_UNKNOWN) {
notifyOverlayAdded(current);
notifyOverlayAdded(current, shouldWait);
notifySettingsChanged();
} else if (current.state != previous.state) {
notifyOverlayChanged(current, previous);
notifyOverlayChanged(current, previous, shouldWait);
notifySettingsChanged();
}
}
@@ -602,32 +602,32 @@ private void notifySettingsChanged() {
}
}
private void notifyOverlayAdded(@NonNull final OverlayInfo oi) {
private void notifyOverlayAdded(@NonNull final OverlayInfo oi, final boolean shouldWait) {
if (DEBUG) {
assertNotNull(oi);
}
for (final ChangeListener listener : mListeners) {
listener.onOverlayAdded(oi);
listener.onOverlayAdded(oi, shouldWait);
}
}
private void notifyOverlayRemoved(@NonNull final OverlayInfo oi) {
private void notifyOverlayRemoved(@NonNull final OverlayInfo oi, final boolean shouldWait) {
if (DEBUG) {
assertNotNull(oi);
}
for (final ChangeListener listener : mListeners) {
listener.onOverlayRemoved(oi);
listener.onOverlayRemoved(oi, shouldWait);
}
}
private void notifyOverlayChanged(@NonNull final OverlayInfo oi,
@NonNull final OverlayInfo oldOi) {
@NonNull final OverlayInfo oldOi, final boolean shouldWait) {
if (DEBUG) {
assertNotNull(oi);
assertNotNull(oldOi);
}
for (final ChangeListener listener : mListeners) {
listener.onOverlayChanged(oi, oldOi);
listener.onOverlayChanged(oi, oldOi, shouldWait);
}
}
@@ -642,9 +642,10 @@ private void notifyOverlayPriorityChanged(@NonNull final OverlayInfo oi) {
interface ChangeListener {
void onSettingsChanged();
void onOverlayAdded(@NonNull OverlayInfo oi);
void onOverlayRemoved(@NonNull OverlayInfo oi);
void onOverlayChanged(@NonNull OverlayInfo oi, @NonNull OverlayInfo oldOi);
void onOverlayAdded(@NonNull OverlayInfo oi, boolean shouldWait);
void onOverlayRemoved(@NonNull OverlayInfo oi, boolean shouldWait);
void onOverlayChanged(@NonNull OverlayInfo oi, @NonNull OverlayInfo oldOi,
boolean shouldWait);
void onOverlayPriorityChanged(@NonNull OverlayInfo oi);
}
Oops, something went wrong.

0 comments on commit 5555a17

Please sign in to comment.