Revert "Add back getFastPairScanEnabled and setFastPairScanEnabled System API"

This reverts commit 4af0e0f784.

Reason for revert: not support the feature anymore

Test: -m
Change-Id: I26c1f1dd5f36ecb6c1386ccf6ec84118fd93017d

Former-commit-id: 960d69d821
This commit is contained in:
Xinyi Zhou 2023-02-04 05:26:09 +00:00
parent 50007cbea7
commit ae521bea3a
4 changed files with 11 additions and 27 deletions

View File

@ -59,9 +59,7 @@ package android.nearby {
}
public class NearbyManager {
method public static boolean isFastPairScanEnabled(@NonNull android.content.Context);
method public void queryOffloadCapability(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.nearby.OffloadCapability>);
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public static void setFastPairScanEnabled(@NonNull android.content.Context, boolean);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_ADVERTISE, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void startBroadcast(@NonNull android.nearby.BroadcastRequest, @NonNull java.util.concurrent.Executor, @NonNull android.nearby.BroadcastCallback);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_SCAN, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int startScan(@NonNull android.nearby.ScanRequest, @NonNull java.util.concurrent.Executor, @NonNull android.nearby.ScanCallback);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_ADVERTISE, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void stopBroadcast(@NonNull android.nearby.BroadcastCallback);

View File

@ -290,27 +290,25 @@ public class NearbyManager {
/**
* Read from {@link Settings} whether Fast Pair scan is enabled.
*
* @param context either activity or application context for caller to query the setting
* @return whether the Fast Pair scan is enabled
* @throws NullPointerException if {@code context} is {@code null}
* @param context the {@link Context} to query the setting
* @return whether the Fast Pair is enabled
* @hide
*/
public static boolean isFastPairScanEnabled(@NonNull Context context) {
Objects.requireNonNull(context);
public static boolean getFastPairScanEnabled(@NonNull Context context) {
final int enabled = Settings.Secure.getInt(
context.getContentResolver(), FAST_PAIR_SCAN_ENABLED, 0);
return enabled != 0;
}
/**
* Write into {@link Settings} whether Fast Pair scan is enabled.
* Write into {@link Settings} whether Fast Pair scan is enabled
*
* @param context either activity or application context, for caller to set the setting
* @param context the {@link Context} to set the setting
* @param enable whether the Fast Pair scan should be enabled
* @throws NullPointerException if {@code context} is {@code null}
* @hide
*/
@RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
public static void setFastPairScanEnabled(@NonNull Context context, boolean enable) {
Objects.requireNonNull(context);
Settings.Secure.putInt(
context.getContentResolver(), FAST_PAIR_SCAN_ENABLED, enable ? 1 : 0);
Log.v(TAG, String.format(

View File

@ -231,7 +231,7 @@ public class FastPairManager {
mIntentFilter, Context.RECEIVER_EXPORTED);
// Default false for now.
mScanEnabled = NearbyManager.isFastPairScanEnabled(mLocatorContextWrapper.getContext());
mScanEnabled = NearbyManager.getFastPairScanEnabled(mLocatorContextWrapper.getContext());
registerFastPairScanChangeContentObserver(mLocatorContextWrapper.getContentResolver());
}
@ -435,15 +435,12 @@ public class FastPairManager {
}
private void registerFastPairScanChangeContentObserver(ContentResolver resolver) {
if (mFastPairScanChangeContentObserver != null) {
unregisterFastPairScanChangeContentObserver(resolver);
}
mFastPairScanChangeContentObserver = new ContentObserver(ForegroundThread.getHandler()) {
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
setScanEnabled(
NearbyManager.isFastPairScanEnabled(mLocatorContextWrapper.getContext()));
NearbyManager.getFastPairScanEnabled(mLocatorContextWrapper.getContext()));
}
};
try {
@ -456,15 +453,6 @@ public class FastPairManager {
}
}
private void unregisterFastPairScanChangeContentObserver(ContentResolver resolver) {
try {
resolver.unregisterContentObserver(mFastPairScanChangeContentObserver);
mFastPairScanChangeContentObserver = null;
} catch (SecurityException | NullPointerException | IllegalArgumentException e) {
Log.w(TAG, "Failed to unregister FastPairScanChange content observer.", e);
}
}
/**
* Processed task in a background thread
*/

View File

@ -169,9 +169,9 @@ public class NearbyManagerTest {
@SdkSuppress(minSdkVersion = 32, codeName = "T")
public void setFastPairScanEnabled() {
mNearbyManager.setFastPairScanEnabled(mContext, true);
assertThat(mNearbyManager.isFastPairScanEnabled(mContext)).isTrue();
assertThat(mNearbyManager.getFastPairScanEnabled(mContext)).isTrue();
mNearbyManager.setFastPairScanEnabled(mContext, false);
assertThat(mNearbyManager.isFastPairScanEnabled(mContext)).isFalse();
assertThat(mNearbyManager.getFastPairScanEnabled(mContext)).isFalse();
}
@Test