Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.4 dev #13

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/upload_released.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
sudo apt-get install tree
tree app/build/outputs
- name: Upload apk file
run: gh release upload ${{steps.version.outputs.VERSION}} app/build/outputs/apk/release/app-release-unsigned.apk
run: gh release upload ${{steps.version.outputs.VERSION}} app/build/outputs/apk/release/app-release.apk
env:
GH_TOKEN: ${{ github.token }}
14 changes: 11 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ plugins {
}

android {
signingConfigs {
release {
storePassword System.getenv("jkspwd")
storeFile file('..\\keystore.jks')
keyAlias "onceshot"
keyPassword System.getenv("jkspwd")
}
}
namespace 'org.aquarngd.onceshot'
compileSdk 34

defaultConfig {
applicationId "org.aquarngd.onceshot"
minSdk 24
targetSdk 34
versionCode 1030000
versionName "1.3.0.0"
versionCode 1040000
versionName "1.4.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -24,6 +31,7 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
compileOptions {
Expand Down
Binary file added app/release/app-release.apk
Binary file not shown.
20 changes: 20 additions & 0 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "org.aquarngd.onceshot",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1040000,
"versionName": "1.4.0.0",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}
16 changes: 16 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
Expand Down Expand Up @@ -34,6 +35,13 @@
android:supportsRtl="true"
android:theme="@style/Theme.Material3.DayNight.NoActionBar"
tools:targetApi="31">
<receiver android:name=".BootBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
<activity
android:name=".FloatingDialog"
android:exported="true"
Expand All @@ -48,6 +56,14 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".ActivityAccessibilityService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
</service>
<service
android:name=".FloatingDialogService"
android:label="FloatingDialogService"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.aquarngd.onceshot

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent

class ActivityAccessibilityService: AccessibilityService() {
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
TODO("Not yet implemented")
}

override fun onInterrupt() {
TODO("Not yet implemented")
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/org/aquarngd/onceshot/BootBroadcastReceiver.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.aquarngd.onceshot

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log

class BootBroadcastReceiver:BroadcastReceiver() {
companion object{
const val classTag="BootBroadcastReceiver"
}
override fun onReceive(context: Context?, intent: Intent?) {
if(intent?.action.equals("android.intent.action.BOOT_COMPLETED")){
Intent(context, ForegroundService::class.java).apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.d(classTag, "Call startForegroundService")
context?.startForegroundService(this)
} else {
context?.startService(this)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class FloatingDialogService : Service() {

private fun onClickShareDeleteButton(contentView: View) {
shareImage()

fadeOut(contentView)
Handler(Looper.getMainLooper()).postDelayed({
deleteImage()
Expand Down Expand Up @@ -218,7 +217,7 @@ class FloatingDialogService : Service() {
MotionEvent.ACTION_UP -> {
if (lastTouchAction == MotionEvent.ACTION_DOWN) {
Log.d(classTag, "performClick because of ACTION_DOWN")
view.performClick()
//view.performClick()

return@OnTouchListener false
} else {
Expand All @@ -227,7 +226,7 @@ class FloatingDialogService : Service() {
classTag,
"performClick because of distance < 400, ${(clickX * clickX - event.rawX * event.rawX) + (clickY * clickY - event.rawY * event.rawY)}"
)
view.performClick()
//view.performClick()
return@OnTouchListener false
}
if ((event.rawX - 20) < -20) {
Expand Down Expand Up @@ -305,6 +304,7 @@ class FloatingDialogService : Service() {
private fun collectUsageData(key: UsageDataKey){
dataCollector?.collect(key)
analysisService.tryUpload(applicationContext)
val d=dataCollector?.getSharedPreference()?.getInt(key.key,-1)
Log.d(classTag,"collect ${key.key} ${dataCollector==null} ${dataCollector?.getSharedPreference()?.getInt(key.key,-1)}")
}
private fun closeFloatingDialogBuiltin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class ForegroundService : Service() {

private fun sendNotification(id: Long) {
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(notificationId, channelId, NotificationManager.IMPORTANCE_HIGH)
Expand Down
58 changes: 44 additions & 14 deletions app/src/main/java/org/aquarngd/onceshot/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ import androidx.compose.ui.unit.sp
import com.tencent.bugly.crashreport.CrashReport
import org.aquarngd.onceshot.ui.theme.OnceShotTheme
import org.aquarngd.stackbricks.StackbricksCompose
import org.aquarngd.stackbricks.msgpvder.GithubApiMsgPvder
import org.aquarngd.stackbricks.msgpvder.WeiboCommentsMsgPvder
import java.util.UUID

class MainActivity : ComponentActivity() {
var status = ForegroundServiceStatus.STATUS_INIT
val permissionList = mutableStateMapOf(
private val permissionList = mutableStateMapOf(
Manifest.permission.SYSTEM_ALERT_WINDOW to false,
"android.permission.READ_MEDIA_IMAGES" to false,
"android.permission.MANAGE_EXTERNAL_STORAGE" to false,
"android.permission.MANAGE_MEDIA" to false,
"android.permission.POST_NOTIFICATIONS" to false,
Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS to false
)
private var permissionCheckCounter = false
Expand All @@ -91,6 +93,7 @@ class MainActivity : ComponentActivity() {
const val REQUEST_PERMISSION_IMAGE = 1002
const val SPKEY_DURATION = "duration"
const val SPKEY_DEVICEID = "device_id"
const val SPKEY_BOOT_PERMISSION="boot_permission"
const val SPNAME = "onceshot"
const val classTag = "MainActivity"
}
Expand Down Expand Up @@ -263,25 +266,42 @@ class MainActivity : ComponentActivity() {
color = colorResource(id = R.color.red_zhuhong)
)
}


checkPermissionPassed = true
}
}
if (!(getSystemService(POWER_SERVICE) as PowerManager).isIgnoringBatteryOptimizations(
packageName
)
) {
permissionList[Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS] = true
if(permissionList[Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS] == true){
CreateCardButton(
onClick = {
startActivity(Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
data = Uri.parse("package:$packageName")
})
},
icon = painterResource(id = R.drawable.icon_battery),
title = stringResource(R.string.mainwindow_requirepermission_battery_title),
text = stringResource(R.string.mainwindow_requirepermission_battery_text),
color = colorResource(id = R.color.red_zhuhong)
)
}
}
if(!getSharedPreferences(SPNAME,Context.MODE_PRIVATE).getBoolean(SPKEY_BOOT_PERMISSION,false)){
CreateCardButton(
onClick = {
startActivity(Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
data = Uri.parse("package:$packageName")
startActivity(Intent(Intent.ACTION_VIEW).apply {
setClassName("com.android.settings","com.android.settings.InstalledAppDetails")
putExtra("com.android.settings.ApplicationPkgName", packageName)
})
getSharedPreferences(SPNAME,Context.MODE_PRIVATE).edit().putBoolean(
SPKEY_BOOT_PERMISSION,true).apply()
},
icon = painterResource(id = R.drawable.icon_battery),
title = stringResource(R.string.mainwindow_requirepermission_battery_title),
text = stringResource(R.string.mainwindow_requirepermission_battery_text),
color = colorResource(id = R.color.red_zhuhong)
icon = painterResource(id = R.drawable.icon_boot),
title = "推荐为应用添加自启动权限",
text = "自启动权限可以保证 OnceShot 的持续后台运行",
color = colorResource(id = R.color.yellow_youcaihuahuang)
)
}
return checkPermissionPassed
Expand Down Expand Up @@ -361,7 +381,7 @@ class MainActivity : ComponentActivity() {
checkPermissionPassed = drawPermissionCheckContent()
StackbricksCompose(
rememberCoroutineScope(),
LocalContext.current, WeiboCommentsMsgPvder.MsgPvderID, "5001248562483153"
LocalContext.current, GithubApiMsgPvder.MsgPvderID, "aquamarine5/OnceShot"
).DrawCompose()
drawDurationSettingCard()
drawUsageDataShower()
Expand Down Expand Up @@ -473,7 +493,18 @@ class MainActivity : ComponentActivity() {
Text(it.value.toString(), fontWeight = FontWeight.Bold, fontSize = 14.sp)
}
}
Text("OnceShot 收集您的使用数据并每日传输至服务器,请放心,这不会泄露您的个人隐私", modifier = Modifier.padding(0.dp,5.dp), fontSize = 12.sp, lineHeight = 15.sp)
Button(onClick = {
for ((index,element) in AnalysisService.UPLOAD_USAGE_VALUES.withIndex()){
usageDataList[index] = AnalysisDataClass(
element,
AnalysisService.USAGE_VALUES_STRING[element] ?: "",
sp.getInt(element.key, 0)
)
}
}){
Text("刷新")
}
//Text("OnceShot 收集您的使用数据并每日传输至服务器,请放心,这不会泄露您的个人隐私", modifier = Modifier.padding(0.dp,5.dp), fontSize = 12.sp, lineHeight = 15.sp)

}
}
Expand Down Expand Up @@ -520,15 +551,15 @@ class MainActivity : ComponentActivity() {
colors = CardDefaults.cardColors(colorResource(id = R.color.blue_jiqing))
) {
Text(
"v1.2 Reanimated",
"v1.4 Improvement",
style = TextStyle(color = Color.Yellow),
modifier = Modifier.padding(5.dp, 2.dp),
fontWeight = FontWeight.Bold
)
}
//Text(" Build version: 3")
}
Text("Build version: 第 269 次测试")
Text("Build version: 第 417 次测试")
}
}
}
Expand Down Expand Up @@ -637,7 +668,6 @@ class MainActivity : ComponentActivity() {
}
}
}

@Composable
fun CreateCardButton(
icon: Painter,
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/icon_boot.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="35dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="35dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18,1.01L8,1c-1.1,0 -2,0.9 -2,2v3h2V5h10v14H8v-1H6v3c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3c0,-1.1 -0.9,-1.99 -2,-1.99zM10,15h2V8H5v2h3.59L3,15.59 4.41,17 10,11.41z"/>
</vector>
Binary file added keystore.jks
Binary file not shown.
Loading