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

Commit eaf38bd3 authored by Chalard Jean's avatar Chalard Jean
Browse files

Add shims for Ikev2VpnProfile and its builder

Shims are necessary to test the new "requiresValidation"
API for VpnManager.

Test: m ; usage of these shims in the next patch.
Change-Id: Ic57b14f85679ba96962327035bae049034c8aa72
parent fc12d63b
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.networkstack.apishim.api29;

import com.android.networkstack.apishim.common.Ikev2VpnProfileBuilderShim;
import com.android.networkstack.apishim.common.UnsupportedApiLevelException;

/**
 * Implementation of Ikev2VpnProfileBuilderShim for API 29.
  *
 * @param <T> type of builder, typically Ikev2VpnProfile.Builder. This is necessary because at
 *            compile time, shims for older releases will not have access to this class as it
 *            debuted in SDK30. So the user of the shim has to pass it in.
 */
// NOTE : the trick with the formal parameter only works because when this shim was introduced,
// the stable API already contained the class that the caller needs to pass in; this won't
// work for a class added in the latest API level.
public class Ikev2VpnProfileBuilderShimImpl<T> implements Ikev2VpnProfileBuilderShim<T> {
    /**
     * @see Ikev2VpnProfile.Builder#setRequiresInternetValidation(boolean)
     */
    @Override
    public T setRequiresInternetValidation(T builder,
            boolean requiresInternetValidation) throws UnsupportedApiLevelException {
        throw new UnsupportedApiLevelException("Only supported from API level 33.");
    }
}
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.networkstack.apishim.api29;

import com.android.networkstack.apishim.common.Ikev2VpnProfileShim;
import com.android.networkstack.apishim.common.UnsupportedApiLevelException;

/**
 * Implementation of Ikev2VpnProfileShim for API 29.
 * @param <T> type of profile, typically Ikev2VpnProfile
 */
public class Ikev2VpnProfileShimImpl<T> implements Ikev2VpnProfileShim<T> {
    /**
     * @see Ikev2VpnProfile#getRequiresInternetValidation(boolean)
     */
    @Override
    public boolean getRequiresInternetValidation(T profile)
            throws UnsupportedApiLevelException {
        throw new UnsupportedApiLevelException("Only supported from API level 33.");
    }
}
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.networkstack.apishim.api29;

import com.android.networkstack.apishim.common.NetworkAgentConfigShim;

/**
 * Implementation of NetworkAgentConfigShim for API 29.
 */
public class NetworkAgentConfigShimImpl implements NetworkAgentConfigShim {
    @Override
    public boolean getVpnRequiresValidation() {
        return false;
    }
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.networkstack.apishim.api30;

import android.net.Ikev2VpnProfile;

import com.android.networkstack.apishim.common.Ikev2VpnProfileBuilderShim;

/**
 * Implementation of Ikev2VpnProfileBuilderShim for API 30.
 */
// TODO : when API29 is no longer supported, remove the type argument
public class Ikev2VpnProfileBuilderShimImpl
        extends com.android.networkstack.apishim.api29.Ikev2VpnProfileBuilderShimImpl<
                Ikev2VpnProfile.Builder
        > {
    /**
     * Returns a new instance of this shim impl.
     */
    public static Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> newInstance() {
        return new Ikev2VpnProfileBuilderShimImpl();
    }
}
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.networkstack.apishim.api30;

import android.net.Ikev2VpnProfile;

import com.android.networkstack.apishim.common.Ikev2VpnProfileShim;

/**
 * Implementation of Ikev2VpnProfileShim for API 30.
 */
// TODO : when API29 is no longer supported, remove the type argument
public class Ikev2VpnProfileShimImpl extends
        com.android.networkstack.apishim.api29.Ikev2VpnProfileShimImpl<Ikev2VpnProfile> {
    /**
     * Returns a new instance of this shim impl.
     */
    public static Ikev2VpnProfileShim<Ikev2VpnProfile> newInstance() {
        return new Ikev2VpnProfileShimImpl();
    }
}
Loading