Merge "MediaRouter: don't scanPackages if unnecessary" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ce4cd092d9
@@ -169,6 +169,8 @@ final class MediaRoute2ProviderServiceProxy extends MediaRoute2Provider
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void rebindIfDisconnected() {
|
public void rebindIfDisconnected() {
|
||||||
|
//TODO: When we are connecting to the service, calling this will unbind and bind again.
|
||||||
|
// We'd better not unbind if we are connecting.
|
||||||
if (mActiveConnection == null && shouldBind()) {
|
if (mActiveConnection == null && shouldBind()) {
|
||||||
unbind();
|
unbind();
|
||||||
bind();
|
bind();
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ final class MediaRoute2ProviderWatcher {
|
|||||||
|
|
||||||
// Scan packages.
|
// Scan packages.
|
||||||
// Also has the side-effect of restarting providers if needed.
|
// Also has the side-effect of restarting providers if needed.
|
||||||
mHandler.post(mScanPackagesRunnable);
|
postScanPackagesIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ final class MediaRoute2ProviderWatcher {
|
|||||||
mRunning = false;
|
mRunning = false;
|
||||||
|
|
||||||
mContext.unregisterReceiver(mScanPackagesReceiver);
|
mContext.unregisterReceiver(mScanPackagesReceiver);
|
||||||
mHandler.removeCallbacks(mScanPackagesRunnable);
|
mHandler.removeCallbacks(this::scanPackages);
|
||||||
|
|
||||||
// Stop all providers.
|
// Stop all providers.
|
||||||
for (int i = mProxies.size() - 1; i >= 0; i--) {
|
for (int i = mProxies.size() - 1; i >= 0; i--) {
|
||||||
@@ -154,20 +154,19 @@ final class MediaRoute2ProviderWatcher {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void postScanPackagesIfNeeded() {
|
||||||
|
if (!mHandler.hasCallbacks(this::scanPackages)) {
|
||||||
|
mHandler.post(this::scanPackages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final BroadcastReceiver mScanPackagesReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mScanPackagesReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "Received package manager broadcast: " + intent);
|
Slog.d(TAG, "Received package manager broadcast: " + intent);
|
||||||
}
|
}
|
||||||
scanPackages();
|
postScanPackagesIfNeeded();
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final Runnable mScanPackagesRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
scanPackages();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user