Add KEY_ENABLE_WHEN_COMPLETED for testing

Per design, we ask user's confirmation before enabling DSU when
install completed. To simplify the process of testing, this CL adds
a paramenter (intent key) "KEY_ENABLE_WHEN_COMPLETED". If the key is
set, the installation service will not ask user before enabling DSU.

Bug: 131866826
Test: adb shell am start-activity -n com.android.dynsystem/com.android.dynsystem.VerificationActivity
      -a android.os.image.action.START_INSTALL
      -d file:///storage/emulated/0/Download/system.raw.gz
      --el KEY_SYSTEM_SIZE 893841408
      --el KEY_USERDATA_SIZE 8589934592
      --ez KEY_ENABLE_WHEN_COMPLETED true

Change-Id: Id38c4c0525199594f6bd6704b5a575d4a42b7b61
This commit is contained in:
Po-Chien Hsueh
2019-05-07 17:23:44 +08:00
parent 92f755e339
commit dfd69d770c
2 changed files with 18 additions and 1 deletions

View File

@@ -70,6 +70,10 @@ public class DynamicSystemInstallationService extends Service
private static final String TAG = "DynSystemInstallationService";
// TODO (b/131866826): This is currently for test only. Will move this to System API.
static final String KEY_ENABLE_WHEN_COMPLETED = "KEY_ENABLE_WHEN_COMPLETED";
/*
* Intent actions
*/
@@ -122,6 +126,9 @@ public class DynamicSystemInstallationService extends Service
private long mInstalledSize;
private boolean mJustCancelledByUser;
// This is for testing only now
private boolean mEnableWhenCompleted;
private InstallationAsyncTask mInstallTask;
@@ -178,6 +185,11 @@ public class DynamicSystemInstallationService extends Service
public void onResult(int result, Throwable detail) {
if (result == RESULT_OK) {
postStatus(STATUS_READY, CAUSE_INSTALL_COMPLETED, null);
// For testing: enable DSU and restart the device when install completed
if (mEnableWhenCompleted) {
executeRebootToDynSystemCommand();
}
return;
}
@@ -224,6 +236,7 @@ public class DynamicSystemInstallationService extends Service
String url = intent.getDataString();
mSystemSize = intent.getLongExtra(DynamicSystemClient.KEY_SYSTEM_SIZE, 0);
mUserdataSize = intent.getLongExtra(DynamicSystemClient.KEY_USERDATA_SIZE, 0);
mEnableWhenCompleted = intent.getBooleanExtra(KEY_ENABLE_WHEN_COMPLETED, false);
mInstallTask = new InstallationAsyncTask(
url, mSystemSize, mUserdataSize, this, mDynSystem, this);
@@ -275,7 +288,7 @@ public class DynamicSystemInstallationService extends Service
private void executeRebootToDynSystemCommand() {
boolean enabled = false;
if (mInstallTask != null && mInstallTask.getStatus() == FINISHED) {
if (mInstallTask != null && mInstallTask.getResult() == RESULT_OK) {
enabled = mInstallTask.commit();
} else if (isDynamicSystemInstalled()) {
enabled = mDynSystem.setEnable(true);

View File

@@ -92,6 +92,8 @@ public class VerificationActivity extends Activity {
Uri url = callingIntent.getData();
long systemSize = callingIntent.getLongExtra(KEY_SYSTEM_SIZE, 0);
long userdataSize = callingIntent.getLongExtra(KEY_USERDATA_SIZE, 0);
boolean enableWhenCompleted = callingIntent.getBooleanExtra(
DynamicSystemInstallationService.KEY_ENABLE_WHEN_COMPLETED, false);
sVerifiedUrl = url.toString();
@@ -101,6 +103,8 @@ public class VerificationActivity extends Activity {
intent.setAction(DynamicSystemClient.ACTION_START_INSTALL);
intent.putExtra(KEY_SYSTEM_SIZE, systemSize);
intent.putExtra(KEY_USERDATA_SIZE, userdataSize);
intent.putExtra(
DynamicSystemInstallationService.KEY_ENABLE_WHEN_COMPLETED, enableWhenCompleted);
Log.d(TAG, "Starting Installation Service");
startServiceAsUser(intent, UserHandle.SYSTEM);