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

Commit cf00adeb authored by Eugene Susla's avatar Eugene Susla
Browse files

API for notification listener for Companioon apps

Test: 1. Trigger the confitrmation dialog.
Ensure it looks exactly like the one from settings.
2. Call an API without associating the appa first
Ensure exception is thrown with a message mentioning the need to associate 1st
Change-Id: I94d4116e1988db869ed445ae3fd018c50590e3f4
parent 47dea3b1
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -8262,6 +8262,8 @@ package android.companion {
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    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";
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
  }
+2 −0
Original line number Original line Diff line number Diff line
@@ -8756,6 +8756,8 @@ package android.companion {
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    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";
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
  }
+2 −0
Original line number Original line Diff line number Diff line
@@ -8293,6 +8293,8 @@ package android.companion {
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void associate(android.companion.AssociationRequest, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    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";
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
  }
+35 −8
Original line number Original line Diff line number Diff line
@@ -22,11 +22,13 @@ import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.IntentSender;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Handler;
import android.os.RemoteException;
import android.os.RemoteException;
import android.service.notification.NotificationListenerService;
import android.util.Log;
import android.util.Log;


import java.util.Collections;
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()) {
        if (!checkFeaturePresent()) {
            return;
            return;
        }
        }
        //TODO implement
        try {
        throw new UnsupportedOperationException("Not yet implemented");
            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()) {
        if (!checkFeaturePresent()) {
            return false;
            return false;
        }
        }
        //TODO implement
        try {
        throw new UnsupportedOperationException("Not yet implemented");
            return mService.hasNotificationAccess(component);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    }


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


package android.companion;
package android.companion;


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


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


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