Loading core/api/current.txt +6 −0 Original line number Original line Diff line number Diff line Loading @@ -140,6 +140,7 @@ package android { field public static final String REQUEST_DELETE_PACKAGES = "android.permission.REQUEST_DELETE_PACKAGES"; field public static final String REQUEST_DELETE_PACKAGES = "android.permission.REQUEST_DELETE_PACKAGES"; field public static final String REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"; field public static final String REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"; field public static final String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES"; field public static final String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES"; field public static final String REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE = "android.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE"; field public static final String REQUEST_PASSWORD_COMPLEXITY = "android.permission.REQUEST_PASSWORD_COMPLEXITY"; field public static final String REQUEST_PASSWORD_COMPLEXITY = "android.permission.REQUEST_PASSWORD_COMPLEXITY"; field @Deprecated public static final String RESTART_PACKAGES = "android.permission.RESTART_PACKAGES"; field @Deprecated public static final String RESTART_PACKAGES = "android.permission.RESTART_PACKAGES"; field public static final String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE"; field public static final String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE"; Loading Loading @@ -9519,6 +9520,8 @@ package android.companion { method @NonNull public java.util.List<java.lang.String> getAssociations(); method @NonNull public java.util.List<java.lang.String> getAssociations(); method public boolean hasNotificationAccess(android.content.ComponentName); method public boolean hasNotificationAccess(android.content.ComponentName); method public void requestNotificationAccess(android.content.ComponentName); method public void requestNotificationAccess(android.content.ComponentName); method @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException; method @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void stopObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException; field public static final String EXTRA_DEVICE = "android.companion.extra.DEVICE"; field public static final String EXTRA_DEVICE = "android.companion.extra.DEVICE"; } } Loading @@ -9539,6 +9542,9 @@ package android.companion { public interface DeviceFilter<D extends android.os.Parcelable> extends android.os.Parcelable { public interface DeviceFilter<D extends android.os.Parcelable> extends android.os.Parcelable { } } public class DeviceNotAssociatedException extends java.lang.Exception { } public final class WifiDeviceFilter implements android.companion.DeviceFilter<android.net.wifi.ScanResult> { public final class WifiDeviceFilter implements android.companion.DeviceFilter<android.net.wifi.ScanResult> { method public int describeContents(); method public int describeContents(); method public void writeToParcel(@NonNull android.os.Parcel, int); method public void writeToParcel(@NonNull android.os.Parcel, int); core/java/android/companion/CompanionDeviceManager.java +72 −0 Original line number Original line Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.os.Handler; import android.os.RemoteException; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserHandle; import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService; import android.util.ExceptionUtils; import android.util.Log; import android.util.Log; import java.util.Collections; import java.util.Collections; Loading Loading @@ -321,6 +322,77 @@ public final class CompanionDeviceManager { } } } } /** * Register to receive callbacks whenever the associated device comes in and out of range. * * The provided device must be {@link #associate associated} with the calling app before * calling this method. * * Caller must implement a single {@link CompanionDeviceService} which will be bound to and * receive callbacks to {@link CompanionDeviceService#onDeviceAppeared} and * {@link CompanionDeviceService#onDeviceDisappeared}. * The app doesn't need to remain running in order to receive its callbacks. * * Calling app must declare uses-permission * {@link android.Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE}. * * Calling app must check for feature presence of * {@link PackageManager#FEATURE_COMPANION_DEVICE_SETUP} before calling this API. * * @param deviceAddress a previously-associated companion device's address * * @throws DeviceNotAssociatedException if the given device was not previously associated * with this app. */ @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull String deviceAddress) throws DeviceNotAssociatedException { if (!checkFeaturePresent()) { return; } Objects.requireNonNull(deviceAddress, "address cannot be null"); try { mService.registerDevicePresenceListenerService( mContext.getPackageName(), deviceAddress); } catch (RemoteException e) { ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class); throw e.rethrowFromSystemServer(); } } /** * Unregister for receiving callbacks whenever the associated device comes in and out of range. * * The provided device must be {@link #associate associated} with the calling app before * calling this method. * * Calling app must declare uses-permission * {@link android.Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE}. * * Calling app must check for feature presence of * {@link PackageManager#FEATURE_COMPANION_DEVICE_SETUP} before calling this API. * * @param deviceAddress a previously-associated companion device's address * * @throws DeviceNotAssociatedException if the given device was not previously associated * with this app. */ @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void stopObservingDevicePresence(@NonNull String deviceAddress) throws DeviceNotAssociatedException { if (!checkFeaturePresent()) { return; } Objects.requireNonNull(deviceAddress, "address cannot be null"); try { mService.unregisterDevicePresenceListenerService( mContext.getPackageName(), deviceAddress); } catch (RemoteException e) { ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class); throw e.rethrowFromSystemServer(); } } private boolean checkFeaturePresent() { private boolean checkFeaturePresent() { boolean featurePresent = mService != null; boolean featurePresent = mService != null; if (!featurePresent && DEBUG) { if (!featurePresent && DEBUG) { Loading core/java/android/companion/DeviceNotAssociatedException.java 0 → 100644 +31 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.companion; import android.annotation.Nullable; /** * An exception for a case when a given device was not * {@link CompanionDeviceManager#associate associated} to the calling app. */ public class DeviceNotAssociatedException extends Exception { /** @hide */ public DeviceNotAssociatedException(@Nullable String deviceName) { super("Device not associated with the current app: " + deviceName); } } core/java/android/companion/ICompanionDeviceManager.aidl +4 −0 Original line number Original line Diff line number Diff line Loading @@ -45,4 +45,8 @@ interface ICompanionDeviceManager { boolean isDeviceAssociatedForWifiConnection(in String packageName, in String macAddress, boolean isDeviceAssociatedForWifiConnection(in String packageName, in String macAddress, int userId); int userId); void registerDevicePresenceListenerService(in String packageName, in String deviceAddress); void unregisterDevicePresenceListenerService(in String packageName, in String deviceAddress); } } core/java/android/os/RemoteException.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -37,6 +37,11 @@ public class RemoteException extends AndroidException { super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace); } } /** @hide */ public RemoteException(Throwable cause) { this(cause.getMessage(), cause, true, false); } /** /** * Rethrow this as an unchecked runtime exception. * Rethrow this as an unchecked runtime exception. * <p> * <p> Loading Loading
core/api/current.txt +6 −0 Original line number Original line Diff line number Diff line Loading @@ -140,6 +140,7 @@ package android { field public static final String REQUEST_DELETE_PACKAGES = "android.permission.REQUEST_DELETE_PACKAGES"; field public static final String REQUEST_DELETE_PACKAGES = "android.permission.REQUEST_DELETE_PACKAGES"; field public static final String REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"; field public static final String REQUEST_IGNORE_BATTERY_OPTIMIZATIONS = "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"; field public static final String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES"; field public static final String REQUEST_INSTALL_PACKAGES = "android.permission.REQUEST_INSTALL_PACKAGES"; field public static final String REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE = "android.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE"; field public static final String REQUEST_PASSWORD_COMPLEXITY = "android.permission.REQUEST_PASSWORD_COMPLEXITY"; field public static final String REQUEST_PASSWORD_COMPLEXITY = "android.permission.REQUEST_PASSWORD_COMPLEXITY"; field @Deprecated public static final String RESTART_PACKAGES = "android.permission.RESTART_PACKAGES"; field @Deprecated public static final String RESTART_PACKAGES = "android.permission.RESTART_PACKAGES"; field public static final String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE"; field public static final String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE"; Loading Loading @@ -9519,6 +9520,8 @@ package android.companion { method @NonNull public java.util.List<java.lang.String> getAssociations(); method @NonNull public java.util.List<java.lang.String> getAssociations(); method public boolean hasNotificationAccess(android.content.ComponentName); method public boolean hasNotificationAccess(android.content.ComponentName); method public void requestNotificationAccess(android.content.ComponentName); method public void requestNotificationAccess(android.content.ComponentName); method @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException; method @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void stopObservingDevicePresence(@NonNull String) throws android.companion.DeviceNotAssociatedException; field public static final String EXTRA_DEVICE = "android.companion.extra.DEVICE"; field public static final String EXTRA_DEVICE = "android.companion.extra.DEVICE"; } } Loading @@ -9539,6 +9542,9 @@ package android.companion { public interface DeviceFilter<D extends android.os.Parcelable> extends android.os.Parcelable { public interface DeviceFilter<D extends android.os.Parcelable> extends android.os.Parcelable { } } public class DeviceNotAssociatedException extends java.lang.Exception { } public final class WifiDeviceFilter implements android.companion.DeviceFilter<android.net.wifi.ScanResult> { public final class WifiDeviceFilter implements android.companion.DeviceFilter<android.net.wifi.ScanResult> { method public int describeContents(); method public int describeContents(); method public void writeToParcel(@NonNull android.os.Parcel, int); method public void writeToParcel(@NonNull android.os.Parcel, int);
core/java/android/companion/CompanionDeviceManager.java +72 −0 Original line number Original line Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.os.Handler; import android.os.RemoteException; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserHandle; import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService; import android.util.ExceptionUtils; import android.util.Log; import android.util.Log; import java.util.Collections; import java.util.Collections; Loading Loading @@ -321,6 +322,77 @@ public final class CompanionDeviceManager { } } } } /** * Register to receive callbacks whenever the associated device comes in and out of range. * * The provided device must be {@link #associate associated} with the calling app before * calling this method. * * Caller must implement a single {@link CompanionDeviceService} which will be bound to and * receive callbacks to {@link CompanionDeviceService#onDeviceAppeared} and * {@link CompanionDeviceService#onDeviceDisappeared}. * The app doesn't need to remain running in order to receive its callbacks. * * Calling app must declare uses-permission * {@link android.Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE}. * * Calling app must check for feature presence of * {@link PackageManager#FEATURE_COMPANION_DEVICE_SETUP} before calling this API. * * @param deviceAddress a previously-associated companion device's address * * @throws DeviceNotAssociatedException if the given device was not previously associated * with this app. */ @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void startObservingDevicePresence(@NonNull String deviceAddress) throws DeviceNotAssociatedException { if (!checkFeaturePresent()) { return; } Objects.requireNonNull(deviceAddress, "address cannot be null"); try { mService.registerDevicePresenceListenerService( mContext.getPackageName(), deviceAddress); } catch (RemoteException e) { ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class); throw e.rethrowFromSystemServer(); } } /** * Unregister for receiving callbacks whenever the associated device comes in and out of range. * * The provided device must be {@link #associate associated} with the calling app before * calling this method. * * Calling app must declare uses-permission * {@link android.Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE}. * * Calling app must check for feature presence of * {@link PackageManager#FEATURE_COMPANION_DEVICE_SETUP} before calling this API. * * @param deviceAddress a previously-associated companion device's address * * @throws DeviceNotAssociatedException if the given device was not previously associated * with this app. */ @RequiresPermission(android.Manifest.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE) public void stopObservingDevicePresence(@NonNull String deviceAddress) throws DeviceNotAssociatedException { if (!checkFeaturePresent()) { return; } Objects.requireNonNull(deviceAddress, "address cannot be null"); try { mService.unregisterDevicePresenceListenerService( mContext.getPackageName(), deviceAddress); } catch (RemoteException e) { ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class); throw e.rethrowFromSystemServer(); } } private boolean checkFeaturePresent() { private boolean checkFeaturePresent() { boolean featurePresent = mService != null; boolean featurePresent = mService != null; if (!featurePresent && DEBUG) { if (!featurePresent && DEBUG) { Loading
core/java/android/companion/DeviceNotAssociatedException.java 0 → 100644 +31 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.companion; import android.annotation.Nullable; /** * An exception for a case when a given device was not * {@link CompanionDeviceManager#associate associated} to the calling app. */ public class DeviceNotAssociatedException extends Exception { /** @hide */ public DeviceNotAssociatedException(@Nullable String deviceName) { super("Device not associated with the current app: " + deviceName); } }
core/java/android/companion/ICompanionDeviceManager.aidl +4 −0 Original line number Original line Diff line number Diff line Loading @@ -45,4 +45,8 @@ interface ICompanionDeviceManager { boolean isDeviceAssociatedForWifiConnection(in String packageName, in String macAddress, boolean isDeviceAssociatedForWifiConnection(in String packageName, in String macAddress, int userId); int userId); void registerDevicePresenceListenerService(in String packageName, in String deviceAddress); void unregisterDevicePresenceListenerService(in String packageName, in String deviceAddress); } }
core/java/android/os/RemoteException.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -37,6 +37,11 @@ public class RemoteException extends AndroidException { super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace); } } /** @hide */ public RemoteException(Throwable cause) { this(cause.getMessage(), cause, true, false); } /** /** * Rethrow this as an unchecked runtime exception. * Rethrow this as an unchecked runtime exception. * <p> * <p> Loading