Check if DSU is in use before feature flag

We are using a feature flag to protect DSU and the device. But when
a Dynamic System is in use, feature flag is set as false by default.

This CL makes DSU bypass feature flag and start GSI service on boot
completed, check if the device is currently running a Dynamic System,
then, stop GSI service if the device isn't.

Bug: 132575851
Test: restart into DSU, check if the "In Use" notification is shown.
Change-Id: I9dabf9bc1716ef18d513278415c6544a5467d510
This commit is contained in:
Po-Chien Hsueh
2019-05-14 16:57:18 +08:00
committed by PO HUNG CHEN
parent 7ad66d5e14
commit 7687aaac1d
2 changed files with 27 additions and 11 deletions

View File

@@ -22,8 +22,8 @@ import android.content.Intent;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.image.DynamicSystemClient; import android.os.image.DynamicSystemClient;
import android.os.image.DynamicSystemManager;
import android.util.FeatureFlagUtils; import android.util.FeatureFlagUtils;
import android.util.Log;
/** /**
@@ -37,21 +37,26 @@ public class BootCompletedReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (!featureFlagEnabled()) { String action = intent.getAction();
if (!Intent.ACTION_BOOT_COMPLETED.equals(action)) {
return; return;
} }
String action = intent.getAction(); DynamicSystemManager dynSystem =
(DynamicSystemManager) context.getSystemService(Context.DYNAMIC_SYSTEM_SERVICE);
Log.d(TAG, "Broadcast received: " + action); boolean isInUse = (dynSystem != null) && dynSystem.isInUse();
if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { if (!isInUse && !featureFlagEnabled()) {
Intent startServiceIntent = new Intent( return;
context, DynamicSystemInstallationService.class);
startServiceIntent.setAction(DynamicSystemClient.ACTION_NOTIFY_IF_IN_USE);
context.startServiceAsUser(startServiceIntent, UserHandle.SYSTEM);
} }
Intent startServiceIntent = new Intent(
context, DynamicSystemInstallationService.class);
startServiceIntent.setAction(DynamicSystemClient.ACTION_NOTIFY_IF_IN_USE);
context.startServiceAsUser(startServiceIntent, UserHandle.SYSTEM);
} }
private boolean featureFlagEnabled() { private boolean featureFlagEnabled() {

View File

@@ -152,7 +152,18 @@ public class DynamicSystemService extends IDynamicSystemService.Stub implements
@Override @Override
public boolean isInUse() throws RemoteException { public boolean isInUse() throws RemoteException {
return getGsiService().isGsiRunning(); boolean gsidWasRunning = "running".equals(SystemProperties.get("init.svc.gsid"));
boolean isInUse = false;
try {
isInUse = getGsiService().isGsiRunning();
} finally {
if (!gsidWasRunning && !isInUse) {
SystemProperties.set("ctl.stop", "gsid");
}
}
return isInUse;
} }
@Override @Override