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

Commit 0d889047 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "API for notification listener for Companioon apps" into oc-dev

parents 41200eac cf00adeb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8267,6 +8267,8 @@ package android.companion {
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    method public boolean hasNotificationAccess(android.content.ComponentName);
    method public void requestNotificationAccess(android.content.ComponentName);
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
+2 −0
Original line number Diff line number Diff line
@@ -8761,6 +8761,8 @@ package android.companion {
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    method public boolean hasNotificationAccess(android.content.ComponentName);
    method public void requestNotificationAccess(android.content.ComponentName);
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
+2 −0
Original line number Diff line number Diff line
@@ -8298,6 +8298,8 @@ package android.companion {
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    method public boolean hasNotificationAccess(android.content.ComponentName);
    method public void requestNotificationAccess(android.content.ComponentName);
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
+35 −8
Original line number Diff line number Diff line
@@ -22,11 +22,13 @@ import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.RemoteException;
import android.service.notification.NotificationListenerService;
import android.util.Log;

import java.util.Collections;
@@ -195,22 +197,47 @@ public final class CompanionDeviceManager {
        }
    }

    /** @hide */
    public void requestNotificationAccess() {
    /**
     * Request notification access for the given component.
     *
     * The given component must follow the protocol specified in {@link NotificationListenerService}
     *
     * Only components from the same {@link ComponentName#getPackageName package} as the calling app
     * are allowed.
     *
     * Your app must have an association with a device before calling this API
     */
    public void requestNotificationAccess(ComponentName component) {
        if (!checkFeaturePresent()) {
            return;
        }
        //TODO implement
        throw new UnsupportedOperationException("Not yet implemented");
        try {
            mService.requestNotificationAccess(component).send();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (PendingIntent.CanceledException e) {
            throw new RuntimeException(e);
        }
    }

    /** @hide */
    public boolean haveNotificationAccess() {
    /**
     * Check whether the given component can access the notifications via a
     * {@link NotificationListenerService}
     *
     * Your app must have an association with a device before calling this API
     *
     * @param component the name of the component
     * @return whether the given component has the notification listener permission
     */
    public boolean hasNotificationAccess(ComponentName component) {
        if (!checkFeaturePresent()) {
            return false;
        }
        //TODO implement
        throw new UnsupportedOperationException("Not yet implemented");
        try {
            return mService.hasNotificationAccess(component);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    private boolean checkFeaturePresent() {
+4 −3
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package android.companion;

import android.app.PendingIntent;
import android.companion.IFindDeviceCallback;
import android.companion.AssociationRequest;
import android.content.ComponentName;

/**
 * Interface for communication with the core companion device manager service.
@@ -32,7 +34,6 @@ interface ICompanionDeviceManager {
    List<String> getAssociations(String callingPackage, int userId);
    void disassociate(String deviceMacAddress, String callingPackage);

    //TODO add these
//    boolean haveNotificationAccess(String packageName);
//    oneway void requestNotificationAccess(String packageName);
    boolean hasNotificationAccess(in ComponentName component);
    PendingIntent requestNotificationAccess(in ComponentName component);
}
Loading