Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
- Android 8.0 (API level 26) or higher
- Java 1.8 or higher
- Android Gradle plugin 8.0 or higher
The API key is required to use the Asleep SDK.
For how to issue an API key, see this link Generate API key
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
...
📘 The REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission is not required.
However, it can be helpful if you have the appropriate permissions to prevent you from falling into Doze mode.
https://developer.android.com/training/monitoring-device-state/doze-standby
📘 The FOREGROUND_SERVICE permission may be required when developing the app .
If you want the app you want to develop to work even when the user is sleeping, you must use this feature.
https://developer.android.com/guide/components/foreground-services
plugins {
...
}
android {
...
}
dependencies {
...
implementation 'org.jetbrains.bio:npy:0.3.5'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
}
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO), 0)
Get AsleepConfig by initAsleepConfig.
Enter apiKey, userId(null if nothing was previously received), baseUrl(address of proxy server, null if not), callbackUrl(address where the session receives the analyzed results), and service(nickname for the app you want to develop).
If you do not have a userId, create a new one and return it from onSuccess(), and if you enter an existing userId, it will be validated and returned by onSuccess().
If the existing userId is in tracking, exit it from inside the SDK.
import ai.asleep.asleepsdk.Asleep
import ai.asleep.asleepsdk.data.AsleepConfig
import ai.asleep.asleepsdk.AsleepErrorCode
...
Asleep.initAsleepConfig(
context = applicationContext,
apiKey = "[input your apiKey]",
userId = "",
baseUrl = null,
callbackUrl = "",
service = "[input your AppName]",
object : Asleep.AsleepConfigListener {
override fun onSuccess(userId: String?, asleepConfig: AsleepConfig?) {
...
/* save userId and asleepConfig */
}
override fun onFail(errorCode: Int, detail: String) {
...
}
})
From initAsleepConfig, Enter AsleepConfig as a parameter.
import ai.asleep.asleepsdk.tracking.SleepTrackingManager
...
var sleepTrackingManager = Asleep.createSleepTrackingManager(asleepConfig, object : SleepTrackingManager.TrackingListener {
override fun onCreate() {
}
override fun onUpload(sequence: Int) {
}
override fun onClose(sessionId: String) {
...
/* save sessionId */
}
override fun onFail(errorCode: Int, detail: String) {
}
})
When you start, the sequence number is called back once every 30 seconds from the onUpload function of the listener that was registered when the SleepTrackingManager was created.
sleepTrackingManager?.startSleepTracking()
sleepTrackingManager?.requestAnalysis(object : SleepTrackingManager.AnalysisListener {
override fun onSuccess(session: Session) {
Log.d("", "${session.toString()}")
}
}
for session information, reference API>Data API>Get a session
When you stop, the sessionId is called back from the onClose function of the listener registered at the time of the SleepTrackingManager creation.
sleepTrackingManager?.stopSleepTracking()
From initAsleepConfig, enter AsleepConfig as a parameter.
val reports = Asleep.createReports(asleepConfig)
enter sessionID when sleepTracking is stopped as a parameter
reports?.getReport(sessionId, object : Reports.ReportListener {
override fun onSuccess(report: Report?) {
}
override fun onFail(errorCode: Int, detail: String) {
}
})
val today = LocalDate.now()
reports?.getReports(today.minusDays(7).toString(), today.toString(), "DESC", 0, 20, object : Reports.ReportsListener {
override fun onSuccess(reports: List<SleepSession>?) {
}
override fun onFail(errorCode: Int, detail: String) {
}
})
Enter SessionID to delete the corresponding recording history.
reports?.deleteReport(sessionId, object : Reports.DeleteReportListener {
override fun onSuccess(sessionId: String?) {
}
override fun onFail(errorCode: Int, detail: String) {
}
})
Deletes the userId and all measured records. The deleted userId is no longer available.
Asleep.deleteUser(object : Asleep.DeleteUserIdListener {
override fun onSuccess(userId: String?) {
}
override fun onFail(errorCode: Int, detail: String) {
}
})
In the Android OS, the Google Play Services package sometimes updates, which can lead to the system forcibly terminating and restarting an app's foreground service. To address this, functionality is provided to continue the operation of the sleepTrackingManager.
Firstly, when the foreground service is restarted by the system, the LifecycleService()'s onStartCommand function is called.
At this time, if there is an unfinished session as determined by the Asleep.hasUnfinishedSession function, the AsleepConfig stored inside the AsleepSDK can be retrieved. A new sleepTrackingManager is then created, and startSleepTracking is called to continue tracking.
private var asleepConfig: AsleepConfig? = null
private var sleepTrackingManager: SleepTrackingManager? = null
...
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
if(Asleep.hasUnfinishedSession(applicationContext)) {
asleepConfig = Asleep.getSavedAsleepConfig(applicationContext, BuildConfig.ASLEEP_API_KEY)
sleepTrackingManager = Asleep.createSleepTrackingManager(asleepConfig, object : SleepTrackingManager.TrackingListener {
override fun onCreate() {
...
}
override fun onUpload(sequence: Int) {
...
}
override fun onClose(sessionId: String) {
...
}
override fun onFail(errorCode: Int, detail: String) {
...
}
}
...
sleepTrackingManager?.startSleepTracking()
}
...
}
FAQs
Asleep SDK for Android
We found that ai.asleep:asleepsdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.