Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Shared Preferences Viewer #21

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
49a6545
imported requestly-android-okhttp in requestly-android
Nov 2, 2022
d2c2a15
created fragment, adaptor and ui
Nov 4, 2022
9feb922
shared pref logic completed
Nov 9, 2022
8f7ca58
minor improvement in Host Switcher
Nov 9, 2022
2ecec7a
hide requestly shared pref files
Nov 9, 2022
b9eaba3
comments added
Nov 9, 2022
0e3466c
removed unused code
Nov 9, 2022
9d42a5a
chore: bump version to 2.4.2
wrongsahil Nov 4, 2022
afb9b74
chore: updated readme
wrongsahil Nov 5, 2022
3f6c1c8
fix: fix sharedpreferences hilt issue
wrongsahil Nov 15, 2022
852194e
chore: update readme
wrongsahil Nov 15, 2022
e5dc9db
chore: added release pipelines
wrongsahil Nov 15, 2022
bf9e16b
chore: added cryptodemo as try now
wrongsahil Nov 16, 2022
50da3c8
chore: update playground link to open in new tab
wrongsahil Nov 16, 2022
da6883f
fix: added sourceCompatibility and targetCompatibility
wrongsahil Nov 17, 2022
f455183
chore: bump version to 2.4.4
wrongsahil Nov 17, 2022
8eb864c
fix: main_nav_graph collision fix
wrongsahil Nov 17, 2022
ad0f49c
chore: bump version to 2.4.5
wrongsahil Nov 17, 2022
3ed1540
fix: fix import error
wrongsahil Nov 17, 2022
9449f4a
chore: update readme
wrongsahil Nov 21, 2022
57dc59a
chore: update readme
wrongsahil Nov 21, 2022
63c91c2
chore: update badges in readme
wrongsahil Nov 21, 2022
9b268b6
chore: updated maven badge in readme
wrongsahil Nov 21, 2022
4f54ec2
fix: move out synchrnous code while init
wrongsahil Nov 21, 2022
869908c
chore: update readme
wrongsahil Nov 21, 2022
d61bd1e
snapshot testing
Nov 21, 2022
700a3fa
merge conflicts removed
Dec 1, 2022
e50a749
unused code removed
Dec 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish Release
on: workflow_dispatch

jobs:
publish:
if: ${{ github.repository == 'requestly/requestly-android-sdk'}}
runs-on: [ubuntu-latest]

steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Publish to Maven Local
run: ./gradlew publishToMavenLocal
env:
ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }}
ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }}

- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: 'requestly-android-sdk-release-artifacts'
path: '~/.m2/repository/'

- name: Publish to the Staging Repository
run: ./gradlew publishReleasePublicationToStagingRepository --no-parallel
env:
ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }}
ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }}
ORG_GRADLE_PROJECT_NEXUS_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_NEXUS_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_NEXUS_PASSWORD }}
31 changes: 31 additions & 0 deletions .github/workflows/publish-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish Snapshot
on: workflow_dispatch

jobs:
publish:
if: ${{ github.repository == 'requestly/requestly-android-sdk'}}
runs-on: [ubuntu-latest]

steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Publish to Maven Local
run: ./gradlew publishToMavenLocal
env:
ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }}
ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }}

- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: 'requestly-android-sdk-snapshot-artifacts'
path: '~/.m2/repository/'

- name: Publish to the Staging Repository
run: ./gradlew publishReleasePublicationToSnapshotRepository --no-parallel
env:
ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }}
ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }}
ORG_GRADLE_PROJECT_NEXUS_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_NEXUS_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_NEXUS_PASSWORD }}
46 changes: 35 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

<p align="center">
<a href="https://github.com/requestly/requestly-android-sdk/releases"><img alt="GitHub release" src="https://img.shields.io/github/release/requestly/requestly-android-sdk.svg"></a>
<a href="https://search.maven.org/search?q=io.requestly%20-library"><img alt="Maven" src="https://img.shields.io/badge/-Maven-green?logo=apachemaven"></a>
<a href="https://search.maven.org/search?q=io.requestly%20-library"><img alt="Maven" src="https://img.shields.io/maven-metadata/v.svg?label=maven-central&color=green&logo=apachemaven&metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Frequestly%2Frequestly-android%2Fmaven-metadata.xml"></a>
<a href="https://bit.ly/requestly-slack"><img alt="Maven" src="https://img.shields.io/badge/[email protected]?logo=slack"></a>
</p>

