Merge "Asynchronously bind/unbind service" into tm-dev
This commit is contained in:
@@ -42,7 +42,19 @@ public interface QuickAccessWalletClient extends Closeable {
|
||||
*/
|
||||
@NonNull
|
||||
static QuickAccessWalletClient create(@NonNull Context context) {
|
||||
return new QuickAccessWalletClientImpl(context);
|
||||
return create(context, null /* bgExecutor */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a client for accessing wallet cards from the {@link QuickAccessWalletService}. If the
|
||||
* service is unavailable, {@link #isWalletServiceAvailable()} will return false.
|
||||
* @param context Context.
|
||||
* @param bgExecutor A background {@link Executor} for service registration.
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
static QuickAccessWalletClient create(@NonNull Context context, @Nullable Executor bgExecutor) {
|
||||
return new QuickAccessWalletClientImpl(context, bgExecutor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,6 +67,7 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
|
||||
private final Context mContext;
|
||||
private final Queue<ApiCaller> mRequestQueue;
|
||||
private final Map<WalletServiceEventListener, String> mEventListeners;
|
||||
private final Executor mLifecycleExecutor;
|
||||
private boolean mIsConnected;
|
||||
/** Timeout for active service connections (1 minute) */
|
||||
private static final long SERVICE_CONNECTION_TIMEOUT_MS = 60 * 1000;
|
||||
@@ -79,10 +80,11 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
|
||||
|
||||
private static final int MSG_TIMEOUT_SERVICE = 5;
|
||||
|
||||
QuickAccessWalletClientImpl(@NonNull Context context) {
|
||||
QuickAccessWalletClientImpl(@NonNull Context context, @Nullable Executor bgExecutor) {
|
||||
mContext = context.getApplicationContext();
|
||||
mServiceInfo = QuickAccessWalletServiceInfo.tryCreate(context);
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
mLifecycleExecutor = (bgExecutor == null) ? Runnable::run : bgExecutor;
|
||||
mRequestQueue = new LinkedList<>();
|
||||
mEventListeners = new HashMap<>(1);
|
||||
}
|
||||
@@ -369,7 +371,7 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
|
||||
Intent intent = new Intent(SERVICE_INTERFACE);
|
||||
intent.setComponent(mServiceInfo.getComponentName());
|
||||
int flags = Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY;
|
||||
mContext.bindService(intent, this, flags);
|
||||
mLifecycleExecutor.execute(() -> mContext.bindService(intent, this, flags));
|
||||
resetServiceConnectionTimeout();
|
||||
}
|
||||
|
||||
@@ -411,7 +413,7 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
|
||||
return;
|
||||
}
|
||||
mIsConnected = false;
|
||||
mContext.unbindService(/*conn=*/ this);
|
||||
mLifecycleExecutor.execute(() -> mContext.unbindService(/*conn=*/ this));
|
||||
mService = null;
|
||||
mEventListeners.clear();
|
||||
mRequestQueue.clear();
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.util.Log;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.animation.ActivityLaunchAnimator;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Background;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.util.settings.SecureSettings;
|
||||
@@ -64,6 +65,7 @@ public class QuickAccessWalletController {
|
||||
private final Context mContext;
|
||||
private final Executor mExecutor;
|
||||
private final Executor mCallbackExecutor;
|
||||
private final Executor mBgExecutor;
|
||||
private final SecureSettings mSecureSettings;
|
||||
private final SystemClock mClock;
|
||||
|
||||
@@ -80,12 +82,14 @@ public class QuickAccessWalletController {
|
||||
Context context,
|
||||
@Main Executor executor,
|
||||
@CallbackExecutor Executor callbackExecutor,
|
||||
@Background Executor bgExecutor,
|
||||
SecureSettings secureSettings,
|
||||
QuickAccessWalletClient quickAccessWalletClient,
|
||||
SystemClock clock) {
|
||||
mContext = context;
|
||||
mExecutor = executor;
|
||||
mCallbackExecutor = callbackExecutor;
|
||||
mBgExecutor = bgExecutor;
|
||||
mSecureSettings = secureSettings;
|
||||
mQuickAccessWalletClient = quickAccessWalletClient;
|
||||
mClock = clock;
|
||||
@@ -182,7 +186,7 @@ public class QuickAccessWalletController {
|
||||
* Re-create the {@link QuickAccessWalletClient} of the controller.
|
||||
*/
|
||||
public void reCreateWalletClient() {
|
||||
mQuickAccessWalletClient = QuickAccessWalletClient.create(mContext);
|
||||
mQuickAccessWalletClient = QuickAccessWalletClient.create(mContext, mBgExecutor);
|
||||
mQawClientCreatedTimeMillis = mClock.elapsedRealtime();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,11 @@ import android.content.Context;
|
||||
import android.service.quickaccesswallet.QuickAccessWalletClient;
|
||||
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Background;
|
||||
import com.android.systemui.wallet.ui.WalletActivity;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
@@ -45,7 +48,8 @@ public abstract class WalletModule {
|
||||
/** */
|
||||
@SysUISingleton
|
||||
@Provides
|
||||
public static QuickAccessWalletClient provideQuickAccessWalletClient(Context context) {
|
||||
return QuickAccessWalletClient.create(context);
|
||||
public static QuickAccessWalletClient provideQuickAccessWalletClient(Context context,
|
||||
@Background Executor bgExecutor) {
|
||||
return QuickAccessWalletClient.create(context, bgExecutor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class WalletActivity extends LifecycleActivity implements
|
||||
getActionBar().setHomeActionContentDescription(R.string.accessibility_desc_close);
|
||||
WalletView walletView = requireViewById(R.id.wallet_view);
|
||||
|
||||
mWalletClient = QuickAccessWalletClient.create(this);
|
||||
mWalletClient = QuickAccessWalletClient.create(this, mExecutor);
|
||||
mWalletScreenController = new WalletScreenController(
|
||||
this,
|
||||
walletView,
|
||||
|
||||
@@ -100,6 +100,7 @@ public class QuickAccessWalletControllerTest extends SysuiTestCase {
|
||||
mContext,
|
||||
MoreExecutors.directExecutor(),
|
||||
MoreExecutors.directExecutor(),
|
||||
MoreExecutors.directExecutor(),
|
||||
mSecureSettings,
|
||||
mQuickAccessWalletClient,
|
||||
mClock);
|
||||
|
||||
Reference in New Issue
Block a user