Merge "BluetoothManager: Make requestControllerActivityInfo one call" into nyc-dev

This commit is contained in:
Adam Lesinski
2016-05-12 00:59:28 +00:00
committed by Android (Google) Code Review
4 changed files with 100 additions and 112 deletions

View File

@@ -472,12 +472,6 @@ public final class BluetoothAdapter {
private static final int ADDRESS_LENGTH = 17; private static final int ADDRESS_LENGTH = 17;
private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30;
/** @hide */
public static final int ACTIVITY_ENERGY_INFO_CACHED = 0;
/** @hide */
public static final int ACTIVITY_ENERGY_INFO_REFRESHED = 1;
/** /**
* Lazily initialized singleton. Guaranteed final after first object * Lazily initialized singleton. Guaranteed final after first object
* constructed. * constructed.
@@ -1374,13 +1368,13 @@ public final class BluetoothAdapter {
* @return a record with {@link BluetoothActivityEnergyInfo} or null if * @return a record with {@link BluetoothActivityEnergyInfo} or null if
* report is unavailable or unsupported * report is unavailable or unsupported
* @deprecated use the asynchronous * @deprecated use the asynchronous
* {@link #requestControllerActivityEnergyInfo(int, ResultReceiver)} instead. * {@link #requestControllerActivityEnergyInfo(ResultReceiver)} instead.
* @hide * @hide
*/ */
@Deprecated @Deprecated
public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) { public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) {
SynchronousResultReceiver receiver = new SynchronousResultReceiver(); SynchronousResultReceiver receiver = new SynchronousResultReceiver();
requestControllerActivityEnergyInfo(updateType, receiver); requestControllerActivityEnergyInfo(receiver);
try { try {
SynchronousResultReceiver.Result result = receiver.awaitResult(1000); SynchronousResultReceiver.Result result = receiver.awaitResult(1000);
if (result.bundle != null) { if (result.bundle != null) {
@@ -1400,34 +1394,24 @@ public final class BluetoothAdapter {
* A null value for the activity info object may be sent if the bluetooth service is * A null value for the activity info object may be sent if the bluetooth service is
* unreachable or the device does not support reporting such information. * unreachable or the device does not support reporting such information.
* *
* @param updateType Type of info, cached vs refreshed.
* @param result The callback to which to send the activity info. * @param result The callback to which to send the activity info.
* @hide * @hide
*/ */
public void requestControllerActivityEnergyInfo(int updateType, ResultReceiver result) { public void requestControllerActivityEnergyInfo(ResultReceiver result) {
if (getState() != STATE_ON) {
result.send(0, null);
return;
}
try { try {
if (!mService.isActivityAndEnergyReportingSupported()) { synchronized(mManagerCallback) {
result.send(0, null); if (mService != null) {
return; mService.requestActivityInfo(result);
} result = null;
synchronized(this) {
if (updateType == ACTIVITY_ENERGY_INFO_REFRESHED) {
mService.getActivityEnergyInfoFromController();
wait(CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS);
} }
mService.requestActivityInfo(result);
} }
} catch (InterruptedException e) {
Log.e(TAG, "getControllerActivityEnergyInfoCallback wait interrupted: " + e);
result.send(0, null);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e); Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e);
result.send(0, null); } finally {
if (result != null) {
// Only send an immediate result if we failed.
result.send(0, null);
}
} }
} }

View File

@@ -102,7 +102,6 @@ interface IBluetooth
boolean isOffloadedFilteringSupported(); boolean isOffloadedFilteringSupported();
boolean isOffloadedScanBatchingSupported(); boolean isOffloadedScanBatchingSupported();
boolean isActivityAndEnergyReportingSupported(); boolean isActivityAndEnergyReportingSupported();
void getActivityEnergyInfoFromController();
BluetoothActivityEnergyInfo reportActivityInfo(); BluetoothActivityEnergyInfo reportActivityInfo();
/** /**

View File

@@ -309,90 +309,97 @@ public class ResourcesImpl {
public void updateConfiguration(Configuration config, DisplayMetrics metrics, public void updateConfiguration(Configuration config, DisplayMetrics metrics,
CompatibilityInfo compat) { CompatibilityInfo compat) {
synchronized (mAccessLock) { Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesImpl#updateConfiguration");
if (false) { try {
Slog.i(TAG, "**** Updating config of " + this + ": old config is " synchronized (mAccessLock) {
+ mConfiguration + " old compat is " + mCompatibilityInfo); if (false) {
Slog.i(TAG, "**** Updating config of " + this + ": new config is " Slog.i(TAG, "**** Updating config of " + this + ": old config is "
+ config + " new compat is " + compat); + mConfiguration + " old compat is " + mCompatibilityInfo);
} Slog.i(TAG, "**** Updating config of " + this + ": new config is "
if (compat != null) { + config + " new compat is " + compat);
mCompatibilityInfo = compat; }
} if (compat != null) {
if (metrics != null) { mCompatibilityInfo = compat;
mMetrics.setTo(metrics); }
} if (metrics != null) {
// NOTE: We should re-arrange this code to create a Display mMetrics.setTo(metrics);
// with the CompatibilityInfo that is used everywhere we deal }
// with the display in relation to this app, rather than // NOTE: We should re-arrange this code to create a Display
// doing the conversion here. This impl should be okay because // with the CompatibilityInfo that is used everywhere we deal
// we make sure to return a compatible display in the places // with the display in relation to this app, rather than
// where there are public APIs to retrieve the display... but // doing the conversion here. This impl should be okay because
// it would be cleaner and more maintainble to just be // we make sure to return a compatible display in the places
// consistently dealing with a compatible display everywhere in // where there are public APIs to retrieve the display... but
// the framework. // it would be cleaner and more maintainble to just be
mCompatibilityInfo.applyToDisplayMetrics(mMetrics); // consistently dealing with a compatible display everywhere in
// the framework.
mCompatibilityInfo.applyToDisplayMetrics(mMetrics);
final @Config int configChanges = calcConfigChanges(config); final @Config int configChanges = calcConfigChanges(config);
LocaleList locales = mConfiguration.getLocales(); LocaleList locales = mConfiguration.getLocales();
if (locales.isEmpty()) { if (locales.isEmpty()) {
locales = LocaleList.getAdjustedDefault(); locales = LocaleList.getAdjustedDefault();
mConfiguration.setLocales(locales); mConfiguration.setLocales(locales);
}
if (mConfiguration.densityDpi != Configuration.DENSITY_DPI_UNDEFINED) {
mMetrics.densityDpi = mConfiguration.densityDpi;
mMetrics.density =
mConfiguration.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
}
mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale;
final int width, height;
if (mMetrics.widthPixels >= mMetrics.heightPixels) {
width = mMetrics.widthPixels;
height = mMetrics.heightPixels;
} else {
//noinspection SuspiciousNameCombination
width = mMetrics.heightPixels;
//noinspection SuspiciousNameCombination
height = mMetrics.widthPixels;
}
final int keyboardHidden;
if (mConfiguration.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO
&& mConfiguration.hardKeyboardHidden
== Configuration.HARDKEYBOARDHIDDEN_YES) {
keyboardHidden = Configuration.KEYBOARDHIDDEN_SOFT;
} else {
keyboardHidden = mConfiguration.keyboardHidden;
}
mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc,
adjustLanguageTag(locales.get(0).toLanguageTag()),
mConfiguration.orientation,
mConfiguration.touchscreen,
mConfiguration.densityDpi, mConfiguration.keyboard,
keyboardHidden, mConfiguration.navigation, width, height,
mConfiguration.smallestScreenWidthDp,
mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
mConfiguration.screenLayout, mConfiguration.uiMode,
Build.VERSION.RESOURCES_SDK_INT);
if (DEBUG_CONFIG) {
Slog.i(TAG, "**** Updating config of " + this + ": final config is "
+ mConfiguration + " final compat is " + mCompatibilityInfo);
}
mDrawableCache.onConfigurationChange(configChanges);
mColorDrawableCache.onConfigurationChange(configChanges);
mComplexColorCache.onConfigurationChange(configChanges);
mAnimatorCache.onConfigurationChange(configChanges);
mStateListAnimatorCache.onConfigurationChange(configChanges);
flushLayoutCache();
} }
if (mConfiguration.densityDpi != Configuration.DENSITY_DPI_UNDEFINED) { synchronized (sSync) {
mMetrics.densityDpi = mConfiguration.densityDpi; if (mPluralRule != null) {
mMetrics.density = mConfiguration.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; mPluralRule = PluralRules.forLocale(mConfiguration.getLocales().get(0));
} }
mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale;
final int width, height;
if (mMetrics.widthPixels >= mMetrics.heightPixels) {
width = mMetrics.widthPixels;
height = mMetrics.heightPixels;
} else {
//noinspection SuspiciousNameCombination
width = mMetrics.heightPixels;
//noinspection SuspiciousNameCombination
height = mMetrics.widthPixels;
}
final int keyboardHidden;
if (mConfiguration.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO
&& mConfiguration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
keyboardHidden = Configuration.KEYBOARDHIDDEN_SOFT;
} else {
keyboardHidden = mConfiguration.keyboardHidden;
}
mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc,
adjustLanguageTag(locales.get(0).toLanguageTag()),
mConfiguration.orientation,
mConfiguration.touchscreen,
mConfiguration.densityDpi, mConfiguration.keyboard,
keyboardHidden, mConfiguration.navigation, width, height,
mConfiguration.smallestScreenWidthDp,
mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
mConfiguration.screenLayout, mConfiguration.uiMode,
Build.VERSION.RESOURCES_SDK_INT);
if (DEBUG_CONFIG) {
Slog.i(TAG, "**** Updating config of " + this + ": final config is "
+ mConfiguration + " final compat is " + mCompatibilityInfo);
}
mDrawableCache.onConfigurationChange(configChanges);
mColorDrawableCache.onConfigurationChange(configChanges);
mComplexColorCache.onConfigurationChange(configChanges);
mAnimatorCache.onConfigurationChange(configChanges);
mStateListAnimatorCache.onConfigurationChange(configChanges);
flushLayoutCache();
}
synchronized (sSync) {
if (mPluralRule != null) {
mPluralRule = PluralRules.forLocale(mConfiguration.getLocales().get(0));
} }
} finally {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
} }
} }

View File

@@ -1448,9 +1448,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) { if (adapter != null) {
bluetoothReceiver = new SynchronousResultReceiver(); bluetoothReceiver = new SynchronousResultReceiver();
adapter.requestControllerActivityEnergyInfo( adapter.requestControllerActivityEnergyInfo(bluetoothReceiver);
BluetoothAdapter.ACTIVITY_ENERGY_INFO_REFRESHED,
bluetoothReceiver);
} }
} }