diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/companion/CompanionDeviceManager.java | 43 | ||||
| -rw-r--r-- | core/java/android/companion/ICompanionDeviceManager.aidl | 7 | ||||
| -rw-r--r-- | core/java/android/os/Binder.java | 30 | ||||
| -rw-r--r-- | core/java/android/provider/SettingsStringUtil.java | 7 |
4 files changed, 73 insertions, 14 deletions
diff --git a/core/java/android/companion/CompanionDeviceManager.java b/core/java/android/companion/CompanionDeviceManager.java index 4d788e783f34..e50b2a97c2d2 100644 --- a/core/java/android/companion/CompanionDeviceManager.java +++ b/core/java/android/companion/CompanionDeviceManager.java @@ -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() { diff --git a/core/java/android/companion/ICompanionDeviceManager.aidl b/core/java/android/companion/ICompanionDeviceManager.aidl index 7798406c35e5..d3952084116c 100644 --- a/core/java/android/companion/ICompanionDeviceManager.aidl +++ b/core/java/android/companion/ICompanionDeviceManager.aidl @@ -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); } diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java index 15bd175949c4..ff0bc69ed325 100644 --- a/core/java/android/os/Binder.java +++ b/core/java/android/os/Binder.java @@ -16,9 +16,15 @@ package android.os; +import android.util.ExceptionUtils; import android.util.Log; import android.util.Slog; + import com.android.internal.util.FastPrintWriter; +import com.android.internal.util.FunctionalUtils; +import com.android.internal.util.FunctionalUtils.ThrowingRunnable; +import com.android.internal.util.FunctionalUtils.ThrowingSupplier; + import libcore.io.IoUtils; import java.io.FileDescriptor; @@ -26,7 +32,6 @@ import java.io.FileOutputStream; import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.lang.reflect.Modifier; -import java.util.function.Supplier; /** * Base class for a remotable object, the core part of a lightweight @@ -251,14 +256,23 @@ public class Binder implements IBinder { * Convenience method for running the provided action enclosed in * {@link #clearCallingIdentity}/{@link #restoreCallingIdentity} * + * Any exception thrown by the given action will be caught and rethrown after the call to + * {@link #restoreCallingIdentity} + * * @hide */ - public static final void withCleanCallingIdentity(Runnable action) { + public static final void withCleanCallingIdentity(ThrowingRunnable action) { long callingIdentity = clearCallingIdentity(); + Throwable throwableToPropagate = null; try { action.run(); + } catch (Throwable throwable) { + throwableToPropagate = throwable; } finally { restoreCallingIdentity(callingIdentity); + if (throwableToPropagate != null) { + throw ExceptionUtils.propagate(throwableToPropagate); + } } } @@ -266,14 +280,24 @@ public class Binder implements IBinder { * Convenience method for running the provided action enclosed in * {@link #clearCallingIdentity}/{@link #restoreCallingIdentity} returning the result * + * Any exception thrown by the given action will be caught and rethrown after the call to + * {@link #restoreCallingIdentity} + * * @hide */ - public static final <T> T withCleanCallingIdentity(Supplier<T> action) { + public static final <T> T withCleanCallingIdentity(ThrowingSupplier<T> action) { long callingIdentity = clearCallingIdentity(); + Throwable throwableToPropagate = null; try { return action.get(); + } catch (Throwable throwable) { + throwableToPropagate = throwable; + return null; // overridden by throwing in finally block } finally { restoreCallingIdentity(callingIdentity); + if (throwableToPropagate != null) { + throw ExceptionUtils.propagate(throwableToPropagate); + } } } diff --git a/core/java/android/provider/SettingsStringUtil.java b/core/java/android/provider/SettingsStringUtil.java index 3dfedea18323..a3dc9471a1d0 100644 --- a/core/java/android/provider/SettingsStringUtil.java +++ b/core/java/android/provider/SettingsStringUtil.java @@ -23,6 +23,7 @@ import android.text.TextUtils; import com.android.internal.util.ArrayUtils; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.function.Function; @@ -80,6 +81,12 @@ public class SettingsStringUtil { return s; } + public static String addAll(String delimitedElements, Collection<String> elements) { + final ColonDelimitedSet<String> set + = new ColonDelimitedSet.OfStrings(delimitedElements); + return set.addAll(elements) ? set.toString() : delimitedElements; + } + public static String add(String delimitedElements, String element) { final ColonDelimitedSet<String> set = new ColonDelimitedSet.OfStrings(delimitedElements); |
