Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b01db00 authored by Hyundo Moon's avatar Hyundo Moon Committed by Gerrit Code Review
Browse files

Merge "Add AuthenticationServiceTest"

parents fa0fd966 fb9494b0
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ class PbapClientConnectionHandler extends Handler {
                break;

            case MSG_DOWNLOAD:
                mAccountCreated = addAccount(mAccount);
                mAccountCreated = addAccount();
                if (!mAccountCreated) {
                    Log.e(TAG, "Account creation failed.");
                    return;
@@ -456,8 +456,8 @@ class PbapClientConnectionHandler extends Handler {
    }

    @VisibleForTesting
    boolean addAccount(Account account) {
        if (mAccountManager.addAccountExplicitly(account, null, null)) {
    boolean addAccount() {
        if (mAccountManager.addAccountExplicitly(mAccount, null, null)) {
            if (DBG) {
                Log.d(TAG, "Added account " + mAccount);
            }
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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 com.android.bluetooth.pbapclient;

import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
import static android.content.pm.PackageManager.DONT_KILL_APP;

import static com.google.common.truth.Truth.assertThat;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import androidx.test.filters.MediumTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ServiceTestRule;
import androidx.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@MediumTest
@RunWith(AndroidJUnit4.class)
public class AuthenticationServiceTest {

    Context mTargetContext;

    @Rule
    public final ServiceTestRule mServiceRule = new ServiceTestRule();

    @Before
    public void setUp() {
        mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        enableService(true);
    }

    @After
    public void tearDown() {
        enableService(false);
    }

    @Test
    public void bind() throws Exception {
        Intent intent = new Intent("android.accounts.AccountAuthenticator");
        intent.setClass(mTargetContext, AuthenticationService.class);

        assertThat(mServiceRule.bindService(intent)).isNotNull();
    }

    private void enableService(boolean enable) {
        int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED
                : COMPONENT_ENABLED_STATE_DEFAULT;
        ComponentName serviceName = new ComponentName(
                mTargetContext, AuthenticationService.class);
        mTargetContext.getPackageManager().setComponentEnabledSetting(
                serviceName, enabledState, DONT_KILL_APP);
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.os.HandlerThread;
import android.os.Looper;
import android.util.Log;

import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;
@@ -54,8 +53,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.HashMap;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class PbapClientConnectionHandlerTest {