-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liushaojing
committed
Jan 31, 2024
0 parents
commit af418d6
Showing
49 changed files
with
1,464 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import org.gradle.internal.impldep.com.jcraft.jsch.ConfigRepository.defaultConfig | ||
import org.jetbrains.kotlin.com.intellij.diagnostic.StartUpMeasurer | ||
|
||
plugins { | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
android { | ||
namespace = "com.iumlab.fxxk1installer" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "com.iumlab.fxxk1installer" | ||
minSdk = 26 | ||
targetSdk = 34 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary = true | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
buildFeatures { | ||
compose = true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = "1.5.1" | ||
} | ||
packaging { | ||
resources { | ||
excludes += "/META-INF/{AL2.0,LGPL2.1}" | ||
} | ||
} | ||
|
||
|
||
} | ||
android.applicationVariants.all { | ||
// 编译类型 | ||
val buildType = this.buildType.name | ||
outputs.all { | ||
// 判断是否是输出 apk 类型 | ||
if (this is com.android.build.gradle.internal.api.ApkVariantOutputImpl) { | ||
this.outputFileName = "${applicationId}_${versionName}_$buildType.apk" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation("androidx.core:core-ktx:1.12.0") | ||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") | ||
implementation("androidx.activity:activity-compose:1.7.0") | ||
implementation(platform("androidx.compose:compose-bom:2023.08.00")) | ||
implementation("androidx.compose.ui:ui") | ||
implementation("androidx.compose.ui:ui-graphics") | ||
implementation("androidx.compose.ui:ui-tooling-preview") | ||
implementation("androidx.compose.material3:material3") | ||
testImplementation("junit:junit:4.13.2") | ||
androidTestImplementation("androidx.test.ext:junit:1.1.5") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") | ||
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00")) | ||
androidTestImplementation("androidx.compose.ui:ui-test-junit4") | ||
debugImplementation("androidx.compose.ui:ui-tooling") | ||
debugImplementation("androidx.compose.ui:ui-test-manifest") | ||
|
||
implementation("com.google.accompanist:accompanist-systemuicontroller:0.27.0") | ||
implementation("com.alibaba:fastjson:1.2.76") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": 3, | ||
"artifactType": { | ||
"type": "APK", | ||
"kind": "Directory" | ||
}, | ||
"applicationId": "com.iumlab.fxxk1installer", | ||
"variantName": "release", | ||
"elements": [ | ||
{ | ||
"type": "SINGLE", | ||
"filters": [], | ||
"attributes": [], | ||
"versionCode": 1, | ||
"versionName": "1.0", | ||
"outputFile": "com.iumlab.fxxk1installer_1.0_release.apk" | ||
} | ||
], | ||
"elementType": "File" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Fxxk1Installer" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.Fxxk1Installer"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".InstallActivity" | ||
android:exported="true" | ||
android:launchMode="singleTop"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.VIEW" /> | ||
|
||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.BROWSABLE" /> | ||
|
||
<data android:mimeType="application/vnd.android.package-archive" /> | ||
<data android:mimeType="application/*" /> | ||
<!-- <data android:mimeType="application/jpg" />--> | ||
</intent-filter> | ||
</activity> | ||
<provider | ||
android:name="androidx.core.content.FileProvider" | ||
android:authorities="${applicationId}.provider" | ||
android:exported="false" | ||
android:grantUriPermissions="true"> | ||
<meta-data | ||
android:name="android.support.FILE_PROVIDER_PATHS" | ||
android:resource="@xml/file_path" /> | ||
</provider> | ||
</application> | ||
|
||
</manifest> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
172 changes: 172 additions & 0 deletions
172
app/src/main/java/com/iumlab/fxxk1installer/InstallActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package com.iumlab.fxxk1installer | ||
|
||
import android.Manifest | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.View | ||
import android.view.WindowManager | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.core.app.ActivityCompat | ||
import androidx.core.content.FileProvider | ||
import com.alibaba.fastjson.JSON | ||
import com.iumlab.fxxk1installer.ui.components.setSystemBar | ||
import com.iumlab.fxxk1installer.ui.theme.AppTheme | ||
import java.io.BufferedInputStream | ||
import java.io.BufferedOutputStream | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.io.OutputStream | ||
|
||
|
||
class InstallActivity : ComponentActivity() { | ||
private val TAG = this.javaClass.name.toString() | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
val window = window | ||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) | ||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) | ||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | ||
window.statusBarColor = Color.Transparent.hashCode() | ||
window.navigationBarColor = Color.Transparent.hashCode() | ||
|
||
super.onCreate(savedInstanceState) | ||
setContent { | ||
AppTheme { | ||
setSystemBar() | ||
// A surface container using the 'background' color from the theme | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
Home() | ||
} | ||
} | ||
} | ||
if (intent != null) { | ||
handleShared(intent) | ||
Log.e(TAG, JSON.toJSONString(intent)) | ||
} | ||
} | ||
|
||
override fun onNewIntent(intent: Intent?) { | ||
super.onNewIntent(intent) | ||
Log.e(TAG, "onNewIntent: " ) | ||
handleShared(intent) | ||
} | ||
|
||
private fun handleShared(i: Intent?) { | ||
Log.e(TAG, "handleShared: ${i == null}" ) | ||
val intent: Intent? = i ?: intent | ||
val action: String? = intent?.action | ||
val type: String? = intent?.type | ||
val uri: Uri? = intent?.data | ||
|
||
val filePath = uri?.encodedPath | ||
if (filePath== null) { | ||
return | ||
} | ||
if (filePath!!.endsWith("apk.1")){ | ||
copyFile(uri) | ||
} else { | ||
install(i) | ||
} | ||
|
||
} | ||
|
||
open fun copyFile(uri : Uri) { | ||
try { | ||
val inputStream: InputStream = | ||
contentResolver.openInputStream(uri) ?: return | ||
val path = this.getExternalFilesDir("cache")!!.absolutePath+ "/temp.apk" | ||
val outputStream: OutputStream = FileOutputStream(path) | ||
copyStream(inputStream, outputStream, path) | ||
inputStream.close() | ||
outputStream.close() | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
private fun copyStream(input: InputStream, output: OutputStream, path: String) { //文件存储 | ||
val BUFFER_SIZE = 1024 * 2 | ||
val buffer = ByteArray(BUFFER_SIZE) | ||
val in0 = BufferedInputStream(input, BUFFER_SIZE) | ||
val out = BufferedOutputStream(output, BUFFER_SIZE) | ||
var count = 0 | ||
var n = 0 | ||
try { | ||
while (in0.read(buffer, 0, BUFFER_SIZE).also { n = it } != -1) { | ||
out.write(buffer, 0, n) | ||
count += n | ||
} | ||
out.flush() | ||
out.close() | ||
in0.close() | ||
val id = application.packageName | ||
val intent = Intent(Intent.ACTION_VIEW) | ||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
val uri = FileProvider.getUriForFile( | ||
this, | ||
"$id.provider", | ||
File(path) | ||
) | ||
intent.setDataAndType(uri, "application/vnd.android.package-archive") | ||
install(intent) | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
private fun install(apk : File) { | ||
// val intent = Intent(Intent.ACTION_VIEW) | ||
// intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
// intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | ||
// val contentUri = FileProvider.getUriForFile(this, mAuthority, apk) | ||
// intent.setDataAndType(contentUri, INTENT_TYPE) | ||
// mActivity.startActivity(intent) | ||
} | ||
|
||
protected open fun install(intent: Intent?) { | ||
if (intent == null) { | ||
return | ||
} | ||
val dataUri = intent.data | ||
// val intent = packageManager.getLaunchIntentForPackage("com.android.packageinstaller")!! | ||
val intent = Intent(Intent.ACTION_VIEW) | ||
|
||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
intent.addFlags( | ||
Intent.FLAG_GRANT_READ_URI_PERMISSION /* | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION*/ | ||
) | ||
intent.setDataAndType(dataUri, "application/vnd.android.package-archive") | ||
startActivity(intent) | ||
} | ||
|
||
private fun install2 (intent: Intent?) { | ||
|
||
startActivity(intent) | ||
} | ||
|
||
|
||
private fun checkPermissions() { | ||
val b = packageManager.canRequestPackageInstalls() | ||
if (b) { | ||
handleShared(intent) | ||
} else { | ||
ActivityCompat.requestPermissions( | ||
this, | ||
arrayOf(Manifest.permission.REQUEST_INSTALL_PACKAGES), | ||
100 | ||
) | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.