Skip to content
Snippets Groups Projects
Commit a5c6f7fd authored by Yo Chiang's avatar Yo Chiang
Browse files

Fix DynamicSystemClient.start() exceptions

* Remove calls to featureFlagEnabled() as they are causing avc denials,
  plus the feature flag is already deprecated.
* Add Intent flag FLAG_ACTIVITY_NEW_TASK to fix the
  AndroidRuntimeException, as the Context object used to startActivity()
  may not be an Activity object instance.
* Check the nullness of mListener before using it to fix the
  NullPointerException.

Bug: 176795908
Test: atest \
  cts/tests/tests/os/src/android/os/image/cts/DynamicSystemClientTest.java
Change-Id: I265d9912e76c39406e0adeacd2490b62873c94e4
parent d15cbc37
No related branches found
No related tags found
No related merge requests found
......@@ -35,8 +35,6 @@ import android.os.Message;
import android.os.Messenger;
import android.os.ParcelableException;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.util.FeatureFlagUtils;
import android.util.Slog;
import java.lang.annotation.Retention;
......@@ -251,13 +249,7 @@ public class DynamicSystemClient {
mService.send(msg);
} catch (RemoteException e) {
Slog.e(TAG, "Unable to get status from installation service");
if (mExecutor != null) {
mExecutor.execute(() -> {
mListener.onStatusChanged(STATUS_UNKNOWN, CAUSE_ERROR_IPC, 0, e);
});
} else {
mListener.onStatusChanged(STATUS_UNKNOWN, CAUSE_ERROR_IPC, 0, e);
}
notifyOnStatusChangedListener(STATUS_UNKNOWN, CAUSE_ERROR_IPC, 0, e);
}
}
......@@ -311,6 +303,20 @@ public class DynamicSystemClient {
mExecutor = null;
}
private void notifyOnStatusChangedListener(
int status, int cause, long progress, Throwable detail) {
if (mListener != null) {
if (mExecutor != null) {
mExecutor.execute(
() -> {
mListener.onStatusChanged(status, cause, progress, detail);
});
} else {
mListener.onStatusChanged(status, cause, progress, detail);
}
}
}
/**
* Bind to {@code DynamicSystem} installation service. Binding to the installation service
* allows it to send status updates to {@link #OnStatusChangedListener}. It is recommanded
......@@ -320,11 +326,6 @@ public class DynamicSystemClient {
@RequiresPermission(android.Manifest.permission.INSTALL_DYNAMIC_SYSTEM)
@SystemApi
public void bind() {
if (!featureFlagEnabled()) {
Slog.w(TAG, FeatureFlagUtils.DYNAMIC_SYSTEM + " not enabled; bind() aborted.");
return;
}
Intent intent = new Intent();
intent.setClassName("com.android.dynsystem",
"com.android.dynsystem.DynamicSystemInstallationService");
......@@ -395,11 +396,6 @@ public class DynamicSystemClient {
@RequiresPermission(android.Manifest.permission.INSTALL_DYNAMIC_SYSTEM)
public void start(@NonNull Uri systemUrl, @BytesLong long systemSize,
@BytesLong long userdataSize) {
if (!featureFlagEnabled()) {
Slog.w(TAG, FeatureFlagUtils.DYNAMIC_SYSTEM + " not enabled; start() aborted.");
return;
}
Intent intent = new Intent();
intent.setClassName("com.android.dynsystem",
......@@ -407,6 +403,7 @@ public class DynamicSystemClient {
intent.setData(systemUrl);
intent.setAction(ACTION_START_INSTALL);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(KEY_SYSTEM_SIZE, systemSize);
intent.putExtra(KEY_USERDATA_SIZE, userdataSize);
......@@ -414,11 +411,6 @@ public class DynamicSystemClient {
mContext.startActivity(intent);
}
private boolean featureFlagEnabled() {
return SystemProperties.getBoolean(
FeatureFlagUtils.PERSIST_PREFIX + FeatureFlagUtils.DYNAMIC_SYSTEM, false);
}
private void handleMessage(Message msg) {
switch (msg.what) {
case MSG_POST_STATUS:
......@@ -432,13 +424,7 @@ public class DynamicSystemClient {
Throwable detail = t == null ? null : t.getCause();
if (mExecutor != null) {
mExecutor.execute(() -> {
mListener.onStatusChanged(status, cause, progress, detail);
});
} else {
mListener.onStatusChanged(status, cause, progress, detail);
}
notifyOnStatusChangedListener(status, cause, progress, detail);
break;
default:
// do nothing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment