Skip to content

Commit

Permalink
Update library
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-juan-docal committed Aug 30, 2023
0 parents commit c0d41b1
Show file tree
Hide file tree
Showing 53 changed files with 5,456 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build-android.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Build Android
on: [workflow_call]
jobs:
build-android:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: gradle
- name: build
run: ./gradlew bundleReleaseAar assembleAccountReleaseXCFramework --parallel
12 changes: 12 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Push checks
on:
push:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
build:
uses: ./.github/workflows/build-android.yaml
test:
uses: ./.github/workflows/test-android.yaml
14 changes: 14 additions & 0 deletions .github/workflows/test-android.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test Android
on: [workflow_call]
jobs:
unit-tests:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: gradle
- name: unit-tests
run: ./gradlew test --parallel
49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
account.podspec

# Android
.DS_Store
.hg
*.o
*.patch
obj
bin
libs
gen
depcomp
t_client.sh
ics-openvpn.zip
zh-CN.zip
zh-TW.zip
.gradle
app/build
gradlew.bat
local.properties
ovpnlibs
.idea
*.iml
.metadata
.project
.settings
.classpath
project.properties
*.apk

# iOS
*.swp
*.pbxuser
**/*.xcworkspace/xcuserdata
**/*.xcodeproj/project.xcworkspace
**/*.xcodeproj/xcuserdata
Pods
fastlane/**/*.html
fastlane/README.md
fastlane/report.xml
fastlane/test_output
fastlane/review_information/demo_*
build
dist
apple_dist
Preview.html
Gemfile.lock
*.podspec
*.xcframework
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2020-Present Private Internet Access

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[![PIA logo][pia-image]][pia-url]

# Private Internet Access

Private Internet Access is the world's leading consumer VPN service. At Private Internet Access we believe in unfettered access for all, and as a firm supporter of the open source ecosystem we have made the decision to open source our VPN clients. For more information about the PIA service, please visit our website [privateinternetaccess.com][pia-url] or check out the [Wiki][pia-wiki].

# Account common library for Android and Apple platforms

With this library, clients from iOS and Android can communicate easily with the Private Internet Access account's services.

## Installation

### Requirements
- Git (latest)
- Xcode (latest)
- Android Studio (latest)
- Gradle (latest)
- ADB installed
- NDK (latest)
- Android 4.1+

#### Download Codebase
Using the terminal:

`git clone https://github.com/pia-foss/mobile-common-account.git *folder-name*`

type in what folder you want to put in without the **

#### Building

Once the project is cloned, you can build the binaries by running the tasks `./gradlew bundleDebugAar` or `./gradlew bundleReleaseAar` for Android. And, `./gradlew assembleAccountDebugXCFramework` or `./gradlew assembleAccountReleaseXCFramework` for iOS. You can find the binaries at `[PROJECT_DIR]/account/build/outputs/aar` and `[PROJECT_DIR]/account/build/XCFrameworks` accordingly.

## Usage

### Android

To use this project in Android, you can run the task `./gradlew publishAndroidReleasePublicationToMavenLocal`. This will publish the package to your maven local (Make sure to have included `mavenLocal()` as part of your gradle repositories). Once successful, you can set the dependency as per any other package, e.g.:
```
implementation("com.kape.android:account:[version_number]")
```
where `[version_number]` is the version as set in `account/build.gradle.kts`.

### iOS

To use this project in iOS, once you have built `account.xcframework`. You can go to your project target. Build Phases. Link Binary With Libraries. (or alternatively drag the file there and skip the rest) Click the `+`. Add Other. Add Files. And look for `account.xcframework`.

## Documentation

#### Architecture

The library is formed by two layers. The common layer. Containing the business logic for all platforms. And, the bridging layer. Containing the platform specific logic being injected into the common layer.

Code structure via packages:

* `commonMain` - Common business logic.
* `androidMain` - Android's bridging layer, providing the platform specific dependencies.
* `iosMain` - iOS's bridging layer, providing the platform specific dependencies.

#### Significant Classes and Interfaces

* `AccountBuilder` - Public builder class responsible for creating an instance of an object conforming to either the `IOSAccountAPI` or `AndroidAccountAPI` interface for the client side.
* `AccountAPI` - Public interfaces defining the API to be offered by the library to the clients.
* `AccountHttpClient` - Class defining the certificate pinning logic on each platform.

## Contributing

By contributing to this project you are agreeing to the terms stated in the Contributor License Agreement (CLA) [here](/CLA.rst).

For more details please see [CONTRIBUTING](/CONTRIBUTING.md).

Issues and Pull Requests should use these templates: [ISSUE](/.github/ISSUE_TEMPLATE.md) and [PULL REQUEST](/.github/PULL_REQUEST_TEMPLATE.md).

## Authors

- Jose Blaya - [ueshiba](https://github.com/ueshiba)
- Juan Docal - [tatostao](https://github.com/tatostao)

## License

This project is licensed under the [MIT (Expat) license](https://choosealicense.com/licenses/mit/), which can be found [here](/LICENSE).

## Acknowledgements

- Ktor - © 2020 (http://ktor.io)

[pia-image]: https://assets-cms.privateinternetaccess.com/img/frontend/pia_menu_logo_light.svg
[pia-url]: https://www.privateinternetaccess.com/
[pia-wiki]: https://en.wikipedia.org/wiki/Private_Internet_Access
94 changes: 94 additions & 0 deletions account/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("com.android.library")
id("maven-publish")
}

publishing {
repositories {
maven {
url = uri("https://maven.pkg.github.com/xvpn/cpz_pia-mobile_shared_account/")
credentials {
username = System.getenv("GITHUB_USERNAME")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}

android {
namespace = "com.kape.account"

compileSdk = 34
defaultConfig {
minSdk = 21
targetSdk = 34
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
group = "com.kape.android"
version = "1.4.0"

// Enable the default target hierarchy.
// It's a template for all possible targets and their shared source sets hardcoded in the
// Kotlin Gradle plugin.
targetHierarchy.default()

// Android
android {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}

// iOS
val xcf = XCFramework()
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
xcf.add(this)
}
}

sourceSets {
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:2.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
implementation("com.russhwolf:multiplatform-settings:1.0.0")
}
}
val androidMain by getting {
dependencies {
implementation("androidx.security:security-crypto:1.1.0-alpha03")
implementation("com.madgag.spongycastle:core:1.58.0.0")
implementation("io.ktor:ktor-client-okhttp:2.3.3")
}
}
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:2.3.3")
}
}
}
}
2 changes: 2 additions & 0 deletions account/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.privateinternetaccess.account

/*
* Copyright (c) 2021 Private Internet Access, Inc.
*
* This file is part of the Private Internet Access Mobile Client.
*
* The Private Internet Access Mobile Client is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* The Private Internet Access Mobile Client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with the Private
* Internet Access Mobile Client. If not, see <https://www.gnu.org/licenses/>.
*/

import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import com.privateinternetaccess.account.internals.AccountContextProvider


class AccountContentProvider : ContentProvider() {

override fun onCreate(): Boolean {
context?.let {
AccountContextProvider.context(it)
return true
}
return false
}

override fun query(uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?, sortOrder: String?): Cursor? = null

override fun getType(uri: Uri): String? = null

override fun insert(uri: Uri, values: ContentValues?): Uri? = null

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int = 0

override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String>?): Int = 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.privateinternetaccess.account.internals

/*
* Copyright (c) 2021 Private Internet Access, Inc.
*
* This file is part of the Private Internet Access Mobile Client.
*
* The Private Internet Access Mobile Client is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* The Private Internet Access Mobile Client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with the Private
* Internet Access Mobile Client. If not, see <https://www.gnu.org/licenses/>.
*/

import android.content.Context


object AccountContextProvider {

@Volatile
internal var applicationContext: Context? = null

internal fun context(context: Context) {
applicationContext = context
}
}
Loading

0 comments on commit c0d41b1

Please sign in to comment.