Skip to content

Commit

Permalink
disable pushing of specific apps
Browse files Browse the repository at this point in the history
  • Loading branch information
ojhdt committed Nov 10, 2022
1 parent 3a0a48d commit 976b067
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 62 deletions.
9 changes: 8 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ dependencies {
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
implementation "com.google.android.material:material:1.8.0-alpha02"

// Chrome Custom Tab
implementation "androidx.browser:browser:1.4.0"

// Room
def room_version = "2.4.3"
implementation "androidx.room:room-runtime:$room_version"
Expand All @@ -74,7 +77,7 @@ dependencies {
implementation "androidx.room:room-ktx:$room_version"

// Development Kit
implementation 'com.ojhdt:parabox-development-kit:1.0.12-SNAPSHOT'
implementation 'com.ojhdt:parabox-development-kit:1.0.5'

// DataStore
implementation "androidx.datastore:datastore-preferences:1.0.0"
Expand All @@ -87,6 +90,10 @@ dependencies {
// Accompanist
implementation "com.google.accompanist:accompanist-systemuicontroller:0.27.0"

// Coroutine Lifecycle Scopes
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"

// ViewModel
def lifecycle_version = "2.6.0-alpha02"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
<queries>
<package android:name="com.ojhdtapp.parabox" />
<package android:name="com.google.android.projection.gearhead" />
<package android:name="com.google.android.apps.messaging"/>
<package android:name="com.google.android.gm"/>
<package android:name="com.google.android.youtube"/>
<package android:name="com.tencent.mobileqq"/>
<package android:name="com.tencent.mm"/>
</queries>

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>

<application
android:name=".core.HiltApplication"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ojhdtapp.parabox.extension.auto.core.util

import android.content.Context
import android.net.Uri
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent

import android.content.Intent


object BrowserUtil {
private val defaultColor = CustomTabColorSchemeParams.Builder()
// .setToolbarColor(colorInt)
.build()

fun launchURL(context: Context, url: String) {
val customTabsIntent = CustomTabsIntent.Builder()
.setDefaultColorSchemeParams(defaultColor)
.build()
customTabsIntent.launchUrl(context, Uri.parse(url))
}

fun composeEmail(context: Context, addresses: Array<String?>?, subject: String?) {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:") // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses)
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
context.startActivity(intent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ package com.ojhdtapp.parabox.extension.auto.core.util

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.AdaptiveIconDrawable
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.net.Uri
import android.os.Build
import androidx.core.content.FileProvider
import com.ojhdtapp.parabox.extension.auto.BuildConfig
import java.io.ByteArrayOutputStream
Expand All @@ -14,12 +20,53 @@ import java.text.SimpleDateFormat
import java.util.*
import kotlin.math.roundToInt


object FileUtil {
fun getUriFromBitmap(context: Context, bm: Bitmap): Uri? {

fun getAppIcon(context: Context, packageName: String): Bitmap? {
try {
val drawable = context.packageManager.getApplicationIcon(packageName)
if (drawable is BitmapDrawable) {
return drawable.bitmap
} else if (drawable is AdaptiveIconDrawable) {
val drr = arrayOfNulls<Drawable>(2)
drr[0] = drawable.background
drr[1] = drawable.foreground
val layerDrawable = LayerDrawable(drr)
val width = layerDrawable.intrinsicWidth
val height = layerDrawable.intrinsicHeight
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
layerDrawable.setBounds(0, 0, canvas.width, canvas.height)
layerDrawable.draw(canvas)
return bitmap
}
} catch (e: Exception) {
e.printStackTrace()
}
return null
}

fun getSmallIcon(context: Context, pkgName: String?, id: Int): Bitmap? {
var smallIcon: Bitmap? = null
val remotePkgContext: Context
try {
remotePkgContext = context.createPackageContext(pkgName, 0)
val drawable = remotePkgContext.resources.getDrawable(id)
if (drawable != null) {
smallIcon = (drawable as BitmapDrawable).bitmap
}
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
return smallIcon
}

fun getUriFromBitmap(context: Context, bm: Bitmap, name: String): Uri? {
val targetDir = File(context.externalCacheDir, "bm")
if (!targetDir.exists()) targetDir.mkdirs()
val tempFile =
File(targetDir, "temp_${System.currentTimeMillis().toDateAndTimeString()}.png")
File(targetDir, "temp_${name}.png")
val bytes = ByteArrayOutputStream()
bm.compress(Bitmap.CompressFormat.PNG, 100, bytes)
val bitmapData = bytes.toByteArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.ojhdtapp.parabox.extension.auto.data

import androidx.room.Database
import androidx.room.RoomDatabase
import com.ojhdtapp.parabox.extension.auto.domain.model.AppModel
import com.ojhdtapp.parabox.extension.auto.domain.model.WxContact

@Database(entities = [WxContact::class], version = 1, exportSchema = false)
@Database(entities = [WxContact::class, AppModel::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
abstract val wxContactDao: WxContactDao
abstract val appModelDao: AppModelDao
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.ojhdtapp.parabox.extension.auto.data

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.ojhdtapp.parabox.extension.auto.domain.model.AppModel
import com.ojhdtapp.parabox.extension.auto.domain.model.AppModelDisabledUpdate
import kotlinx.coroutines.flow.Flow

@Dao
interface AppModelDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(appModel: AppModel): Long

@Query("SELECT * FROM appmodel WHERE packageName = :packageName LIMIT 1")
suspend fun queryByPackageName(packageName: String): AppModel?

@Update(entity = AppModel::class)
fun updateDisabledState(appModelDisabledUpdate: AppModelDisabledUpdate)

@Query("SELECT * FROM appmodel")
fun getAll(): Flow<List<AppModel>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ojhdtapp.parabox.extension.auto.domain.model

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity
data class AppModel(
val packageName: String,
val appName: String,
@PrimaryKey(autoGenerate = true) val id: Long = 0,
val disabled: Boolean = false,
)

data class AppModelDisabledUpdate(
@ColumnInfo(name = "id") val id: Long,
@ColumnInfo(name = "disabled") val disabled: Boolean
)
Loading

0 comments on commit 976b067

Please sign in to comment.