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

Commit ef06f6db authored by Xiaowen Lei's avatar Xiaowen Lei
Browse files

Add isCommunalMode() to CommunalManager SystemApi.

Design: go/communal-manager-api.

Test: atest CtsAppTestCases:CommunalManagerTest
Test: atest FrameworksMockingServicesTests:CommunalManagerServiceTest

Bug: 206054365
Change-Id: Ib1b964b17a7742b4e337862efa2b4e0562322fd0
parent b1db3547
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1309,6 +1309,14 @@ package android.app.backup {
}
package android.app.communal {
  public final class CommunalManager {
    method @RequiresPermission("android.permission.READ_COMMUNAL_STATE") public boolean isCommunalMode();
  }
}
package android.app.compat {
  public final class CompatChanges {
+17 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app.communal;
import android.Manifest;
import android.annotation.RequiresFeature;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.compat.annotation.ChangeId;
import android.compat.annotation.Disabled;
@@ -33,6 +34,7 @@ import android.os.RemoteException;
 *
 * @hide
 */
@SystemApi(client = SystemApi.Client.PRIVILEGED_APPS)
@SystemService(Context.COMMUNAL_MANAGER_SERVICE)
@RequiresFeature(PackageManager.FEATURE_COMMUNAL_MODE)
public final class CommunalManager {
@@ -59,6 +61,7 @@ public final class CommunalManager {
    @Disabled
    public static final long ALLOW_COMMUNAL_MODE_WITH_USER_CONSENT = 200324021L;

    /** @hide */
    public CommunalManager(ICommunalManager service) {
        mService = service;
    }
@@ -67,6 +70,8 @@ public final class CommunalManager {
     * Updates whether or not the communal view is currently showing over the lockscreen.
     *
     * @param isShowing Whether communal view is showing.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_COMMUNAL_STATE)
    public void setCommunalViewShowing(boolean isShowing) {
@@ -76,4 +81,16 @@ public final class CommunalManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Check 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();
        }
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ package android.app.communal;
 *
 * @hide
 */
oneway interface ICommunalManager {
    void setCommunalViewShowing(boolean isShowing);
interface ICommunalManager {
    oneway void setCommunalViewShowing(boolean isShowing);
    boolean isCommunalMode();
}
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -5535,6 +5535,12 @@
    <permission android:name="android.permission.WRITE_COMMUNAL_STATE"
                android:protectionLevel="signature" />

    <!-- Allows an application to view information from the currently active
     {@link com.android.server.communal.CommunalManagerService}.
     @hide -->
    <permission android:name="android.permission.READ_COMMUNAL_STATE"
                android:protectionLevel="signature|privileged"/>

    <!-- Allows the holder to manage whether the system can bind to services
         provided by instant apps. This permission is intended to protect
         test/development fucntionality and should be used only in such cases.
+12 −0
Original line number Diff line number Diff line
@@ -254,6 +254,18 @@ public final class CommunalManagerService extends SystemService {
                            + "permission required to modify communal state.");
            mCommunalViewIsShowing.set(isShowing);
        }

        /**
         * Checks whether or not we are in communal mode.
         */
        @RequiresPermission(Manifest.permission.READ_COMMUNAL_STATE)
        @Override
        public boolean isCommunalMode() {
            mContext.enforceCallingPermission(Manifest.permission.READ_COMMUNAL_STATE,
                    Manifest.permission.READ_COMMUNAL_STATE
                            + "permission required to read communal state.");
            return mCommunalViewIsShowing.get();
        }
    }

    /**
Loading