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

Commit d308f2de authored by kholoud mohamed's avatar kholoud mohamed
Browse files

Added some testAPIs in ContentSuggestionsManager

Added the following testAPIs to replace the usage
of adb shell commands in tests:
* resetTemporaryService
* setTemporaryService
* setDefaultServiceEnabled

Bug: 180328483
Test: atest MixedProfileOwnerTest#testDisallowContentSuggestions_allowed
using the new test APIs

Change-Id: I021784d12dd784a5cef4e2c70b2fa82ca85f03f0
parent e1891e1e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -545,6 +545,16 @@ package android.app.blob {

}

package android.app.contentsuggestions {

  public final class ContentSuggestionsManager {
    method @RequiresPermission(android.Manifest.permission.MANAGE_CONTENT_SUGGESTIONS) public void resetTemporaryService(int);
    method @RequiresPermission(android.Manifest.permission.MANAGE_CONTENT_SUGGESTIONS) public void setDefaultServiceEnabled(int, boolean);
    method @RequiresPermission(android.Manifest.permission.MANAGE_CONTENT_SUGGESTIONS) public void setTemporaryService(int, @NonNull String, int);
  }

}

package android.app.prediction {

  public final class AppPredictor {
+68 −0
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ package android.app.contentsuggestions;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.graphics.Bitmap;
import android.os.Binder;
@@ -219,6 +221,72 @@ public final class ContentSuggestionsManager {
        }
    }

    /**
     * Resets the temporary service implementation to the default component.
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(android.Manifest.permission.MANAGE_CONTENT_SUGGESTIONS)
    public void resetTemporaryService(@UserIdInt int userId) {
        if (mService == null) {
            Log.e(TAG, "resetTemporaryService called, but no ContentSuggestionsManager "
                    + "configured");
            return;
        }
        try {
            mService.resetTemporaryService(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Temporarily sets the service implementation.
     *
     * @param userId user Id to set the temporary service on.
     * @param serviceName name of the new component
     * @param duration how long the change will be valid (the service will be automatically reset
     *            to the default component after this timeout expires).
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(android.Manifest.permission.MANAGE_CONTENT_SUGGESTIONS)
    public void setTemporaryService(
            @UserIdInt int userId, @NonNull String serviceName, int duration) {
        if (mService == null) {
            Log.e(TAG, "setTemporaryService called, but no ContentSuggestionsManager "
                    + "configured");
            return;
        }
        try {
            mService.setTemporaryService(userId, serviceName, duration);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Sets whether the default service should be used.
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(android.Manifest.permission.MANAGE_CONTENT_SUGGESTIONS)
    public void setDefaultServiceEnabled(@UserIdInt int userId, boolean enabled) {
        if (mService == null) {
            Log.e(TAG, "setDefaultServiceEnabled called, but no ContentSuggestionsManager "
                    + "configured");
            return;
        }
        try {
            mService.setDefaultServiceEnabled(userId, enabled);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Callback to receive content selections from
     *  {@link #suggestContentSelections(SelectionsRequest, Executor, SelectionsCallback)}.
+3 −0
Original line number Diff line number Diff line
@@ -45,4 +45,7 @@ oneway interface IContentSuggestionsManager {
            in IClassificationsCallback callback);
    void notifyInteraction(int userId, in String requestId, in Bundle interaction);
    void isEnabled(int userId, in IResultReceiver receiver);
    void resetTemporaryService(int userId);
    void setTemporaryService(int userId, in String serviceName, int duration);
    void setDefaultServiceEnabled(int userId, boolean enabled);
}
+18 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.contentsuggestions.ClassificationsRequest;
import android.app.contentsuggestions.ContentSuggestionsManager;
import android.app.contentsuggestions.IClassificationsCallback;
@@ -253,6 +254,23 @@ public class ContentSuggestionsManagerService extends
            receiver.send(isDisabled ? 0 : 1, null);
        }

        @Override
        public void resetTemporaryService(@UserIdInt int userId) {
            ContentSuggestionsManagerService.this.resetTemporaryService(userId);
        }

        @Override
        public void setTemporaryService(
                @UserIdInt int userId, @NonNull String serviceName, int duration) {
            ContentSuggestionsManagerService.this.setTemporaryService(
                    userId, serviceName, duration);
        }

        @Override
        public void setDefaultServiceEnabled(@UserIdInt int userId, boolean enabled) {
            ContentSuggestionsManagerService.this.setDefaultServiceEnabled(userId, enabled);
        }

        public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out,
                @Nullable FileDescriptor err,
                @NonNull String[] args, @Nullable ShellCallback callback,