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

Commit e8ce925b authored by Xiaowen Lei's avatar Xiaowen Lei Committed by Android (Google) Code Review
Browse files

Merge changes from topic "CM-API-mode"

* changes:
  Add callback registration mechanism for listening to communal state changes.
  Add isCommunalMode() to CommunalManager SystemApi.
parents 157d6623 a676d9b3
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -224,6 +224,7 @@ package android {
    field public static final String READ_APP_SPECIFIC_LOCALES = "android.permission.READ_APP_SPECIFIC_LOCALES";
    field public static final String READ_CARRIER_APP_INFO = "android.permission.READ_CARRIER_APP_INFO";
    field public static final String READ_CELL_BROADCASTS = "android.permission.READ_CELL_BROADCASTS";
    field public static final String READ_COMMUNAL_STATE = "android.permission.READ_COMMUNAL_STATE";
    field public static final String READ_CONTENT_RATING_SYSTEMS = "android.permission.READ_CONTENT_RATING_SYSTEMS";
    field public static final String READ_DEVICE_CONFIG = "android.permission.READ_DEVICE_CONFIG";
    field public static final String READ_DREAM_STATE = "android.permission.READ_DREAM_STATE";
@@ -1309,6 +1310,20 @@ package android.app.backup {
}
package android.app.communal {
  public final class CommunalManager {
    method @RequiresPermission(android.Manifest.permission.READ_COMMUNAL_STATE) public void addCommunalModeListener(@NonNull java.util.concurrent.Executor, @NonNull android.app.communal.CommunalManager.CommunalModeListener);
    method @RequiresPermission(android.Manifest.permission.READ_COMMUNAL_STATE) public boolean isCommunalMode();
    method @RequiresPermission(android.Manifest.permission.READ_COMMUNAL_STATE) public void removeCommunalModeListener(@NonNull android.app.communal.CommunalManager.CommunalModeListener);
  }
  @java.lang.FunctionalInterface public static interface CommunalManager.CommunalModeListener {
    method public void onCommunalModeChanged(boolean);
  }
}
package android.app.compat {
  public final class CompatChanges {
@@ -2491,6 +2506,7 @@ package android.content {
    field public static final String BATTERY_STATS_SERVICE = "batterystats";
    field @Deprecated public static final int BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS = 1048576; // 0x100000
    field public static final int BIND_ALLOW_FOREGROUND_SERVICE_STARTS_FROM_BACKGROUND = 262144; // 0x40000
    field public static final String COMMUNAL_SERVICE = "communal";
    field public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
    field public static final String CONTEXTHUB_SERVICE = "contexthub";
    field public static final String ETHERNET_SERVICE = "ethernet";
+10 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ package android {
    field public static final String TEST_BIOMETRIC = "android.permission.TEST_BIOMETRIC";
    field public static final String TEST_MANAGE_ROLLBACKS = "android.permission.TEST_MANAGE_ROLLBACKS";
    field public static final String UPGRADE_RUNTIME_PERMISSIONS = "android.permission.UPGRADE_RUNTIME_PERMISSIONS";
    field public static final String WRITE_COMMUNAL_STATE = "android.permission.WRITE_COMMUNAL_STATE";
    field public static final String WRITE_DEVICE_CONFIG = "android.permission.WRITE_DEVICE_CONFIG";
    field @Deprecated public static final String WRITE_MEDIA_STORAGE = "android.permission.WRITE_MEDIA_STORAGE";
    field public static final String WRITE_OBB = "android.permission.WRITE_OBB";
@@ -608,6 +609,14 @@ package android.app.blob {

}

package android.app.communal {

  public final class CommunalManager {
    method @RequiresPermission(android.Manifest.permission.WRITE_COMMUNAL_STATE) public void setCommunalViewShowing(boolean);
  }

}

package android.app.contentsuggestions {

  public final class ContentSuggestionsManager {
@@ -819,6 +828,7 @@ package android.content.pm {
    method public void holdLock(android.os.IBinder, int);
    method @RequiresPermission(android.Manifest.permission.KEEP_UNINSTALLED_PACKAGES) public void setKeepUninstalledPackages(@NonNull java.util.List<java.lang.String>);
    field public static final String FEATURE_ADOPTABLE_STORAGE = "android.software.adoptable_storage";
    field public static final String FEATURE_COMMUNAL_MODE = "android.software.communal_mode";
    field public static final String FEATURE_FILE_BASED_ENCRYPTION = "android.software.file_based_encryption";
    field public static final String FEATURE_HDMI_CEC = "android.hardware.hdmi.cec";
    field public static final int FLAG_PERMISSION_REVOKE_WHEN_REQUESTED = 128; // 0x80
+2 −2
Original line number Diff line number Diff line
@@ -1513,7 +1513,7 @@ public final class SystemServiceRegistry {
                    }
                });

        registerService(Context.COMMUNAL_MANAGER_SERVICE, CommunalManager.class,
        registerService(Context.COMMUNAL_SERVICE, CommunalManager.class,
                new CachedServiceFetcher<CommunalManager>() {
                    @Override
                    public CommunalManager createService(ContextImpl ctx) {
@@ -1522,7 +1522,7 @@ public final class SystemServiceRegistry {
                            return null;
                        }
                        IBinder iBinder =
                                ServiceManager.getService(Context.COMMUNAL_MANAGER_SERVICE);
                                ServiceManager.getService(Context.COMMUNAL_SERVICE);
                        return iBinder != null ? new CommunalManager(
                                ICommunalManager.Stub.asInterface(iBinder)) : null;
                    }
+82 −1
Original line number Diff line number Diff line
@@ -17,15 +17,21 @@
package android.app.communal;

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.RequiresFeature;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.compat.annotation.ChangeId;
import android.compat.annotation.Disabled;
import android.compat.annotation.Overridable;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.util.ArrayMap;

import java.util.concurrent.Executor;

/**
 * System private class for talking with the
@@ -33,10 +39,12 @@ import android.os.RemoteException;
 *
 * @hide
 */
@SystemService(Context.COMMUNAL_MANAGER_SERVICE)
@SystemApi(client = SystemApi.Client.PRIVILEGED_APPS)
@SystemService(Context.COMMUNAL_SERVICE)
@RequiresFeature(PackageManager.FEATURE_COMMUNAL_MODE)
public final class CommunalManager {
    private final ICommunalManager mService;
    private final ArrayMap<CommunalModeListener, ICommunalModeListener> mCommunalModeListeners;

    /**
     * This change id is used to annotate packages which can run in communal mode by default,
@@ -59,15 +67,20 @@ public final class CommunalManager {
    @Disabled
    public static final long ALLOW_COMMUNAL_MODE_WITH_USER_CONSENT = 200324021L;

    /** @hide */
    public CommunalManager(ICommunalManager service) {
        mService = service;
        mCommunalModeListeners = new ArrayMap<CommunalModeListener, ICommunalModeListener>();
    }

    /**
     * Updates whether or not the communal view is currently showing over the lockscreen.
     *
     * @param isShowing Whether communal view is showing.
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(Manifest.permission.WRITE_COMMUNAL_STATE)
    public void setCommunalViewShowing(boolean isShowing) {
        try {
@@ -76,4 +89,72 @@ public final class CommunalManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Checks whether or not the communal view is currently showing over the lockscreen.
     */
    @RequiresPermission(Manifest.permission.READ_COMMUNAL_STATE)
    public boolean isCommunalMode() {
        try {
            return mService.isCommunalMode();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Listener for communal state changes.
     */
    @FunctionalInterface
    public interface CommunalModeListener {
        /**
         * Callback function that executes when the communal state changes.
         */
        void onCommunalModeChanged(boolean isCommunalMode);
    }

    /**
     * Registers a callback to execute when the communal state changes.
     *
     * @param listener The listener to add to receive communal state changes.
     * @param executor {@link Executor} to dispatch to. To dispatch the callback to the main
     *                 thread of your application, use
     *                 {@link android.content.Context#getMainExecutor()}.
     */
    @RequiresPermission(Manifest.permission.READ_COMMUNAL_STATE)
    public void addCommunalModeListener(@NonNull Executor executor,
            @NonNull CommunalModeListener listener) {
        synchronized (mCommunalModeListeners) {
            try {
                ICommunalModeListener iListener = new ICommunalModeListener.Stub() {
                    @Override
                    public void onCommunalModeChanged(boolean isCommunalMode) {
                        executor.execute(() -> listener.onCommunalModeChanged(isCommunalMode));
                    }
                };
                mService.addCommunalModeListener(iListener);
                mCommunalModeListeners.put(listener, iListener);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
     * Unregisters a callback that executes when communal state changes.
     */
    @RequiresPermission(Manifest.permission.READ_COMMUNAL_STATE)
    public void removeCommunalModeListener(@NonNull CommunalModeListener listener) {
        synchronized (mCommunalModeListeners) {
            ICommunalModeListener iListener = mCommunalModeListeners.get(listener);
            if (iListener != null) {
                try {
                    mService.removeCommunalModeListener(iListener);
                    mCommunalModeListeners.remove(listener);
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                }
            }
        }
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -16,12 +16,17 @@

package android.app.communal;

import android.app.communal.ICommunalModeListener;

/**
 * System private API for talking with the communal manager service that handles communal mode
 * state.
 *
 * @hide
 */
oneway interface ICommunalManager {
    void setCommunalViewShowing(boolean isShowing);
interface ICommunalManager {
    oneway void setCommunalViewShowing(boolean isShowing);
    boolean isCommunalMode();
    void addCommunalModeListener(in ICommunalModeListener listener);
    void removeCommunalModeListener(in ICommunalModeListener listener);
}
 No newline at end of file
Loading