Merge "Added some testAPIs in ContentSuggestionsManager" into sc-dev

This commit is contained in:
Kholoud Mohamed
2021-03-01 12:06:19 +00:00
committed by Android (Google) Code Review
4 changed files with 99 additions and 0 deletions

View File

@@ -564,6 +564,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 {

View File

@@ -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)}.

View File

@@ -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);
}

View File

@@ -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,