Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d204b39 authored by Po-Chien Hsueh's avatar Po-Chien Hsueh Committed by Android (Google) Code Review
Browse files

Merge changes from topic "dyn_system_ff"

* changes:
  Use setEnable() when there is an installed image
  Use gsid.isGsiEnabled to refine DynamicSystemService
  Use FeatureFlagPersistent to guard DynamicSystem
  Make feature flag settings_dynamic_system persistent
parents be8b2e85 91508ea2
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,8 @@ import android.os.Message;
import android.os.Messenger;
import android.os.Messenger;
import android.os.ParcelableException;
import android.os.ParcelableException;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.util.FeatureFlagUtils;
import android.util.Slog;
import android.util.Slog;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
@@ -315,6 +317,11 @@ public class DynamicSystemClient {
     */
     */
    @RequiresPermission(android.Manifest.permission.INSTALL_DYNAMIC_SYSTEM)
    @RequiresPermission(android.Manifest.permission.INSTALL_DYNAMIC_SYSTEM)
    public void bind() {
    public void bind() {
        if (!featureFlagEnabled()) {
            Slog.w(TAG, FeatureFlagUtils.DYNAMIC_SYSTEM + " not enabled; bind() aborted.");
            return;
        }

        Intent intent = new Intent();
        Intent intent = new Intent();
        intent.setClassName("com.android.dynsystem",
        intent.setClassName("com.android.dynsystem",
                "com.android.dynsystem.DynamicSystemInstallationService");
                "com.android.dynsystem.DynamicSystemInstallationService");
@@ -381,6 +388,11 @@ public class DynamicSystemClient {
    @RequiresPermission(android.Manifest.permission.INSTALL_DYNAMIC_SYSTEM)
    @RequiresPermission(android.Manifest.permission.INSTALL_DYNAMIC_SYSTEM)
    public void start(@NonNull Uri systemUrl, @BytesLong long systemSize,
    public void start(@NonNull Uri systemUrl, @BytesLong long systemSize,
            @BytesLong long userdataSize) {
            @BytesLong long userdataSize) {
        if (!featureFlagEnabled()) {
            Slog.w(TAG, FeatureFlagUtils.DYNAMIC_SYSTEM + " not enabled; start() aborted.");
            return;
        }

        Intent intent = new Intent();
        Intent intent = new Intent();


        intent.setClassName("com.android.dynsystem",
        intent.setClassName("com.android.dynsystem",
@@ -395,6 +407,11 @@ public class DynamicSystemClient {
        mContext.startActivity(intent);
        mContext.startActivity(intent);
    }
    }


    private boolean featureFlagEnabled() {
        return SystemProperties.getBoolean(
                FeatureFlagUtils.PERSIST_PREFIX + FeatureFlagUtils.DYNAMIC_SYSTEM, false);
    }

    private void handleMessage(Message msg) {
    private void handleMessage(Message msg) {
        switch (msg.what) {
        switch (msg.what) {
            case MSG_POST_STATUS:
            case MSG_POST_STATUS:
+13 −4
Original line number Original line Diff line number Diff line
@@ -159,6 +159,16 @@ public class DynamicSystemManager {
        }
        }
    }
    }


    /** @return {@code true} if the device has a dynamic system enabled */
    @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
    public boolean isEnabled() {
        try {
            return mService.isEnabled();
        } catch (RemoteException e) {
            throw new RuntimeException(e.toString());
        }
    }

    /**
    /**
     * Remove DynamicSystem installation if present
     * Remove DynamicSystem installation if present
     *
     *
@@ -174,14 +184,13 @@ public class DynamicSystemManager {
    }
    }


    /**
    /**
     * Enable DynamicSystem when it's not enabled, otherwise, disable it.
     * Enable or disable DynamicSystem.
     *
     * @return {@code true} if the call succeeds. {@code false} if there is no installed image.
     * @return {@code true} if the call succeeds. {@code false} if there is no installed image.
     */
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
    @RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
    public boolean toggle() {
    public boolean setEnable(boolean enable) {
        try {
        try {
            return mService.toggle();
            return mService.setEnable(enable);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw new RuntimeException(e.toString());
            throw new RuntimeException(e.toString());
        }
        }
+7 −2
Original line number Original line Diff line number Diff line
@@ -57,6 +57,11 @@ interface IDynamicSystemService
     */
     */
    boolean isInstalled();
    boolean isInstalled();


    /**
     * @return true if the device has an DynamicSystem image enabled
     */
    boolean isEnabled();

    /**
    /**
     * Remove DynamicSystem installation if present
     * Remove DynamicSystem installation if present
     *
     *
@@ -65,11 +70,11 @@ interface IDynamicSystemService
    boolean remove();
    boolean remove();


    /**
    /**
     * Enable DynamicSystem when it's not enabled, otherwise, disable it.
     * Enable or disable DynamicSystem.
     *
     *
     * @return true if the call succeeds
     * @return true if the call succeeds
     */
     */
    boolean toggle();
    boolean setEnable(boolean enable);


    /**
    /**
     * Write a chunk of the DynamicSystem system image
     * Write a chunk of the DynamicSystem system image
+2 −1
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ public class FeatureFlagUtils {
    public static final String GLOBAL_ACTIONS_GRID_ENABLED = "settings_global_actions_grid_enabled";
    public static final String GLOBAL_ACTIONS_GRID_ENABLED = "settings_global_actions_grid_enabled";
    public static final String GLOBAL_ACTIONS_PANEL_ENABLED =
    public static final String GLOBAL_ACTIONS_PANEL_ENABLED =
            "settings_global_actions_panel_enabled";
            "settings_global_actions_panel_enabled";
    public static final String DYNAMIC_SYSTEM = "settings_dynamic_system";


    private static final Map<String, String> DEFAULT_FLAGS;
    private static final Map<String, String> DEFAULT_FLAGS;


@@ -52,7 +53,7 @@ public class FeatureFlagUtils {
        DEFAULT_FLAGS.put("settings_slice_injection", "true");
        DEFAULT_FLAGS.put("settings_slice_injection", "true");
        DEFAULT_FLAGS.put("settings_systemui_theme", "true");
        DEFAULT_FLAGS.put("settings_systemui_theme", "true");
        DEFAULT_FLAGS.put("settings_mainline_module", "true");
        DEFAULT_FLAGS.put("settings_mainline_module", "true");
        DEFAULT_FLAGS.put("settings_dynamic_system", "false");
        DEFAULT_FLAGS.put(DYNAMIC_SYSTEM, "false");
        DEFAULT_FLAGS.put(SEAMLESS_TRANSFER, "false");
        DEFAULT_FLAGS.put(SEAMLESS_TRANSFER, "false");
        DEFAULT_FLAGS.put(HEARING_AID_SETTINGS, "false");
        DEFAULT_FLAGS.put(HEARING_AID_SETTINGS, "false");
        DEFAULT_FLAGS.put(SAFETY_HUB, "true");
        DEFAULT_FLAGS.put(SAFETY_HUB, "true");
+11 −0
Original line number Original line Diff line number Diff line
@@ -19,8 +19,10 @@ package com.android.dynsystem;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.image.DynamicSystemClient;
import android.os.image.DynamicSystemClient;
import android.util.FeatureFlagUtils;
import android.util.Log;
import android.util.Log;




@@ -35,6 +37,10 @@ public class BootCompletedReceiver extends BroadcastReceiver {


    @Override
    @Override
    public void onReceive(Context context, Intent intent) {
    public void onReceive(Context context, Intent intent) {
        if (!featureFlagEnabled()) {
            return;
        }

        String action = intent.getAction();
        String action = intent.getAction();


        Log.d(TAG, "Broadcast received: " + action);
        Log.d(TAG, "Broadcast received: " + action);
@@ -47,4 +53,9 @@ public class BootCompletedReceiver extends BroadcastReceiver {
            context.startServiceAsUser(startServiceIntent, UserHandle.SYSTEM);
            context.startServiceAsUser(startServiceIntent, UserHandle.SYSTEM);
        }
        }
    }
    }

    private boolean featureFlagEnabled() {
        return SystemProperties.getBoolean(
                FeatureFlagUtils.PERSIST_PREFIX + FeatureFlagUtils.DYNAMIC_SYSTEM, false);
    }
}
}
Loading