<p align="center">
Expand All @@ -13,6 +14,7 @@

Requestly Android SDK lets you debug your android apps without needing you to setup any proxies or install any certificates everytime. It makes easy to identify & debug your Android Apps faster and save your time.

- [Try Now](#try-now)
- [Installation](#installation)
- [SDK Initialization](#sdk-initialization)
- [API Debugger Initialization](#api-debugger-initialization)
Expand All @@ -21,8 +23,26 @@ Requestly Android SDK lets you debug your android apps without needing you to se
- [Features](#features)
- [API Debugger](#api-debugger)
- [Analytics Event Debugger](#analytics-event-debugger)
- [Logs Debugger](#logs-debugger-coming-soon)
- [Logs Debugger](#logs-debugger)
- [Host Switcher](#host-switcher)
- [Acknowledgments](#acknowledgments)

## Try Now
### ↓ Click on Screenshots to try Apps ↓
<a href="https://appetize.io/embed/ctumozxsaz6cj4wox36vjc7jwy?device=pixel6pro&osVersion=12.0&scale=75&deviceColor=black" target="_blank">
<img width="250" alt="Try Now" src="https://user-images.githubusercontent.com/16779465/202981047-81ae477c-9ff8-49ed-9c03-0140bd9bb537.png">
</a>
<a href="https://appetize.io/embed/s3w5vwumwjtvj4kn2xsez5b4cy?device=pixel6pro&osVersion=12.0&scale=75&deviceColor=black" target="_blank">
<img width="250" alt="Try Now" src="https://user-images.githubusercontent.com/16779465/202981055-63253e28-0a7e-4ebc-889e-672f12a38dbc.png">
</a>
<a href="https://appetize.io/embed/hngjeexnhwrcm3acdclsqkye6e?device=pixel6pro&osVersion=12.0&scale=75&deviceColor=black" target="_blank">
<img width="250" alt="Try Now" src="https://user-images.githubusercontent.com/16779465/202981457-7c5f57fe-3216-4f9e-b55e-89c9f71c514a.png">
</a>

### OR
- [Dowload CryptoDemo Apk](https://github.com/requestly/android-debugger-examples/releases/latest/download/cryptodemo-debug.apk)
- [Download Infinity Reddit Apk](https://github.com/requestly/android-debugger-examples/releases/latest/download/infinity-reddit-debug.apk)
- [Download Pokedex Apk](https://github.com/requestly/android-debugger-examples/releases/latest/download/pokedex-debug.apk)

## Installation
The best way to install the Requestly Android SDK is with a build system like Gradle. This ensures you can easily upgrade to the latest versions.
Expand All @@ -31,10 +51,10 @@ RQInterceptor is distributed through [Maven Central](https://search.maven.org/se

```
dependencies {
debugImplementation "io.requestly:requestly-android:2.4.0"
releaseImplementation "io.requestly:requestly-android-noop:2.4.0"
debugImplementation "io.requestly:requestly-android-okhttp:2.4.0"
releaseImplementation "io.requestly:requestly-android-okhttp-noop:2.4.0"
debugImplementation "io.requestly:requestly-android:2.4.3"
releaseImplementation "io.requestly:requestly-android-noop:2.4.3"
debugImplementation "io.requestly:requestly-android-okhttp:2.4.3"
releaseImplementation "io.requestly:requestly-android-okhttp-noop:2.4.3"
}
```

Expand All @@ -47,12 +67,12 @@ class App : Application(){
super.onCreate()

// Initialize Requestly SDK like this
Requestly.Builder(this, "<your-sdk-key>")
Requestly.Builder(this, [optional "<your-sdk-key>"])
.build()
}
}
```

> `sdk-key` is optional. You can use local devtool features without sdk-key. <br/>
To get the sdk key, you need to create an app. Follow the steps [here](https://docs.requestly.io/android/tutorial/create-app) to create an app.

## API Debugger Initialization
Expand Down Expand Up @@ -97,11 +117,15 @@ RequestlyEvent.send(<eventName: String>, <eventData:Map<String, Any>>)

<img width="400" alt="Events Debugger" src="./assets/events-debugger.png">

### Logs Debugger (Coming Soon)
### Logs Debugger
Debug your Logs directly from your App. No need to connect your device to your computer to know what's happening inside your app.

<img width="400" alt="Logs Debugger" src="./assets/logs-debugger.png">

### Host Switcher
Switch between production and staging APIs easily in your Android debug builds. Eg. api.requestly.io → staging.requestly.io

<img width="400" alt="Logs Debugger" src="./assets/host-switcher.jpeg">

## Acknowledgments
Special Thanks to chuckerteam for maintaining such an awesome project because of which rq-interceptor was possible
https://github.com/chuckerteam/chucker
Special Thanks to [chuckerteam](https://github.com/chuckerteam/chucker) for maintaining such an awesome project [Chucker](https://github.com/chuckerteam/chucker) because of which requestly-android-sdk was possible.
Binary file added assets/host-switcher.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ org.gradle.parallel=true

android.useAndroidX=true

VERSION_NAME=2.4.1
VERSION_NAME=2.4.5-SNAPSHOT
# 1*100*100 + 0*100 + 0 => 10000
VERSION_CODE=20401
VERSION_CODE=20405
GROUP=io.requestly

POM_REPO_NAME=Requestly Android SDK
Expand Down
6 changes: 6 additions & 0 deletions requestly-android-core-noop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ android {
'-module-name', "io.requestly.android.core",
"-Xexplicit-api=strict"
]
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

buildFeatures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,56 @@ import android.content.Context
import android.content.SharedPreferences
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.io.File
import java.lang.ref.WeakReference

data class SharedPrefFileData(
val key: String,
val value: Any?,
val dataType: SharedPrefType?,
val fileName: String,
)

enum class SharedPrefType {
STRING {
override fun toString() = "String"
},
INTEGER {
override fun toString() = "Integer"
},
DOUBLE {
override fun toString() = "Double"
},
LONG {
override fun toString() = "Long"
},
BOOLEAN {
override fun toString() = "Boolean"
},
STRING_SET {
override fun toString() = "StringSet"
};

abstract override fun toString(): String
}

object KeyValueStorageManager {

private const val FILE_NAME = "io.requestly.requestly_pref_file"
private const val REQUESTLY_SHARED_PREF_FILE_PREFIX = "io.requestly."
private const val FILE_NAME = "${REQUESTLY_SHARED_PREF_FILE_PREFIX}requestly_pref_file"

/**
* Full path to the default directory assigned to the package for its
* persistent data.
*/
private lateinit var mContext: WeakReference<Context>
private lateinit var mSharedPref: SharedPreferences
private lateinit var gson: Gson
private var changeListeners: MutableList<SharedPreferences.OnSharedPreferenceChangeListener> = mutableListOf()
private var changeListeners: MutableList<SharedPreferences.OnSharedPreferenceChangeListener> =
mutableListOf()

fun initialize(context: Context) {
mContext = WeakReference(context)
mSharedPref = context.getSharedPreferences(FILE_NAME, 0)
gson = Gson()
}
Expand Down Expand Up @@ -50,6 +90,63 @@ object KeyValueStorageManager {
return gson.fromJson(json, typeToken.type)
}

fun deleteKeyFromFile(keyName: String, fileName: String) {
val pref = mContext.get()?.getSharedPreferences(fileName, 0) ?: return

with(pref.edit()) {
this.remove(keyName)
this.commit()
}
}

fun putStringInfile(value: String, keyName: String, fileName: String) {
val pref = mContext.get()?.getSharedPreferences(fileName, 0) ?: return
with(pref.edit()) {
this.putString(keyName, value)
this.commit()
}
}

fun putStringSetInfile(value: Set<String>, keyName: String, fileName: String) {
val pref = mContext.get()?.getSharedPreferences(fileName, 0) ?: return
with(pref.edit()) {
this.putStringSet(keyName, value)
this.commit()
}
}

fun putIntegerInfile(value: Int, keyName: String, fileName: String) {
val pref = mContext.get()?.getSharedPreferences(fileName, 0) ?: return
with(pref.edit()) {
this.putInt(keyName, value)
this.commit()
}
}

fun putDoubleInfile(value: Double, keyName: String, fileName: String) {
val pref = mContext.get()?.getSharedPreferences(fileName, 0) ?: return
with(pref.edit()) {
this.putFloat(keyName, value.toFloat())
this.commit()
}
}

fun putLongInfile(value: Long, keyName: String, fileName: String) {
val pref = mContext.get()?.getSharedPreferences(fileName, 0) ?: return
with(pref.edit()) {
this.putLong(keyName, value)
this.commit()
}
}

fun putBooleanInfile(value: Boolean, keyName: String, fileName: String) {
val pref = mContext.get()?.getSharedPreferences(fileName, 0) ?: return
with(pref.edit()) {
this.putBoolean(keyName, value)
this.commit()
}
}

fun registerChangeListener(forKey: String, changeListener: () -> Unit) {
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
if (key === forKey) {
Expand All @@ -59,4 +156,44 @@ object KeyValueStorageManager {
changeListeners.add(listener)
mSharedPref.registerOnSharedPreferenceChangeListener(listener)
}

@Suppress("CANDIDATE_CHOSEN_USING_OVERLOAD_RESOLUTION_BY_LAMBDA_ANNOTATION")
fun fetchDataFromAllSharedPrefFiles(): List<SharedPrefFileData> {
val context = mContext.get() ?: return emptyList()

val prefsDir = File(context.applicationInfo.dataDir, "shared_prefs")

if (!prefsDir.exists() || !prefsDir.isDirectory) return emptyList()

return prefsDir
.list()
?.filter { !it.startsWith(REQUESTLY_SHARED_PREF_FILE_PREFIX) }
?.flatMap { filename ->
val fileNameWithOutExtension = filename.removeSuffix(".xml")
val thisPref = context.getSharedPreferences(fileNameWithOutExtension, 0)
return@flatMap thisPref.all.map { entry ->
SharedPrefFileData(
key = entry.key,
value = entry.value,
dataType = detectType(entry.value),
fileName = fileNameWithOutExtension,
)
}
} ?: emptyList()
}

private fun detectType(value: Any?): SharedPrefType? {
if (value == null) return null

return when (value::class.simpleName) {
"Int" -> SharedPrefType.INTEGER
"Float" -> SharedPrefType.DOUBLE
"Long" -> SharedPrefType.LONG
"HashSet" -> SharedPrefType.STRING_SET
"Boolean" -> SharedPrefType.BOOLEAN
"String" -> SharedPrefType.STRING
else -> null
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ class Requestly {
// End Configuration

fun build() {
applicationScope.launch {
Log.d(Constants.LOG_TAG, "Start: Building Core")
Log.d(Constants.LOG_TAG, "Start: Building Core")

// Create Requestly Instance
INSTANCE = Requestly()
getInstance().applicationContext = applicationContext
getInstance().listNotificationHelper = ListNotificationHelper(applicationContext)
// Create Requestly Instance
INSTANCE = Requestly()
getInstance().applicationContext = applicationContext
getInstance().listNotificationHelper = ListNotificationHelper(applicationContext)

// Init KeyValueStorageManager
KeyValueStorageManager.initialize(applicationContext)
// Init KeyValueStorageManager
KeyValueStorageManager.initialize(applicationContext)

applicationScope.launch {
// Init SettingsManager Singleton
// Overrides the token set previously
appToken?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class HostSwitcherFragment : Fragment() {
val adaptor = HostSwitchItemAdaptor(items)
viewModel.rulesListLive.observe(viewLifecycleOwner) {
adaptor.items = it.map(mapper)
// Its fine to use notifyDataSetChanged here.
// Data size is small enough to not cause Frame skips or lags.
adaptor.notifyDataSetChanged()
}
mainBinding.hostSwitcherRulesRecyclerView.adapter = adaptor
Expand Down
Loading